本文整理汇总了C++中CPLString::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ CPLString::resize方法的具体用法?C++ CPLString::resize怎么用?C++ CPLString::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPLString
的用法示例。
在下文中一共展示了CPLString::resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
示例2: GetExtent
OGRErr OGRSQLiteSelectLayerCommonBehaviour::GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce)
{
if( iGeomField < 0 || iGeomField >= poLayer->GetLayerDefn()->GetGeomFieldCount() ||
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeomField)->GetType() == wkbNone )
{
if( iGeomField != 0 )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Invalid geometry field index : %d", iGeomField);
}
return OGRERR_FAILURE;
}
/* Caching of extent by SQL string is interesting to speed-up the */
/* establishment of the WFS GetCapabilities document for a MapServer mapfile */
/* which has several layers, only differing by scale rules */
if( iGeomField == 0 )
{
const OGREnvelope* psCachedExtent = poDS->GetEnvelopeFromSQL(osSQLBase);
if (psCachedExtent)
{
memcpy(psExtent, psCachedExtent, sizeof(*psCachedExtent));
return OGRERR_NONE;
}
}
CPLString osSQLCommand = osSQLBase;
/* ORDER BY are costly to evaluate and are not necessary to establish */
/* the layer extent. */
size_t nOrderByPos = osSQLCommand.ifind(" ORDER BY ");
if( osSQLCommand.ifind("SELECT ") == 0 &&
osSQLCommand.ifind("SELECT ", 1) == std::string::npos && /* Ensure there's no sub SELECT that could confuse our heuristics */
nOrderByPos != std::string::npos &&
osSQLCommand.ifind(" LIMIT ") == std::string::npos &&
osSQLCommand.ifind(" UNION ") == std::string::npos &&
osSQLCommand.ifind(" INTERSECT ") == std::string::npos &&
osSQLCommand.ifind(" EXCEPT ") == std::string::npos)
{
osSQLCommand.resize(nOrderByPos);
OGRLayer* poTmpLayer = poDS->ExecuteSQL(osSQLCommand.c_str(), NULL, NULL);
if (poTmpLayer)
{
OGRErr eErr = poTmpLayer->GetExtent(iGeomField, psExtent, bForce);
poDS->ReleaseResultSet(poTmpLayer);
return eErr;
}
}
OGRErr eErr;
if( iGeomField == 0 )
eErr = poLayer->BaseGetExtent(psExtent, bForce);
else
eErr = poLayer->BaseGetExtent(iGeomField, psExtent, bForce);
if (iGeomField == 0 && eErr == OGRERR_NONE && poDS->GetUpdate() == FALSE)
poDS->SetEnvelopeForSQL(osSQLBase, *psExtent);
return eErr;
}
示例3: VSIFReadL
const char *RDataset::ASCIIFGets()
{
char chNextChar;
osLastStringRead.resize(0);
do
{
chNextChar = '\n';
VSIFReadL( &chNextChar, 1, 1, fp );
if( chNextChar != '\n' )
osLastStringRead += chNextChar;
} while( chNextChar != '\n' && chNextChar != '\0' );
return osLastStringRead;
}
示例4: GetExtent
OGRErr OGRSQLiteSelectLayer::GetExtent(OGREnvelope *psExtent, int bForce)
{
if (GetGeomType() == wkbNone)
return OGRERR_FAILURE;
/* Caching of extent by SQL string is interesting to speed-up the */
/* establishment of the WFS GetCapabilities document for a MapServer mapfile */
/* which has several layers, only differing by scale rules */
const OGREnvelope* psCachedExtent = poDS->GetEnvelopeFromSQL(osSQLBase);
if (psCachedExtent)
{
memcpy(psExtent, psCachedExtent, sizeof(*psCachedExtent));
return OGRERR_NONE;
}
CPLString osSQLCommand = osSQLBase;
/* ORDER BY are costly to evaluate and are not necessary to establish */
/* the layer extent. */
size_t nOrderByPos = osSQLCommand.ifind(" ORDER BY ");
if( osSQLCommand.ifind("SELECT ") == 0 &&
nOrderByPos != std::string::npos &&
osSQLCommand.ifind(" LIMIT ") == std::string::npos &&
osSQLCommand.ifind(" UNION ") == std::string::npos &&
osSQLCommand.ifind(" INTERSECT ") == std::string::npos &&
osSQLCommand.ifind(" EXCEPT ") == std::string::npos)
{
osSQLCommand.resize(nOrderByPos);
OGRLayer* poTmpLayer = poDS->ExecuteSQL(osSQLCommand.c_str(), NULL, NULL);
if (poTmpLayer)
{
OGRErr eErr = poTmpLayer->GetExtent(psExtent, bForce);
poDS->ReleaseResultSet(poTmpLayer);
return eErr;
}
}
OGRErr eErr = OGRSQLiteLayer::GetExtent(psExtent, bForce);
if (eErr == OGRERR_NONE && poDS->GetUpdate() == FALSE)
poDS->SetEnvelopeForSQL(osSQLBase, *psExtent);
return eErr;
}
示例5: switch
swq_expr_node *SWQCastEvaluator( swq_expr_node *node,
swq_expr_node **sub_node_values )
{
swq_expr_node *poRetNode = NULL;
swq_expr_node *poSrcNode = sub_node_values[0];
switch( node->field_type )
{
case SWQ_INTEGER:
{
poRetNode = new swq_expr_node( 0 );
switch( poSrcNode->field_type )
{
case SWQ_INTEGER:
case SWQ_BOOLEAN:
poRetNode->int_value = poSrcNode->int_value;
break;
case SWQ_FLOAT:
poRetNode->int_value = (int) poSrcNode->float_value;
break;
default:
poRetNode->int_value = atoi(poSrcNode->string_value);
break;
}
}
break;
case SWQ_FLOAT:
{
poRetNode = new swq_expr_node( 0.0 );
switch( poSrcNode->field_type )
{
case SWQ_INTEGER:
case SWQ_BOOLEAN:
poRetNode->float_value = poSrcNode->int_value;
break;
case SWQ_FLOAT:
poRetNode->float_value = poSrcNode->float_value;
break;
default:
poRetNode->float_value = atof(poSrcNode->string_value);
break;
}
}
break;
// everything else is a string.
default:
{
CPLString osRet;
switch( poSrcNode->field_type )
{
case SWQ_INTEGER:
case SWQ_BOOLEAN:
osRet.Printf( "%d", poSrcNode->int_value );
break;
case SWQ_FLOAT:
osRet.Printf( "%.15g", poSrcNode->float_value );
break;
default:
osRet = poSrcNode->string_value;
break;
}
if( node->nSubExprCount > 2 )
{
int nWidth;
nWidth = sub_node_values[2]->int_value;
if( nWidth > 0 && (int) strlen(osRet) > nWidth )
osRet.resize(nWidth);
}
poRetNode = new swq_expr_node( osRet.c_str() );
}
}
return poRetNode;
}
示例6: if
//.........这里部分代码省略.........
if( node->nSubExprCount == 3 )
chEscape = sub_node_values[2]->string_value[0];
poRet->int_value = swq_test_like(sub_node_values[0]->string_value,
sub_node_values[1]->string_value,
chEscape);
break;
}
case SWQ_ISNULL:
poRet->int_value = sub_node_values[0]->is_null;
break;
case SWQ_CONCAT:
case SWQ_ADD:
{
CPLString osResult = sub_node_values[0]->string_value;
for( int i = 1; i < node->nSubExprCount; i++ )
osResult += sub_node_values[i]->string_value;
poRet->string_value = CPLStrdup(osResult);
poRet->is_null = sub_node_values[0]->is_null;
break;
}
case SWQ_SUBSTR:
{
int nOffset, nSize;
const char *pszSrcStr = sub_node_values[0]->string_value;
if( SWQ_IS_INTEGER(sub_node_values[1]->field_type) )
nOffset = (int)sub_node_values[1]->int_value;
else if( sub_node_values[1]->field_type == SWQ_FLOAT )
nOffset = (int) sub_node_values[1]->float_value;
else
nOffset = 0;
if( node->nSubExprCount < 3 )
nSize = 100000;
else if( SWQ_IS_INTEGER(sub_node_values[2]->field_type) )
nSize = (int)sub_node_values[2]->int_value;
else if( sub_node_values[2]->field_type == SWQ_FLOAT )
nSize = (int) sub_node_values[2]->float_value;
else
nSize = 0;
int nSrcStrLen = (int)strlen(pszSrcStr);
/* In SQL, the first character is at offset 1 */
/* And 0 is considered as 1 */
if (nOffset > 0)
nOffset --;
/* Some implementations allow negative offsets, to start */
/* from the end of the string */
else if( nOffset < 0 )
{
if( nSrcStrLen + nOffset >= 0 )
nOffset = nSrcStrLen + nOffset;
else
nOffset = 0;
}
if( nSize < 0 || nOffset > nSrcStrLen )
{
nOffset = 0;
nSize = 0;
}
else if( nOffset + nSize > nSrcStrLen )
nSize = nSrcStrLen - nOffset;
CPLString osResult = pszSrcStr + nOffset;
if( (int)osResult.size() > nSize )
osResult.resize( nSize );
poRet->string_value = CPLStrdup(osResult);
poRet->is_null = sub_node_values[0]->is_null;
break;
}
case SWQ_HSTORE_GET_VALUE:
{
const char *pszHStore = sub_node_values[0]->string_value;
const char *pszSearchedKey = sub_node_values[1]->string_value;
char* pszRet = OGRHStoreGetValue(pszHStore, pszSearchedKey);
poRet->string_value = pszRet ? pszRet : CPLStrdup("");
poRet->is_null = (pszRet == NULL);
break;
}
default:
CPLAssert( false );
delete poRet;
poRet = NULL;
break;
}
}
return poRet;
}
示例7: switch
//.........这里部分代码省略.........
case SWQ_INTEGER64:
case SWQ_BOOLEAN:
poRetNode->float_value = (double) poSrcNode->int_value;
break;
case SWQ_FLOAT:
poRetNode->float_value = poSrcNode->float_value;
break;
default:
poRetNode->float_value = CPLAtof(poSrcNode->string_value);
break;
}
}
break;
case SWQ_GEOMETRY:
{
poRetNode = new swq_expr_node( (OGRGeometry*) NULL );
if( !poSrcNode->is_null )
{
switch( poSrcNode->field_type )
{
case SWQ_GEOMETRY:
{
poRetNode->geometry_value =
poSrcNode->geometry_value->clone();
poRetNode->is_null = FALSE;
break;
}
case SWQ_STRING:
{
char* pszTmp = poSrcNode->string_value;
OGRGeometryFactory::createFromWkt(&pszTmp, NULL,
&(poRetNode->geometry_value));
if( poRetNode->geometry_value != NULL )
poRetNode->is_null = FALSE;
break;
}
default:
break;
}
}
break;
}
// everything else is a string.
default:
{
CPLString osRet;
switch( poSrcNode->field_type )
{
case SWQ_INTEGER:
case SWQ_BOOLEAN:
case SWQ_INTEGER64:
osRet.Printf( CPL_FRMT_GIB, poSrcNode->int_value );
break;
case SWQ_FLOAT:
osRet.Printf( "%.15g", poSrcNode->float_value );
break;
case SWQ_GEOMETRY:
{
if( poSrcNode->geometry_value != NULL )
{
char* pszWKT = NULL;
poSrcNode->geometry_value->exportToWkt(&pszWKT);
osRet = pszWKT;
CPLFree(pszWKT);
}
else
osRet = "";
break;
}
default:
osRet = poSrcNode->string_value;
break;
}
if( node->nSubExprCount > 2 )
{
int nWidth;
nWidth = (int) sub_node_values[2]->int_value;
if( nWidth > 0 && (int) strlen(osRet) > nWidth )
osRet.resize(nWidth);
}
poRetNode = new swq_expr_node( osRet.c_str() );
poRetNode->is_null = poSrcNode->is_null;
}
}
return poRetNode;
}
示例8: AddComputedAttribute
void OGROSMLayer::AddComputedAttribute(const char* pszName,
OGRFieldType eType,
const char* pszSQL)
{
if( poDS->hDBForComputedAttributes == NULL )
{
int rc;
#ifdef HAVE_SQLITE_VFS
rc = sqlite3_open_v2( ":memory:", &(poDS->hDBForComputedAttributes),
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX, NULL );
#else
rc = sqlite3_open( ":memory:", &(poDS->hDBForComputedAttributes) );
#endif
if( rc != SQLITE_OK )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Cannot open temporary sqlite DB" );
return;
}
}
if( poFeatureDefn->GetFieldIndex(pszName) >= 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"A field with same name %s already exists", pszName );
return;
}
CPLString osSQL(pszSQL);
std::vector<CPLString> aosAttrToBind;
std::vector<int> anIndexToBind;
size_t nStartSearch = 0;
while(TRUE)
{
size_t nPos = osSQL.find("[", nStartSearch);
if( nPos == std::string::npos )
break;
nStartSearch = nPos + 1;
if( nPos > 0 && osSQL[nPos-1] != '\\' )
{
CPLString osAttr = osSQL.substr(nPos + 1);
size_t nPos2 = osAttr.find("]");
if( nPos2 == std::string::npos )
break;
osAttr.resize(nPos2);
osSQL = osSQL.substr(0, nPos) + "?" + osSQL.substr(nPos + 1 + nPos2+1);
aosAttrToBind.push_back(osAttr);
anIndexToBind.push_back(poFeatureDefn->GetFieldIndex(osAttr));
}
}
while(TRUE)
{
size_t nPos = osSQL.find("\\");
if( nPos == std::string::npos || nPos == osSQL.size() - 1 )
break;
osSQL = osSQL.substr(0, nPos) + osSQL.substr(nPos + 1);
}
CPLDebug("OSM", "SQL : \"%s\"", osSQL.c_str());
sqlite3_stmt *hStmt;
int rc = sqlite3_prepare( poDS->hDBForComputedAttributes, osSQL, -1,
&hStmt, NULL );
if( rc != SQLITE_OK )
{
CPLError( CE_Failure, CPLE_AppDefined,
"sqlite3_prepare() failed : %s",
sqlite3_errmsg(poDS->hDBForComputedAttributes) );
return;
}
OGRFieldDefn oField(pszName, eType);
poFeatureDefn->AddFieldDefn(&oField);
oComputedAttributes.push_back(OGROSMComputedAttribute(pszName));
oComputedAttributes[oComputedAttributes.size()-1].eType = eType;
oComputedAttributes[oComputedAttributes.size()-1].nIndex = poFeatureDefn->GetFieldCount() - 1;
oComputedAttributes[oComputedAttributes.size()-1].osSQL = pszSQL;
oComputedAttributes[oComputedAttributes.size()-1].hStmt = hStmt;
oComputedAttributes[oComputedAttributes.size()-1].aosAttrToBind = aosAttrToBind;
oComputedAttributes[oComputedAttributes.size()-1].anIndexToBind = anIndexToBind;
}
示例9: WFS_ExprDumpAsOGCFilter
static int WFS_ExprDumpAsOGCFilter(CPLString& osFilter,
const Expr* expr,
int bExpectBinary,
ExprDumpFilterOptions* psOptions)
{
switch(expr->eType)
{
case TOKEN_VAR_NAME:
{
if (bExpectBinary)
return FALSE;
/* Special fields not understood by server */
if (EQUAL(expr->pszVal, "gml_id") ||
EQUAL(expr->pszVal, "FID") ||
EQUAL(expr->pszVal, "OGR_GEOMETRY") ||
EQUAL(expr->pszVal, "OGR_GEOM_WKT") ||
EQUAL(expr->pszVal, "OGR_GEOM_AREA") ||
EQUAL(expr->pszVal, "OGR_STYLE"))
{
CPLDebug("WFS", "Attribute refers to a OGR special field. Cannot use server-side filtering");
return FALSE;
}
const char* pszFieldname;
CPLString osVal;
if (expr->pszVal[0] == '\'' || expr->pszVal[0] == '"')
{
osVal = expr->pszVal + 1;
osVal.resize(osVal.size() - 1);
pszFieldname = osVal.c_str();
}
else
pszFieldname = expr->pszVal;
if (psOptions->poFDefn->GetFieldIndex(pszFieldname) == -1)
{
CPLDebug("WFS", "Field '%s' unknown. Cannot use server-side filtering",
pszFieldname);
return FALSE;
}
if (psOptions->nVersion >= 200)
osFilter += "<ValueReference>";
else
osFilter += "<PropertyName>";
char* pszFieldnameXML = CPLEscapeString(pszFieldname, -1, CPLES_XML);
osFilter += pszFieldnameXML;
CPLFree(pszFieldnameXML);
if (psOptions->nVersion >= 200)
osFilter += "</ValueReference>";
else
osFilter += "</PropertyName>";
break;
}
case TOKEN_LITERAL:
{
if (bExpectBinary)
return FALSE;
const char* pszLiteral;
CPLString osVal;
if (expr->pszVal[0] == '\'' || expr->pszVal[0] == '"')
{
osVal = expr->pszVal + 1;
osVal.resize(osVal.size() - 1);
pszLiteral = osVal.c_str();
}
else
pszLiteral = expr->pszVal;
osFilter += "<Literal>";
char* pszLiteralXML = CPLEscapeString(pszLiteral, -1, CPLES_XML);
osFilter += pszLiteralXML;
CPLFree(pszLiteralXML);
osFilter += "</Literal>";
break;
}
case TOKEN_NOT:
osFilter += "<Not>";
if (!WFS_ExprDumpAsOGCFilter(osFilter, expr->expr1, TRUE, psOptions))
return FALSE;
osFilter += "</Not>";
break;
case TOKEN_LIKE:
{
CPLString osVal;
char ch;
char firstCh = 0;
int i;
if (psOptions->nVersion == 100)
osFilter += "<PropertyIsLike wildCard='*' singleChar='_' escape='!'>";
else
osFilter += "<PropertyIsLike wildCard='*' singleChar='_' escapeChar='!'>";
if (!WFS_ExprDumpAsOGCFilter(osFilter, expr->expr1, FALSE, psOptions))
return FALSE;
//.........这里部分代码省略.........
示例10: AnalyseAzureFileList
bool VSIDIRAz::AnalyseAzureFileList(
const CPLString& osBaseURL,
const char* pszXML)
{
#if DEBUG_VERBOSE
CPLDebug("AZURE", "%s", pszXML);
#endif
CPLXMLNode* psTree = CPLParseXMLString(pszXML);
if( psTree == nullptr )
return false;
CPLXMLNode* psEnumerationResults = CPLGetXMLNode(psTree, "=EnumerationResults");
bool bNonEmpty = false;
if( psEnumerationResults )
{
CPLString osPrefix = CPLGetXMLValue(psEnumerationResults, "Prefix", "");
CPLXMLNode* psBlobs = CPLGetXMLNode(psEnumerationResults, "Blobs");
if( psBlobs == nullptr )
{
psBlobs = CPLGetXMLNode(psEnumerationResults, "Containers");
if( psBlobs != nullptr )
bNonEmpty = true;
}
// Count the number of occurrences of a path. Can be 1 or 2. 2 in the case
// that both a filename and directory exist
std::map<CPLString, int> aoNameCount;
for(CPLXMLNode* psIter = psBlobs ? psBlobs->psChild : nullptr;
psIter != nullptr; psIter = psIter->psNext )
{
if( psIter->eType != CXT_Element )
continue;
if( strcmp(psIter->pszValue, "Blob") == 0 )
{
const char* pszKey = CPLGetXMLValue(psIter, "Name", nullptr);
if( pszKey && strstr(pszKey, GDAL_MARKER_FOR_DIR) != nullptr )
{
bNonEmpty = true;
}
else if( pszKey && strlen(pszKey) > osPrefix.size() )
{
bNonEmpty = true;
aoNameCount[pszKey + osPrefix.size()] ++;
}
}
else if( strcmp(psIter->pszValue, "BlobPrefix") == 0 ||
strcmp(psIter->pszValue, "Container") == 0 )
{
bNonEmpty = true;
const char* pszKey = CPLGetXMLValue(psIter, "Name", nullptr);
if( pszKey && strncmp(pszKey, osPrefix, osPrefix.size()) == 0 )
{
CPLString osKey = pszKey;
if( !osKey.empty() && osKey.back() == '/' )
osKey.resize(osKey.size()-1);
if( osKey.size() > osPrefix.size() )
{
aoNameCount[osKey.c_str() + osPrefix.size()] ++;
}
}
}
}
for(CPLXMLNode* psIter = psBlobs ? psBlobs->psChild : nullptr;
psIter != nullptr; psIter = psIter->psNext )
{
if( psIter->eType != CXT_Element )
continue;
if( strcmp(psIter->pszValue, "Blob") == 0 )
{
const char* pszKey = CPLGetXMLValue(psIter, "Name", nullptr);
if( pszKey && strstr(pszKey, GDAL_MARKER_FOR_DIR) != nullptr )
{
if( nRecurseDepth < 0 )
{
aoEntries.push_back(
std::unique_ptr<VSIDIREntry>(new VSIDIREntry()));
auto& entry = aoEntries.back();
entry->pszName = CPLStrdup(pszKey + osPrefix.size());
char* pszMarker = strstr(entry->pszName, GDAL_MARKER_FOR_DIR);
if( pszMarker )
*pszMarker = '\0';
entry->nMode = S_IFDIR;
entry->bModeKnown = true;
}
}
else if( pszKey && strlen(pszKey) > osPrefix.size() )
{
aoEntries.push_back(
std::unique_ptr<VSIDIREntry>(new VSIDIREntry()));
auto& entry = aoEntries.back();
entry->pszName = CPLStrdup(pszKey + osPrefix.size());
entry->nSize = static_cast<GUIntBig>(
CPLAtoGIntBig(CPLGetXMLValue(psIter, "Properties.Content-Length", "0")));
entry->bSizeKnown = true;
entry->nMode = S_IFDIR;
entry->bModeKnown = true;
//.........这里部分代码省略.........
示例11: 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;
}
示例12: 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");
if (SQLITE_OK != sqlite3_open(osDbName, &m_poDB)) {
CPLError(CE_Failure, CPLE_AppDefined,
"Creating SQLite DB failed");
}
else {
char* pszErrMsg = NULL;
CPL_IGNORE_RET_VAL(sqlite3_exec(m_poDB, "PRAGMA synchronous = OFF", NULL, NULL, &pszErrMsg));
sqlite3_free(pszErrMsg);
}
if (m_bNewDb) {
/* new DB, create support metadata tables */
osCommand.Printf("CREATE TABLE %s (file_name text, table_name text, num_records integer, "
"num_features integer, num_geometries integer, table_defn text)",
VFK_DB_TABLE);
ExecuteSQL(osCommand.c_str());
/* header table */
osCommand.Printf("CREATE TABLE %s (key text, value text)", VFK_DB_HEADER);
ExecuteSQL(osCommand.c_str());
}
}
示例13: if
//.........这里部分代码省略.........
case SWQ_LE:
poRet->int_value =
strcasecmp(sub_node_values[0]->string_value,
sub_node_values[1]->string_value) <= 0;
break;
case SWQ_IN:
{
int i;
poRet->int_value = 0;
for( i = 1; i < node->nSubExprCount; i++ )
{
if( strcasecmp(sub_node_values[0]->string_value,
sub_node_values[i]->string_value) == 0 )
{
poRet->int_value = 1;
break;
}
}
}
break;
case SWQ_BETWEEN:
poRet->int_value =
strcasecmp(sub_node_values[0]->string_value,
sub_node_values[1]->string_value) >= 0 &&
strcasecmp(sub_node_values[0]->string_value,
sub_node_values[2]->string_value) <= 0;
break;
case SWQ_LIKE:
poRet->int_value = swq_test_like(sub_node_values[0]->string_value,
sub_node_values[1]->string_value);
break;
case SWQ_ISNULL:
poRet->int_value = sub_node_values[0]->is_null;
break;
case SWQ_CONCAT:
case SWQ_ADD:
{
CPLString osResult = sub_node_values[0]->string_value;
int i;
for( i = 1; i < node->nSubExprCount; i++ )
osResult += sub_node_values[i]->string_value;
poRet->string_value = CPLStrdup(osResult);
break;
}
case SWQ_SUBSTR:
{
int nOffset, nSize;
const char *pszSrcStr = sub_node_values[0]->string_value;
if( sub_node_values[1]->field_type == SWQ_INTEGER )
nOffset = sub_node_values[1]->int_value;
else if( sub_node_values[1]->field_type == SWQ_FLOAT )
nOffset = (int) sub_node_values[1]->float_value;
else
nOffset = 0;
if( node->nSubExprCount < 3 )
nSize = 100000;
else if( sub_node_values[2]->field_type == SWQ_INTEGER )
nSize = sub_node_values[2]->int_value;
else if( sub_node_values[2]->field_type == SWQ_FLOAT )
nSize = (int) sub_node_values[2]->float_value;
else
nSize = 0;
int nSrcStrLen = (int)strlen(pszSrcStr);
if( nOffset < 0 || nSize < 0 || nOffset > nSrcStrLen )
{
nOffset = 0;
nSize = 0;
}
else if( nOffset + nSize > nSrcStrLen )
nSize = nSrcStrLen - nOffset;
CPLString osResult = pszSrcStr + nOffset;
if( (int)osResult.size() > nSize )
osResult.resize( nSize );
poRet->string_value = CPLStrdup(osResult);
break;
}
default:
CPLAssert( FALSE );
delete poRet;
poRet = NULL;
break;
}
}
return poRet;
}
示例14: CPLParseXMLString
static
CPLXMLNode * GDALWMSDatasetGetConfigFromURL(GDALOpenInfo *poOpenInfo)
{
const char* pszBaseURL = poOpenInfo->pszFilename;
if (EQUALN(pszBaseURL, "WMS:", 4))
pszBaseURL += 4;
CPLString osLayer = CPLURLGetValue(pszBaseURL, "LAYERS");
CPLString osVersion = CPLURLGetValue(pszBaseURL, "VERSION");
CPLString osSRS = CPLURLGetValue(pszBaseURL, "SRS");
CPLString osCRS = CPLURLGetValue(pszBaseURL, "CRS");
CPLString osBBOX = CPLURLGetValue(pszBaseURL, "BBOX");
CPLString osFormat = CPLURLGetValue(pszBaseURL, "FORMAT");
CPLString osTransparent = CPLURLGetValue(pszBaseURL, "TRANSPARENT");
/* GDAL specific extensions to alter the default settings */
CPLString osOverviewCount = CPLURLGetValue(pszBaseURL, "OVERVIEWCOUNT");
CPLString osTileSize = CPLURLGetValue(pszBaseURL, "TILESIZE");
CPLString osMinResolution = CPLURLGetValue(pszBaseURL, "MINRESOLUTION");
CPLString osBBOXOrder = CPLURLGetValue(pszBaseURL, "BBOXORDER");
CPLString osBaseURL = pszBaseURL;
/* Remove all keywords to get base URL */
osBaseURL = CPLURLAddKVP(osBaseURL, "VERSION", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "REQUEST", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "LAYERS", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "SRS", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "CRS", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "BBOX", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "FORMAT", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "TRANSPARENT", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "STYLES", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "WIDTH", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "HEIGHT", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "OVERVIEWCOUNT", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "TILESIZE", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "MINRESOLUTION", NULL);
osBaseURL = CPLURLAddKVP(osBaseURL, "BBOXORDER", NULL);
if (osBaseURL.size() > 0 && osBaseURL[osBaseURL.size() - 1] == '&')
osBaseURL.resize(osBaseURL.size() - 1);
if (osVersion.size() == 0)
osVersion = "1.1.1";
CPLString osSRSTag;
CPLString osSRSValue;
if(VersionStringToInt(osVersion.c_str())>= VersionStringToInt("1.3.0"))
{
if (osSRS.size())
{
CPLError(CE_Warning, CPLE_AppDefined,
"WMS version 1.3 and above expects CRS however SRS was set instead.");
}
osSRSValue = osCRS;
osSRSTag = "CRS";
}
else
{
if (osCRS.size())
{
CPLError(CE_Warning, CPLE_AppDefined,
"WMS version 1.1.1 and below expects SRS however CRS was set instead.");
}
osSRSValue = osSRS;
osSRSTag = "SRS";
}
if (osSRSValue.size() == 0)
osSRSValue = "EPSG:4326";
if (osBBOX.size() == 0)
{
if (osBBOXOrder.compare("yxYX") == 0)
osBBOX = "-90,-180,90,180";
else
osBBOX = "-180,-90,180,90";
}
char** papszTokens = CSLTokenizeStringComplex(osBBOX, ",", 0, 0);
if (CSLCount(papszTokens) != 4)
{
CSLDestroy(papszTokens);
return NULL;
}
const char* pszMinX = papszTokens[0];
const char* pszMinY = papszTokens[1];
const char* pszMaxX = papszTokens[2];
const char* pszMaxY = papszTokens[3];
if (osBBOXOrder.compare("yxYX") == 0)
{
std::swap(pszMinX, pszMinY);
std::swap(pszMaxX, pszMaxY);
}
double dfMinX = CPLAtofM(pszMinX);
double dfMinY = CPLAtofM(pszMinY);
//.........这里部分代码省略.........
示例15: if
char **CPL_STDCALL GDALLoadRPBFile( const char *pszFilename,
char **papszSiblingFiles )
{
/* -------------------------------------------------------------------- */
/* Try to identify the RPB file in upper or lower case. */
/* -------------------------------------------------------------------- */
CPLString osTarget = CPLResetExtension( pszFilename, "RPB" );
/* Is this already a RPB file ? */
if (EQUAL(CPLGetExtension(pszFilename), "RPB"))
osTarget = pszFilename;
else if( papszSiblingFiles == NULL )
{
VSIStatBufL sStatBuf;
if( VSIStatL( osTarget, &sStatBuf ) != 0 )
{
osTarget = CPLResetExtension( pszFilename, "rpb" );
if( VSIStatL( osTarget, &sStatBuf ) != 0 )
return NULL;
}
}
else
{
int iSibling = CSLFindString( papszSiblingFiles,
CPLGetFilename(osTarget) );
if( iSibling < 0 )
return NULL;
osTarget.resize(osTarget.size() - strlen(papszSiblingFiles[iSibling]));
osTarget += papszSiblingFiles[iSibling];
}
/* -------------------------------------------------------------------- */
/* Read file and parse. */
/* -------------------------------------------------------------------- */
CPLKeywordParser oParser;
VSILFILE *fp = VSIFOpenL( osTarget, "r" );
if( fp == NULL )
return NULL;
if( !oParser.Ingest( fp ) )
{
VSIFCloseL( fp );
return NULL;
}
VSIFCloseL( fp );
/* -------------------------------------------------------------------- */
/* Extract RPC information, in a GDAL "standard" metadata format. */
/* -------------------------------------------------------------------- */
int i;
char **papszMD = NULL;
for( i = 0; apszRPBMap[i] != NULL; i += 2 )
{
const char *pszRPBVal = oParser.GetKeyword( apszRPBMap[i+1] );
CPLString osAdjVal;
if( pszRPBVal == NULL )
{
CPLError( CE_Failure, CPLE_AppDefined,
"%s file found, but missing %s field (and possibly others).",
osTarget.c_str(), apszRPBMap[i+1] );
CSLDestroy( papszMD );
return NULL;
}
if( strchr(pszRPBVal,',') == NULL )
osAdjVal = pszRPBVal;
else
{
// strip out commas and turn newlines into spaces.
int j;
for( j = 0; pszRPBVal[j] != '\0'; j++ )
{
switch( pszRPBVal[j] )
{
case ',':
case '\n':
case '\r':
osAdjVal += ' ';
break;
case '(':
case ')':
break;
default:
osAdjVal += pszRPBVal[j];
}
}
}
papszMD = CSLSetNameValue( papszMD, apszRPBMap[i], osAdjVal );
//.........这里部分代码省略.........