本文整理汇总了C++中CPLStringList::SetNameValue方法的典型用法代码示例。如果您正苦于以下问题:C++ CPLStringList::SetNameValue方法的具体用法?C++ CPLStringList::SetNameValue怎么用?C++ CPLStringList::SetNameValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPLStringList
的用法示例。
在下文中一共展示了CPLStringList::SetNameValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ensure
void object::test<9>()
{
// Test some name=value handling stuff *with* sorting active.
CPLStringList oNVL;
oNVL.Sort();
oNVL.AddNameValue( "KEY1", "VALUE1" );
oNVL.AddNameValue( "2KEY", "VALUE2" );
ensure_equals( "91", oNVL.Count(), 2 );
ensure( "92", EQUAL(oNVL.FetchNameValue("KEY1"),"VALUE1") );
ensure( "93", EQUAL(oNVL.FetchNameValue("2KEY"),"VALUE2") );
ensure( "94", oNVL.FetchNameValue("MISSING") == NULL );
oNVL.AddNameValue( "KEY1", "VALUE3" );
ensure_equals( "95", oNVL.Count(), 3 );
ensure( "96", EQUAL(oNVL.FetchNameValue("KEY1"),"VALUE1") );
ensure( "97", EQUAL(oNVL.FetchNameValueDef("MISSING","X"),"X") );
oNVL.SetNameValue( "2KEY", "VALUE4" );
ensure( "98", EQUAL(oNVL.FetchNameValue("2KEY"),"VALUE4") );
ensure_equals( "99", oNVL.Count(), 3 );
// make sure deletion works.
oNVL.SetNameValue( "2KEY", NULL );
ensure( "9a", oNVL.FetchNameValue("2KEY") == NULL );
ensure_equals( "9b", oNVL.Count(), 2 );
// Test insertion logic pretty carefully.
oNVL.Clear();
ensure( "9c", oNVL.IsSorted() == TRUE );
oNVL.SetNameValue( "B", "BB" );
oNVL.SetNameValue( "A", "AA" );
oNVL.SetNameValue( "D", "DD" );
oNVL.SetNameValue( "C", "CC" );
// items should be in sorted order.
ensure( "9c1", EQUAL(oNVL[0],"A=AA") );
ensure( "9c2", EQUAL(oNVL[1],"B=BB") );
ensure( "9c3", EQUAL(oNVL[2],"C=CC") );
ensure( "9c4", EQUAL(oNVL[3],"D=DD") );
ensure( "9d", EQUAL(oNVL.FetchNameValue("A"),"AA") );
ensure( "9e", EQUAL(oNVL.FetchNameValue("B"),"BB") );
ensure( "9f", EQUAL(oNVL.FetchNameValue("C"),"CC") );
ensure( "9g", EQUAL(oNVL.FetchNameValue("D"),"DD") );
}
示例2: ParseSimpleJson
static CPLStringList ParseSimpleJson(const char *pszJson)
{
/* -------------------------------------------------------------------- */
/* We are expecting simple documents like the following with no */
/* heirarchy or complex structure. */
/* -------------------------------------------------------------------- */
/*
{
"access_token":"1/fFBGRNJru1FQd44AzqT3Zg",
"expires_in":3920,
"token_type":"Bearer"
}
*/
CPLStringList oWords(
CSLTokenizeString2(pszJson, " \n\t,:{}", CSLT_HONOURSTRINGS ));
CPLStringList oNameValue;
for( int i=0; i < oWords.size(); i += 2 )
{
oNameValue.SetNameValue( oWords[i], oWords[i+1] );
}
return oNameValue;
}
示例3: CTBException
/**
* @details This method is the heart of the tiler. A `TileCoordinate` is used
* to obtain the geospatial extent associated with that tile as related to the
* underlying GDAL dataset. This mapping may require a reprojection if the
* underlying dataset is not in the tile projection system. This information
* is then encapsulated as a GDAL virtual raster (VRT) dataset and returned to
* the caller.
*
* It is the caller's responsibility to call `GDALClose()` on the returned
* dataset.
*/
GDALTile *
GDALTiler::createRasterTile(double (&adfGeoTransform)[6]) const {
if (poDataset == NULL) {
throw CTBException("No GDAL dataset is set");
}
// The source and sink datasets
GDALDatasetH hSrcDS = (GDALDatasetH) dataset();
GDALDatasetH hDstDS;
// The transformation option list
CPLStringList transformOptions;
// The source, sink and grid srs
const char *pszSrcWKT = GDALGetProjectionRef(hSrcDS),
*pszGridWKT = pszSrcWKT;
if (!strlen(pszSrcWKT))
throw CTBException("The source dataset no longer has a spatial reference system assigned");
// Populate the SRS WKT strings if we need to reproject
if (requiresReprojection()) {
pszGridWKT = crsWKT.c_str();
transformOptions.SetNameValue("SRC_SRS", pszSrcWKT);
transformOptions.SetNameValue("DST_SRS", pszGridWKT);
}
// Set the warp options
GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();
psWarpOptions->eResampleAlg = options.resampleAlg;
psWarpOptions->dfWarpMemoryLimit = options.warpMemoryLimit;
psWarpOptions->hSrcDS = hSrcDS;
psWarpOptions->nBandCount = poDataset->GetRasterCount();
psWarpOptions->panSrcBands =
(int *) CPLMalloc(sizeof(int) * psWarpOptions->nBandCount );
psWarpOptions->panDstBands =
(int *) CPLMalloc(sizeof(int) * psWarpOptions->nBandCount );
for (short unsigned int i = 0; i < psWarpOptions->nBandCount; ++i) {
psWarpOptions->panDstBands[i] = psWarpOptions->panSrcBands[i] = i + 1;
}
// Create the image to image transformer
void *transformerArg = GDALCreateGenImgProjTransformer2(hSrcDS, NULL, transformOptions.List());
if(transformerArg == NULL) {
GDALDestroyWarpOptions(psWarpOptions);
throw CTBException("Could not create image to image transformer");
}
// Try and get an overview from the source dataset that corresponds more
// closely to the resolution of this tile.
GDALDatasetH hWrkSrcDS = getOverviewDataset(hSrcDS, GDALGenImgProjTransform, transformerArg);
if (hWrkSrcDS == NULL) {
hWrkSrcDS = psWarpOptions->hSrcDS = hSrcDS;
} else {
// We need to recreate the transform when operating on an overview.
GDALDestroyGenImgProjTransformer( transformerArg );
transformerArg = GDALCreateGenImgProjTransformer2( hWrkSrcDS, NULL, transformOptions.List() );
if(transformerArg == NULL) {
GDALDestroyWarpOptions(psWarpOptions);
throw CTBException("Could not create overview image to image transformer");
}
}
// Specify the destination geotransform
GDALSetGenImgProjTransformerDstGeoTransform(transformerArg, adfGeoTransform );
// Decide if we are doing an approximate or exact transformation
if (options.errorThreshold) {
// approximate: wrap the transformer with a linear approximator
psWarpOptions->pTransformerArg =
GDALCreateApproxTransformer(GDALGenImgProjTransform, transformerArg, options.errorThreshold);
if (psWarpOptions->pTransformerArg == NULL) {
GDALDestroyWarpOptions(psWarpOptions);
GDALDestroyGenImgProjTransformer(transformerArg);
throw CTBException("Could not create linear approximator");
}
psWarpOptions->pfnTransformer = GDALApproxTransform;
} else {
// exact: no wrapping required
psWarpOptions->pTransformerArg = transformerArg;
psWarpOptions->pfnTransformer = GDALGenImgProjTransform;
}
// Specify a multi threaded warp operation using all CPU cores
CPLStringList warpOptions(psWarpOptions->papszWarpOptions, false);
//.........这里部分代码省略.........
示例4: if
MAIN_START(argc, argv)
{
// Check that we are running against at least GDAL 1.5.
// Note to developers: if we use newer API, please change the requirement.
if (atoi(GDALVersionInfo("VERSION_NUM")) < 1500)
{
fprintf(stderr,
"At least, GDAL >= 1.5.0 is required for this version of %s, "
"which was compiled against GDAL %s\n",
argv[0], GDAL_RELEASE_NAME);
exit(1);
}
GDALAllRegister();
argc = GDALGeneralCmdLineProcessor( argc, &argv, 0 );
if( argc < 1 )
exit( -argc );
const char *pszSrcFilename = nullptr;
const char *pszDstFilename = nullptr;
int nOrder = 0;
void *hTransformArg;
GDALTransformerFunc pfnTransformer = nullptr;
int nGCPCount = 0;
GDAL_GCP *pasGCPs = nullptr;
int bInverse = FALSE;
CPLStringList aosTO;
int bOutputXY = FALSE;
double dfX = 0.0;
double dfY = 0.0;
double dfZ = 0.0;
double dfT = 0.0;
bool bCoordOnCommandLine = false;
/* -------------------------------------------------------------------- */
/* Parse arguments. */
/* -------------------------------------------------------------------- */
for( int i = 1; i < argc && argv[i] != nullptr; i++ )
{
if( EQUAL(argv[i], "--utility_version") )
{
printf("%s was compiled against GDAL %s and "
"is running against GDAL %s\n",
argv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME"));
CSLDestroy(argv);
return 0;
}
else if( EQUAL(argv[i],"--help") )
{
Usage();
}
else if( EQUAL(argv[i],"-t_srs") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
const char *pszSRS = argv[++i];
if( !IsValidSRS(pszSRS) )
exit(1);
aosTO.SetNameValue("DST_SRS", pszSRS );
}
else if( EQUAL(argv[i],"-s_srs") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
const char *pszSRS = argv[++i];
if( !IsValidSRS(pszSRS) )
exit(1);
aosTO.SetNameValue("SRC_SRS", pszSRS );
}
else if( EQUAL(argv[i],"-ct") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
const char *pszCT = argv[++i];
aosTO.SetNameValue("COORDINATE_OPERATION", pszCT );
}
else if( EQUAL(argv[i],"-order") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
nOrder = atoi(argv[++i]);
aosTO.SetNameValue("MAX_GCP_ORDER", argv[i] );
}
else if( EQUAL(argv[i],"-tps") )
{
aosTO.SetNameValue("METHOD", "GCP_TPS" );
nOrder = -1;
}
else if( EQUAL(argv[i],"-rpc") )
{
aosTO.SetNameValue("METHOD", "RPC" );
}
else if( EQUAL(argv[i],"-geoloc") )
{
aosTO.SetNameValue("METHOD", "GEOLOC_ARRAY" );
}
else if( EQUAL(argv[i],"-i") )
{
bInverse = TRUE;
}
else if( EQUAL(argv[i],"-to") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
//.........这里部分代码省略.........
示例5: XMLInit
int GDALMultiDomainMetadata::XMLInit( CPLXMLNode *psTree, CPL_UNUSED int bMerge )
{
CPLXMLNode *psMetadata;
/* ==================================================================== */
/* Process all <Metadata> elements, each for one domain. */
/* ==================================================================== */
for( psMetadata = psTree->psChild;
psMetadata != NULL; psMetadata = psMetadata->psNext )
{
CPLXMLNode *psMDI;
const char *pszDomain, *pszFormat;
if( psMetadata->eType != CXT_Element
|| !EQUAL(psMetadata->pszValue,"Metadata") )
continue;
pszDomain = CPLGetXMLValue( psMetadata, "domain", "" );
pszFormat = CPLGetXMLValue( psMetadata, "format", "" );
// Make sure we have a CPLStringList for this domain,
// without wiping out an existing one.
if( GetMetadata( pszDomain ) == NULL )
SetMetadata( NULL, pszDomain );
int iDomain = CSLFindString( papszDomainList, pszDomain );
CPLAssert( iDomain != -1 );
CPLStringList *poMDList = papoMetadataLists[iDomain];
/* -------------------------------------------------------------------- */
/* XML format subdocuments. */
/* -------------------------------------------------------------------- */
if( EQUAL(pszFormat,"xml") )
{
CPLXMLNode *psSubDoc;
/* find first non-attribute child of current element */
psSubDoc = psMetadata->psChild;
while( psSubDoc != NULL && psSubDoc->eType == CXT_Attribute )
psSubDoc = psSubDoc->psNext;
char *pszDoc = CPLSerializeXMLTree( psSubDoc );
poMDList->Clear();
poMDList->AddStringDirectly( pszDoc );
}
/* -------------------------------------------------------------------- */
/* Name value format. */
/* <MDI key="...">value_Text</MDI> */
/* -------------------------------------------------------------------- */
else
{
for( psMDI = psMetadata->psChild; psMDI != NULL;
psMDI = psMDI->psNext )
{
if( !EQUAL(psMDI->pszValue,"MDI")
|| psMDI->eType != CXT_Element
|| psMDI->psChild == NULL
|| psMDI->psChild->psNext == NULL
|| psMDI->psChild->eType != CXT_Attribute
|| psMDI->psChild->psChild == NULL )
continue;
char* pszName = psMDI->psChild->psChild->pszValue;
char* pszValue = psMDI->psChild->psNext->pszValue;
if( pszName != NULL && pszValue != NULL )
poMDList->SetNameValue( pszName, pszValue );
}
}
}
return CSLCount(papszDomainList) != 0;
}