本文整理汇总了C++中CPLString类的典型用法代码示例。如果您正苦于以下问题:C++ CPLString类的具体用法?C++ CPLString怎么用?C++ CPLString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CPLString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OGRSQLiteExecuteSQL
OGRLayer * OGRSQLiteExecuteSQL( OGRDataSource* poDS,
const char *pszStatement,
OGRGeometry *poSpatialFilter,
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 void* 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 usefull 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 );
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
//.........这里部分代码省略.........
示例2: osChangedSQL
int OGRGFTResultLayer::RunSQL()
{
CPLString osChangedSQL(osSQL);
int bHasSetLimit = FALSE;
OGRGFTTableLayer* poTableLayer = NULL;
OGRFeatureDefn* poTableDefn = NULL;
CPLString osTableId;
if (STARTS_WITH_CI(osSQL.c_str(), "SELECT"))
{
size_t nPosFROM = osSQL.ifind(" FROM ");
if (nPosFROM == std::string::npos)
{
CPLError(CE_Failure, CPLE_AppDefined, "RunSQL() failed. Missing FROM in SELECT");
return FALSE;
}
CPLString osReminder;
nPosFROM += 6;
osTableId = OGRGFTExtractTableID(osSQL.c_str() + nPosFROM, osReminder);
poTableLayer = (OGRGFTTableLayer*) poDS->GetLayerByName(osTableId);
if (poTableLayer != NULL)
poTableDefn = poTableLayer->GetLayerDefn();
if (poTableLayer != NULL &&
poTableLayer->GetTableId().size() &&
!EQUAL(osTableId, poTableLayer->GetTableId()))
{
osChangedSQL = osSQL;
osChangedSQL.resize(nPosFROM);
osChangedSQL += poTableLayer->GetTableId();
osChangedSQL += osReminder;
osSQL = osChangedSQL;
CPLDebug("GFT", "Patching table name (%s) to table id (%s)",
osTableId.c_str(), poTableLayer->GetTableId().c_str());
}
int nFeaturesToFetch = GetFeaturesToFetch();
if (osSQL.ifind(" OFFSET ") == std::string::npos &&
osSQL.ifind(" LIMIT ") == std::string::npos &&
nFeaturesToFetch > 0)
{
osChangedSQL += CPLSPrintf(" LIMIT %d", nFeaturesToFetch);
bHasSetLimit = TRUE;
}
}
else
{
bGotAllRows = bEOF = TRUE;
poFeatureDefn->SetGeomType( wkbNone );
}
CPLHTTPResult * psResult = poDS->RunSQL(osChangedSQL);
if (psResult == NULL)
return FALSE;
char* pszLine = (char*) psResult->pabyData;
if (pszLine == NULL ||
psResult->pszErrBuf != NULL)
{
CPLError(CE_Failure, CPLE_AppDefined, "RunSQL() failed");
CPLHTTPDestroyResult(psResult);
return FALSE;
}
if (STARTS_WITH_CI(osSQL.c_str(), "SELECT") ||
EQUAL(osSQL.c_str(), "SHOW TABLES") ||
STARTS_WITH_CI(osSQL.c_str(), "DESCRIBE"))
{
ParseCSVResponse(pszLine, aosRows);
if (aosRows.size() > 0)
{
char** papszTokens = OGRGFTCSVSplitLine(aosRows[0], ',');
for(int i=0;papszTokens && papszTokens[i];i++)
{
CPLString osLaunderedColName(LaunderColName(papszTokens[i]));
int iIndex = (poTableDefn) ? poTableDefn->GetFieldIndex(osLaunderedColName) : -1;
if (iIndex >= 0)
{
poFeatureDefn->AddFieldDefn(poTableDefn->GetFieldDefn(iIndex));
if (iIndex == poTableLayer->GetGeometryFieldIndex())
iGeometryField = i;
if (iIndex == poTableLayer->GetLatitudeFieldIndex())
iLatitudeField = i;
if (iIndex == poTableLayer->GetLongitudeFieldIndex())
iLongitudeField = i;
}
else
{
OGRFieldType eType = OFTString;
if (EQUAL(osLaunderedColName, "COUNT()"))
eType = OFTInteger;
OGRFieldDefn oFieldDefn(osLaunderedColName, eType);
poFeatureDefn->AddFieldDefn(&oFieldDefn);
}
}
CSLDestroy(papszTokens);
aosRows.erase(aosRows.begin());
}
//.........这里部分代码省略.........
示例3: CreateReader
VSIArchiveReader* VSIArchiveFilesystemHandler::OpenArchiveFile(const char* archiveFilename,
const char* fileInArchiveName)
{
VSIArchiveReader* poReader = CreateReader(archiveFilename);
if (poReader == NULL)
{
return NULL;
}
if (fileInArchiveName == NULL || strlen(fileInArchiveName) == 0)
{
if (poReader->GotoFirstFile() == FALSE)
{
delete(poReader);
return NULL;
}
/* Skip optionnal leading subdir */
CPLString osFileName = poReader->GetFileName();
const char* fileName = osFileName.c_str();
if (fileName[strlen(fileName)-1] == '/' || fileName[strlen(fileName)-1] == '\\')
{
if (poReader->GotoNextFile() == FALSE)
{
delete(poReader);
return NULL;
}
}
if (poReader->GotoNextFile())
{
CPLString msg;
msg.Printf("Support only 1 file in archive file %s when no explicit in-archive filename is specified",
archiveFilename);
const VSIArchiveContent* content = GetContentOfArchive(archiveFilename, poReader);
if (content)
{
int i;
msg += "\nYou could try one of the following :\n";
for(i=0;i<content->nEntries;i++)
{
msg += CPLString().Printf(" %s/%s/%s\n", GetPrefix(), archiveFilename, content->entries[i].fileName);
}
}
CPLError(CE_Failure, CPLE_NotSupported, "%s", msg.c_str());
delete(poReader);
return NULL;
}
}
else
{
const VSIArchiveEntry* archiveEntry = NULL;
if (FindFileInArchive(archiveFilename, fileInArchiveName, &archiveEntry) == FALSE ||
archiveEntry->bIsDir)
{
delete(poReader);
return NULL;
}
if (!poReader->GotoFileOffset(archiveEntry->file_pos))
{
delete poReader;
return NULL;
}
}
return poReader;
}
示例4: VSIFPrintfL
unsigned int ISIS2Dataset::WriteFormatting(VSILFILE *fpLabel, CPLString data)
{
int ret = VSIFPrintfL(fpLabel,"%s\n", data.c_str());
return ret;
}
示例5: CPLError
GDALDataset *ISIS2Dataset::Create(const char* pszFilename,
int nXSize, int nYSize, int nBands,
GDALDataType eType, char** papszParmList) {
/* Verify settings. In Isis 2 core pixel values can be represented in
* three different ways : 1, 2 4, or 8 Bytes */
if( eType != GDT_Byte && eType != GDT_Int16 && eType != GDT_Float32
&& eType != GDT_UInt16 && eType != GDT_Float64 ){
CPLError(CE_Failure, CPLE_AppDefined,
"The ISIS2 driver does not supporting creating files of type %s.",
GDALGetDataTypeName( eType ) );
return NULL;
}
/* (SAMPLE, LINE, BAND) - Band Sequential (BSQ) - default choice
(SAMPLE, BAND, LINE) - Band Interleaved by Line (BIL)
(BAND, SAMPLE, LINE) - Band Interleaved by Pixel (BIP) */
const char *pszInterleaving = "(SAMPLE,LINE,BAND)";
const char *pszInterleavingParam = CSLFetchNameValue( papszParmList, "INTERLEAVE" );
if ( pszInterleavingParam ) {
if ( EQUALN( pszInterleavingParam, "bip", 3 ) )
pszInterleaving = "(BAND,SAMPLE,LINE)";
else if ( EQUALN( pszInterleavingParam, "bil", 3 ) )
pszInterleaving = "(SAMPLE,BAND,LINE)";
else
pszInterleaving = "(SAMPLE,LINE,BAND)";
}
/* default labeling method is attached */
bool bAttachedLabelingMethod = true;
/* check if labeling method is set : check the all three first chars */
const char *pszLabelingMethod = CSLFetchNameValue( papszParmList, "LABELING_METHOD" );
if ( pszLabelingMethod ){
if ( EQUALN( pszLabelingMethod, "detached", 3 ) ){
bAttachedLabelingMethod = false;
}
if ( EQUALN( pszLabelingMethod, "attached", 3 ) ){
bAttachedLabelingMethod = true;
}
}
/* set the label and data files */
CPLString osLabelFile, osRasterFile, osOutFile;
if( bAttachedLabelingMethod ) {
osLabelFile = "";
osRasterFile = pszFilename;
osOutFile = osRasterFile;
}
else
{
CPLString sExtension = "cub";
const char* pszExtension = CSLFetchNameValue( papszParmList, "IMAGE_EXTENSION" );
if( pszExtension ){
sExtension = pszExtension;
}
if( EQUAL(CPLGetExtension( pszFilename ), sExtension) )
{
CPLError( CE_Failure, CPLE_AppDefined,
"IMAGE_EXTENSION (%s) cannot match LABEL file extension.",
sExtension.c_str() );
return NULL;
}
osLabelFile = pszFilename;
osRasterFile = CPLResetExtension( osLabelFile, sExtension );
osOutFile = osLabelFile;
}
const char *pszObject = CSLFetchNameValue( papszParmList, "OBJECT" );
CPLString sObject = "QUBE"; // default choice
if (pszObject) {
if ( EQUAL( pszObject, "IMAGE") ){
sObject = "IMAGE";
}
if ( EQUAL( pszObject, "SPECTRAL_QUBE")){
sObject = "SPECTRAL_QUBE";
}
}
GUIntBig iRecords = ISIS2Dataset::RecordSizeCalculation(nXSize, nYSize, nBands, eType);
GUIntBig iLabelRecords(2);
CPLDebug("ISIS2","irecord = %i",static_cast<int>(iRecords));
if( bAttachedLabelingMethod )
{
ISIS2Dataset::WriteLabel(osRasterFile, "", sObject, nXSize, nYSize, nBands, eType, iRecords, pszInterleaving, iLabelRecords, true);
}
else
{
ISIS2Dataset::WriteLabel(osLabelFile, osRasterFile, sObject, nXSize, nYSize, nBands, eType, iRecords, pszInterleaving, iLabelRecords);
}
if( !ISIS2Dataset::WriteRaster(osRasterFile, bAttachedLabelingMethod,
iRecords, iLabelRecords, eType,
pszInterleaving) )
return NULL;
return (GDALDataset *) GDALOpen( osOutFile, GA_Update );
//.........这里部分代码省略.........
示例6: CPLStrdup
char *swq_expr_node::Unparse( swq_field_list *field_list, char chColumnQuote )
{
CPLString osExpr;
/* -------------------------------------------------------------------- */
/* Handle constants. */
/* -------------------------------------------------------------------- */
if( eNodeType == SNT_CONSTANT )
{
if( is_null )
return CPLStrdup("NULL");
if( field_type == SWQ_INTEGER || field_type == SWQ_INTEGER64 ||
field_type == SWQ_BOOLEAN )
osExpr.Printf( CPL_FRMT_GIB, int_value );
else if( field_type == SWQ_FLOAT )
{
osExpr.Printf( "%.15g", float_value );
// Make sure this is interpreted as a floating point value
// and not as an integer later.
if( strchr(osExpr, '.') == nullptr && strchr(osExpr, 'e') == nullptr &&
strchr(osExpr, 'E') == nullptr )
osExpr += '.';
}
else
{
osExpr = Quote( string_value );
}
return CPLStrdup(osExpr);
}
/* -------------------------------------------------------------------- */
/* Handle columns. */
/* -------------------------------------------------------------------- */
if( eNodeType == SNT_COLUMN )
{
if( field_list == nullptr )
{
if( table_name )
osExpr.Printf(
"%s.%s",
QuoteIfNecessary(table_name, chColumnQuote).c_str(),
QuoteIfNecessary(string_value, chColumnQuote).c_str() );
else
osExpr.Printf(
"%s",
QuoteIfNecessary(string_value, chColumnQuote).c_str() );
}
else if( field_index != -1
&& table_index < field_list->table_count
&& table_index > 0 )
{
// We deliberately browse through the list starting from the end
// This is for the case where the FID column exists both as
// FID and then real_fid_name. We want real_fid_name to be used
for( int i = field_list->count - 1; i >= 0; i-- )
{
if( field_list->table_ids[i] == table_index &&
field_list->ids[i] == field_index )
{
osExpr.Printf( "%s.%s",
QuoteIfNecessary(field_list->table_defs[table_index].table_name, chColumnQuote).c_str(),
QuoteIfNecessary(field_list->names[i], chColumnQuote).c_str() );
break;
}
}
}
else if( field_index != -1 )
{
// We deliberately browse through the list starting from the end
// This is for the case where the FID column exists both as
// FID and then real_fid_name. We want real_fid_name to be used
for( int i = field_list->count - 1; i >= 0; i-- )
{
if( field_list->table_ids[i] == table_index &&
field_list->ids[i] == field_index )
{
osExpr.Printf( "%s", QuoteIfNecessary(field_list->names[i], chColumnQuote).c_str() );
break;
}
}
}
if( osExpr.empty() )
{
return CPLStrdup(CPLSPrintf("%c%c", chColumnQuote, chColumnQuote));
}
// The string is just alphanum and not a reserved SQL keyword,
// no needs to quote and escape.
return CPLStrdup(osExpr.c_str());
}
/* -------------------------------------------------------------------- */
/* Operation - start by unparsing all the subexpressions. */
/* -------------------------------------------------------------------- */
std::vector<char*> apszSubExpr;
//.........这里部分代码省略.........
示例7: main
//.........这里部分代码省略.........
exit( 1 );
/* -------------------------------------------------------------------- */
/* Setup coordinate transformation, if required */
/* -------------------------------------------------------------------- */
OGRSpatialReferenceH hSrcSRS = NULL, hTrgSRS = NULL;
OGRCoordinateTransformationH hCT = NULL;
if( pszSourceSRS != NULL && !EQUAL(pszSourceSRS,"-geoloc") )
{
hSrcSRS = OSRNewSpatialReference( pszSourceSRS );
hTrgSRS = OSRNewSpatialReference( GDALGetProjectionRef( hSrcDS ) );
hCT = OCTNewCoordinateTransformation( hSrcSRS, hTrgSRS );
if( hCT == NULL )
exit( 1 );
}
/* -------------------------------------------------------------------- */
/* If no bands were requested, we will query them all. */
/* -------------------------------------------------------------------- */
if( anBandList.size() == 0 )
{
for( i = 0; i < GDALGetRasterCount( hSrcDS ); i++ )
anBandList.push_back( i+1 );
}
/* -------------------------------------------------------------------- */
/* Turn the location into a pixel and line location. */
/* -------------------------------------------------------------------- */
int inputAvailable = 1;
double dfGeoX;
double dfGeoY;
CPLString osXML;
if( pszLocX == NULL && pszLocY == NULL )
{
if (fscanf(stdin, "%lf %lf", &dfGeoX, &dfGeoY) != 2)
{
inputAvailable = 0;
}
}
else
{
dfGeoX = CPLAtof(pszLocX);
dfGeoY = CPLAtof(pszLocY);
}
while (inputAvailable)
{
int iPixel, iLine;
if (hCT)
{
if( !OCTTransform( hCT, 1, &dfGeoX, &dfGeoY, NULL ) )
exit( 1 );
}
if( pszSourceSRS != NULL )
{
double adfGeoTransform[6], adfInvGeoTransform[6];
if( GDALGetGeoTransform( hSrcDS, adfGeoTransform ) != CE_None )
exit( 1 );
GDALInvGeoTransform( adfGeoTransform, adfInvGeoTransform );
示例8: oBox
int GDALJP2Metadata::ReadBoxes( VSILFILE *fpVSIL )
{
GDALJP2Box oBox( fpVSIL );
int iBox = 0;
oBox.ReadFirst();
while( strlen(oBox.GetType()) > 0 )
{
/* -------------------------------------------------------------------- */
/* Collect geotiff box. */
/* -------------------------------------------------------------------- */
if( EQUAL(oBox.GetType(),"uuid")
&& memcmp( oBox.GetUUID(), msi_uuid2, 16 ) == 0 )
{
nGeoTIFFSize = (int) oBox.GetDataLength();
pabyGeoTIFFData = oBox.ReadBoxData();
}
/* -------------------------------------------------------------------- */
/* Collect MSIG box. */
/* -------------------------------------------------------------------- */
if( EQUAL(oBox.GetType(),"uuid")
&& memcmp( oBox.GetUUID(), msig_uuid, 16 ) == 0 )
{
nMSIGSize = (int) oBox.GetDataLength();
pabyMSIGData = oBox.ReadBoxData();
if( nMSIGSize < 70
|| memcmp( pabyMSIGData, "MSIG/", 5 ) != 0 )
{
CPLFree( pabyMSIGData );
pabyMSIGData = NULL;
nMSIGSize = 0;
}
}
/* -------------------------------------------------------------------- */
/* Process asoc box looking for Labelled GML data. */
/* -------------------------------------------------------------------- */
if( EQUAL(oBox.GetType(),"asoc") )
{
GDALJP2Box oSubBox( fpVSIL );
oSubBox.ReadFirstChild( &oBox );
if( EQUAL(oSubBox.GetType(),"lbl ") )
{
char *pszLabel = (char *) oSubBox.ReadBoxData();
if( EQUAL(pszLabel,"gml.data") )
{
CollectGMLData( &oBox );
}
CPLFree( pszLabel );
}
}
/* -------------------------------------------------------------------- */
/* Process simple xml boxes. */
/* -------------------------------------------------------------------- */
if( EQUAL(oBox.GetType(),"xml ") )
{
CPLString osBoxName;
char *pszXML = (char *) oBox.ReadBoxData();
osBoxName.Printf( "BOX_%d", iBox++ );
papszGMLMetadata = CSLSetNameValue( papszGMLMetadata,
osBoxName, pszXML );
CPLFree( pszXML );
}
/* -------------------------------------------------------------------- */
/* Check for a resd box in jp2h. */
/* -------------------------------------------------------------------- */
if( EQUAL(oBox.GetType(),"jp2h") )
{
GDALJP2Box oSubBox( fpVSIL );
for( oSubBox.ReadFirstChild( &oBox );
strlen(oSubBox.GetType()) > 0;
oSubBox.ReadNextChild( &oBox ) )
{
if( EQUAL(oSubBox.GetType(),"res ") )
{
GDALJP2Box oResBox( fpVSIL );
oResBox.ReadFirstChild( &oSubBox );
// we will use either the resd or resc box, which ever
// happens to be first. Should we prefer resd?
if( oResBox.GetDataLength() == 10 )
{
unsigned char *pabyResData = oResBox.ReadBoxData();
int nVertNum, nVertDen, nVertExp;
int nHorzNum, nHorzDen, nHorzExp;
nVertNum = pabyResData[0] * 256 + pabyResData[1];
nVertDen = pabyResData[2] * 256 + pabyResData[3];
nHorzNum = pabyResData[4] * 256 + pabyResData[5];
//.........这里部分代码省略.........
示例9: VSIFOpenL
//.........这里部分代码省略.........
adfYVector[0] = adfGeoTransform[4];
adfYVector[1] = adfGeoTransform[5];
if( bNeedAxisFlip
&& CSLTestBoolean( CPLGetConfigOption( "GDAL_IGNORE_AXIS_ORIENTATION",
"FALSE" ) ) )
{
bNeedAxisFlip = FALSE;
CPLDebug( "GMLJP2", "Supressed axis flipping on write based on GDAL_IGNORE_AXIS_ORIENTATION." );
}
if( bNeedAxisFlip )
{
double dfTemp;
CPLDebug( "GMLJP2", "Flipping GML coverage axis order." );
dfTemp = adfOrigin[0];
adfOrigin[0] = adfOrigin[1];
adfOrigin[1] = dfTemp;
dfTemp = adfXVector[0];
adfXVector[0] = adfXVector[1];
adfXVector[1] = dfTemp;
dfTemp = adfYVector[0];
adfYVector[0] = adfYVector[1];
adfYVector[1] = dfTemp;
}
/* -------------------------------------------------------------------- */
/* For now we hardcode for a minimal instance format. */
/* -------------------------------------------------------------------- */
CPLString osDoc;
osDoc.Printf(
"<gml:FeatureCollection\n"
" xmlns:gml=\"http://www.opengis.net/gml\"\n"
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
" xsi:schemaLocation=\"http://www.opengeospatial.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/gmlJP2Profile/1.0.0/gmlJP2Profile.xsd\">\n"
" <gml:boundedBy>\n"
" <gml:Null>withheld</gml:Null>\n"
" </gml:boundedBy>\n"
" <gml:featureMember>\n"
" <gml:FeatureCollection>\n"
" <gml:featureMember>\n"
" <gml:RectifiedGridCoverage dimension=\"2\" gml:id=\"RGC0001\">\n"
" <gml:rectifiedGridDomain>\n"
" <gml:RectifiedGrid dimension=\"2\">\n"
" <gml:limits>\n"
" <gml:GridEnvelope>\n"
" <gml:low>0 0</gml:low>\n"
" <gml:high>%d %d</gml:high>\n"
" </gml:GridEnvelope>\n"
" </gml:limits>\n"
" <gml:axisName>x</gml:axisName>\n"
" <gml:axisName>y</gml:axisName>\n"
" <gml:origin>\n"
" <gml:Point gml:id=\"P0001\" srsName=\"%s\">\n"
" <gml:pos>%.15g %.15g</gml:pos>\n"
" </gml:Point>\n"
" </gml:origin>\n"
" <gml:offsetVector srsName=\"%s\">%.15g %.15g</gml:offsetVector>\n"
" <gml:offsetVector srsName=\"%s\">%.15g %.15g</gml:offsetVector>\n"
" </gml:RectifiedGrid>\n"
" </gml:rectifiedGridDomain>\n"
示例10: CPLError
//.........这里部分代码省略.........
bool bPointLayer = FALSE; /* Initialize four layers for the different geometry types */
bool bCurveLayer = FALSE;
bool bPolyLayer = FALSE;
bool bTextLayer = FALSE;
poPolyHeaders = new S2I();
poPointHeaders = new S2I();
poCurveHeaders = new S2I();
poTextHeaders = new S2I();
LC_SBSn(&oSnradm, poFileadm, 0, nNumFeatures); /* Set FYBA search limits */
LC_InitNextBgr(poNextSerial);
/* Prebuilding simple features and extracting layer information. */
while (LC_NextBgr(poNextSerial,LC_FRAMGR)) {
/* Fetch next group information */
nName = LC_RxGr(poNextSerial, LES_OPTIMALT, &nNumLines, &nNumCoo, &nInfo);
S2S oHeaders;
S2S::iterator iHeaders;
int iH;
/* Extract all strings from group header. */
for (short i=1; i<=nNumLines; i++) {
char *pszLine = LC_GetGi(i); /* Get one header line */
if ((pszLine[0] == ':')||(pszLine[0] == '(')) continue; /* If we have a continued REF line, skip it. */
if (pszLine[0] == '!') continue; /* If we have a comment line, skip it. */
char *pszUTFLine = CPLRecode(pszLine, pszEncoding, CPL_ENC_UTF8); /* switch to UTF encoding here, if it is known. */
char *pszUTFLineIter = pszUTFLine;
while (pszUTFLineIter[0] == '.') pszUTFLineIter++; /* Skipping the dots at the beginning of a SOSI line */
char *pszPos = strstr(pszUTFLineIter, " "); /* Split header and value */
if (pszPos != NULL) {
CPLString osKey = CPLString(std::string(pszUTFLineIter,pszPos)); /* FIXME: clean instantiation of CPLString? */
CPLString osValue = CPLString(pszPos+1);
oHeaders[osKey]=osValue; /* Add to header map */
switch (nName) { /* Add to header list for the corresponding layer, if it is not */
case L_FLATE: { /* in there already */
if (poPolyHeaders->find(osKey) == poPolyHeaders->end()) {
iH = poPolyHeaders->size();
(*poPolyHeaders)[osKey] = iH;
}
break;
}
case L_KURVE: {
if (poCurveHeaders->find(osKey) == poCurveHeaders->end()) {
iH = poCurveHeaders->size();
(*poCurveHeaders)[osKey] = iH;
}
break;
}
case L_PUNKT: {
if (poPointHeaders->find(osKey) == poPointHeaders->end()) {
iH = poPointHeaders->size();
(*poPointHeaders)[osKey] = iH;
}
break;
}
case L_TEKST: {
if (poTextHeaders->find(osKey) == poTextHeaders->end()) {
iH = poTextHeaders->size();
(*poTextHeaders)[osKey] = iH;
}
break;
}
示例11: BlendMaskGenerator
static CPLErr
BlendMaskGenerator( int nXOff, int nYOff, int nXSize, int nYSize,
GByte *pabyPolyMask, float *pafValidityMask,
OGRGeometryH hPolygon, double dfBlendDist )
{
#ifndef HAVE_GEOS
CPLError( CE_Failure, CPLE_AppDefined,
"Blend distance support not available without the GEOS library.");
return CE_Failure;
#else /* HAVE_GEOS */
/* -------------------------------------------------------------------- */
/* Convert the polygon into a collection of lines so that we */
/* measure distance from the edge even on the inside. */
/* -------------------------------------------------------------------- */
OGRGeometry *poLines
= OGRGeometryFactory::forceToMultiLineString(
((OGRGeometry *) hPolygon)->clone() );
/* -------------------------------------------------------------------- */
/* Prepare a clipping polygon a bit bigger than the area of */
/* interest in the hopes of simplifying the cutline down to */
/* stuff that will be relavent for this area of interest. */
/* -------------------------------------------------------------------- */
CPLString osClipRectWKT;
osClipRectWKT.Printf( "POLYGON((%g %g,%g %g,%g %g,%g %g,%g %g))",
nXOff - (dfBlendDist+1),
nYOff - (dfBlendDist+1),
nXOff + nXSize + (dfBlendDist+1),
nYOff - (dfBlendDist+1),
nXOff + nXSize + (dfBlendDist+1),
nYOff + nYSize + (dfBlendDist+1),
nXOff - (dfBlendDist+1),
nYOff + nYSize + (dfBlendDist+1),
nXOff - (dfBlendDist+1),
nYOff - (dfBlendDist+1) );
OGRPolygon *poClipRect = NULL;
char *pszWKT = (char *) osClipRectWKT.c_str();
OGRGeometryFactory::createFromWkt( &pszWKT, NULL,
(OGRGeometry**) (&poClipRect) );
if( poClipRect )
{
OGRGeometry *poClippedLines =
poLines->Intersection( poClipRect );
delete poLines;
poLines = poClippedLines;
delete poClipRect;
}
/* -------------------------------------------------------------------- */
/* Convert our polygon into GEOS format, and compute an */
/* envelope to accelerate later distance operations. */
/* -------------------------------------------------------------------- */
OGREnvelope sEnvelope;
int iXMin, iYMin, iXMax, iYMax;
GEOSGeom poGEOSPoly;
poGEOSPoly = poLines->exportToGEOS();
OGR_G_GetEnvelope( hPolygon, &sEnvelope );
delete poLines;
if( sEnvelope.MinY - dfBlendDist > nYOff+nYSize
|| sEnvelope.MaxY + dfBlendDist < nYOff
|| sEnvelope.MinX - dfBlendDist > nXOff+nXSize
|| sEnvelope.MaxX + dfBlendDist < nXOff )
return CE_None;
iXMin = MAX(0,(int) floor(sEnvelope.MinX - dfBlendDist - nXOff));
iXMax = MIN(nXSize, (int) ceil(sEnvelope.MaxX + dfBlendDist - nXOff));
iYMin = MAX(0,(int) floor(sEnvelope.MinY - dfBlendDist - nYOff));
iYMax = MIN(nYSize, (int) ceil(sEnvelope.MaxY + dfBlendDist - nYOff));
/* -------------------------------------------------------------------- */
/* Loop over potential area within blend line distance, */
/* processing each pixel. */
/* -------------------------------------------------------------------- */
int iY, iX;
double dfLastDist;
for( iY = 0; iY < nYSize; iY++ )
{
dfLastDist = 0.0;
for( iX = 0; iX < nXSize; iX++ )
{
if( iX < iXMin || iX >= iXMax
|| iY < iYMin || iY > iYMax
|| dfLastDist > dfBlendDist + 1.5 )
{
if( pabyPolyMask[iX + iY * nXSize] == 0 )
pafValidityMask[iX + iY * nXSize] = 0.0;
dfLastDist -= 1.0;
//.........这里部分代码省略.........
示例12: SetGeogCSCitation
void SetGeogCSCitation(GTIF * psGTIF, OGRSpatialReference *poSRS, char* angUnitName, int nDatum, short nSpheroid)
{
int bRewriteGeogCitation = FALSE;
char szName[256];
CPLString osCitation;
size_t n = 0;
if( GTIFKeyGet( psGTIF, GeogCitationGeoKey, szName, 0, sizeof(szName) ) )
n = strlen(szName);
if (n == 0)
return;
if(!EQUALN(szName, "GCS Name = ", strlen("GCS Name = ")))
{
osCitation = "GCS Name = ";
osCitation += szName;
}
else
{
osCitation = szName;
}
if(nDatum == KvUserDefined )
{
const char* datumName = poSRS->GetAttrValue( "DATUM" );
if(datumName && strlen(datumName) > 0)
{
osCitation += "|Datum = ";
osCitation += datumName;
bRewriteGeogCitation = TRUE;
}
}
if(nSpheroid == KvUserDefined )
{
const char* spheroidName = poSRS->GetAttrValue( "SPHEROID" );
if(spheroidName && strlen(spheroidName) > 0)
{
osCitation += "|Ellipsoid = ";
osCitation += spheroidName;
bRewriteGeogCitation = TRUE;
}
}
const char* primemName = poSRS->GetAttrValue( "PRIMEM" );
if(primemName && strlen(primemName) > 0)
{
osCitation += "|Primem = ";
osCitation += primemName;
bRewriteGeogCitation = TRUE;
double primemValue = poSRS->GetPrimeMeridian(NULL);
if(angUnitName && !EQUAL(angUnitName, "Degree"))
{
double aUnit = poSRS->GetAngularUnits(NULL);
primemValue *= aUnit;
}
GTIFKeySet( psGTIF, GeogPrimeMeridianLongGeoKey, TYPE_DOUBLE, 1,
primemValue );
}
if(angUnitName && strlen(angUnitName) > 0 && !EQUAL(angUnitName, "Degree"))
{
osCitation += "|AUnits = ";
osCitation += angUnitName;
bRewriteGeogCitation = TRUE;
}
if (osCitation[strlen(osCitation) - 1] != '|')
osCitation += "|";
if (bRewriteGeogCitation)
GTIFKeySet( psGTIF, GeogCitationGeoKey, TYPE_ASCII, 0, osCitation.c_str() );
return;
}
示例13: WriteHeader
CPLErr SAGADataset::WriteHeader( CPLString osHDRFilename, GDALDataType eType,
GInt16 nXSize, GInt16 nYSize,
double dfMinX, double dfMinY,
double dfCellsize, double dfNoData,
double dfZFactor, bool bTopToBottom )
{
FILE *fp;
fp = VSIFOpenL( osHDRFilename, "wt" );
if( fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Failed to write .sgrd file %s.",
osHDRFilename.c_str() );
return CE_Failure;
}
VSIFPrintfL( fp, "NAME\t= %s\n", CPLGetBasename( osHDRFilename ) );
VSIFPrintfL( fp, "DESCRIPTION\t=\n" );
VSIFPrintfL( fp, "UNIT\t=\n" );
VSIFPrintfL( fp, "DATAFILE_OFFSET\t= 0\n" );
if( eType == GDT_Int32 )
VSIFPrintfL( fp, "DATAFORMAT\t= INTEGER\n" );
else if( eType == GDT_UInt32 )
VSIFPrintfL( fp, "DATAFORMAT\t= INTEGER_UNSIGNED\n" );
else if( eType == GDT_Int16 )
VSIFPrintfL( fp, "DATAFORMAT\t= SHORTINT\n" );
else if( eType == GDT_UInt16 )
VSIFPrintfL( fp, "DATAFORMAT\t= SHORTINT_UNSIGNED\n" );
else if( eType == GDT_Byte )
VSIFPrintfL( fp, "DATAFORMAT\t= BYTE_UNSIGNED\n" );
else if( eType == GDT_Float32 )
VSIFPrintfL( fp, "DATAFORMAT\t= FLOAT\n" );
else //if( eType == GDT_Float64 )
VSIFPrintfL( fp, "DATAFORMAT\t= DOUBLE\n" );
#ifdef CPL_LSB
VSIFPrintfL( fp, "BYTEORDER_BIG\t= FALSE\n" );
#else
VSIFPrintfL( fp, "BYTEORDER_BIG\t= TRUE\n" );
#endif
VSIFPrintfL( fp, "POSITION_XMIN\t= %.10f\n", dfMinX );
VSIFPrintfL( fp, "POSITION_YMIN\t= %.10f\n", dfMinY );
VSIFPrintfL( fp, "CELLCOUNT_X\t= %d\n", nXSize );
VSIFPrintfL( fp, "CELLCOUNT_Y\t= %d\n", nYSize );
VSIFPrintfL( fp, "CELLSIZE\t= %.10f\n", dfCellsize );
VSIFPrintfL( fp, "Z_FACTOR\t= %f\n", dfZFactor );
VSIFPrintfL( fp, "NODATA_VALUE\t= %f\n", dfNoData );
if (bTopToBottom)
VSIFPrintfL( fp, "TOPTOBOTTOM\t= TRUE\n" );
else
VSIFPrintfL( fp, "TOPTOBOTTOM\t= FALSE\n" );
VSIFCloseL( fp );
return CE_None;
}
示例14: 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;
if( EQUALN(pszNewName,"GEOMEDIA:",9) )
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);
sprintf( pszDSN, 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 = 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",
osGeometryProperties.c_str(),
oSession.GetLastError() );
return FALSE;
//.........这里部分代码省略.........
示例15: GetSpatialWhere
CPLString OGRSQLiteViewLayer::GetSpatialWhere(int iGeomCol,
OGRGeometry* poFilterGeom)
{
if (HasLayerDefnError() || poFeatureDefn == NULL ||
iGeomCol < 0 || iGeomCol >= poFeatureDefn->GetGeomFieldCount())
return "";
if( poFilterGeom != NULL && bHasSpatialIndex )
{
OGREnvelope sEnvelope;
poFilterGeom->getEnvelope( &sEnvelope );
/* We first check that the spatial index table exists */
if (!bHasCheckedSpatialIndexTable)
{
bHasCheckedSpatialIndexTable = TRUE;
char **papszResult;
int nRowCount, nColCount;
char *pszErrMsg = NULL;
CPLString osSQL;
osSQL.Printf("SELECT name FROM sqlite_master "
"WHERE name='idx_%s_%s'",
pszEscapedUnderlyingTableName,
OGRSQLiteEscape(osUnderlyingGeometryColumn).c_str());
int rc = sqlite3_get_table( poDS->GetDB(), osSQL.c_str(),
&papszResult, &nRowCount,
&nColCount, &pszErrMsg );
if( rc != SQLITE_OK )
{
CPLError( CE_Failure, CPLE_AppDefined, "Error: %s",
pszErrMsg );
sqlite3_free( pszErrMsg );
bHasSpatialIndex = FALSE;
}
else
{
if (nRowCount != 1)
{
bHasSpatialIndex = FALSE;
}
sqlite3_free_table(papszResult);
}
}
if (bHasSpatialIndex)
{
return FormatSpatialFilterFromRTree(poFilterGeom,
CPLSPrintf("\"%s\"", OGRSQLiteEscapeName(pszFIDColumn).c_str()),
pszEscapedUnderlyingTableName,
OGRSQLiteEscape(osUnderlyingGeometryColumn).c_str());
}
else
{
CPLDebug("SQLITE", "Count not find idx_%s_%s layer. Disabling spatial index",
pszEscapedUnderlyingTableName, osUnderlyingGeometryColumn.c_str());
}
}
if( poFilterGeom != NULL && poDS->IsSpatialiteLoaded() )
{
return FormatSpatialFilterFromMBR(poFilterGeom,
OGRSQLiteEscapeName(poFeatureDefn->GetGeomFieldDefn(iGeomCol)->GetNameRef()).c_str());
}
return "";
}