本文整理汇总了C++中OGRDataSource::ExecuteSQL方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRDataSource::ExecuteSQL方法的具体用法?C++ OGRDataSource::ExecuteSQL怎么用?C++ OGRDataSource::ExecuteSQL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRDataSource
的用法示例。
在下文中一共展示了OGRDataSource::ExecuteSQL方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MyOGRHandler
MyOGRHandler(const std::string& filename) :
m_data_source(NULL),
m_layer_point(NULL),
m_filter(true),
m_tohstore() {
OGRRegisterAll();
OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("PostgreSQL");
if (driver == NULL) {
std::cerr << "PostgreSQL OGR driver not available.\n";
exit(1);
}
// using COPY is much faster than INSERT
CPLSetConfigOption("PG_USE_COPY", "YES");
const char* options[] = { NULL };
m_data_source = driver->CreateDataSource(filename.c_str(), const_cast<char**>(options));
if (m_data_source == NULL) {
std::cerr << "Database open failed.\n";
exit(1);
}
// OGR can't create a table with hstore column, so we do it ourselves here
OGRLayer* dummy = m_data_source->ExecuteSQL("CREATE TABLE nodes (id VARCHAR, tags hstore);", NULL, NULL);
if (dummy) {
m_data_source->ReleaseResultSet(dummy);
}
dummy = m_data_source->ExecuteSQL("SELECT AddGeometryColumn('nodes', 'geom', 4326, 'POINT', 2);", NULL, NULL);
if (dummy) {
m_data_source->ReleaseResultSet(dummy);
}
m_layer_point = m_data_source->GetLayerByName("nodes");
if (!m_layer_point) {
std::cerr << "Something went wrong setting up the 'nodes' layer.\n";
exit(1);
}
// using transactions makes this much faster than without
m_layer_point->StartTransaction();
m_filter.add(false, "created_by");
m_filter.add(false, "odbl");
}
示例2:
OGRLayer * OGRDataSourceWithTransaction::ExecuteSQL( const char *pszStatement,
OGRGeometry *poSpatialFilter,
const char *pszDialect )
{
if( !m_poBaseDataSource ) return NULL;
OGRLayer* poLayer = m_poBaseDataSource->ExecuteSQL(pszStatement, poSpatialFilter,
pszDialect);
if( poLayer != NULL )
m_oSetExecuteSQLLayers.insert(poLayer);
return poLayer;
}
示例3:
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRDataSource_executeSQLNat
(JNIEnv *env, jobject obj, jlong cPtr, jstring pszStatement, jlong ptr_spatialFilter, jstring pszDialect){
OGRDataSource *ds = (OGRDataSource *) 0 ;
OGRGeometry *geom = (OGRGeometry *) 0 ;
OGRLayer *layer;
long ptro_layer=-1;
ds = *(OGRDataSource **)&cPtr;
geom = *(OGRGeometry **)&ptr_spatialFilter;
if(ds!=NULL ){
const char *stat = env->GetStringUTFChars( pszStatement, 0);
const char *dialect = env->GetStringUTFChars( pszDialect, 0);
layer = ds->ExecuteSQL(stat, geom, dialect);
env->ReleaseStringUTFChars( pszStatement, stat);
env->ReleaseStringUTFChars( pszDialect, dialect);
if(layer!=NULL)
ptro_layer = (long)&(*layer);
}
return ptro_layer;
}
示例4: main
//.........这里部分代码省略.........
exit( 1 );
}
CPLAssert( poDriver != NULL);
/* -------------------------------------------------------------------- */
/* 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 );
}
示例5: export_
// export
bool ImportExportGdal::export_(const QList<Feature *>& featList)
{
const char *pszDriverName = "SQLite";
OGRSFDriver *poDriver;
OGRRegisterAll();
poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName);
if( poDriver == NULL )
{
qDebug( "%s driver not available.", pszDriverName );
return false;
}
OGRDataSource *poDS;
QFile::remove(QString(HOMEDIR + "/test.sqlite"));
poDS = poDriver->CreateDataSource( QString(HOMEDIR + "/test.sqlite").toUtf8().constData(), NULL );
if( poDS == NULL )
{
qDebug( "Creation of output file failed." );
return false;
}
poDS->ExecuteSQL("PRAGMA synchronous = OFF", NULL, NULL);
OGRSpatialReference *poSRS;
poSRS = new OGRSpatialReference();
poSRS->importFromEPSG(4326);
char **papszOptions = NULL;
papszOptions = CSLSetNameValue( papszOptions, "SPATIALITE", "YES" );
papszOptions = CSLSetNameValue( papszOptions, "FORMAT", "SPATIALITE" );
papszOptions = CSLSetNameValue( papszOptions, "SPATIAL_INDEX", "YES" );
OGRLayer *poLayer;
poLayer = poDS->CreateLayer( "osm", poSRS, wkbUnknown, papszOptions);
CSLDestroy( papszOptions );
if( poLayer == NULL )
{
qDebug( "Layer creation failed." );
return false;
}
OGRFieldDefn oField("osm_id", OFTReal);
if( poLayer->CreateField( &oField ) != OGRERR_NONE )
{
qDebug( "Creating field failed." );
return false;
}
oField.Set("osm_version", OFTInteger );
poLayer->CreateField( &oField );
oField.Set("osm_timestamp", OFTInteger );
poLayer->CreateField( &oField );
OGRFeature *poFeature;
foreach (Feature* F, featList) {
poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
poFeature->SetField( "osm_id", (qreal)(F->id().numId));
#ifndef FRISIUS_BUILD
poFeature->SetField( "osm_version", F->versionNumber());
poFeature->SetField( "osm_timestamp", (int)F->time().toTime_t());
#endif
if (CHECK_NODE(F)) {
Node* N = STATIC_CAST_NODE(F);
OGRPoint pt;
pt.setX(N->position().x());
pt.setY(N->position().y());
poFeature->SetGeometry( &pt );
} else if (CHECK_WAY(F)) {
Way* W = STATIC_CAST_WAY(F);
OGRLineString ls;
ls.setNumPoints(W->size());
for (int i=0; i<W->size(); ++i) {
ls.setPoint(i, W->getNode(i)->position().x(), W->getNode(i)->position().y(), 0);
}
poFeature->SetGeometry( &ls );
}
if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
{
qDebug( "Failed to create feature in output." );
return false;
}
OGRFeature::DestroyFeature( poFeature );
}
示例6: 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;
}
示例7: main
//.........这里部分代码省略.........
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' 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
{