本文整理汇总了C++中CPLGetConfigOption函数的典型用法代码示例。如果您正苦于以下问题:C++ CPLGetConfigOption函数的具体用法?C++ CPLGetConfigOption怎么用?C++ CPLGetConfigOption使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CPLGetConfigOption函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CPLMutexHolderOptionalLockD
OGRErr FGdbDriver::RollbackTransaction(OGRDataSource*& poDSInOut, int& bOutHasReopenedDS)
{
CPLMutexHolderOptionalLockD(hMutex);
bOutHasReopenedDS = FALSE;
OGRMutexedDataSource* poMutexedDS = (OGRMutexedDataSource*)poDSInOut;
FGdbDataSource* poDS = (FGdbDataSource* )poMutexedDS->GetBaseDataSource();
FGdbDatabaseConnection* pConnection = poDS->GetConnection();
if( !pConnection->IsLocked() )
{
CPLError(CE_Failure, CPLE_NotSupported,
"No transaction in progress");
return OGRERR_FAILURE;
}
bOutHasReopenedDS = TRUE;
CPLString osName(poMutexedDS->GetName());
CPLString osNameOri(osName);
if( osName[osName.size()-1] == '/' || osName[osName.size()-1] == '\\' )
osName.resize(osName.size()-1);
//int bPerLayerCopyingForTransaction = poDS->HasPerLayerCopyingForTransaction();
pConnection->m_nRefCount ++;
delete poDSInOut;
poDSInOut = NULL;
poMutexedDS = NULL;
poDS = NULL;
pConnection->CloseGeodatabase();
CPLString osEditedName(osName);
osEditedName += ".ogredited";
OGRErr eErr = OGRERR_NONE;
if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE1") ||
CPLUnlinkTree(osEditedName) != 0 )
{
CPLError(CE_Warning, CPLE_AppDefined,
"Cannot remove %s. Manual cleanup required", osEditedName.c_str());
eErr = OGRERR_FAILURE;
}
pConnection->m_pGeodatabase = new Geodatabase;
long hr = ::OpenGeodatabase(StringToWString(osName), *(pConnection->m_pGeodatabase));
if (EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE2") ||
FAILED(hr))
{
delete pConnection->m_pGeodatabase;
pConnection->m_pGeodatabase = NULL;
pConnection->SetLocked(FALSE);
Release(osName);
GDBErr(hr, "Failed to re-open Geodatabase. Dataset should be closed");
return OGRERR_FAILURE;
}
FGdbDataSource* pDS = new FGdbDataSource(this, pConnection);
pDS->Open(osNameOri, TRUE, NULL);
//pDS->SetPerLayerCopyingForTransaction(bPerLayerCopyingForTransaction);
poDSInOut = new OGRMutexedDataSource(pDS, TRUE, hMutex, TRUE);
pConnection->SetLocked(FALSE);
return eErr;
}
示例2: CleanOverviews
CPLErr
GDALDefaultOverviews::BuildOverviews(
const char * pszBasename,
const char * pszResampling,
int nOverviews, int * panOverviewList,
int nBands, int * panBandList,
GDALProgressFunc pfnProgress, void * pProgressData)
{
if( pfnProgress == nullptr )
pfnProgress = GDALDummyProgress;
if( nOverviews == 0 )
return CleanOverviews();
/* -------------------------------------------------------------------- */
/* If we don't already have an overview file, we need to decide */
/* what format to use. */
/* -------------------------------------------------------------------- */
if( poODS == nullptr )
{
bOvrIsAux = CPLTestBool(CPLGetConfigOption( "USE_RRD", "NO" ));
if( bOvrIsAux )
{
osOvrFilename = CPLResetExtension(poDS->GetDescription(),"aux");
VSIStatBufL sStatBuf;
if( VSIStatExL( osOvrFilename, &sStatBuf,
VSI_STAT_EXISTS_FLAG ) == 0 )
osOvrFilename.Printf( "%s.aux", poDS->GetDescription() );
}
}
/* -------------------------------------------------------------------- */
/* If we already have the overviews open, but they are */
/* read-only, then try and reopen them read-write. */
/* -------------------------------------------------------------------- */
else if( poODS->GetAccess() == GA_ReadOnly )
{
GDALClose( poODS );
poODS = GDALDataset::Open(
osOvrFilename, GDAL_OF_RASTER | GDAL_OF_UPDATE);
if( poODS == nullptr )
return CE_Failure;
}
/* -------------------------------------------------------------------- */
/* Our TIFF overview support currently only works safely if all */
/* bands are handled at the same time. */
/* -------------------------------------------------------------------- */
if( !bOvrIsAux && nBands != poDS->GetRasterCount() )
{
CPLError( CE_Failure, CPLE_NotSupported,
"Generation of overviews in external TIFF currently only "
"supported when operating on all bands. "
"Operation failed." );
return CE_Failure;
}
/* -------------------------------------------------------------------- */
/* If a basename is provided, use it to override the internal */
/* overview filename. */
/* -------------------------------------------------------------------- */
if( pszBasename == nullptr && osOvrFilename.length() == 0 )
pszBasename = poDS->GetDescription();
if( pszBasename != nullptr )
{
if( bOvrIsAux )
osOvrFilename.Printf( "%s.aux", pszBasename );
else
osOvrFilename.Printf( "%s.ovr", pszBasename );
}
/* -------------------------------------------------------------------- */
/* Establish which of the overview levels we already have, and */
/* which are new. We assume that band 1 of the file is */
/* representative. */
/* -------------------------------------------------------------------- */
GDALRasterBand *poBand = poDS->GetRasterBand( 1 );
int nNewOverviews = 0;
int *panNewOverviewList = static_cast<int *>(
CPLCalloc(sizeof(int), nOverviews) );
double dfAreaNewOverviews = 0;
double dfAreaRefreshedOverviews = 0;
std::vector<bool> abValidLevel(nOverviews, true);
std::vector<bool> abRequireRefresh(nOverviews, false);
bool bFoundSinglePixelOverview = false;
for( int i = 0; i < nOverviews && poBand != nullptr; i++ )
{
// If we already have a 1x1 overview and this new one would result
// in it too, then don't create it.
if( bFoundSinglePixelOverview &&
(poBand->GetXSize() + panOverviewList[i] - 1)
/ panOverviewList[i] == 1 &&
(poBand->GetXSize() + panOverviewList[i] - 1)
/ panOverviewList[i] == 1 )
{
abValidLevel[i] = false;
continue;
//.........这里部分代码省略.........
示例3: CPLGetConfigOption
int S57ClassRegistrar::LoadInfo( const char * pszDirectory,
const char * pszProfile,
int bReportErr )
{
FILE *fp;
char szTargetFile[1024];
if( pszDirectory == NULL )
pszDirectory = CPLGetConfigOption("S57_CSV",NULL);
/* ==================================================================== */
/* Read the s57objectclasses file. */
/* ==================================================================== */
if( pszProfile == NULL )
pszProfile = CPLGetConfigOption( "S57_PROFILE", "" );
if( EQUAL(pszProfile, "Additional_Military_Layers") )
{
sprintf( szTargetFile, "s57objectclasses_%s.csv", "aml" );
}
else if ( EQUAL(pszProfile, "Inland_Waterways") )
{
sprintf( szTargetFile, "s57objectclasses_%s.csv", "iw" );
}
else if( strlen(pszProfile) > 0 )
{
sprintf( szTargetFile, "s57objectclasses_%s.csv", pszProfile );
}
else
{
strcpy( szTargetFile, "s57objectclasses.csv" );
}
if( !FindFile( szTargetFile, pszDirectory, bReportErr, &fp ) )
return FALSE;
/* -------------------------------------------------------------------- */
/* Skip the line defining the column titles. */
/* -------------------------------------------------------------------- */
const char * pszLine = ReadLine( fp );
if( !EQUAL(pszLine,
"\"Code\",\"ObjectClass\",\"Acronym\",\"Attribute_A\","
"\"Attribute_B\",\"Attribute_C\",\"Class\",\"Primitives\"" ) )
{
CPLError( CE_Failure, CPLE_AppDefined,
"s57objectclasses columns don't match expected format!\n" );
return FALSE;
}
/* -------------------------------------------------------------------- */
/* Read and form string list. */
/* -------------------------------------------------------------------- */
CSLDestroy( papszClassesInfo );
papszClassesInfo = (char **) CPLCalloc(sizeof(char *),MAX_CLASSES);
nClasses = 0;
while( nClasses < MAX_CLASSES
&& (pszLine = ReadLine(fp)) != NULL )
{
papszClassesInfo[nClasses] = CPLStrdup(pszLine);
if( papszClassesInfo[nClasses] == NULL )
break;
nClasses++;
}
if( nClasses == MAX_CLASSES )
CPLError( CE_Warning, CPLE_AppDefined,
"MAX_CLASSES exceeded in S57ClassRegistrar::LoadInfo().\n" );
/* -------------------------------------------------------------------- */
/* Cleanup, and establish state. */
/* -------------------------------------------------------------------- */
if( fp != NULL )
VSIFClose( fp );
iCurrentClass = -1;
if( nClasses == 0 )
return FALSE;
/* ==================================================================== */
/* Read the attributes list. */
/* ==================================================================== */
if( EQUAL(pszProfile, "Additional_Military_Layers") )
{
sprintf( szTargetFile, "s57attributes_%s.csv", "aml" );
}
else if ( EQUAL(pszProfile, "Inland_Waterways") )
{
sprintf( szTargetFile, "s57attributes_%s.csv", "iw" );
}
else if( strlen(pszProfile) > 0 )
{
sprintf( szTargetFile, "s57attributes_%s.csv", pszProfile );
}
//.........这里部分代码省略.........
示例4: CPLAssert
int OGRVRTDataSource::Initialize( CPLXMLNode *psTree, const char *pszNewName,
int bUpdate )
{
CPLAssert( nLayers == 0 );
this->psTree = psTree;
/* -------------------------------------------------------------------- */
/* Set name, and capture the directory path so we can use it */
/* for relative datasources. */
/* -------------------------------------------------------------------- */
CPLString osVRTDirectory = CPLGetPath( pszNewName );
pszName = CPLStrdup( pszNewName );
/* -------------------------------------------------------------------- */
/* Look for the OGRVRTDataSource node, it might be after an */
/* <xml> node. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psVRTDSXML = CPLGetXMLNode( psTree, "=OGRVRTDataSource" );
if( psVRTDSXML == NULL )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Did not find the <OGRVRTDataSource> node in the root of the document,\n"
"this is not really an OGR VRT." );
return FALSE;
}
/* -------------------------------------------------------------------- */
/* Determine if we must proxy layers. */
/* -------------------------------------------------------------------- */
int nOGRVRTLayerCount = CountOGRVRTLayers(psVRTDSXML);
int nMaxSimultaneouslyOpened = atoi(CPLGetConfigOption("OGR_VRT_MAX_OPENED", "100"));
if( nMaxSimultaneouslyOpened < 1 )
nMaxSimultaneouslyOpened = 1;
if( nOGRVRTLayerCount > nMaxSimultaneouslyOpened )
poLayerPool = new OGRLayerPool(nMaxSimultaneouslyOpened);
/* -------------------------------------------------------------------- */
/* Apply any dataset level metadata. */
/* -------------------------------------------------------------------- */
oMDMD.XMLInit( psVRTDSXML, TRUE );
/* -------------------------------------------------------------------- */
/* Look for layers. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psLTree;
for( psLTree=psVRTDSXML->psChild; psLTree != NULL; psLTree=psLTree->psNext )
{
if( psLTree->eType != CXT_Element )
continue;
/* -------------------------------------------------------------------- */
/* Create the layer object. */
/* -------------------------------------------------------------------- */
OGRLayer *poLayer = InstanciateLayer(psLTree, osVRTDirectory, bUpdate);
if( poLayer == NULL )
continue;
/* -------------------------------------------------------------------- */
/* Add layer to data source layer list. */
/* -------------------------------------------------------------------- */
nLayers ++;
papoLayers = (OGRLayer **)
CPLRealloc( papoLayers, sizeof(OGRLayer *) * nLayers );
papoLayers[nLayers-1] = poLayer;
paeLayerType = (OGRLayerType*)
CPLRealloc( paeLayerType, sizeof(int) * nLayers );
if( poLayerPool != NULL && EQUAL(psLTree->pszValue,"OGRVRTLayer"))
{
paeLayerType[nLayers - 1] = OGR_VRT_PROXIED_LAYER;
}
else if( EQUAL(psLTree->pszValue,"OGRVRTLayer") )
{
paeLayerType[nLayers - 1] = OGR_VRT_LAYER;
}
else
{
paeLayerType[nLayers - 1] = OGR_VRT_OTHER_LAYER;
}
}
return TRUE;
}
示例5: CPLError
GDALDataset* ZMapDataset::CreateCopy( const char * pszFilename,
GDALDataset *poSrcDS,
int bStrict,
CPL_UNUSED char ** papszOptions,
GDALProgressFunc pfnProgress,
void * pProgressData )
{
/* -------------------------------------------------------------------- */
/* Some some rudimentary checks */
/* -------------------------------------------------------------------- */
int nBands = poSrcDS->GetRasterCount();
if (nBands == 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"ZMap driver does not support source dataset with zero band.\n");
return NULL;
}
if (nBands != 1)
{
CPLError( (bStrict) ? CE_Failure : CE_Warning, CPLE_NotSupported,
"ZMap driver only uses the first band of the dataset.\n");
if (bStrict)
return NULL;
}
if( pfnProgress && !pfnProgress( 0.0, NULL, pProgressData ) )
return NULL;
/* -------------------------------------------------------------------- */
/* Get source dataset info */
/* -------------------------------------------------------------------- */
const int nXSize = poSrcDS->GetRasterXSize();
const int nYSize = poSrcDS->GetRasterYSize();
if (nXSize == 1 || nYSize == 1)
{
return NULL;
}
double adfGeoTransform[6];
poSrcDS->GetGeoTransform(adfGeoTransform);
if (adfGeoTransform[2] != 0 || adfGeoTransform[4] != 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"ZMap driver does not support CreateCopy() from skewed or "
"rotated dataset.\n");
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create target file */
/* -------------------------------------------------------------------- */
VSILFILE* fp = VSIFOpenL(pszFilename, "wb");
if (fp == NULL)
{
CPLError( CE_Failure, CPLE_AppDefined,
"Cannot create %s", pszFilename );
return NULL;
}
const int nFieldSize = 20;
const int nValuesPerLine = 4;
const int nDecimalCount = 7;
int bHasNoDataValue = FALSE;
double dfNoDataValue =
poSrcDS->GetRasterBand(1)->GetNoDataValue(&bHasNoDataValue);
if (!bHasNoDataValue)
dfNoDataValue = 1.e30;
VSIFPrintfL(fp, "!\n");
VSIFPrintfL(fp, "! Created by GDAL.\n");
VSIFPrintfL(fp, "!\n");
VSIFPrintfL(fp, "@GRID FILE, GRID, %d\n", nValuesPerLine);
WriteRightJustified(fp, nFieldSize, 10);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, dfNoDataValue, 10);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, "", 10);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, nDecimalCount, 10);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, 1, 10);
VSIFPrintfL(fp, "\n");
WriteRightJustified(fp, nYSize, 10);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, nXSize, 10);
VSIFPrintfL(fp, ",");
if (CPLTestBool(CPLGetConfigOption("ZMAP_PIXEL_IS_POINT", "FALSE")))
{
WriteRightJustified(fp, adfGeoTransform[0] + adfGeoTransform[1] / 2, 14, 7);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, adfGeoTransform[0] + adfGeoTransform[1] * nXSize -
adfGeoTransform[1] / 2, 14, 7);
VSIFPrintfL(fp, ",");
//.........这里部分代码省略.........
示例6: VFKReader
/*!
\brief VFKReaderSQLite constructor
*/
VFKReaderSQLite::VFKReaderSQLite(const char *pszFilename) : VFKReader(pszFilename)
{
const char *pszDbNameConf;
CPLString osDbName;
CPLString osCommand;
VSIStatBufL sStatBufDb, sStatBufVfk;
/* open tmp SQLite DB (re-use DB file if already exists) */
pszDbNameConf = CPLGetConfigOption("OGR_VFK_DB_NAME", NULL);
if (pszDbNameConf) {
osDbName = pszDbNameConf;
}
else {
osDbName = CPLResetExtension(m_pszFilename, "db");
}
size_t nLen = osDbName.length();
if( nLen > 2048 )
{
nLen = 2048;
osDbName.resize(nLen);
}
m_pszDBname = new char [nLen+1];
std::strncpy(m_pszDBname, osDbName.c_str(), nLen);
m_pszDBname[nLen] = 0;
CPLDebug("OGR-VFK", "Using internal DB: %s",
m_pszDBname);
if (CPLTestBool(CPLGetConfigOption("OGR_VFK_DB_SPATIAL", "YES")))
m_bSpatial = TRUE; /* build geometry from DB */
else
m_bSpatial = FALSE; /* store also geometry in DB */
m_bNewDb = TRUE;
if (VSIStatL(osDbName, &sStatBufDb) == 0) {
if (CPLTestBool(CPLGetConfigOption("OGR_VFK_DB_OVERWRITE", "NO"))) {
m_bNewDb = TRUE; /* overwrite existing DB */
CPLDebug("OGR-VFK", "Internal DB (%s) already exists and will be overwritten",
m_pszDBname);
VSIUnlink(osDbName);
}
else {
if (VSIStatL(pszFilename, &sStatBufVfk) == 0 &&
sStatBufVfk.st_mtime > sStatBufDb.st_mtime) {
CPLDebug("OGR-VFK",
"Found %s but ignoring because it appears\n"
"be older than the associated VFK file.",
osDbName.c_str());
m_bNewDb = TRUE;
VSIUnlink(osDbName);
}
else {
m_bNewDb = FALSE; /* re-use existing DB */
}
}
}
/*
if (m_bNewDb) {
CPLError(CE_Warning, CPLE_AppDefined,
"INFO: No internal SQLite DB found. Reading VFK data may take some time...");
}
*/
CPLDebug("OGR-VFK", "New DB: %s Spatial: %s",
m_bNewDb ? "yes" : "no", m_bSpatial ? "yes" : "no");
char* pszErrMsg;
if (SQLITE_OK != sqlite3_open(osDbName, &m_poDB)) {
CPLError(CE_Failure, CPLE_AppDefined,
"Creating SQLite DB failed: %s",
sqlite3_errmsg(m_poDB));
}
if (!m_bNewDb) {
char** papszResult;
int nRowCount, nColCount;
/* check if DB is up-to-date datasource */
pszErrMsg = NULL;
papszResult = NULL;
nRowCount = nColCount = 0;
osCommand.Printf("SELECT * FROM %s LIMIT 1", VFK_DB_TABLE);
sqlite3_get_table(m_poDB,
osCommand.c_str(),
&papszResult,
&nRowCount, &nColCount, &pszErrMsg);
sqlite3_free_table(papszResult);
sqlite3_free(pszErrMsg);
pszErrMsg = NULL;
if (nColCount != 6) {
/* it seems that DB is outdated, let's create new DB from
* scratch */
if (SQLITE_OK != sqlite3_close(m_poDB)) {
CPLError(CE_Failure, CPLE_AppDefined,
"Closing SQLite DB failed: %s",
sqlite3_errmsg(m_poDB));
//.........这里部分代码省略.........
示例7: CPLGetConfigOption
OGRDGNLayer::OGRDGNLayer( const char * pszName, DGNHandle hDGN,
int bUpdate )
{
this->hDGN = hDGN;
this->bUpdate = bUpdate;
/* -------------------------------------------------------------------- */
/* Work out what link format we are using. */
/* -------------------------------------------------------------------- */
OGRFieldType eLinkFieldType;
pszLinkFormat = (char *) CPLGetConfigOption( "DGN_LINK_FORMAT", "FIRST" );
if( EQUAL(pszLinkFormat,"FIRST") )
eLinkFieldType = OFTInteger;
else if( EQUAL(pszLinkFormat,"LIST") )
eLinkFieldType = OFTIntegerList;
else if( EQUAL(pszLinkFormat,"STRING") )
eLinkFieldType = OFTString;
else
{
CPLError( CE_Warning, CPLE_AppDefined,
"DGN_LINK_FORMAT=%s, but only FIRST, LIST or STRING supported.",
pszLinkFormat );
pszLinkFormat = (char *) "FIRST";
eLinkFieldType = OFTInteger;
}
pszLinkFormat = CPLStrdup(pszLinkFormat);
/* -------------------------------------------------------------------- */
/* Create the feature definition. */
/* -------------------------------------------------------------------- */
poFeatureDefn = new OGRFeatureDefn( pszName );
poFeatureDefn->Reference();
OGRFieldDefn oField( "", OFTInteger );
/* -------------------------------------------------------------------- */
/* Element type */
/* -------------------------------------------------------------------- */
oField.SetName( "Type" );
oField.SetType( OFTInteger );
oField.SetWidth( 2 );
oField.SetPrecision( 0 );
poFeatureDefn->AddFieldDefn( &oField );
/* -------------------------------------------------------------------- */
/* Level number. */
/* -------------------------------------------------------------------- */
oField.SetName( "Level" );
oField.SetType( OFTInteger );
oField.SetWidth( 2 );
oField.SetPrecision( 0 );
poFeatureDefn->AddFieldDefn( &oField );
/* -------------------------------------------------------------------- */
/* graphic group */
/* -------------------------------------------------------------------- */
oField.SetName( "GraphicGroup" );
oField.SetType( OFTInteger );
oField.SetWidth( 4 );
oField.SetPrecision( 0 );
poFeatureDefn->AddFieldDefn( &oField );
/* -------------------------------------------------------------------- */
/* ColorIndex */
/* -------------------------------------------------------------------- */
oField.SetName( "ColorIndex" );
oField.SetType( OFTInteger );
oField.SetWidth( 3 );
oField.SetPrecision( 0 );
poFeatureDefn->AddFieldDefn( &oField );
/* -------------------------------------------------------------------- */
/* Weight */
/* -------------------------------------------------------------------- */
oField.SetName( "Weight" );
oField.SetType( OFTInteger );
oField.SetWidth( 2 );
oField.SetPrecision( 0 );
poFeatureDefn->AddFieldDefn( &oField );
/* -------------------------------------------------------------------- */
/* Style */
/* -------------------------------------------------------------------- */
oField.SetName( "Style" );
oField.SetType( OFTInteger );
oField.SetWidth( 1 );
oField.SetPrecision( 0 );
poFeatureDefn->AddFieldDefn( &oField );
/* -------------------------------------------------------------------- */
/* EntityNum */
/* -------------------------------------------------------------------- */
oField.SetName( "EntityNum" );
oField.SetType( eLinkFieldType );
oField.SetWidth( 0 );
oField.SetPrecision( 0 );
poFeatureDefn->AddFieldDefn( &oField );
//.........这里部分代码省略.........
示例8: RasterliteCreateTables
OGRDataSourceH RasterliteCreateTables(OGRDataSourceH hDS, const char* pszTableName,
int nSRSId, int bWipeExistingData)
{
CPLString osSQL;
CPLString osOldVal = CPLGetConfigOption("SQLITE_LIST_ALL_TABLES", "FALSE");
CPLString osDBName = OGR_DS_GetName(hDS);
CPLString osRasterLayer;
osRasterLayer.Printf("%s_rasters", pszTableName);
CPLString osMetatadataLayer;
osMetatadataLayer.Printf("%s_metadata", pszTableName);
OGRLayerH hLyr;
if (OGR_DS_GetLayerByName(hDS, osRasterLayer.c_str()) == NULL)
{
/* -------------------------------------------------------------------- */
/* The table don't exist. Create them */
/* -------------------------------------------------------------------- */
/* Create _rasters table */
osSQL.Printf ("CREATE TABLE \"%s\" ("
"id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"
"raster BLOB NOT NULL)", osRasterLayer.c_str());
OGR_DS_ExecuteSQL(hDS, osSQL.c_str(), NULL, NULL);
/* Create _metadata table */
osSQL.Printf ("CREATE TABLE \"%s\" ("
"id INTEGER NOT NULL PRIMARY KEY,"
"source_name TEXT NOT NULL,"
"tile_id INTEGER NOT NULL,"
"width INTEGER NOT NULL,"
"height INTEGER NOT NULL,"
"pixel_x_size DOUBLE NOT NULL,"
"pixel_y_size DOUBLE NOT NULL)",
osMetatadataLayer.c_str());
OGR_DS_ExecuteSQL(hDS, osSQL.c_str(), NULL, NULL);
/* Add geometry column to _metadata table */
osSQL.Printf("SELECT AddGeometryColumn('%s', 'geometry', %d, 'POLYGON', 2)",
osMetatadataLayer.c_str(), nSRSId);
if ((hLyr = OGR_DS_ExecuteSQL(hDS, osSQL.c_str(), NULL, NULL)) == NULL)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Check that the OGR SQLite driver has Spatialite support");
OGRReleaseDataSource(hDS);
return NULL;
}
OGR_DS_ReleaseResultSet(hDS, hLyr);
/* Create spatial index on _metadata table */
osSQL.Printf("SELECT CreateSpatialIndex('%s', 'geometry')",
osMetatadataLayer.c_str());
if ((hLyr = OGR_DS_ExecuteSQL(hDS, osSQL.c_str(), NULL, NULL)) == NULL)
{
OGRReleaseDataSource(hDS);
return NULL;
}
OGR_DS_ReleaseResultSet(hDS, hLyr);
/* Re-open the DB to take into account the new tables*/
OGRReleaseDataSource(hDS);
CPLSetThreadLocalConfigOption("SQLITE_LIST_ALL_TABLES", "TRUE");
hDS = OGROpen(osDBName.c_str(), TRUE, NULL);
CPLSetThreadLocalConfigOption("SQLITE_LIST_ALL_TABLES", osOldVal.c_str());
}
else
{
/* Check that the existing SRS is consistent with the one of the new */
/* data to be inserted */
osSQL.Printf("SELECT srid FROM geometry_columns WHERE f_table_name = '%s'",
osMetatadataLayer.c_str());
hLyr = OGR_DS_ExecuteSQL(hDS, osSQL.c_str(), NULL, NULL);
if (hLyr)
{
int nExistingSRID = -1;
OGRFeatureH hFeat = OGR_L_GetNextFeature(hLyr);
if (hFeat)
{
nExistingSRID = OGR_F_GetFieldAsInteger(hFeat, 0);
OGR_F_Destroy(hFeat);
}
OGR_DS_ReleaseResultSet(hDS, hLyr);
if (nExistingSRID != nSRSId)
{
if (bWipeExistingData)
{
osSQL.Printf("UPDATE geometry_columns SET srid = %d "
"WHERE f_table_name = \"%s\"",
nSRSId, osMetatadataLayer.c_str());
OGR_DS_ExecuteSQL(hDS, osSQL.c_str(), NULL, NULL);
/* Re-open the DB to take into account the change of SRS */
OGRReleaseDataSource(hDS);
CPLSetThreadLocalConfigOption("SQLITE_LIST_ALL_TABLES", "TRUE");
//.........这里部分代码省略.........
示例9: RasterliteCreateCopy
//.........这里部分代码省略.........
{
if (bExists)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Database already exists. Explicit table name must be specified");
return NULL;
}
osTableName = CPLGetBasename(osDBName.c_str());
}
CPLString osRasterLayer;
osRasterLayer.Printf("%s_rasters", osTableName.c_str());
CPLString osMetatadataLayer;
osMetatadataLayer.Printf("%s_metadata", osTableName.c_str());
/* -------------------------------------------------------------------- */
/* Create or open the SQLite DB */
/* -------------------------------------------------------------------- */
if (OGRGetDriverCount() == 0)
OGRRegisterAll();
OGRSFDriverH hSQLiteDriver = OGRGetDriverByName("SQLite");
if (hSQLiteDriver == NULL)
{
CPLError(CE_Failure, CPLE_AppDefined, "Cannot load OGR SQLite driver");
return NULL;
}
OGRDataSourceH hDS;
CPLString osOldVal =
CPLGetConfigOption("SQLITE_LIST_ALL_TABLES", "FALSE");
CPLSetThreadLocalConfigOption("SQLITE_LIST_ALL_TABLES", "TRUE");
if (!bExists)
{
char** papszOGROptions = CSLAddString(NULL, "SPATIALITE=YES");
hDS = OGR_Dr_CreateDataSource(hSQLiteDriver,
osDBName.c_str(), papszOGROptions);
CSLDestroy(papszOGROptions);
}
else
{
hDS = OGROpen(osDBName.c_str(), TRUE, NULL);
}
CPLSetThreadLocalConfigOption("SQLITE_LIST_ALL_TABLES", osOldVal.c_str());
if (hDS == NULL)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot load or create SQLite database");
return NULL;
}
CPLString osSQL;
/* -------------------------------------------------------------------- */
/* Get the SRID for the SRS */
/* -------------------------------------------------------------------- */
int nSRSId = RasterliteInsertSRID(hDS, poSrcDS->GetProjectionRef());
/* -------------------------------------------------------------------- */
/* Create or wipe existing tables */
/* -------------------------------------------------------------------- */
int bWipeExistingData =
示例10: CPLAssert
bool OGRVRTDataSource::Initialize( CPLXMLNode *psTreeIn, const char *pszNewName,
int bUpdate )
{
CPLAssert(nLayers == 0);
AddForbiddenNames(pszNewName);
psTree = psTreeIn;
// Set name, and capture the directory path so we can use it
// for relative datasources.
CPLString osVRTDirectory = CPLGetPath(pszNewName);
pszName = CPLStrdup(pszNewName);
// Look for the OGRVRTDataSource node, it might be after an <xml> node.
CPLXMLNode *psVRTDSXML = CPLGetXMLNode(psTree, "=OGRVRTDataSource");
if( psVRTDSXML == nullptr )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Did not find the <OGRVRTDataSource> node in the root of the "
"document, this is not really an OGR VRT.");
return false;
}
// Determine if we must proxy layers.
const int nOGRVRTLayerCount = CountOGRVRTLayers(psVRTDSXML);
const int nMaxSimultaneouslyOpened =
std::max(atoi(CPLGetConfigOption("OGR_VRT_MAX_OPENED", "100")), 1);
if( nOGRVRTLayerCount > nMaxSimultaneouslyOpened )
poLayerPool = new OGRLayerPool(nMaxSimultaneouslyOpened);
// Apply any dataset level metadata.
oMDMD.XMLInit(psVRTDSXML, TRUE);
// Look for layers.
for( CPLXMLNode *psLTree = psVRTDSXML->psChild; psLTree != nullptr;
psLTree = psLTree->psNext )
{
if( psLTree->eType != CXT_Element )
continue;
// Create the layer object.
OGRLayer *poLayer = InstantiateLayer(psLTree, osVRTDirectory, bUpdate);
if( poLayer == nullptr )
continue;
// Add layer to data source layer list.
nLayers++;
papoLayers = static_cast<OGRLayer **>(
CPLRealloc(papoLayers, sizeof(OGRLayer *) * nLayers));
papoLayers[nLayers - 1] = poLayer;
paeLayerType = static_cast<OGRLayerType *>(
CPLRealloc(paeLayerType, sizeof(int) * nLayers));
if( poLayerPool != nullptr && EQUAL(psLTree->pszValue, "OGRVRTLayer") )
{
paeLayerType[nLayers - 1] = OGR_VRT_PROXIED_LAYER;
}
else if( EQUAL(psLTree->pszValue, "OGRVRTLayer") )
{
paeLayerType[nLayers - 1] = OGR_VRT_LAYER;
}
else
{
paeLayerType[nLayers - 1] = OGR_VRT_OTHER_LAYER;
}
}
return true;
}
示例11: while
OGRDataSource *OGRVRTDriver::Open( const char * pszFilename,
int bUpdate )
{
OGRVRTDataSource *poDS;
char *pszXML = NULL;
/* -------------------------------------------------------------------- */
/* Are we being passed the XML definition directly? */
/* Skip any leading spaces/blanks. */
/* -------------------------------------------------------------------- */
const char *pszTestXML = pszFilename;
while( *pszTestXML != '\0' && isspace( (unsigned char)*pszTestXML ) )
pszTestXML++;
if( EQUALN(pszTestXML,"<OGRVRTDataSource>",18) )
{
pszXML = CPLStrdup(pszTestXML);
}
/* -------------------------------------------------------------------- */
/* Open file and check if it contains appropriate XML. */
/* -------------------------------------------------------------------- */
else
{
VSILFILE *fp;
char achHeader[512];
fp = VSIFOpenL( pszFilename, "rb" );
if( fp == NULL )
return NULL;
memset( achHeader, 0, sizeof(achHeader) );
VSIFReadL( achHeader, 1, sizeof(achHeader)-1, fp );
if( strstr(achHeader,"<OGRVRTDataSource") == NULL )
{
VSIFCloseL( fp );
return NULL;
}
VSIStatBufL sStatBuf;
if ( VSIStatL( pszFilename, &sStatBuf ) != 0 ||
sStatBuf.st_size > 1024 * 1024 )
{
CPLDebug( "VRT", "Unreasonable long file, not likely really VRT" );
VSIFCloseL( fp );
return NULL;
}
/* -------------------------------------------------------------------- */
/* It is the right file, now load the full XML definition. */
/* -------------------------------------------------------------------- */
int nLen = (int) sStatBuf.st_size;
VSIFSeekL( fp, 0, SEEK_SET );
pszXML = (char *) VSIMalloc(nLen+1);
if (pszXML == NULL)
{
VSIFCloseL( fp );
return NULL;
}
pszXML[nLen] = '\0';
if( ((int) VSIFReadL( pszXML, 1, nLen, fp )) != nLen )
{
CPLFree( pszXML );
VSIFCloseL( fp );
return NULL;
}
VSIFCloseL( fp );
}
/* -------------------------------------------------------------------- */
/* Parse the XML. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psTree = CPLParseXMLString( pszXML );
if( psTree == NULL )
{
CPLFree( pszXML );
return NULL;
}
/* -------------------------------------------------------------------- */
/* XML Validation. */
/* -------------------------------------------------------------------- */
if( CSLTestBoolean(CPLGetConfigOption("GDAL_XML_VALIDATION", "YES")) )
{
const char* pszXSD = CPLFindFile( "gdal", "ogrvrt.xsd" );
if( pszXSD != NULL )
{
std::vector<CPLString> aosErrors;
CPLPushErrorHandlerEx(OGRVRTErrorHandler, &aosErrors);
int bRet = CPLValidateXML(pszXML, pszXSD, NULL);
CPLPopErrorHandler();
if( !bRet )
{
if( aosErrors.size() > 0 &&
//.........这里部分代码省略.........
示例12: CPLGetConfigOption
int OGRMDBJavaEnv::Init()
{
if (jvm_static == NULL)
{
JavaVM* vmBuf[1];
jsize nVMs;
/* Are we already called from Java ? */
if (JNI_GetCreatedJavaVMs(vmBuf, 1, &nVMs) == JNI_OK && nVMs == 1)
{
jvm = vmBuf[0];
if (jvm->GetEnv((void **)&env, JNI_VERSION_1_2) == JNI_OK)
{
bCalledFromJava = TRUE;
}
else
{
jvm = NULL;
env = NULL;
}
}
else
{
JavaVMInitArgs args;
JavaVMOption options[1];
args.version = JNI_VERSION_1_2;
const char* pszClassPath = CPLGetConfigOption("CLASSPATH", NULL);
CPLString osClassPathOption;
if (pszClassPath)
{
args.nOptions = 1;
osClassPathOption.Printf("-Djava.class.path=%s", pszClassPath);
options[0].optionString = (char*) osClassPathOption.c_str();
args.options = options;
}
else
args.nOptions = 0;
args.ignoreUnrecognized = JNI_FALSE;
int ret = JNI_CreateJavaVM(&jvm, (void **)&env, &args);
if (ret != 0 || jvm == NULL || env == NULL)
{
CPLError(CE_Failure, CPLE_AppDefined, "JNI_CreateJavaVM failed (%d)", ret);
return FALSE;
}
jvm_static = jvm;
env_static = env;
}
}
else
{
jvm = jvm_static;
env = env_static;
}
CHECK(byteArray_class, env->FindClass("[B"));
CHECK(file_class, env->FindClass("java/io/File"));
CHECK(file_constructor, env->GetMethodID(file_class, "<init>", "(Ljava/lang/String;)V"));
CHECK(database_class, env->FindClass("com/healthmarketscience/jackcess/Database"));
CHECK(database_open, env->GetStaticMethodID(database_class, "open", "(Ljava/io/File;Z)Lcom/healthmarketscience/jackcess/Database;"));
CHECK(database_close, env->GetMethodID(database_class, "close", "()V"));
CHECK(database_getTableNames, env->GetMethodID(database_class, "getTableNames", "()Ljava/util/Set;"));
CHECK(database_getTable, env->GetMethodID(database_class, "getTable", "(Ljava/lang/String;)Lcom/healthmarketscience/jackcess/Table;"));
CHECK(table_class, env->FindClass("com/healthmarketscience/jackcess/Table"));
CHECK(table_getColumns, env->GetMethodID(table_class, "getColumns", "()Ljava/util/List;"));
CHECK(table_iterator, env->GetMethodID(table_class, "iterator", "()Ljava/util/Iterator;"));
CHECK(table_getRowCount, env->GetMethodID(table_class, "getRowCount", "()I"));
CHECK(column_class, env->FindClass("com/healthmarketscience/jackcess/Column"));
CHECK(column_getName, env->GetMethodID(column_class, "getName", "()Ljava/lang/String;"));
CHECK(column_getType, env->GetMethodID(column_class, "getType", "()Lcom/healthmarketscience/jackcess/DataType;"));
CHECK(column_getLength, env->GetMethodID(column_class, "getLength", "()S"));
CHECK(column_isVariableLength, env->GetMethodID(column_class, "isVariableLength", "()Z"));
CHECK(datatype_class, env->FindClass("com/healthmarketscience/jackcess/DataType"));
CHECK(datatype_getValue, env->GetMethodID(datatype_class, "getValue", "()B"));
CHECK(list_class, env->FindClass("java/util/List"));
CHECK(list_iterator, env->GetMethodID(list_class, "iterator", "()Ljava/util/Iterator;"));
CHECK(set_class, env->FindClass("java/util/Set"));
CHECK(set_iterator, env->GetMethodID(set_class, "iterator", "()Ljava/util/Iterator;"));
CHECK(map_class, env->FindClass("java/util/Map"));
CHECK(map_get, env->GetMethodID(map_class, "get", "(Ljava/lang/Object;)Ljava/lang/Object;"));
CHECK(iterator_class, env->FindClass("java/util/Iterator"));
CHECK(iterator_hasNext, env->GetMethodID(iterator_class, "hasNext", "()Z"));
CHECK(iterator_next, env->GetMethodID(iterator_class, "next", "()Ljava/lang/Object;"));
CHECK(object_class, env->FindClass("java/lang/Object"));
CHECK(object_toString, env->GetMethodID(object_class, "toString", "()Ljava/lang/String;"));
CHECK(object_getClass, env->GetMethodID(object_class, "getClass", "()Ljava/lang/Class;"));
CHECK(boolean_class, env->FindClass("java/lang/Boolean"));
CHECK(boolean_booleanValue, env->GetMethodID(boolean_class, "booleanValue", "()Z"));
//.........这里部分代码省略.........
示例13: CPLAssert
int OGRGeomediaDataSource::Open( const char * pszNewName, int bUpdate,
CPL_UNUSED int bTestOpen )
{
CPLAssert( nLayers == 0 );
/* -------------------------------------------------------------------- */
/* If this is the name of an MDB file, then construct the */
/* appropriate connection string. Otherwise clip of GEOMEDIA: to */
/* get the DSN. */
/* */
/* -------------------------------------------------------------------- */
char *pszDSN = NULL;
if( STARTS_WITH_CI(pszNewName, "GEOMEDIA:") )
pszDSN = CPLStrdup( pszNewName + 9 );
else
{
const char *pszDSNStringTemplate = NULL;
pszDSNStringTemplate = CPLGetConfigOption( "GEOMEDIA_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb);DBQ=%s");
if (!CheckDSNStringTemplate(pszDSNStringTemplate))
{
CPLError( CE_Failure, CPLE_AppDefined,
"Illegal value for GEOMEDIA_DRIVER_TEMPLATE option");
return FALSE;
}
pszDSN = (char *) CPLMalloc(strlen(pszNewName)+strlen(pszDSNStringTemplate)+100);
/* coverity[tainted_string] */
snprintf( pszDSN,
strlen(pszNewName)+strlen(pszDSNStringTemplate)+100,
pszDSNStringTemplate, pszNewName );
}
/* -------------------------------------------------------------------- */
/* Initialize based on the DSN. */
/* -------------------------------------------------------------------- */
CPLDebug( "Geomedia", "EstablishSession(%s)", pszDSN );
if( !oSession.EstablishSession( pszDSN, NULL, NULL ) )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Unable to initialize ODBC connection to DSN for %s,\n"
"%s", pszDSN, oSession.GetLastError() );
CPLFree( pszDSN );
return FALSE;
}
CPLFree( pszDSN );
pszName = CPLStrdup( pszNewName );
bDSUpdate = bUpdate;
/* -------------------------------------------------------------------- */
/* Collect list of tables and their supporting info from */
/* GAliasTable. */
/* -------------------------------------------------------------------- */
CPLString osGFeaturesTable = GetTableNameFromType("INGRFeatures");
if (osGFeaturesTable.size() == 0)
return FALSE;
CPLString osGeometryProperties = GetTableNameFromType("INGRGeometryProperties");
CPLString osGCoordSystemTable = GetTableNameFromType("GCoordSystemTable");
std::vector<char **> apapszGeomColumns;
{
CPLODBCStatement oStmt( &oSession );
oStmt.Appendf( "SELECT FeatureName, PrimaryGeometryFieldName FROM %s", osGFeaturesTable.c_str() );
if( !oStmt.ExecuteSQL() )
{
CPLDebug( "GEOMEDIA",
"SELECT on %s fails, perhaps not a geomedia geodatabase?\n%s",
osGFeaturesTable.c_str(),
oSession.GetLastError() );
return FALSE;
}
while( oStmt.Fetch() )
{
int i, iNew = static_cast<int>(apapszGeomColumns.size());
char **papszRecord = NULL;
for( i = 0; i < 2; i++ )
papszRecord = CSLAddString( papszRecord,
oStmt.GetColData(i) );
apapszGeomColumns.resize(iNew+1);
apapszGeomColumns[iNew] = papszRecord;
}
}
std::vector<OGRSpatialReference*> apoSRS;
if (osGeometryProperties.size() != 0 && osGCoordSystemTable.size() != 0)
{
std::vector<CPLString> aosGUID;
{
CPLODBCStatement oStmt( &oSession );
oStmt.Appendf( "SELECT GCoordSystemGUID FROM %s", osGeometryProperties.c_str() );
if( !oStmt.ExecuteSQL() )
{
CPLDebug( "GEOMEDIA",
"SELECT on %s fails, perhaps not a geomedia geodatabase?\n%s",
//.........这里部分代码省略.........
示例14: OGRSQLiteExecuteSQL
OGRLayer * OGRSQLiteExecuteSQL( GDALDataset* poDS,
const char *pszStatement,
OGRGeometry *poSpatialFilter,
CPL_UNUSED const char *pszDialect )
{
char* pszTmpDBName = (char*) CPLMalloc(256);
sprintf(pszTmpDBName, "/vsimem/ogr2sqlite/temp_%p.db", pszTmpDBName);
OGRSQLiteDataSource* poSQLiteDS = NULL;
int nRet;
int bSpatialiteDB = FALSE;
CPLString osOldVal;
const char* pszOldVal = CPLGetConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", NULL);
if( pszOldVal != NULL )
{
osOldVal = pszOldVal;
pszOldVal = osOldVal.c_str();
}
/* -------------------------------------------------------------------- */
/* Create in-memory sqlite/spatialite DB */
/* -------------------------------------------------------------------- */
#ifdef HAVE_SPATIALITE
/* -------------------------------------------------------------------- */
/* Creating an empty spatialite DB (with spatial_ref_sys populated */
/* has a non-neglectable cost. So at the first attempt, let's make */
/* one and cache it for later use. */
/* -------------------------------------------------------------------- */
#if 1
static vsi_l_offset nEmptyDBSize = 0;
static GByte* pabyEmptyDB = NULL;
{
static CPLMutex* hMutex = NULL;
CPLMutexHolder oMutexHolder(&hMutex);
static int bTried = FALSE;
if( !bTried &&
CSLTestBoolean(CPLGetConfigOption("OGR_SQLITE_DIALECT_USE_SPATIALITE", "YES")) )
{
bTried = TRUE;
char* pszCachedFilename = (char*) CPLMalloc(256);
sprintf(pszCachedFilename, "/vsimem/ogr2sqlite/reference_%p.db",pszCachedFilename);
char** papszOptions = CSLAddString(NULL, "SPATIALITE=YES");
OGRSQLiteDataSource* poCachedDS = new OGRSQLiteDataSource();
nRet = poCachedDS->Create( pszCachedFilename, papszOptions );
CSLDestroy(papszOptions);
papszOptions = NULL;
delete poCachedDS;
if( nRet )
/* Note: the reference file keeps the ownership of the data, so that */
/* it gets released with VSICleanupFileManager() */
pabyEmptyDB = VSIGetMemFileBuffer( pszCachedFilename, &nEmptyDBSize, FALSE );
CPLFree( pszCachedFilename );
}
}
/* The following configuration option is useful mostly for debugging/testing */
if( pabyEmptyDB != NULL && CSLTestBoolean(CPLGetConfigOption("OGR_SQLITE_DIALECT_USE_SPATIALITE", "YES")) )
{
GByte* pabyEmptyDBClone = (GByte*)VSIMalloc(nEmptyDBSize);
if( pabyEmptyDBClone == NULL )
{
CPLFree(pszTmpDBName);
return NULL;
}
memcpy(pabyEmptyDBClone, pabyEmptyDB, nEmptyDBSize);
VSIFCloseL(VSIFileFromMemBuffer( pszTmpDBName, pabyEmptyDBClone, nEmptyDBSize, TRUE ));
poSQLiteDS = new OGRSQLiteDataSource();
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", "NO");
nRet = poSQLiteDS->Open( pszTmpDBName, TRUE, NULL );
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", pszOldVal);
if( !nRet )
{
/* should not happen really ! */
delete poSQLiteDS;
VSIUnlink(pszTmpDBName);
CPLFree(pszTmpDBName);
return NULL;
}
bSpatialiteDB = TRUE;
}
#else
/* No caching version */
poSQLiteDS = new OGRSQLiteDataSource();
char** papszOptions = CSLAddString(NULL, "SPATIALITE=YES");
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", "NO");
nRet = poSQLiteDS->Create( pszTmpDBName, papszOptions );
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", pszOldVal);
CSLDestroy(papszOptions);
papszOptions = NULL;
if( nRet )
{
bSpatialiteDB = TRUE;
}
#endif
else
//.........这里部分代码省略.........
示例15: CPLXMLSchemaResolveInclude
static
void CPLXMLSchemaResolveInclude( const char* pszMainSchemaLocation,
CPLXMLNode *psSchemaNode )
{
std::set<CPLString> osAlreadyIncluded;
bool bTryAgain;
do
{
CPLXMLNode *psLast = NULL;
bTryAgain = false;
CPLXMLNode *psThis = psSchemaNode->psChild;
for( ; psThis != NULL; psThis = psThis->psNext )
{
if( psThis->eType == CXT_Element &&
EQUAL(psThis->pszValue,"include") )
{
const char* pszSchemaLocation =
CPLGetXMLValue(psThis, "schemaLocation", NULL);
if( pszSchemaLocation != NULL &&
osAlreadyIncluded.count( pszSchemaLocation) == 0 )
{
osAlreadyIncluded.insert( pszSchemaLocation );
if( !STARTS_WITH(pszSchemaLocation, "http://") &&
!STARTS_WITH(pszSchemaLocation, "https://") &&
CPLIsFilenameRelative(pszSchemaLocation ) )
{
pszSchemaLocation = CPLFormFilename(
CPLGetPath(pszMainSchemaLocation), pszSchemaLocation, NULL );
}
CPLXMLNode *psIncludedXSDTree =
GMLParseXMLFile( pszSchemaLocation );
if( psIncludedXSDTree != NULL )
{
CPLStripXMLNamespace( psIncludedXSDTree, NULL, TRUE );
CPLXMLNode *psIncludedSchemaNode =
CPLGetXMLNode( psIncludedXSDTree, "=schema" );
if( psIncludedSchemaNode != NULL )
{
/* Substitute de <include> node by its content */
CPLXMLNode* psFirstChildElement =
CPLGetFirstChildNode(psIncludedSchemaNode);
if( psFirstChildElement != NULL )
{
CPLXMLNode* psCopy = CPLCloneXMLTree(psFirstChildElement);
if( psLast != NULL )
psLast->psNext = psCopy;
else
psSchemaNode->psChild = psCopy;
CPLXMLNode* psNext = psThis->psNext;
psThis->psNext = NULL;
CPLDestroyXMLNode(psThis);
psThis = CPLGetLastNode(psCopy);
psThis->psNext = psNext;
/* In case the included schema also contains */
/* includes */
bTryAgain = true;
}
}
CPLDestroyXMLNode( psIncludedXSDTree );
}
}
}
psLast = psThis;
}
} while( bTryAgain );
const char* pszSchemaOutputName =
CPLGetConfigOption("GML_SCHEMA_OUTPUT_NAME", NULL);
if( pszSchemaOutputName != NULL )
{
CPLSerializeXMLTreeToFile( psSchemaNode, pszSchemaOutputName );
}
}