本文整理汇总了C++中OGRDataSource::GetLayerCount方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRDataSource::GetLayerCount方法的具体用法?C++ OGRDataSource::GetLayerCount怎么用?C++ OGRDataSource::GetLayerCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRDataSource
的用法示例。
在下文中一共展示了OGRDataSource::GetLayerCount方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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");
}
}
示例2: readFile
virtual ReadResult readFile(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
if (OGRSFDriverRegistrar::GetRegistrar()->GetDriverCount() == 0)
OGRRegisterAll();
// Try to open data source
OGRDataSource* file = OGRSFDriverRegistrar::Open(fileName.c_str());
if (!file)
return 0;
bool useRandomColorByFeature = false;
bool addGroupPerFeature = false;
if (options)
{
if (options->getOptionString().find("UseRandomColorByFeature") != std::string::npos)
useRandomColorByFeature = true;
if (options->getOptionString().find("useRandomColorByFeature") != std::string::npos)
useRandomColorByFeature = true;
if (options->getOptionString().find("addGroupPerFeature") != std::string::npos)
addGroupPerFeature = true;
}
osg::Group* group = new osg::Group;
for (int i = 0; i < file->GetLayerCount(); i++)
{
osg::Group* node = readLayer(file->GetLayer(i), file->GetName(), useRandomColorByFeature, addGroupPerFeature);
if (node)
group->addChild( node );
}
OGRDataSource::DestroyDataSource( file );
return group;
}
示例3: GetSummaryRefCount
int OGRDataSource::GetSummaryRefCount() const
{
int nSummaryCount = m_nRefCount;
int iLayer;
OGRDataSource *poUseThis = (OGRDataSource *) this;
for( iLayer=0; iLayer < poUseThis->GetLayerCount(); iLayer++ )
nSummaryCount += poUseThis->GetLayer( iLayer )->GetRefCount();
return nSummaryCount;
}
示例4:
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_JNIBase_getLayerCountNat
(JNIEnv *env, jobject obj, jlong cPtr){
int res=-1;
OGRDataSource *ds = (OGRDataSource *) 0 ;
ds = *(OGRDataSource **)&cPtr;
if(ds!=NULL)
res = ds->GetLayerCount();
return res;
}
示例5: GetSummaryRefCount
int OGRDataSource::GetSummaryRefCount() const
{
CPLMutexHolderD( (void **) &m_hMutex );
int nSummaryCount = m_nRefCount;
int iLayer;
OGRDataSource *poUseThis = (OGRDataSource *) this;
for( iLayer=0; iLayer < poUseThis->GetLayerCount(); iLayer++ )
nSummaryCount += poUseThis->GetLayer( iLayer )->GetRefCount();
return nSummaryCount;
}
示例6: main
//.........这里部分代码省略.........
}
if( poDriver == NULL )
{
fprintf( stderr, "Unable to find driver `%s'.\n", pszFormat );
fprintf( stderr, "The following drivers are available:\n" );
for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
{
fprintf( stderr, " -> `%s'\n", poR->GetDriver(iDriver)->GetName() );
}
exit( 1 );
}
if( !poDriver->TestCapability( ODrCCreateDataSource ) )
{
fprintf( stderr, "%s driver does not support data source creation.\n",
pszFormat );
exit( 1 );
}
/* -------------------------------------------------------------------- */
/* Now create it. */
/* -------------------------------------------------------------------- */
poDstDS = poDriver->CreateDataSource( pszOutputName, NULL );
if( poDstDS == NULL )
{
fprintf( stderr, "%s driver failed to create %s\n",
pszFormat, pszOutputName );
exit( 1 );
}
if( poDstDS->GetLayerCount() == 0 )
{
OGRFieldDefn oLocation( pszTileIndexField, OFTString );
oLocation.SetWidth( 200 );
if( nFirstSourceDataset < nArgc && papszArgv[nFirstSourceDataset][0] == '-' )
{
nFirstSourceDataset++;
}
OGRSpatialReference* poSrcSpatialRef = NULL;
/* Fetches the SRS of the first layer and use it when creating the tileindex layer */
if (nFirstSourceDataset < nArgc)
{
OGRDataSource* poDS = OGRSFDriverRegistrar::Open( papszArgv[nFirstSourceDataset],
FALSE );
if (poDS)
{
int iLayer;
for( iLayer = 0; iLayer < poDS->GetLayerCount(); iLayer++ )
{
int bRequested = bLayersWildcarded;
OGRLayer *poLayer = poDS->GetLayer(iLayer);
for( iArg = 1; iArg < nArgc && !bRequested; iArg++ )
{
if( EQUAL(papszArgv[iArg],"-lnum")
&& atoi(papszArgv[iArg+1]) == iLayer )
bRequested = TRUE;
示例7: OGR2SQLITE_ogr_datasource_load_layers
static
void OGR2SQLITE_ogr_datasource_load_layers(sqlite3_context* pContext,
int argc, sqlite3_value** argv)
{
sqlite3* hDB = (sqlite3*) sqlite3_user_data(pContext);
if( (argc < 1 || argc > 3) || sqlite3_value_type (argv[0]) != SQLITE_TEXT )
{
sqlite3_result_int (pContext, 0);
return;
}
const char* pszDataSource = (const char*) sqlite3_value_text(argv[0]);
int bUpdate = FALSE;
if( argc >= 2 )
{
if( sqlite3_value_type(argv[1]) != SQLITE_INTEGER )
{
sqlite3_result_int (pContext, 0);
return;
}
bUpdate = sqlite3_value_int(argv[1]);
}
const char* pszPrefix = NULL;
if( argc >= 3 )
{
if( sqlite3_value_type(argv[2]) != SQLITE_TEXT )
{
sqlite3_result_int (pContext, 0);
return;
}
pszPrefix = (const char*) sqlite3_value_text(argv[2]);
}
OGRDataSource* poDS = (OGRDataSource*)OGROpenShared(pszDataSource, bUpdate, NULL);
if( poDS == NULL )
{
CPLError(CE_Failure, CPLE_AppDefined, "Cannot open %s", pszDataSource);
sqlite3_result_int (pContext, 0);
return;
}
CPLString osEscapedDataSource = OGRSQLiteEscape(pszDataSource);
for(int i=0; i<poDS->GetLayerCount(); i++)
{
const char* pszLayerName = poDS->GetLayer(i)->GetName();
CPLString osEscapedLayerName = OGRSQLiteEscape(pszLayerName);
CPLString osTableName;
if( pszPrefix != NULL )
{
osTableName = pszPrefix;
osTableName += "_";
osTableName += OGRSQLiteEscapeName(pszLayerName);
}
else
{
osTableName = OGRSQLiteEscapeName(pszLayerName);
}
char* pszErrMsg = NULL;
if( sqlite3_exec(hDB, CPLSPrintf(
"CREATE VIRTUAL TABLE \"%s\" USING VirtualOGR('%s', %d, '%s')",
osTableName.c_str(),
osEscapedDataSource.c_str(),
bUpdate,
osEscapedLayerName.c_str()),
NULL, NULL, &pszErrMsg) != SQLITE_OK )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot create table \"%s\" : %s",
osTableName.c_str(), pszErrMsg);
sqlite3_free(pszErrMsg);
}
}
poDS->Release();
sqlite3_result_int (pContext, 1);
}
示例8: main
//.........这里部分代码省略.........
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() );
if( poLayer->GetLayerDefn()->GetGeomType() != wkbUnknown )
printf( " (%s)",
OGRGeometryTypeToName(
poLayer->GetLayerDefn()->GetGeomType() ) );
printf( "\n" );
}
示例9:
int OGRDataSourceWithTransaction::GetLayerCount()
{
if( !m_poBaseDataSource ) return 0;
return m_poBaseDataSource->GetLayerCount();
}
示例10: main
//.........这里部分代码省略.........
if( pszDataSource == NULL )
Usage();
/* -------------------------------------------------------------------- */
/* Open data source. */
/* -------------------------------------------------------------------- */
OGRDataSource *poDS;
OGRSFDriver *poDriver;
poDS = OGRSFDriverRegistrar::Open( pszDataSource, !bReadOnly, &poDriver );
if( poDS == NULL && !bReadOnly )
{
poDS = OGRSFDriverRegistrar::Open( pszDataSource, FALSE, &poDriver );
if( poDS != NULL && bVerbose )
{
printf( "Had to open data source read-only.\n" );
bReadOnly = TRUE;
}
}
/* -------------------------------------------------------------------- */
/* Report failure */
/* -------------------------------------------------------------------- */
if( poDS == NULL )
{
OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar();
printf( "FAILURE:\n"
"Unable to open datasource `%s' with the following drivers.\n",
pszDataSource );
for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
{
printf( " -> %s\n", poR->GetDriver(iDriver)->GetName() );
}
exit( 1 );
}
/* -------------------------------------------------------------------- */
/* 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 );
}
/* -------------------------------------------------------------------- */
/* 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( CSLCount(papszLayers) == 0 )
{
printf( "%d: %s",
iLayer+1,
poLayer->GetLayerDefn()->GetName() );
if( poLayer->GetLayerDefn()->GetGeomType() != wkbUnknown )
printf( " (%s)",
OGRGeometryTypeToName(
poLayer->GetLayerDefn()->GetGeomType() ) );
printf( "\n" );
}
else if( CSLFindString( papszLayers,
poLayer->GetLayerDefn()->GetName() ) != -1 )
{
ReportOnLayer( poLayer, pszWHERE, poSpatialFilter );
}
}
/* -------------------------------------------------------------------- */
/* Close down. */
/* -------------------------------------------------------------------- */
delete poDS;
#ifdef DBMALLOC
malloc_dump(1);
#endif
return 0;
}
示例11: main
//.........这里部分代码省略.........
for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
{
printf( " -> %s\n", poR->GetDriver(iDriver)->GetName() );
}
exit( 1 );
}
/* -------------------------------------------------------------------- */
/* Some information messages. */
/* -------------------------------------------------------------------- */
if( bVerbose )
printf( "INFO: Open of `%s' 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 );
}
/* -------------------------------------------------------------------- */
/* Process optionnal SQL request. */
/* -------------------------------------------------------------------- */
if (pszSQLStatement != NULL)
{
OGRLayer *poResultSet = poDS->ExecuteSQL(pszSQLStatement, NULL, NULL);
if (poResultSet == NULL)
exit(1);
printf( "INFO: Testing layer %s.\n",
poResultSet->GetName() );
bRet = TestOGRLayer( poDS, poResultSet, TRUE );
poDS->ReleaseResultSet(poResultSet);
}
/* -------------------------------------------------------------------- */
/* Process each data source layer. */
/* -------------------------------------------------------------------- */
else if (papszLayers == NULL)
{
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 );
}
printf( "INFO: Testing layer %s.\n",
poLayer->GetName() );
bRet &= TestOGRLayer( poDS, poLayer, FALSE );
}
}
else
{
/* -------------------------------------------------------------------- */
/* Or process layers specified by the user */
/* -------------------------------------------------------------------- */
char** papszLayerIter = papszLayers;
while (*papszLayerIter)
{
OGRLayer *poLayer = poDS->GetLayerByName(*papszLayerIter);
if( poLayer == NULL )
{
printf( "FAILURE: Couldn't fetch requested layer %s!\n",
*papszLayerIter );
exit( 1 );
}
printf( "INFO: Testing layer %s.\n",
poLayer->GetName() );
bRet &= TestOGRLayer( poDS, poLayer, FALSE );
papszLayerIter ++;
}
}
/* -------------------------------------------------------------------- */
/* Close down. */
/* -------------------------------------------------------------------- */
OGRDataSource::DestroyDataSource(poDS);
OGRCleanupAll();
CSLDestroy(papszLayers);
CSLDestroy(papszArgv);
#ifdef DBMALLOC
malloc_dump(1);
#endif
return (bRet) ? 0 : 1;
}
示例12: main
int main(int argc, char **argv)
{
// Get data from ogr
OGRRegisterAll();
std::cout << "Opening: " << argv[1] << std::endl;
OGRDataSource *shp = OGRSFDriverRegistrar::Open(argv[1], FALSE);
IsValid(shp, "Error opening file.");
std::cout << "Shape contains " << shp->GetLayerCount() << " layers." << std::endl;
OGRLayer *layer = shp->GetLayerByName(argv[2]);
IsValid(layer, "Couldn't grab layer");
OGRSpatialReference *srcSRS = NULL;
srcSRS = layer->GetSpatialRef();
// Set up writing
const char *kDriverName = "ESRI Shapefile";
OGRSFDriver *shpDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(kDriverName);
IsValid(shpDriver, "Couldn't grab the shapefile driver.");
IsValid(argv[3], "Please provide a output shp.");
std::cout << "Writing to: " << argv[3] << std::endl;
OGRDataSource *shpOut = shpDriver->CreateDataSource(argv[3], NULL);
IsValid(shpOut, "Couldn't open output file");
OGRLayer *outLayer = shpOut->CreateLayer(layer->GetName(), srcSRS, wkbMultiLineString, NULL);
IsValid(outLayer, "Couldn't create an output layer");
// copy over the fields from the source file
OGRFeatureDefn *source = layer->GetLayerDefn();
for(int i=0; i < source->GetFieldCount(); i++){
OGRFieldDefn *field = source->GetFieldDefn(i);
if(outLayer->CreateField(field) != OGRERR_NONE) {
std::cout << "Couldn't make layer" << std::endl; exit(1);
};
}
// Loop through features and grab the hull and put it into CGAL then
// skeletonize the points
OGRFeature *feature;
int count = 0;
while((feature = layer->GetNextFeature()) != NULL)
{
OGRMultiPolygon *geometry = dynamic_cast<OGRMultiPolygon *>(OGRGeometryFactory::forceToMultiPolygon(feature->GetGeometryRef()));
IsValid(geometry, "No geometry.");
OGRFeature *outFeature = OGRFeature::CreateFeature(outLayer->GetLayerDefn());
IsValid(outFeature, "Couldn't make a feature.");
for(int i=0; i < source->GetFieldCount(); i++){
OGRField *field = feature->GetRawFieldRef(i);
outFeature->SetField(i, field);
}
OGRGeometry* line = NULL;
for(int i=0; i < geometry->getNumGeometries(); i++){
OGRGeometry* segment = BuildMultiLine(geometry->getGeometryRef(i));
if(segment != NULL){
if(line == NULL) { line = new OGRLineString; }
OGRGeometry* tmp = line->Union(segment);
if(tmp != NULL){
delete line;
line = tmp;
}
delete segment;
}
}
outFeature->SetGeometry(line);
if(outLayer->CreateFeature(outFeature) != OGRERR_NONE){
std::cout << "Couldn't create feature." << std::endl;
exit(1);
}
// clean up
OGRFeature::DestroyFeature(outFeature);
std::cout << std::endl << ++count << std::endl;
}
// cleanup
OGRDataSource::DestroyDataSource(shp);
OGRDataSource::DestroyDataSource(shpOut);
return 0;
}