本文整理汇总了C++中OGRFeature::GetFieldAsString方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFeature::GetFieldAsString方法的具体用法?C++ OGRFeature::GetFieldAsString怎么用?C++ OGRFeature::GetFieldAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRFeature
的用法示例。
在下文中一共展示了OGRFeature::GetFieldAsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
//.........这里部分代码省略.........
oLine.setPoint( 0, oArrow1.x, oArrow1.y );
oLine.setPoint( 1,
oArrow1.x + dfVec2X*3 + dfVec1X,
oArrow1.y + dfVec2Y*3 + dfVec1Y );
poMLS->addGeometry( &oLine );
oLine.setPoint( 0, oArrow1.x, oArrow1.y );
oLine.setPoint( 1,
oArrow1.x + dfVec2X*3 - dfVec1X,
oArrow1.y + dfVec2Y*3 - dfVec1Y );
poMLS->addGeometry( &oLine );
// add arrow2 arrow head.
oLine.setPoint( 0, dfArrowX2, dfArrowY2 );
oLine.setPoint( 1,
dfArrowX2 - dfVec2X*3 + dfVec1X,
dfArrowY2 - dfVec2Y*3 + dfVec1Y );
poMLS->addGeometry( &oLine );
oLine.setPoint( 0, dfArrowX2, dfArrowY2 );
oLine.setPoint( 1,
dfArrowX2 - dfVec2X*3 - dfVec1X,
dfArrowY2 - dfVec2Y*3 - dfVec1Y );
poMLS->addGeometry( &oLine );
poFeature->SetGeometryDirectly( poMLS );
PrepareLineStyle( poFeature );
/* -------------------------------------------------------------------- */
/* Is the layer disabled/hidden/frozen/off? */
/* -------------------------------------------------------------------- */
CPLString osLayer = poFeature->GetFieldAsString("Layer");
int bHidden =
EQUAL(poDS->LookupLayerProperty( osLayer, "Hidden" ), "1");
/* -------------------------------------------------------------------- */
/* Work out the color for this feature. */
/* -------------------------------------------------------------------- */
int nColor = 256;
if( oStyleProperties.count("Color") > 0 )
nColor = atoi(oStyleProperties["Color"]);
// Use layer color?
if( nColor < 1 || nColor > 255 )
{
const char *pszValue = poDS->LookupLayerProperty( osLayer, "Color" );
if( pszValue != NULL )
nColor = atoi(pszValue);
}
if( nColor < 1 || nColor > 255 )
nColor = 8;
/* -------------------------------------------------------------------- */
/* Prepare a new feature to serve as the dimension text label */
/* feature. We will push it onto the layer as a pending */
/* feature for the next feature read. */
/* -------------------------------------------------------------------- */
// a single space suppresses labeling.
if( osText == " " )
return poFeature;
示例2: getLaneNumber
int
NIImporter_ArcView::getLaneNo(OGRFeature& poFeature, const std::string& edgeid,
SUMOReal speed) {
if (myOptions.isSet("shapefile.type-id")) {
return (int) myTypeCont.getNumLanes(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
}
// try to get definitions as to be found in SUMO-XML-definitions
// idea by John Michael Calandrino
int index = poFeature.GetDefnRef()->GetFieldIndex("nolanes");
if (index >= 0 && poFeature.IsFieldSet(index)) {
return (int) poFeature.GetFieldAsInteger(index);
}
index = poFeature.GetDefnRef()->GetFieldIndex("NOLANES");
if (index >= 0 && poFeature.IsFieldSet(index)) {
return (int) poFeature.GetFieldAsInteger(index);
}
index = poFeature.GetDefnRef()->GetFieldIndex("rnol");
if (index >= 0 && poFeature.IsFieldSet(index)) {
return (int) poFeature.GetFieldAsInteger(index);
}
index = poFeature.GetDefnRef()->GetFieldIndex("LANE_CAT");
if (index >= 0 && poFeature.IsFieldSet(index)) {
std::string def = poFeature.GetFieldAsString(index);
return NINavTeqHelper::getLaneNumber(edgeid, def, speed);
}
return 0;
}
示例3:
//---------------------------------------------------------
CSG_Shapes * COGR_DataSource::Read_Shapes(int iLayer)
{
OGRLayer *pLayer = Get_Layer(iLayer);
//-----------------------------------------------------
if( pLayer && Get_Type(iLayer) != SHAPE_TYPE_Undefined )
{
int iField;
OGRFeature *pFeature;
OGRFeatureDefn *pDef = pLayer->GetLayerDefn();
CSG_Shapes *pShapes = SG_Create_Shapes(Get_Type(iLayer), CSG_String(pDef->GetName()));
for(iField=0; iField<pDef->GetFieldCount(); iField++)
{
OGRFieldDefn *pDefField = pDef->GetFieldDefn(iField);
pShapes->Add_Field(pDefField->GetNameRef(), COGR_Driver::Get_Type(pDefField->GetType()));
}
pLayer->ResetReading();
//-------------------------------------------------
while( (pFeature = pLayer->GetNextFeature()) != NULL && SG_UI_Process_Get_Okay(false) )
{
OGRGeometry *pGeometry = pFeature->GetGeometryRef();
if( pGeometry != NULL )
{
CSG_Shape *pShape = pShapes->Add_Shape();
for(iField=0; iField<pDef->GetFieldCount(); iField++)
{
OGRFieldDefn *pDefField = pDef->GetFieldDefn(iField);
switch( pDefField->GetType() )
{
default: pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField))); break;
case OFTString: pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField))); break;
case OFTInteger: pShape->Set_Value(iField, pFeature->GetFieldAsInteger(iField)); break;
case OFTReal: pShape->Set_Value(iField, pFeature->GetFieldAsDouble (iField)); break;
}
}
//-----------------------------------------
if( _Read_Geometry(pShape, pGeometry) == false )
{
pShapes->Del_Shape(pShape);
}
}
OGRFeature::DestroyFeature(pFeature);
}
return( pShapes );
}
//-----------------------------------------------------
return( NULL );
}
示例4: main
int main() {
// Read in raster data for night time lights
int band_number = 1; // only one band, starts with one
Raster* raster = import_raster("raster.tif", band_number);
// Read in shapefile data containing municipality administrative regions
int layer_number = 0; // only one layer, starts with zero
OGRLayer* shapelayer = import_shapefile("MEX_adm2.shp", layer_number);
shapelayer->SetAttributeFilter("ID_1 = 1834"); // Filter for Yucatan
const int idx_of_number_field = 5; // Column number of municipality number
const int idx_of_name_field = 6; // Column number of municipality name
OGRFeature* poFeature;
int feature_ctr = 0;
while( (poFeature = shapelayer->GetNextFeature()) != NULL ) {
cerr << "Feature: " << feature_ctr++ << "\t";
int feature_num = poFeature->GetFieldAsInteger(idx_of_number_field);
string feature_name = poFeature->GetFieldAsString(idx_of_name_field);
OGRFeatureDefn *poFDefn = shapelayer->GetLayerDefn();
for( int iField = 0; iField < poFDefn->GetFieldCount(); iField++ ) {
OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );
if( poFieldDefn->GetType() == OFTString ) cerr << poFeature->GetFieldAsString(iField) << ",";
}
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
if( poGeometry != NULL) {
// For contiguous regions
if ( wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon ) {
cerr << " polygon" << endl;
report_raster_data_within_polygon(raster, (OGRPolygon *) poGeometry, feature_num, feature_name);
// For disjoint regions
} else if ( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon ) {
cerr << " multipolygon" << endl;
OGRMultiPolygon *multipolygon = (OGRMultiPolygon *) poGeometry;
for (int i = 0; i<multipolygon->getNumGeometries(); i++) {
report_raster_data_within_polygon(raster, (OGRPolygon*) multipolygon->getGeometryRef(i), feature_num, feature_name);
}
// Is this really the right shapefile?
} else {
cerr << "No polygon or multipolygon geometry for this feature: " << poGeometry->getGeometryName() << endl;
}
} else {
cerr << "No geometry for this feature" << endl;
}
}
OGRFeature::DestroyFeature( poFeature );
}
示例5: OGRFeatureFetcher
static swq_expr_node* OGRFeatureFetcher(swq_expr_node *op, void *pFeatureIn)
{
OGRFeature *poFeature = (OGRFeature*) pFeatureIn;
swq_expr_node *poRetNode = NULL;
switch (op->field_type)
{
case SWQ_INTEGER:
case SWQ_BOOLEAN:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsInteger(op->field_index));
break;
case SWQ_FLOAT:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsDouble(op->field_index));
break;
default:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsString(op->field_index));
break;
}
poRetNode->is_null = !(poFeature->IsFieldSet(op->field_index));
return poRetNode;
}
示例6: CSVWriteVectorValues
void Raster::CSVWriteVectorValues(OGRLayer * poLayer, const char * psFieldName, const char * sRasterOutputPath){
// use the filename with CSV added onto the end.
QFileInfo sOutputFileInfo(sRasterOutputPath);
QDir sNewDir = QDir(sOutputFileInfo.absolutePath());
QString sCSVFullPath = sNewDir.filePath(sOutputFileInfo.completeBaseName() + ".csv");
QFile csvFile(sCSVFullPath);
if (csvFile.open(QFile::WriteOnly|QFile::Truncate))
{
QTextStream stream(&csvFile);
// Write CSV file header
stream << "\"index\", " << "\""<< psFieldName << "\""<< "\n"; // this writes first line with two columns
OGRFeature *poFeature;
poLayer->ResetReading();
poLayer->SetSpatialFilter(NULL);
while( (poFeature = poLayer->GetNextFeature()) != NULL){
const char * sFieldVal = poFeature->GetFieldAsString(psFieldName);
// write line to file
stream << poFeature->GetFID() << ", " << "\"" << sFieldVal << "\"" << "\n"; // this writes first line with two columns
OGRFeature::DestroyFeature( poFeature );
}
csvFile.close();
}
return;
}
示例7: LoadFeaturesLayer
CPLErr GNMGenericNetwork::LoadFeaturesLayer(GDALDataset * const pDS)
{
m_poFeaturesLayer = pDS->GetLayerByName(GNM_SYSLAYER_FEATURES);
if(NULL == m_poFeaturesLayer)
{
CPLError( CE_Failure, CPLE_AppDefined, "Loading of '%s' layer failed",
GNM_SYSLAYER_FEATURES );
return CE_Failure;
}
OGRFeature *poFeature;
m_poFeaturesLayer->ResetReading();
while ((poFeature = m_poFeaturesLayer->GetNextFeature()) != NULL)
{
GNMGFID nFID = poFeature->GetFieldAsGNMGFID(GNM_SYSFIELD_GFID);
const char *pFeatureClass = poFeature->GetFieldAsString(
GNM_SYSFIELD_LAYERNAME);
if(nFID >= m_nGID)
m_nGID = nFID + 1;
m_moFeatureFIDMap[nFID] = pFeatureClass;
// Load network layer. No error handling as we want to load whole network
LoadNetworkLayer(pFeatureClass);
OGRFeature::DestroyFeature(poFeature);
}
return CE_None;
}
示例8: GetGeomediaSRS
OGRSpatialReference* OGRGeomediaDataSource::GetGeomediaSRS(const char* pszGCoordSystemTable,
const char* pszGCoordSystemGUID)
{
if (pszGCoordSystemTable == NULL || pszGCoordSystemGUID == NULL)
return NULL;
OGRLayer* poGCoordSystemTable = GetLayerByName(pszGCoordSystemTable);
if (poGCoordSystemTable == NULL)
return NULL;
poGCoordSystemTable->ResetReading();
OGRFeature* poFeature;
while((poFeature = poGCoordSystemTable->GetNextFeature()) != NULL)
{
const char* pszCSGUID = poFeature->GetFieldAsString("CSGUID");
if (pszCSGUID && strcmp(pszCSGUID, pszGCoordSystemGUID) == 0)
{
OGRSpatialReference* poSRS = OGRGetGeomediaSRS(poFeature);
delete poFeature;
return poSRS;
}
delete poFeature;
}
return NULL;
}
示例9: HashAirwayIntersectionFeatureFunc
static unsigned long HashAirwayIntersectionFeatureFunc(const void* _feature)
{
OGRFeature* feature = (OGRFeature*)_feature;
OGRPoint* point = (OGRPoint*) feature->GetGeometryRef();
unsigned long hash = CPLHashSetHashStr((unsigned char*)feature->GetFieldAsString(0));
const double x = point->getX();
const double y = point->getY();
return hash ^ OGRXPlaneAirwayHashDouble(x) ^ OGRXPlaneAirwayHashDouble(y);
}
示例10: while
OGRFeature *OGRSEGUKOOALineLayer::GetNextRawFeature()
{
if( bEOF )
return nullptr;
/* Merge points of base layer that have same value for attribute(0) */
/* into a single linestring */
OGRFeature* poFeature = nullptr;
OGRLineString* poLS = nullptr;
if (poNextBaseFeature == nullptr)
poNextBaseFeature = poBaseLayer->GetNextFeature();
while(poNextBaseFeature != nullptr)
{
if (poNextBaseFeature->IsFieldSetAndNotNull(0) &&
poNextBaseFeature->GetFieldAsString(0)[0] != '\0')
{
if (poFeature != nullptr &&
strcmp(poFeature->GetFieldAsString(0),
poNextBaseFeature->GetFieldAsString(0)) != 0)
{
poFeature->SetGeometryDirectly(poLS);
return poFeature;
}
OGRGeometry* poGeom =
poNextBaseFeature->GetGeometryRef();
OGRPoint* poPoint = poGeom ? poGeom->toPoint(): nullptr;
if (poPoint != nullptr)
{
if (poFeature == nullptr)
{
poFeature = new OGRFeature(poFeatureDefn);
poFeature->SetFID(nNextFID ++);
poFeature->SetField(0,
poNextBaseFeature->GetFieldAsString(0));
poLS = new OGRLineString();
if (poBaseLayer->GetSpatialRef())
poLS->assignSpatialReference(
poBaseLayer->GetSpatialRef());
}
poLS->addPoint(poPoint);
}
}
delete poNextBaseFeature;
poNextBaseFeature = poBaseLayer->GetNextFeature();
}
bEOF = true;
if( poFeature )
poFeature->SetGeometryDirectly(poLS);
return poFeature;
}
示例11: OGR2SQLITE_ogr_geocode_set_result
static
void OGR2SQLITE_ogr_geocode_set_result(sqlite3_context* pContext,
OGRLayerH hLayer,
const char* pszField)
{
if( hLayer == NULL )
sqlite3_result_null (pContext);
else
{
OGRLayer* poLayer = (OGRLayer*)hLayer;
OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
OGRFeature* poFeature = poLayer->GetNextFeature();
int nIdx = -1;
if( poFeature == NULL )
sqlite3_result_null (pContext);
else if( strcmp(pszField, "geometry") == 0 &&
poFeature->GetGeometryRef() != NULL )
{
GByte* pabyGeomBLOB = NULL;
int nGeomBLOBLen = 0;
if( OGRSQLiteLayer::ExportSpatiaLiteGeometry(
poFeature->GetGeometryRef(), 4326, wkbNDR, FALSE, FALSE, FALSE,
&pabyGeomBLOB,
&nGeomBLOBLen ) != CE_None )
{
sqlite3_result_null (pContext);
}
else
{
sqlite3_result_blob (pContext, pabyGeomBLOB, nGeomBLOBLen, CPLFree);
}
}
else if( (nIdx = poFDefn->GetFieldIndex(pszField)) >= 0 &&
poFeature->IsFieldSet(nIdx) )
{
OGRFieldType eType = poFDefn->GetFieldDefn(nIdx)->GetType();
if( eType == OFTInteger )
sqlite3_result_int(pContext,
poFeature->GetFieldAsInteger(nIdx));
else if( eType == OFTInteger64 )
sqlite3_result_int64(pContext,
poFeature->GetFieldAsInteger64(nIdx));
else if( eType == OFTReal )
sqlite3_result_double(pContext,
poFeature->GetFieldAsDouble(nIdx));
else
sqlite3_result_text(pContext,
poFeature->GetFieldAsString(nIdx),
-1, SQLITE_TRANSIENT);
}
else
sqlite3_result_null (pContext);
delete poFeature;
OGRGeocodeFreeResult(hLayer);
}
}
示例12: WriteNewBlockRecords
bool OGRDXFWriterDS::WriteNewBlockRecords( VSILFILE * fpIn )
{
std::set<CPLString> aosAlreadyHandled;
/* ==================================================================== */
/* Loop over all block objects written via the blocks layer. */
/* ==================================================================== */
for( size_t iBlock=0; iBlock < poBlocksLayer->apoBlocks.size(); iBlock++ )
{
OGRFeature* poThisBlockFeat = poBlocksLayer->apoBlocks[iBlock];
/* -------------------------------------------------------------------- */
/* Is this block already defined in the template header? */
/* -------------------------------------------------------------------- */
CPLString osBlockName = poThisBlockFeat->GetFieldAsString("BlockName");
if( oHeaderDS.LookupBlock( osBlockName ) != NULL )
continue;
/* -------------------------------------------------------------------- */
/* Have we already written a BLOCK_RECORD for this block? */
/* -------------------------------------------------------------------- */
if( aosAlreadyHandled.find(osBlockName) != aosAlreadyHandled.end() )
continue;
aosAlreadyHandled.insert( osBlockName );
/* -------------------------------------------------------------------- */
/* Write the block record. */
/* -------------------------------------------------------------------- */
WriteValue( fpIn, 0, "BLOCK_RECORD" );
WriteEntityID( fpIn );
WriteValue( fpIn, 100, "AcDbSymbolTableRecord" );
WriteValue( fpIn, 100, "AcDbBlockTableRecord" );
WriteValue( fpIn, 2, poThisBlockFeat->GetFieldAsString("BlockName") );
if( !WriteValue( fpIn, 340, "0" ) )
return false;
}
return true;
}
示例13: while
OGRFeature *OGRSEGUKOOALineLayer::GetNextRawFeature()
{
if (bEOF)
return NULL;
/* Merge points of base layer that have same value for attribute(0) */
/* into a single linestring */
OGRFeature* poFeature = NULL;
OGRLineString* poLS = NULL;
if (poNextBaseFeature == NULL)
poNextBaseFeature = poBaseLayer->GetNextFeature();
while(poNextBaseFeature != NULL)
{
if (poNextBaseFeature->IsFieldSet(0) &&
poNextBaseFeature->GetFieldAsString(0)[0] != '\0')
{
if (poFeature != NULL &&
strcmp(poFeature->GetFieldAsString(0),
poNextBaseFeature->GetFieldAsString(0)) != 0)
{
return poFeature;
}
OGRPoint* poPoint =
(OGRPoint*) poNextBaseFeature->GetGeometryRef();
if (poPoint != NULL)
{
if (poFeature == NULL)
{
poFeature = new OGRFeature(poFeatureDefn);
poFeature->SetFID(nNextFID ++);
poFeature->SetField(0,
poNextBaseFeature->GetFieldAsString(0));
poLS = new OGRLineString();
if (poBaseLayer->GetSpatialRef())
poLS->assignSpatialReference(
poBaseLayer->GetSpatialRef());
poFeature->SetGeometryDirectly(poLS);
}
poLS->addPoint(poPoint);
}
}
delete poNextBaseFeature;
poNextBaseFeature = poBaseLayer->GetNextFeature();
}
bEOF = TRUE;
return poFeature;
}
示例14: ResetReading
OGRFeature *OGRILI1Layer::GetFeatureRef( const char *fid )
{
ResetReading();
OGRFeature *poFeature = nullptr;
while( (poFeature = GetNextFeatureRef()) != nullptr )
{
if( !strcmp( poFeature->GetFieldAsString(0), fid ) )
return poFeature;
}
return nullptr;
}
示例15: getSpeed
SUMOReal
NIImporter_ArcView::getSpeed(OGRFeature& poFeature, const std::string& edgeid) {
if (myOptions.isSet("shapefile.type-id")) {
return myTypeCont.getSpeed(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
}
// try to get definitions as to be found in SUMO-XML-definitions
// idea by John Michael Calandrino
int index = poFeature.GetDefnRef()->GetFieldIndex("speed");
if (index >= 0 && poFeature.IsFieldSet(index)) {
return (SUMOReal) poFeature.GetFieldAsDouble(index);
}
index = poFeature.GetDefnRef()->GetFieldIndex("SPEED");
if (index >= 0 && poFeature.IsFieldSet(index)) {
return (SUMOReal) poFeature.GetFieldAsDouble(index);
}
// try to get the NavTech-information
index = poFeature.GetDefnRef()->GetFieldIndex("SPEED_CAT");
if (index >= 0 && poFeature.IsFieldSet(index)) {
std::string def = poFeature.GetFieldAsString(index);
return NINavTeqHelper::getSpeed(edgeid, def);
}
return -1;
}