本文整理汇总了C++中OGRLayer::SetAttributeFilter方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRLayer::SetAttributeFilter方法的具体用法?C++ OGRLayer::SetAttributeFilter怎么用?C++ OGRLayer::SetAttributeFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRLayer
的用法示例。
在下文中一共展示了OGRLayer::SetAttributeFilter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FixIndexes
int FGdbDataSource::FixIndexes()
{
int bRet = TRUE;
if( m_pConnection && m_pConnection->IsFIDHackInProgress() )
{
m_pConnection->CloseGeodatabase();
char* apszDrivers[2];
apszDrivers[0] = (char*) "OpenFileGDB";
apszDrivers[1] = NULL;
const char* pszSystemCatalog = CPLFormFilename(m_osFSName, "a00000001.gdbtable", NULL);
GDALDataset* poOpenFileGDBDS = (GDALDataset*)
GDALOpenEx(pszSystemCatalog, GDAL_OF_VECTOR,
apszDrivers, NULL, NULL);
if( poOpenFileGDBDS == NULL || poOpenFileGDBDS->GetLayer(0) == NULL )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot open %s with OpenFileGDB driver. "
"Should not happen. Some layers will be corrupted",
pszSystemCatalog);
bRet = FALSE;
}
else
{
OGRLayer* poLayer = poOpenFileGDBDS->GetLayer(0);
size_t count = m_layers.size();
for(size_t i = 0; i < count; ++i )
{
if( m_layers[i]->m_oMapOGRFIDToFGDBFID.size() == 0)
continue;
CPLString osFilter = "name = '";
osFilter += m_layers[i]->GetName();
osFilter += "'";
poLayer->SetAttributeFilter(osFilter);
poLayer->ResetReading();
OGRFeature* poF = poLayer->GetNextFeature();
if( poF == NULL )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot find filename for layer %s",
m_layers[i]->GetName());
bRet = FALSE;
}
else
{
if( !m_layers[i]->EditIndexesForFIDHack(CPLFormFilename(m_osFSName,
CPLSPrintf("a%08x", (int)poF->GetFID()), NULL)) )
{
bRet = FALSE;
}
}
delete poF;
}
}
GDALClose(poOpenFileGDBDS);
m_pConnection->SetFIDHackInProgress(FALSE);
}
return bRet;
}
示例2: 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 );
}
示例3: main
//.........这里部分代码省略.........
/* -------------------------------------------------------------------- */
/* Some information messages. */
/* -------------------------------------------------------------------- */
if( bVerbose )
printf( "INFO: Open of `%s'\n"
" using driver `%s' successful.\n",
pszDataSource, poDriver->GetName() );
if( bVerbose && !EQUAL(pszDataSource,poDS->GetName()) )
{
printf( "INFO: Internal data source name `%s'\n"
" different from user name `%s'.\n",
poDS->GetName(), pszDataSource );
}
/* -------------------------------------------------------------------- */
/* Special case for -sql clause. No source layers required. */
/* -------------------------------------------------------------------- */
if( pszSQLStatement != NULL )
{
OGRLayer *poResultSet = NULL;
nRepeatCount = 0; // skip layer reporting.
if( CSLCount(papszLayers) > 0 )
printf( "layer names ignored in combination with -sql.\n" );
poResultSet = poDS->ExecuteSQL( pszSQLStatement, poSpatialFilter,
pszDialect );
if( poResultSet != NULL )
{
if( pszWHERE != NULL )
poResultSet->SetAttributeFilter( pszWHERE );
ReportOnLayer( poResultSet, NULL, NULL );
poDS->ReleaseResultSet( poResultSet );
}
}
CPLDebug( "OGR", "GetLayerCount() = %d\n", poDS->GetLayerCount() );
for( int iRepeat = 0; iRepeat < nRepeatCount; iRepeat++ )
{
if ( CSLCount(papszLayers) == 0 )
{
/* -------------------------------------------------------------------- */
/* Process each data source layer. */
/* -------------------------------------------------------------------- */
for( int iLayer = 0; iLayer < poDS->GetLayerCount(); iLayer++ )
{
OGRLayer *poLayer = poDS->GetLayer(iLayer);
if( poLayer == NULL )
{
printf( "FAILURE: Couldn't fetch advertised layer %d!\n",
iLayer );
exit( 1 );
}
if (!bAllLayers)
{
printf( "%d: %s",
iLayer+1,
poLayer->GetLayerDefn()->GetName() );
示例4: LoadGeometry
static OGRGeometryCollection* LoadGeometry( const char* pszDS,
const char* pszSQL,
const char* pszLyr,
const char* pszWhere )
{
OGRDataSource *poDS;
OGRLayer *poLyr;
OGRFeature *poFeat;
OGRGeometryCollection *poGeom = NULL;
poDS = OGRSFDriverRegistrar::Open( pszDS, FALSE );
if ( poDS == NULL )
return NULL;
if ( pszSQL != NULL )
poLyr = poDS->ExecuteSQL( pszSQL, NULL, NULL );
else if ( pszLyr != NULL )
poLyr = poDS->GetLayerByName( pszLyr );
else
poLyr = poDS->GetLayer(0);
if ( poLyr == NULL )
{
fprintf( stderr,
"FAILURE: Failed to identify source layer from datasource.\n" );
OGRDataSource::DestroyDataSource( poDS );
return NULL;
}
if ( pszWhere )
poLyr->SetAttributeFilter( pszWhere );
while ( (poFeat = poLyr->GetNextFeature()) != NULL )
{
OGRGeometry* poSrcGeom = poFeat->GetGeometryRef();
if ( poSrcGeom )
{
OGRwkbGeometryType eType =
wkbFlatten( poSrcGeom->getGeometryType() );
if ( poGeom == NULL )
poGeom = new OGRMultiPolygon();
if ( eType == wkbPolygon )
poGeom->addGeometry( poSrcGeom );
else if ( eType == wkbMultiPolygon )
{
int iGeom;
int nGeomCount =
((OGRMultiPolygon *)poSrcGeom)->getNumGeometries();
for ( iGeom = 0; iGeom < nGeomCount; iGeom++ )
{
poGeom->addGeometry(
((OGRMultiPolygon *)poSrcGeom)->getGeometryRef(iGeom) );
}
}
else
{
fprintf( stderr, "FAILURE: Geometry not of polygon type.\n" );
OGRGeometryFactory::destroyGeometry( poGeom );
OGRFeature::DestroyFeature( poFeat );
if ( pszSQL != NULL )
poDS->ReleaseResultSet( poLyr );
OGRDataSource::DestroyDataSource( poDS );
return NULL;
}
}
OGRFeature::DestroyFeature( poFeat );
}
if( pszSQL != NULL )
poDS->ReleaseResultSet( poLyr );
OGRDataSource::DestroyDataSource( poDS );
return poGeom;
}
示例5: CalAsShp
void DataCvt_Log::CalAsShp()
{
double ptmptime_start = MPI_Wtime();
OGRRegisterAll();
//create a new shp to caculate
CBaseOperate pbaseOperate;
if(rankid==0)
{
pbaseOperate.CreateCopyShp(m_DatasourceConStr.c_str(),m_PathOrTableName.c_str(),m_ResultPathOrTableName.c_str());
}
MPI_Barrier(MPI_COMM_WORLD);
string pLayerName = m_ResultPathOrTableName;
if(strcmp(m_DatasourceConStr.c_str(),"")==0)//input is shp file
{
m_DatasourceConStr = m_ResultPathOrTableName;
string pShpPath = m_ResultPathOrTableName;
string p_LayerName = GetFileNameOnly(pShpPath.c_str());
int pindex = p_LayerName.find_first_of('.');
pLayerName = p_LayerName.erase(pindex,p_LayerName.size()-1);
}
OGRDataSource* poDS = OGRSFDriverRegistrar::Open(m_DatasourceConStr.c_str(),TRUE);
OGRLayer* poLayer = poDS->GetLayerByName(pLayerName.c_str());
OGRFeature * pFeature =poLayer->GetNextFeature();
m_RowNum = poLayer->GetFeatureCount();
//if -c argv is null, all field will be used
m_ColNum= pFeature->GetFieldCount();
if(c_CaculateCols.size()==0)
{
if(rankid==0)
cout<<"!!!!!!! No input columns ids, all fields in the input file will be used..."<<endl<<endl;
for(int i=0;i<m_ColNum;i++)
{
c_CaculateCols.push_back(i);
}
}
double ptmptime_end = MPI_Wtime();
m_GdalIOInCal_Time=m_GdalIOInCal_Time+ptmptime_end-ptmptime_start;
//assign number to each process
int pnum_start,pnum_end;
int pMyProcessNum=0; int pRemainder=m_RowNum%numproc;
if(rankid<pRemainder)
{
pMyProcessNum = m_RowNum/numproc+1;
pnum_start = rankid*pMyProcessNum;
pnum_end = pnum_start+pMyProcessNum-1;
}
else
{
pMyProcessNum = m_RowNum/numproc;
pnum_start = pRemainder*(pMyProcessNum+1)+(rankid-pRemainder)*pMyProcessNum;
pnum_end = pnum_start+pMyProcessNum-1;
}
//postgis: fid begins from 1, not 0
string pwhere="";
if(strcmp(m_DatasourceConStr.substr(0,3).c_str(),"PG:")==0)//input is postgis
{
pwhere = "gid>="+toString(pnum_start+1)+" and gid<="+toString(pnum_end+1);
}
else//shpfile: fid begins from 0, not 1
{
pwhere = "fid>="+toString(pnum_start)+" and fid<="+toString(pnum_end);
}
poLayer->SetAttributeFilter(pwhere.c_str());
pFeature = poLayer->GetNextFeature();
while(pFeature!=NULL)
{
for(int i=0;i<c_CaculateCols.size();i++)
{
double tmp = pFeature->GetFieldAsDouble(c_CaculateCols[i]);
if(tmp!=0)
tmp = log(fabs(tmp));
else
tmp=0;
double pstart = MPI_Wtime();
pFeature->SetField(c_CaculateCols[i],tmp);
poLayer->SetFeature(pFeature);
double pend = MPI_Wtime();
m_GdalIOInCal_Time = m_GdalIOInCal_Time+pend-pstart;
}
pFeature = poLayer->GetNextFeature();
}
OGRDataSource::DestroyDataSource( poDS );
double ptmptime_endall = MPI_Wtime();
Mpi_Caculate_Time = ptmptime_endall-ptmptime_start-m_GdalIOInCal_Time;
double tmp=Mpi_Caculate_Time;
MPI_Reduce(&Mpi_Caculate_Time,&tmp,1,MPI_DOUBLE,MPI_MIN,0,MPI_COMM_WORLD);
Mpi_Caculate_Time = tmp;
}
示例6: if
//.........这里部分代码省略.........
{
printf("INFO: Internal data source name `%s'\n"
" different from user name `%s'.\n",
poDS->GetDescription(), pszDataSource);
}
GDALInfoReportMetadata(static_cast<GDALMajorObjectH>(poDS),
bListMDD,
bShowMetadata,
papszExtraMDDomains);
if( bDatasetGetNextFeature )
{
nRepeatCount = 0; // skip layer reporting.
/* -------------------------------------------------------------------- */
/* Set filters if provided. */
/* -------------------------------------------------------------------- */
if( pszWHERE != nullptr || poSpatialFilter != nullptr )
{
for( int iLayer = 0; iLayer < poDS->GetLayerCount(); iLayer++ )
{
OGRLayer *poLayer = poDS->GetLayer(iLayer);
if( poLayer == nullptr )
{
printf("FAILURE: Couldn't fetch advertised layer %d!\n",
iLayer);
exit(1);
}
if( pszWHERE != nullptr )
{
if( poLayer->SetAttributeFilter(pszWHERE) != OGRERR_NONE )
{
printf("WARNING: SetAttributeFilter(%s) "
"failed on layer %s.\n",
pszWHERE, poLayer->GetName());
}
}
if( poSpatialFilter != nullptr )
{
if( pszGeomField != nullptr )
{
OGRFeatureDefn *poDefn = poLayer->GetLayerDefn();
const int iGeomField =
poDefn->GetGeomFieldIndex(pszGeomField);
if( iGeomField >= 0 )
poLayer->SetSpatialFilter(iGeomField,
poSpatialFilter);
else
printf("WARNING: Cannot find geometry field %s.\n",
pszGeomField);
}
else
{
poLayer->SetSpatialFilter(poSpatialFilter);
}
}
}
}
std::set<OGRLayer*> oSetLayers;
while( true )
{