本文整理汇总了C++中OGRFeatureDefn::GetFieldCount方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFeatureDefn::GetFieldCount方法的具体用法?C++ OGRFeatureDefn::GetFieldCount怎么用?C++ OGRFeatureDefn::GetFieldCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRFeatureDefn
的用法示例。
在下文中一共展示了OGRFeatureDefn::GetFieldCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//---------------------------------------------------------
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 );
}
示例2: main
int main( int nArgc, char ** papszArgv )
{
OGROCISession *poSession = NULL;
const char *pszStatement = "SELECT * FROM NEPSITE";
int nColCount;
char **papszResult;
if( nArgc > 1 )
pszStatement = papszArgv[1];
poSession = OGRGetOCISession( "system", "LetoKing", "" );
if( poSession == NULL )
exit( 1 );
OGROCIStatement oStatement( poSession );
if( oStatement.Execute( pszStatement ) == CE_Failure )
exit( 2 );
while( (papszResult = oStatement.SimpleFetchRow()) != NULL )
{
OGRFeatureDefn *poDefn = oStatement.GetResultDefn();
int nColCount = poDefn->GetFieldCount();
int i;
printf( "\n" );
for( i = 0; i < nColCount; i++ )
{
printf( " %s = %s\n",
poDefn->GetFieldDefn(i)->GetNameRef(),
papszResult[i] );
}
}
}
示例3: while
QDebug operator<<(QDebug dbg, OGRLayer* layer)
{
layer->ResetReading();
OGRFeatureDefn* def = layer->GetLayerDefn();
FeaturePtr feat;
while ((feat = FeaturePtr(layer->GetNextFeature())) != nullptr)
{
for (int i = 0; i < def->GetFieldCount(); ++i)
{
OGRFieldDefn* fdef = def->GetFieldDefn(i);
switch (fdef->GetType())
{
case OFTInteger:
dbg << fdef->GetNameRef() << feat->GetFieldAsInteger(i);
break;
case OFTReal:
dbg << fdef->GetNameRef() << feat->GetFieldAsDouble(i);
break;
case OFTString:
dbg << fdef->GetNameRef() << feat->GetFieldAsString(i);
break;
default:
dbg << "Unknown type:" << fdef->GetType();
}
}
dbg << "-----";
}
return dbg;
}
示例4: NODE_THROW
Handle<Value> LayerFields::getNames(const Arguments& args)
{
HandleScope scope;
Handle<Object> parent = args.This()->GetHiddenValue(String::NewSymbol("parent_"))->ToObject();
Layer *layer = ObjectWrap::Unwrap<Layer>(parent);
if (!layer->get()) {
return NODE_THROW("Layer object already destroyed");
}
OGRFeatureDefn *def = layer->get()->GetLayerDefn();
if (!def) {
return NODE_THROW("Layer has no layer definition set");
}
int n = def->GetFieldCount();
Handle<Array> result = Array::New(n);
for (int i = 0; i < n; i++) {
OGRFieldDefn *field_def = def->GetFieldDefn(i);
result->Set(i, SafeString::New(field_def->GetNameRef()));
}
return scope.Close(result);
}
示例5: oField
OGRPLScenesLayer::OGRPLScenesLayer(OGRPLScenesDataset* poDS,
const char* pszName,
const char* pszBaseURL,
json_object* poObjCount10)
{
this->poDS = poDS;
osBaseURL = pszBaseURL;
SetDescription(pszName);
poFeatureDefn = new OGRFeatureDefn(pszName);
poFeatureDefn->SetGeomType(wkbMultiPolygon);
for(int i = 0; i < (int)sizeof(apsAttrs) / (int)sizeof(apsAttrs[0]); i++)
{
OGRFieldDefn oField(apsAttrs[i].pszName, apsAttrs[i].eType);
poFeatureDefn->AddFieldDefn(&oField);
}
poFeatureDefn->Reference();
poSRS = new OGRSpatialReference(SRS_WKT_WGS84);
poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(poSRS);
bEOF = FALSE;
nFeatureCount = -1;
nNextFID = 1;
poGeoJSONDS = NULL;
poGeoJSONLayer = NULL;
poMainFilter = NULL;
nPageSize = atoi(CPLGetConfigOption("PLSCENES_PAGE_SIZE", "1000"));
bStillInFirstPage = FALSE;
bAcquiredAscending = -1;
bFilterMustBeClientSideEvaluated = FALSE;
ResetReading();
if( poObjCount10 != NULL )
{
json_object* poCount = json_object_object_get(poObjCount10, "count");
if( poCount != NULL )
nFeatureCount = MAX(0, json_object_get_int64(poCount));
OGRGeoJSONDataSource* poTmpDS = new OGRGeoJSONDataSource();
OGRGeoJSONReader oReader;
oReader.SetFlattenNestedAttributes(true, '.');
oReader.ReadLayer( poTmpDS, "layer", poObjCount10 );
OGRLayer* poTmpLayer = poTmpDS->GetLayer(0);
if( poTmpLayer )
{
OGRFeatureDefn* poTmpFDefn = poTmpLayer->GetLayerDefn();
std::vector<CPLString> aosNewFields;
for(int i=0;i<poTmpFDefn->GetFieldCount();i++)
{
if( poFeatureDefn->GetFieldIndex(poTmpFDefn->GetFieldDefn(i)->GetNameRef()) < 0 )
aosNewFields.push_back(poTmpFDefn->GetFieldDefn(i)->GetNameRef());
}
std::sort(aosNewFields.begin(), aosNewFields.end(), OGRPLScenesLayerFieldNameComparator);
for(int i=0;i<(int)aosNewFields.size();i++)
{
OGRFieldDefn oField(poTmpFDefn->GetFieldDefn(poTmpFDefn->GetFieldIndex(aosNewFields[i])));
poFeatureDefn->AddFieldDefn(&oField);
}
}
delete poTmpDS;
}
}
示例6:
void cvct2gdal::CVCT2GDALLayer( VCTLayer * poVCTLayer, OGRLayer * poOGRLayer )
{
OGRFeatureDefn * poOGRFeatDefn =
cvct2gdal::CVCT2GDALFeatureDefn ( & (poVCTLayer->featuredefn ) );
for ( int ifield = 0; ifield < poOGRFeatDefn->GetFieldCount(); ++ifield )
{
poOGRLayer->CreateField ( poOGRFeatDefn->GetFieldDefn ( ifield ) );
}
for (auto ifeat = 0; ifeat != poVCTLayer->GetFeatureCount(); ++ifeat)
{
VCTFeature * poVCTFeat = poVCTLayer->GetFeatureByIndex(ifeat);
//注意:feature在析构时,会将featuredefn也析构
//将featuredefn复制后传入
OGRFeature * poOGRFeat = cvct2gdal::CVCT2GDALFeature ( poVCTFeat, poOGRFeatDefn->Clone());
poOGRLayer->CreateFeature ( poOGRFeat );
//在window下,释放内存会报错
#ifndef WIN32
OGRFeature::DestroyFeature(poOGRFeat);
#endif
}
//在window下,释放内存会报错
#ifndef WIN32
poOGRFeatDefn->Release();
#endif
}
示例7: main
//#include "s57.h"
int main(int argc, char **argv)
{
OGRRegisterAll();
OGRDataSource *poDS;
printf("Opening %s\n",argv[1]);
poDS = OGRSFDriverRegistrar::Open( argv[1], FALSE );
if( poDS == NULL )
{
printf( "Open failed.\n" );
exit( 1 );
}
OGRLayer *poLayer;
int layers = poDS->GetLayerCount();
for (int layer =0 ; layer< layers; layer++) {
poLayer = poDS->GetLayer(layer);
if (poLayer == NULL) continue;
printf("%d, %s, %s",layer, poLayer->GetName(), OGRGeometryTypeToName(poLayer->GetGeomType()));
poLayer->ResetReading();
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
int iField;
for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );
printf(", %s",poFieldDefn->GetNameRef());
}
printf("\n");
}
}
示例8: wxDynamicCast
wxGISGridTable::wxGISGridTable(wxGISDataset* pGISDataset)
{
m_nRows = m_nCols = 0;
m_pGISDataset = wxDynamicCast(pGISDataset, wxGISTable);
OGRFeatureDefn* pOGRFeatureDefn = m_pGISDataset->GetDefinition();
if(pOGRFeatureDefn)
{
m_nCols = pOGRFeatureDefn->GetFieldCount();
m_nRows = m_pGISDataset->GetFeatureCount();
}
}
示例9:
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_JNIBase_getFieldCountNat
(JNIEnv *env, jobject obj, jlong cPtr){
OGRFeatureDefn *df = (OGRFeatureDefn *) 0 ;
int nfields=-1;
df = *(OGRFeatureDefn **)&cPtr;
if(df!=NULL){
nfields = df->GetFieldCount();
}
return nfields;
}
示例10: OGR2SQLITE_IgnoreAllFieldsExceptGeometry
static
void OGR2SQLITE_IgnoreAllFieldsExceptGeometry(OGRLayer* poLayer)
{
char** papszIgnored = NULL;
papszIgnored = CSLAddString(papszIgnored, "OGR_STYLE");
OGRFeatureDefn* poFeatureDefn = poLayer->GetLayerDefn();
for(int i=0; i < poFeatureDefn->GetFieldCount(); i++)
{
papszIgnored = CSLAddString(papszIgnored,
poFeatureDefn->GetFieldDefn(i)->GetNameRef());
}
poLayer->SetIgnoredFields((const char**)papszIgnored);
CSLDestroy(papszIgnored);
}
示例11: 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 );
}
示例12: OGRGMEAttributesToGeoJSON
json_object* OGRGMEAttributesToGeoJSON( OGRFeature* poFeature )
{
if ( NULL == poFeature )
return NULL;
json_object* pjoProperties = json_object_new_object();
CPLAssert( NULL != pjoProperties );
OGRFeatureDefn* poDefn = poFeature->GetDefnRef();
for( int nField = 0; nField < poDefn->GetFieldCount(); ++nField ) {
json_object* pjoProperty = NULL;
OGRFieldDefn* poFieldDefn = poDefn->GetFieldDefn( nField );
if ( NULL == poFieldDefn )
continue;
OGRFieldType eType = poFieldDefn->GetType();
if( !poFeature->IsFieldSet(nField) )
pjoProperty = NULL;
// In GME integers are encoded as strings.
else if( OFTInteger == eType )
pjoProperty = json_object_new_string( poFeature->GetFieldAsString( nField ) );
else if( OFTReal == eType )
pjoProperty = json_object_new_gme_double( poFeature->GetFieldAsDouble(nField) );
// Supported types are integer, double and string. So treating everything else as strings
else
pjoProperty = json_object_new_string( poFeature->GetFieldAsString(nField) );
json_object_object_add( pjoProperties, poFieldDefn->GetNameRef(), pjoProperty );
}
int nGxId = poFeature->GetFieldIndex("gx_id");
if (nGxId < 0) {
json_object* pjoProperty = NULL;
GIntBig nFID = poFeature->GetFID();
char acGxId[128];
snprintf(acGxId, 128, "GDAL-" CPL_FRMT_GIB, nFID);
CPLDebug("GME", "gx_id is not set, so adding \"gx_id\": \"%s\" field.",
acGxId);
pjoProperty = json_object_new_string( acGxId );
json_object_object_add( pjoProperties, "gx_id", pjoProperty);
}
return pjoProperties;
}
示例13: OGRFeatureDefn
OGRESRIFeatureServiceLayer::OGRESRIFeatureServiceLayer(OGRESRIFeatureServiceDataset* poDS)
{
this->poDS = poDS;
OGRFeatureDefn* poSrcFeatDefn = poDS->GetUnderlyingLayer()->GetLayerDefn();
poFeatureDefn = new OGRFeatureDefn(poSrcFeatDefn->GetName());
SetDescription(poFeatureDefn->GetName());
poFeatureDefn->Reference();
poFeatureDefn->SetGeomType(wkbNone);
for(int i=0;i<poSrcFeatDefn->GetFieldCount();i++)
poFeatureDefn->AddFieldDefn(poSrcFeatDefn->GetFieldDefn(i));
for(int i=0;i<poSrcFeatDefn->GetGeomFieldCount();i++)
poFeatureDefn->AddGeomFieldDefn(poSrcFeatDefn->GetGeomFieldDefn(i));
nFeaturesRead = 0;
nLastFID = 0;
bOtherPage = FALSE;
bUseSequentialFID = FALSE;
}
示例14: ReportOnLayer
static void ReportOnLayer( OGRLayer * poLayer )
{
OGRFeatureDefn *poDefn = poLayer->GetLayerDefn();
printf( "\n" );
printf( "Layer name: %s\n", poDefn->GetName() );
printf( "Feature Count: %d\n", poLayer->GetFeatureCount() );
if( bVerbose )
{
char *pszWKT;
if( poLayer->GetSpatialRef() == NULL )
pszWKT = CPLStrdup( "(NULL)" );
else
poLayer->GetSpatialRef()->exportToWkt( &pszWKT );
printf( "Layer SRS WKT: %s\n", pszWKT );
CPLFree( pszWKT );
}
for( int iAttr = 0; iAttr < poDefn->GetFieldCount(); iAttr++ )
{
OGRFieldDefn *poField = poDefn->GetFieldDefn( iAttr );
printf( "%s: %s (%d.%d)\n",
poField->GetNameRef(),
poField->GetFieldTypeName( poField->GetType() ),
poField->GetWidth(),
poField->GetPrecision() );
}
/* -------------------------------------------------------------------- */
/* Read, and dump features. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature;
while( (poFeature = poLayer->GetNextFeature()) != NULL )
{
poFeature->DumpReadable( stdout );
delete poFeature;
}
}
示例15: poDS
OGRESRIFeatureServiceLayer::OGRESRIFeatureServiceLayer(
OGRESRIFeatureServiceDataset* poDSIn) :
poDS(poDSIn),
nFeaturesRead(0),
nLastFID(0),
bOtherPage(false),
bUseSequentialFID(false)
{
OGRFeatureDefn* poSrcFeatDefn = poDS->GetUnderlyingLayer()->GetLayerDefn();
poFeatureDefn = new OGRFeatureDefn(poSrcFeatDefn->GetName());
SetDescription(poFeatureDefn->GetName());
poFeatureDefn->Reference();
poFeatureDefn->SetGeomType(wkbNone);
for(int i=0;i<poSrcFeatDefn->GetFieldCount();i++)
poFeatureDefn->AddFieldDefn(poSrcFeatDefn->GetFieldDefn(i));
for(int i=0;i<poSrcFeatDefn->GetGeomFieldCount();i++)
poFeatureDefn->AddGeomFieldDefn(poSrcFeatDefn->GetGeomFieldDefn(i));
}