本文整理汇总了C++中CPLString::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ CPLString::substr方法的具体用法?C++ CPLString::substr怎么用?C++ CPLString::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPLString
的用法示例。
在下文中一共展示了CPLString::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
static CPLString GDALGMLJP2EvalExpr(const CPLString& osTemplate,
xmlXPathContextPtr pXPathCtx,
xmlDocPtr pDoc)
{
CPLString osXMLRes;
size_t nPos = 0;
while( true )
{
// Get next expression.
size_t nStartPos = osTemplate.find("{{{", nPos);
if( nStartPos == std::string::npos)
{
// Add terminating portion of the template.
osXMLRes += osTemplate.substr(nPos);
break;
}
// Add portion of template before the expression.
osXMLRes += osTemplate.substr(nPos, nStartPos - nPos);
const char* pszExpr = osTemplate.c_str() + nStartPos;
GDALGMLJP2Expr* poExpr = GDALGMLJP2Expr::Build(pszExpr, pszExpr);
if( poExpr == nullptr )
break;
nPos = static_cast<size_t>(pszExpr - osTemplate.c_str());
osXMLRes += poExpr->Evaluate(pXPathCtx,pDoc).osValue;
delete poExpr;
}
return osXMLRes;
}
示例2: osStatement
/*
* ExecuteSQL()
*/
OGRLayer *OGRNGWDataset::ExecuteSQL( const char *pszStatement,
OGRGeometry *poSpatialFilter, const char *pszDialect )
{
// Clean statement string.
CPLString osStatement(pszStatement);
osStatement = osStatement.Trim().replaceAll(" ", " ");
if( STARTS_WITH_CI(osStatement.c_str(), "DELLAYER:") )
{
CPLString osLayerName = osStatement.substr(9);
if( osLayerName.endsWith(";") )
{
osLayerName = osLayerName.substr(0, osLayerName.size() - 1);
osLayerName.Trim();
}
CPLDebug("NGW", "Delete layer with name %s.", osLayerName.c_str());
for( int iLayer = 0; iLayer < nLayers; ++iLayer )
{
if( EQUAL(papoLayers[iLayer]->GetName(), osLayerName.c_str() ) )
{
DeleteLayer( iLayer );
break;
}
}
return nullptr;
}
if( STARTS_WITH_CI(osStatement.c_str(), "DELETE FROM") )
{
// Get layer name from pszStatement DELETE FROM layer;.
CPLString osLayerName = osStatement.substr(12);
if( osLayerName.endsWith(";") )
{
osLayerName = osLayerName.substr(0, osLayerName.size() - 1);
osLayerName.Trim();
}
CPLDebug("NGW", "Delete features from layer with name %s.", osLayerName.c_str());
OGRNGWLayer *poLayer = static_cast<OGRNGWLayer*>(GetLayerByName(osLayerName));
if( poLayer )
{
poLayer->DeleteAllFeatures();
}
else
{
CPLError(CE_Failure, CPLE_AppDefined, "Unknown layer : %s",
osLayerName.c_str());
}
return nullptr;
}
return GDALDataset::ExecuteSQL(pszStatement, poSpatialFilter, pszDialect);
}
示例3: Set
void ERSHdrNode::Set( const char *pszPath, const char *pszValue )
{
CPLString osPath = pszPath;
int iDot;
iDot = osPath.find_first_of('.');
/* -------------------------------------------------------------------- */
/* We have an intermediate node, find or create it and */
/* recurse. */
/* -------------------------------------------------------------------- */
if( iDot != -1 )
{
CPLString osPathFirst = osPath.substr(0,iDot);
CPLString osPathRest = osPath.substr(iDot+1);
ERSHdrNode *poFirst = FindNode( osPathFirst );
if( poFirst == NULL )
{
poFirst = new ERSHdrNode();
MakeSpace();
papszItemName[nItemCount] = CPLStrdup(osPathFirst);
papszItemValue[nItemCount] = NULL;
papoItemChild[nItemCount] = poFirst;
nItemCount++;
}
poFirst->Set( osPathRest, pszValue );
return;
}
/* -------------------------------------------------------------------- */
/* This is the final item name. Find or create it. */
/* -------------------------------------------------------------------- */
int i;
for( i = 0; i < nItemCount; i++ )
{
if( EQUAL(osPath,papszItemName[i])
&& papszItemValue[i] != NULL )
{
CPLFree( papszItemValue[i] );
papszItemValue[i] = CPLStrdup( pszValue );
return;
}
}
MakeSpace();
papszItemName[nItemCount] = CPLStrdup(osPath);
papszItemValue[nItemCount] = CPLStrdup(pszValue);
papoItemChild[nItemCount] = NULL;
nItemCount++;
}
示例4: if
CPLString OGRPLScenesDataV1Dataset::InsertAPIKeyInURL(CPLString osURL)
{
if( STARTS_WITH(osURL, "http://") )
{
osURL = "http://" + m_osAPIKey + ":@" + osURL.substr(strlen("http://"));
}
else if( STARTS_WITH(osURL, "https://") )
{
osURL = "https://" + m_osAPIKey + ":@" + osURL.substr(strlen("https://"));
}
return osURL;
}
示例5: osErrMsg
void GDALGMLJP2Expr::ReportError( const char* pszOriStr,
const char* pszStr,
const char* pszIntroMessage )
{
size_t nDist = static_cast<size_t>(pszStr - pszOriStr);
if( nDist > 40 )
nDist = 40;
CPLString osErrMsg(pszIntroMessage);
CPLString osInvalidExpr = CPLString(pszStr - nDist).substr(0, nDist + 20);
for( int i = static_cast<int>(nDist) - 1; i >= 0; --i )
{
if( osInvalidExpr[i] == '\n' )
{
osInvalidExpr = osInvalidExpr.substr(i+1);
nDist -= i + 1;
break;
}
}
for( size_t i = nDist; i < osInvalidExpr.size(); ++i )
{
if( osInvalidExpr[i] == '\n' )
{
osInvalidExpr.resize(i);
break;
}
}
osErrMsg += osInvalidExpr;
osErrMsg += "\n";
for( size_t i = 0; i < nDist; ++i )
osErrMsg += " ";
osErrMsg += "^";
CPLError(CE_Failure, CPLE_AppDefined, "%s", osErrMsg.c_str());
}
示例6: CPLStrip
/**
* CPLStrip()
*/
CPLString CPLStrip(const CPLString& sString, const char cChar)
{
if(sString.empty())
return sString;
size_t dCopyFrom = 0;
size_t dCopyCount = sString.size();
if (sString[0] == cChar)
{
dCopyFrom++;
dCopyCount--;
}
if (sString[sString.size() - 1] == cChar)
dCopyCount--;
if(dCopyCount == 0)
return CPLString();
return sString.substr(dCopyFrom, dCopyCount);
}
示例7: OpenTable
int OGRSelafinDataSource::OpenTable(const char * pszFilename) {
#ifdef DEBUG_VERBOSE
CPLDebug("Selafin", "OpenTable(%s,%i)",
pszFilename, static_cast<int>(bUpdate));
#endif
// Open the file
VSILFILE *fp = nullptr;
if( bUpdate )
{
fp = VSIFOpenExL( pszFilename, "rb+", true );
}
else
{
fp = VSIFOpenExL( pszFilename, "rb", true );
}
if( fp == nullptr ) {
CPLError( CE_Warning, CPLE_OpenFailed, "Failed to open %s.", VSIGetLastErrorMsg() );
return FALSE;
}
if( !bUpdate && strstr(pszFilename, "/vsigzip/") == nullptr && strstr(pszFilename, "/vsizip/") == nullptr ) fp = (VSILFILE*) VSICreateBufferedReaderHandle((VSIVirtualHandle*)fp);
// Quickly check if the file is in Selafin format, before actually starting to read to make it faster
char szBuf[9];
VSIFReadL(szBuf,1,4,fp);
if (szBuf[0]!=0 || szBuf[1]!=0 || szBuf[2]!=0 || szBuf[3]!=0x50) {
VSIFCloseL(fp);
return FALSE;
}
VSIFSeekL(fp,84,SEEK_SET);
VSIFReadL(szBuf,1,8,fp);
if (szBuf[0]!=0 || szBuf[1]!=0 || szBuf[2]!=0 || szBuf[3]!=0x50 || szBuf[4]!=0 || szBuf[5]!=0 || szBuf[6]!=0 || szBuf[7]!=8) {
VSIFCloseL(fp);
return FALSE;
}
/* VSIFSeekL(fp,76,SEEK_SET);
VSIFReadL(szBuf,1,8,fp);
if (STRNCASECMP(szBuf,"Seraphin",8)!=0 && STRNCASECMP(szBuf,"Serafin",7)!=0) {
VSIFCloseL(fp);
return FALSE;
} */
// Get layer base name
CPLString osBaseLayerName = CPLGetBasename(pszFilename);
CPLString osExt = CPLGetExtension(pszFilename);
if( STARTS_WITH(pszFilename, "/vsigzip/") && EQUAL(osExt, "gz") ) {
size_t nPos=std::string::npos;
if (strlen(pszFilename)>3) nPos=osExt.find_last_of('.',strlen(pszFilename)-4);
if (nPos!=std::string::npos) {
osExt=osExt.substr(nPos+1,strlen(pszFilename)-4-nPos);
osBaseLayerName=osBaseLayerName.substr(0,nPos);
} else {
osExt="";
}
}
// Read header of file to get common information for all layers
// poHeader now owns fp
poHeader=Selafin::read_header(fp,pszFilename);
if (poHeader==nullptr) {
CPLError( CE_Failure, CPLE_OpenFailed, "Failed to open %s, wrong format.\n", pszFilename);
return FALSE;
}
if (poHeader->nEpsg!=0) {
poSpatialRef=new OGRSpatialReference();
poSpatialRef->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
if (poSpatialRef->importFromEPSG(poHeader->nEpsg)!=OGRERR_NONE) {
CPLError( CE_Warning, CPLE_AppDefined, "EPSG %d not found. Could not set datasource SRS.\n", poHeader->nEpsg);
delete poSpatialRef;
poSpatialRef=nullptr;
}
}
// To prevent int overflow in poRange.getSize() call where we do
// nSteps * 2
if( poHeader->nSteps >= INT_MAX / 2 )
{
CPLError( CE_Failure, CPLE_OpenFailed, "Invalid nSteps value" );
return FALSE;
}
// Create two layers for each selected time step: one for points, the other for elements
poRange.setMaxValue(poHeader->nSteps);
const int nNewLayers = static_cast<int>(poRange.getSize());
if (EQUAL(pszFilename, "/vsistdin/")) osBaseLayerName = "layer";
CPLString osLayerName;
papoLayers = (OGRSelafinLayer **) CPLRealloc(papoLayers, sizeof(void*) * (nLayers+nNewLayers));
for (size_t j=0;j<2;++j) {
SelafinTypeDef eType=(j==0)?POINTS:ELEMENTS;
for (int i=0;i<poHeader->nSteps;++i) {
if (poRange.contains(eType,i)) {
char szTemp[30];
double dfTime = 0.0;
if( VSIFSeekL(fp, poHeader->getPosition(i)+4, SEEK_SET)!=0 ||
Selafin::read_float(fp, dfTime)==0 )
{
CPLError( CE_Failure, CPLE_OpenFailed, "Failed to open %s, wrong format.\n", pszFilename);
return FALSE;
}
if (poHeader->panStartDate==nullptr) snprintf(szTemp,29,"%d",i); else {
//.........这里部分代码省略.........
示例8: oFieldDefn
int ILI1Reader::ReadTable(CPL_UNUSED const char *layername) {
char **tokens = NULL;
int ret = TRUE;
int warned = FALSE;
int geomIdx = -1;
OGRFeatureDefn *featureDef = curLayer->GetLayerDefn();
OGRFeature *feature = NULL;
bool bFeatureAdded = false;
while (ret && (tokens = ReadParseLine()) != NULL)
{
const char *firsttok = CSLGetField(tokens, 0);
if (EQUAL(firsttok, "OBJE"))
{
if (featureDef->GetFieldCount() == 0 && curLayer->GetFeatureCount() == 0)
{
CPLError( CE_Warning, CPLE_AppDefined,
"No field definition found for table: %s",
featureDef->GetName() );
// Model not read - use heuristics.
for( int fIndex=1; fIndex<CSLCount(tokens); fIndex++ )
{
char szFieldName[32];
snprintf(szFieldName, sizeof(szFieldName), "Field%02d", fIndex);
OGRFieldDefn oFieldDefn(szFieldName, OFTString);
featureDef->AddFieldDefn(&oFieldDefn);
}
}
//start new feature
if( !bFeatureAdded )
delete feature;
feature = new OGRFeature(featureDef);
for( int fIndex=1, fieldno = 0;
fIndex<CSLCount(tokens) && fieldno < featureDef->GetFieldCount();
fIndex++, fieldno++ )
{
if (!(tokens[fIndex][0] == codeUndefined && tokens[fIndex][1] == '\0')) {
#ifdef DEBUG_VERBOSE
CPLDebug( "READ TABLE OGR_ILI", "Setting Field %d (Type %d): %s",
fieldno, featureDef->GetFieldDefn(fieldno)->GetType(),
tokens[fIndex] );
#endif
if (featureDef->GetFieldDefn(fieldno)->GetType() == OFTString) {
// Interlis 1 encoding is ISO 8859-1 (Latin1) -> Recode to UTF-8
char* pszRecoded = CPLRecode(
tokens[fIndex], CPL_ENC_ISO8859_1, CPL_ENC_UTF8);
// Replace space marks
for( char* pszString = pszRecoded;
*pszString != '\0';
pszString++ ) {
if (*pszString == codeBlank) *pszString = ' ';
}
feature->SetField(fieldno, pszRecoded);
CPLFree(pszRecoded);
} else {
feature->SetField(fieldno, tokens[fIndex]);
}
if (featureDef->GetFieldDefn(fieldno)->GetType() == OFTReal
&& fieldno > 0
&& featureDef->GetFieldDefn(fieldno-1)->GetType() == OFTReal) {
// Check for Point geometry (Coord type).
// If there is no ili model read,
// we have no chance to detect the
// geometry column.
CPLString geomfldname
= featureDef->GetFieldDefn(fieldno)->GetNameRef();
// Check if name ends with _1.
if (geomfldname.size() >= 2 && geomfldname[geomfldname.size()-2]
== '_') {
geomfldname = geomfldname.substr(0, geomfldname.size()-2);
geomIdx = featureDef->GetGeomFieldIndex(geomfldname.c_str());
if (geomIdx == -1)
{
CPLError( CE_Warning, CPLE_AppDefined,
"No matching definition for field '%s' of "
"table %s found",
geomfldname.c_str(), featureDef->GetName() );
}
} else {
geomIdx = -1;
}
if (geomIdx >= 0) {
if (featureDef->GetGeomFieldDefn(geomIdx)->GetType() ==
wkbPoint) {
// Add Point geometry.
OGRPoint *ogrPoint = new OGRPoint(
CPLAtof(tokens[fIndex-1]), CPLAtof(tokens[fIndex]));
feature->SetGeomFieldDirectly(geomIdx, ogrPoint);
} else if (featureDef->GetGeomFieldDefn(geomIdx)->GetType() ==
wkbPoint25D && fieldno > 1 &&
featureDef->GetFieldDefn(fieldno-2)->GetType() ==
OFTReal) {
// Add 3D Point geometry.
OGRPoint *ogrPoint = new OGRPoint(
CPLAtof(tokens[fIndex-2]), CPLAtof(tokens[fIndex-1]),
CPLAtof(tokens[fIndex]) );
feature->SetGeomFieldDirectly(geomIdx, ogrPoint);
}
//.........这里部分代码省略.........
示例9: ParseImage
//.........这里部分代码省略.........
"%s layout not supported. Abort\n\n", value);
return FALSE;
}
/*********** Grab Qube record bytes **********/
record_bytes = atoi(GetKeyword(osPrefix+"IMAGE.RECORD_BYTES"));
if (record_bytes == 0)
record_bytes = atoi(GetKeyword(osPrefix+"RECORD_BYTES"));
// this can happen with "record_type = undefined".
if( record_bytes == 0 )
record_bytes = 1;
if( nQube >0 && osQube.find("<BYTES>") != CPLString::npos )
nSkipBytes = nQube - 1;
else if (nQube > 0 )
nSkipBytes = (nQube - 1) * record_bytes;
else if( nDetachedOffset > 0 )
{
if (bDetachedOffsetInBytes)
nSkipBytes = nDetachedOffset;
else
nSkipBytes = nDetachedOffset * record_bytes;
}
else
nSkipBytes = 0;
nSkipBytes += atoi(GetKeyword(osPrefix+"IMAGE.LINE_PREFIX_BYTES",""));
/*********** Grab SAMPLE_TYPE *****************/
/** if keyword not found leave as "M" or "MSB" **/
CPLString osST = GetKeyword( osPrefix+"IMAGE.SAMPLE_TYPE" );
if( osST.size() >= 2 && osST[0] == '"' && osST[osST.size()-1] == '"' )
osST = osST.substr( 1, osST.size() - 2 );
if( (EQUAL(osST,"LSB_INTEGER")) ||
(EQUAL(osST,"LSB")) || // just incase
(EQUAL(osST,"LSB_UNSIGNED_INTEGER")) ||
(EQUAL(osST,"LSB_SIGNED_INTEGER")) ||
(EQUAL(osST,"UNSIGNED_INTEGER")) ||
(EQUAL(osST,"VAX_REAL")) ||
(EQUAL(osST,"VAX_INTEGER")) ||
(EQUAL(osST,"PC_INTEGER")) || //just incase
(EQUAL(osST,"PC_REAL")) ) {
chByteOrder = 'I';
}
/**** Grab format type - pds supports 1,2,4,8,16,32,64 (in theory) **/
/**** I have only seen 8, 16, 32 (float) in released datasets **/
itype = atoi(GetKeyword(osPrefix+"IMAGE.SAMPLE_BITS",""));
switch(itype) {
case 8 :
eDataType = GDT_Byte;
dfNoData = NULL1;
break;
case 16 :
if( strstr(osST,"UNSIGNED") != NULL )
eDataType = GDT_UInt16;
else
eDataType = GDT_Int16;
dfNoData = NULL2;
break;
case 32 :
eDataType = GDT_Float32;
dfNoData = NULL3;
break;
示例10: if
//.........这里部分代码省略.........
else if( EQUAL(osCellType,"IEEE4ByteReal") )
eType = GDT_Float32;
else if( EQUAL(osCellType,"IEEE8ByteReal") )
eType = GDT_Float64;
else
{
CPLDebug( "ERS", "Unknown CellType '%s'", osCellType.c_str() );
eType = GDT_Byte;
}
/* -------------------------------------------------------------------- */
/* Pick up the word order. */
/* -------------------------------------------------------------------- */
int bNative;
#ifdef CPL_LSB
bNative = EQUAL(poHeader->Find( "ByteOrder", "LSBFirst" ),
"LSBFirst");
#else
bNative = EQUAL(poHeader->Find( "ByteOrder", "MSBFirst" ),
"MSBFirst");
#endif
/* -------------------------------------------------------------------- */
/* Figure out the name of the target file. */
/* -------------------------------------------------------------------- */
CPLString osPath = CPLGetPath( poOpenInfo->pszFilename );
CPLString osDataFile = poHeader->Find( "DataFile", "" );
CPLString osDataFilePath;
if( osDataFile.length() == 0 ) // just strip off extension.
{
osDataFile = CPLGetFilename( poOpenInfo->pszFilename );
osDataFile = osDataFile.substr( 0, osDataFile.find_last_of('.') );
}
osDataFilePath = CPLFormFilename( osPath, osDataFile, NULL );
/* -------------------------------------------------------------------- */
/* DataSetType = Translated files are links to things like ecw */
/* files. */
/* -------------------------------------------------------------------- */
if( EQUAL(poHeader->Find("DataSetType",""),"Translated") )
{
poDS->poDepFile = (GDALDataset *)
GDALOpenShared( osDataFilePath, poOpenInfo->eAccess );
if( poDS->poDepFile != NULL
&& poDS->poDepFile->GetRasterCount() >= nBands )
{
int iBand;
for( iBand = 0; iBand < nBands; iBand++ )
{
// Assume pixel interleaved.
poDS->SetBand( iBand+1,
poDS->poDepFile->GetRasterBand( iBand+1 ) );
}
}
}
/* ==================================================================== */
/* While ERStorage indicates a raw file. */
/* ==================================================================== */
else if( EQUAL(poHeader->Find("DataSetType",""),"ERStorage") )
{
示例11: OpenRasterScene
GDALDataset* OGRPLScenesDataset::OpenRasterScene(GDALOpenInfo* poOpenInfo,
CPLString osScene,
char** papszOptions)
{
if( !(poOpenInfo->nOpenFlags & GDAL_OF_RASTER) )
{
return NULL;
}
for( char** papszIter = papszOptions; papszIter && *papszIter; papszIter ++ )
{
char* pszKey;
const char* pszValue = CPLParseNameValue(*papszIter, &pszKey);
if( pszValue != NULL )
{
if( !EQUAL(pszKey, "api_key") &&
!EQUAL(pszKey, "scene") &&
!EQUAL(pszKey, "product_type") )
{
CPLError(CE_Failure, CPLE_NotSupported, "Unsupported option %s", pszKey);
CPLFree(pszKey);
return NULL;
}
CPLFree(pszKey);
}
}
const char* pszProductType = CSLFetchNameValueDef(papszOptions, "product_type",
CSLFetchNameValueDef(poOpenInfo->papszOpenOptions, "PRODUCT_TYPE", "visual"));
CPLString osRasterURL;
osRasterURL = osBaseURL;
osRasterURL += "ortho/";
osRasterURL += osScene;
json_object* poObj = RunRequest( osRasterURL );
if( poObj == NULL )
return NULL;
json_object* poProperties = json_object_object_get(poObj, "properties");
if( poProperties == NULL || json_object_get_type(poProperties) != json_type_object )
{
CPLError(CE_Failure, CPLE_AppDefined, "Cannot find properties object");
json_object_put(poObj);
return NULL;
}
const char* pszLink = NULL;
if( EQUAL(pszProductType, "thumb") )
{
json_object* poLinks = json_object_object_get(poProperties, "links");
if( poLinks != NULL && json_object_get_type(poLinks) == json_type_object )
{
json_object* poThumbnail = json_object_object_get(poLinks, "thumbnail");
if( poThumbnail && json_object_get_type(poThumbnail) == json_type_string )
pszLink = json_object_get_string(poThumbnail);
}
}
else
{
json_object* poData = json_object_object_get(poProperties, "data");
if( poData != NULL && json_object_get_type(poData) == json_type_object )
{
json_object* poProducts = json_object_object_get(poData, "products");
if( poProducts != NULL && json_object_get_type(poProducts) == json_type_object )
{
json_object* poProduct = json_object_object_get(poProducts, pszProductType);
if( poProduct != NULL && json_object_get_type(poProduct) == json_type_object )
{
json_object* poFull = json_object_object_get(poProduct, "full");
if( poFull && json_object_get_type(poFull) == json_type_string )
pszLink = json_object_get_string(poFull);
}
}
}
}
osRasterURL = pszLink ? pszLink : "";
json_object_put(poObj);
if( osRasterURL.size() == 0 )
{
CPLError(CE_Failure, CPLE_AppDefined, "Cannot find link to scene %s",
osScene.c_str());
return NULL;
}
if( strncmp(osRasterURL, "http://", strlen("http://")) == 0 )
{
osRasterURL = "http://" + osAPIKey + ":@" + osRasterURL.substr(strlen("http://"));
}
else if( strncmp(osRasterURL, "https://", strlen("https://")) == 0 )
{
osRasterURL = "https://" + osAPIKey + ":@" + osRasterURL.substr(strlen("https://"));
}
CPLString osOldHead(CPLGetConfigOption("CPL_VSIL_CURL_USE_HEAD", ""));
CPLString osOldExt(CPLGetConfigOption("CPL_VSIL_CURL_ALLOWED_EXTENSIONS", ""));
int bUseVSICURL = CSLFetchBoolean(poOpenInfo->papszOpenOptions, "RANDOM_ACCESS", TRUE);
if( bUseVSICURL && !(strncmp(osBaseURL, "/vsimem/", strlen("/vsimem/")) == 0) )
{
CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_USE_HEAD", "NO");
CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_ALLOWED_EXTENSIONS", "{noext}");
//.........这里部分代码省略.........
示例12: WriteTEXT
OGRErr OGRDXFWriterLayer::WriteTEXT( OGRFeature *poFeature )
{
WriteValue( 0, "MTEXT" );
WriteCore( poFeature );
WriteValue( 100, "AcDbEntity" );
WriteValue( 100, "AcDbMText" );
/* -------------------------------------------------------------------- */
/* Do we have styling information? */
/* -------------------------------------------------------------------- */
OGRStyleTool *poTool = nullptr;
OGRStyleMgr oSM;
if( poFeature->GetStyleString() != nullptr )
{
oSM.InitFromFeature( poFeature );
if( oSM.GetPartCount() > 0 )
poTool = oSM.GetPart(0);
}
/* ==================================================================== */
/* Process the LABEL tool. */
/* ==================================================================== */
double dfDx = 0.0;
double dfDy = 0.0;
if( poTool && poTool->GetType() == OGRSTCLabel )
{
OGRStyleLabel *poLabel = (OGRStyleLabel *) poTool;
GBool bDefault;
/* -------------------------------------------------------------------- */
/* Color */
/* -------------------------------------------------------------------- */
if( poLabel->ForeColor(bDefault) != nullptr && !bDefault )
WriteValue( 62, ColorStringToDXFColor(
poLabel->ForeColor(bDefault) ) );
/* -------------------------------------------------------------------- */
/* Angle */
/* -------------------------------------------------------------------- */
const double dfAngle = poLabel->Angle(bDefault);
if( !bDefault )
WriteValue( 50, dfAngle );
/* -------------------------------------------------------------------- */
/* Height - We need to fetch this in georeferenced units - I'm */
/* doubt the default translation mechanism will be much good. */
/* -------------------------------------------------------------------- */
poTool->SetUnit( OGRSTUGround );
const double dfHeight = poLabel->Size(bDefault);
if( !bDefault )
WriteValue( 40, dfHeight );
/* -------------------------------------------------------------------- */
/* Anchor / Attachment Point */
/* -------------------------------------------------------------------- */
const int nAnchor = poLabel->Anchor(bDefault);
if( !bDefault )
{
const static int anAnchorMap[] =
{ -1, 7, 8, 9, 4, 5, 6, 1, 2, 3, 7, 8, 9 };
if( nAnchor > 0 && nAnchor < 13 )
WriteValue( 71, anAnchorMap[nAnchor] );
}
/* -------------------------------------------------------------------- */
/* Offset */
/* -------------------------------------------------------------------- */
dfDx = poLabel->SpacingX(bDefault);
dfDy = poLabel->SpacingY(bDefault);
/* -------------------------------------------------------------------- */
/* Escape the text, and convert to ISO8859. */
/* -------------------------------------------------------------------- */
const char *pszText = poLabel->TextString( bDefault );
if( pszText != nullptr && !bDefault )
{
CPLString osEscaped = TextEscape( pszText );
while( osEscaped.size() > 250 )
{
WriteValue( 3, osEscaped.substr( 0, 250 ).c_str() );
osEscaped.erase( 0, 250 );
}
WriteValue( 1, osEscaped );
}
/* -------------------------------------------------------------------- */
/* Store the text style in the map. */
/* -------------------------------------------------------------------- */
std::map<CPLString, CPLString> oTextStyleDef =
PrepareTextStyleDefinition( poLabel );
CPLString osStyleName;
//.........这里部分代码省略.........
示例13: ParseChildren
int ERSHdrNode::ParseChildren( VSILFILE * fp )
{
while( TRUE )
{
size_t iOff;
CPLString osLine;
/* -------------------------------------------------------------------- */
/* Read the next line (or multi-line for bracketed value). */
/* -------------------------------------------------------------------- */
if( !ReadLine( fp, osLine ) )
return FALSE;
/* -------------------------------------------------------------------- */
/* Got a Name=Value. */
/* -------------------------------------------------------------------- */
if( (iOff = osLine.find_first_of( '=' )) != std::string::npos )
{
CPLString osName = osLine.substr(0,iOff-1);
osName.Trim();
CPLString osValue = osLine.c_str() + iOff + 1;
osValue.Trim();
MakeSpace();
papszItemName[nItemCount] = CPLStrdup(osName);
papszItemValue[nItemCount] = CPLStrdup(osValue);
papoItemChild[nItemCount] = NULL;
nItemCount++;
}
/* -------------------------------------------------------------------- */
/* Got a Begin for an object. */
/* -------------------------------------------------------------------- */
else if( (iOff = osLine.ifind( " Begin" )) != std::string::npos )
{
CPLString osName = osLine.substr(0,iOff);
osName.Trim();
MakeSpace();
papszItemName[nItemCount] = CPLStrdup(osName);
papszItemValue[nItemCount] = NULL;
papoItemChild[nItemCount] = new ERSHdrNode();
nItemCount++;
if( !papoItemChild[nItemCount-1]->ParseChildren( fp ) )
return FALSE;
}
/* -------------------------------------------------------------------- */
/* Got an End for our object. Well, at least we *assume* it */
/* must be for our object. */
/* -------------------------------------------------------------------- */
else if( osLine.ifind( " End" ) != std::string::npos )
{
return TRUE;
}
/* -------------------------------------------------------------------- */
/* Error? */
/* -------------------------------------------------------------------- */
else if( osLine.Trim().length() > 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Unexpected line parsing .ecw:\n%s",
osLine.c_str() );
return FALSE;
}
}
}
示例14: oHolder
VSIVirtualHandle *
VSIMemFilesystemHandler::Open( const char *pszFilename,
const char *pszAccess,
bool bSetError )
{
CPLMutexHolder oHolder( &hMutex );
CPLString osFilename = pszFilename;
NormalizePath( osFilename );
if( osFilename.empty() )
return nullptr;
vsi_l_offset nMaxLength = GUINTBIG_MAX;
const size_t iPos = osFilename.find("||maxlength=");
if( iPos != std::string::npos )
{
nMaxLength = static_cast<vsi_l_offset>(CPLAtoGIntBig(
osFilename.substr(iPos + strlen("||maxlength=")).c_str()));
}
/* -------------------------------------------------------------------- */
/* Get the filename we are opening, create if needed. */
/* -------------------------------------------------------------------- */
VSIMemFile *poFile = nullptr;
if( oFileList.find(osFilename) != oFileList.end() )
poFile = oFileList[osFilename];
// If no file and opening in read, error out.
if( strstr(pszAccess, "w") == nullptr
&& strstr(pszAccess, "a") == nullptr
&& poFile == nullptr )
{
if( bSetError )
{
VSIError(VSIE_FileError, "No such file or directory");
}
errno = ENOENT;
return nullptr;
}
// Create.
if( poFile == nullptr )
{
poFile = new VSIMemFile;
poFile->osFilename = osFilename;
oFileList[poFile->osFilename] = poFile;
CPLAtomicInc(&(poFile->nRefCount)); // For file list.
poFile->nMaxLength = nMaxLength;
}
// Overwrite
else if( strstr(pszAccess, "w") )
{
poFile->SetLength(0);
poFile->nMaxLength = nMaxLength;
}
if( poFile->bIsDirectory )
{
errno = EISDIR;
return nullptr;
}
/* -------------------------------------------------------------------- */
/* Setup the file handle on this file. */
/* -------------------------------------------------------------------- */
VSIMemHandle *poHandle = new VSIMemHandle;
poHandle->poFile = poFile;
poHandle->m_nOffset = 0;
poHandle->bEOF = false;
poHandle->bUpdate =
strstr(pszAccess, "w") ||
strstr(pszAccess, "+") ||
strstr(pszAccess, "a");
CPLAtomicInc(&(poFile->nRefCount));
if( strstr(pszAccess, "a") )
poHandle->m_nOffset = poFile->nLength;
return poHandle;
}
示例15: if
static CPLString GetProj4Filename(const char* pszFilename)
{
CPLString osFilename;
/* or fixed path: /name, ./name or ../name */
if ( !CPLIsFilenameRelative(pszFilename) || *pszFilename == '.' )
{
return pszFilename;
}
#if defined(PROJ_STATIC) && PROJ_VERSION >= 5
PJ_GRID_INFO info = proj_grid_info(pszFilename);
if( info.filename[0] )
{
osFilename = info.filename;
}
#elif defined(PROJ_STATIC) && PJ_VERSION > 493
osFilename.resize(2048);
projCtx ctx = pj_ctx_alloc();
if( pj_find_file(ctx, pszFilename, &osFilename[0], osFilename.size()) )
{
osFilename.resize( strlen(osFilename) );
}
else
{
osFilename.clear();
}
pj_ctx_free(ctx);
#else
// Transpose some of the proj.4 pj_open_lib() logic...
/* check if ~/name */
char* pszSysname;
if (*pszFilename == '~' &&
(pszFilename[1] == '/' || pszFilename[1] == '\\') )
{
if ((pszSysname = getenv("HOME")) != nullptr)
{
osFilename = CPLFormFilename(pszSysname, pszFilename + 1, nullptr);
}
return osFilename;
}
/* or is environment PROJ_LIB defined */
else if ((pszSysname = getenv("PROJ_LIB")) != nullptr)
{
osFilename = CPLFormFilename(pszSysname, pszFilename, nullptr);
VSIStatBufL sStat;
if( VSIStatL(osFilename, &sStat) == 0 )
return osFilename;
osFilename.clear();
}
#if defined(PROJ_STATIC) && PJ_VERSION >= 490
// Super messy. proj.4 up to 4.9.3 had no public API to return the full
// path to a resource file, so we rely on the fact that it emits a log
// message with it...
// Basically this is needed in the case where the file is in the
// resource installation directory of proj.4, which we have no way to
// know otherwise.
CPLString osMsg;
projCtx ctx = pj_ctx_alloc();
pj_ctx_set_app_data(ctx, &osMsg);
pj_ctx_set_debug(ctx, PJ_LOG_DEBUG_MAJOR);
pj_ctx_set_logger(ctx, my_proj4_logger);
PAFile f = pj_open_lib(ctx, pszFilename, "rb");
if( f )
{
pj_ctx_fclose(ctx, f);
size_t nPos = osMsg.find("fopen(");
if( nPos != std::string::npos )
{
osFilename = osMsg.substr(nPos + strlen("fopen("));
nPos = osFilename.find(")");
if( nPos != std::string::npos )
osFilename = osFilename.substr(0, nPos);
}
}
pj_ctx_free(ctx);
#endif
#endif
return osFilename;
}