int gv_symbol_manager_save_vector_symbol( GvSymbolManager *manager, const char *symbol_name, const char *new_name ) { GvSymbolObj *symbol; /* allocate a new symbol object */ symbol = g_hash_table_lookup( manager->symbol_cache, symbol_name ); CPLDebug("OpenEV", "save_vector_symbol(%s->%s)", symbol_name, new_name ); if ( symbol && symbol->type == GV_SYMBOL_VECTOR ) { GvShape *shape; CPLXMLNode *xml_shape; shape = (GvShape *)symbol->buffer; xml_shape = gv_shape_to_xml_tree( shape ); if ( CPLSerializeXMLTreeToFile( xml_shape, new_name ) ) { CPLDestroyXMLNode( xml_shape ); return TRUE; } } return FALSE; }
void GDALJP2AbstractDataset::LoadVectorLayers(int bOpenRemoteResources) { char** papszGMLJP2 = GetMetadata("xml:gml.root-instance"); if( papszGMLJP2 == NULL ) return; GDALDriver* poMemDriver = (GDALDriver*)GDALGetDriverByName("Memory"); if( poMemDriver == NULL ) return; CPLXMLNode* psRoot = CPLParseXMLString(papszGMLJP2[0]); if( psRoot == NULL ) return; CPLXMLNode* psCC = CPLGetXMLNode(psRoot, "=gmljp2:GMLJP2CoverageCollection"); if( psCC == NULL ) { CPLDestroyXMLNode(psRoot); return; } // Find feature collections CPLXMLNode* psCCChildIter = psCC->psChild; int nLayersAtCC = 0; int nLayersAtGC = 0; for( ; psCCChildIter != NULL; psCCChildIter = psCCChildIter->psNext ) { if( psCCChildIter->eType != CXT_Element || strcmp(psCCChildIter->pszValue, "gmljp2:featureMember") != 0 || psCCChildIter->psChild == NULL || psCCChildIter->psChild->eType != CXT_Element ) continue; CPLXMLNode* psGCorGMLJP2Features = psCCChildIter->psChild; int bIsGC = ( strstr(psGCorGMLJP2Features->pszValue, "GridCoverage") != NULL ); CPLXMLNode* psGCorGMLJP2FeaturesChildIter = psGCorGMLJP2Features->psChild; for( ; psGCorGMLJP2FeaturesChildIter != NULL; psGCorGMLJP2FeaturesChildIter = psGCorGMLJP2FeaturesChildIter->psNext ) { if( psGCorGMLJP2FeaturesChildIter->eType != CXT_Element || strcmp(psGCorGMLJP2FeaturesChildIter->pszValue, "gmljp2:feature") != 0 || psGCorGMLJP2FeaturesChildIter->psChild == NULL ) continue; CPLXMLNode* psFC = NULL; int bFreeFC = FALSE; CPLString osGMLTmpFile; CPLXMLNode* psChild = psGCorGMLJP2FeaturesChildIter->psChild; if( psChild->eType == CXT_Attribute && strcmp(psChild->pszValue, "xlink:href") == 0 && strncmp(psChild->psChild->pszValue, "gmljp2://xml/", strlen("gmljp2://xml/")) == 0 ) { const char* pszBoxName = psChild->psChild->pszValue + strlen("gmljp2://xml/"); char** papszBoxData = GetMetadata(CPLSPrintf("xml:%s", pszBoxName)); if( papszBoxData != NULL ) { psFC = CPLParseXMLString(papszBoxData[0]); bFreeFC = TRUE; } else { CPLDebug("GMLJP2", "gmljp2:feature references %s, but no corresponding box found", psChild->psChild->pszValue); } } if( psChild->eType == CXT_Attribute && strcmp(psChild->pszValue, "xlink:href") == 0 && (strncmp(psChild->psChild->pszValue, "http://", strlen("http://")) == 0 || strncmp(psChild->psChild->pszValue, "https://", strlen("https://")) == 0) ) { if( !bOpenRemoteResources ) CPLDebug("GMLJP2", "Remote feature collection %s mentionned in GMLJP2 box", psChild->psChild->pszValue); else osGMLTmpFile = "/vsicurl/" + CPLString(psChild->psChild->pszValue); } else if( psChild->eType == CXT_Element && strstr(psChild->pszValue, "FeatureCollection") != NULL ) { psFC = psChild; } if( psFC == NULL && osGMLTmpFile.size() == 0 ) continue; if( psFC != NULL ) { osGMLTmpFile = CPLSPrintf("/vsimem/gmljp2/%p/my.gml", this); // Create temporary .gml file CPLSerializeXMLTreeToFile(psFC, osGMLTmpFile); } CPLDebug("GMLJP2", "Found a FeatureCollection at %s level", (bIsGC) ? "GridCoverage" : "CoverageCollection"); CPLString osXSDTmpFile; if( psFC ) { // Try to localize its .xsd schema in a GMLJP2 auxiliary box const char* pszSchemaLocation = CPLGetXMLValue(psFC, "xsi:schemaLocation", NULL); if( pszSchemaLocation ) { char **papszTokens = CSLTokenizeString2( pszSchemaLocation, " \t\n", CSLT_HONOURSTRINGS | CSLT_STRIPLEADSPACES | CSLT_STRIPENDSPACES); if( (CSLCount(papszTokens) % 2) == 0 ) { for(char** papszIter = papszTokens; *papszIter; papszIter += 2 ) { if( strncmp(papszIter[1], "gmljp2://xml/", strlen("gmljp2://xml/")) == 0 ) { const char* pszBoxName = papszIter[1] + strlen("gmljp2://xml/"); char** papszBoxData = GetMetadata(CPLSPrintf("xml:%s", pszBoxName)); if( papszBoxData != NULL ) { osXSDTmpFile = CPLSPrintf("/vsimem/gmljp2/%p/my.xsd", this); VSIFCloseL(VSIFileFromMemBuffer(osXSDTmpFile, (GByte*)papszBoxData[0], strlen(papszBoxData[0]), FALSE)); } else { CPLDebug("GMLJP2", "Feature collection references %s, but no corresponding box found", papszIter[1]); } break; } } } CSLDestroy(papszTokens); } if( bFreeFC ) { CPLDestroyXMLNode(psFC); psFC = NULL; } } GDALDriverH hDrv = GDALIdentifyDriver(osGMLTmpFile, NULL); GDALDriverH hGMLDrv = GDALGetDriverByName("GML"); if( hDrv != NULL && hDrv == hGMLDrv ) { char* apszOpenOptions[2]; apszOpenOptions[0] = (char*) "FORCE_SRS_DETECTION=YES"; apszOpenOptions[1] = NULL; GDALDataset* poTmpDS = (GDALDataset*)GDALOpenEx( osGMLTmpFile, GDAL_OF_VECTOR, NULL, apszOpenOptions, NULL ); if( poTmpDS ) { int nLayers = poTmpDS->GetLayerCount(); for(int i=0;i<nLayers;i++) { if( poMemDS == NULL ) poMemDS = poMemDriver->Create("", 0, 0, 0, GDT_Unknown, NULL); OGRLayer* poSrcLyr = poTmpDS->GetLayer(i); const char* pszLayerName; if( bIsGC ) pszLayerName = CPLSPrintf("FC_GridCoverage_%d_%s", ++nLayersAtGC, poSrcLyr->GetName()); else pszLayerName = CPLSPrintf("FC_CoverageCollection_%d_%s", ++nLayersAtCC, poSrcLyr->GetName()); poMemDS->CopyLayer(poSrcLyr, pszLayerName, NULL); } GDALClose(poTmpDS); // In case we don't have a schema, a .gfs might have been generated VSIUnlink(CPLSPrintf("/vsimem/gmljp2/%p/my.gfs", this)); } } else { CPLDebug("GMLJP2", "No GML driver found to read feature collection"); } if( strncmp(osGMLTmpFile, "/vsicurl/", strlen("/vsicurl/")) != 0 ) VSIUnlink(osGMLTmpFile); if( osXSDTmpFile.size() ) VSIUnlink(osXSDTmpFile); } } // Find annotations psCCChildIter = psCC->psChild; int nAnnotations = 0; for( ; psCCChildIter != NULL; psCCChildIter = psCCChildIter->psNext ) { if( psCCChildIter->eType != CXT_Element || strcmp(psCCChildIter->pszValue, "gmljp2:featureMember") != 0 || psCCChildIter->psChild == NULL || psCCChildIter->psChild->eType != CXT_Element ) continue; CPLXMLNode* psGCorGMLJP2Features = psCCChildIter->psChild; int bIsGC = ( strstr(psGCorGMLJP2Features->pszValue, "GridCoverage") != NULL ); if( !bIsGC ) continue; CPLXMLNode* psGCorGMLJP2FeaturesChildIter = psGCorGMLJP2Features->psChild; for( ; psGCorGMLJP2FeaturesChildIter != NULL; psGCorGMLJP2FeaturesChildIter = psGCorGMLJP2FeaturesChildIter->psNext ) { if( psGCorGMLJP2FeaturesChildIter->eType != CXT_Element || strcmp(psGCorGMLJP2FeaturesChildIter->pszValue, "gmljp2:annotation") != 0 || psGCorGMLJP2FeaturesChildIter->psChild == NULL || psGCorGMLJP2FeaturesChildIter->psChild->eType != CXT_Element || strstr(psGCorGMLJP2FeaturesChildIter->psChild->pszValue, "kml") == NULL ) continue; CPLDebug("GMLJP2", "Found a KML annotation"); // Create temporary .kml file CPLXMLNode* psKML = psGCorGMLJP2FeaturesChildIter->psChild; CPLString osKMLTmpFile(CPLSPrintf("/vsimem/gmljp2/%p/my.kml", this)); CPLSerializeXMLTreeToFile(psKML, osKMLTmpFile); GDALDataset* poTmpDS = (GDALDataset*)GDALOpenEx( osKMLTmpFile, GDAL_OF_VECTOR, NULL, NULL, NULL ); if( poTmpDS ) { int nLayers = poTmpDS->GetLayerCount(); for(int i=0;i<nLayers;i++) { if( poMemDS == NULL ) poMemDS = poMemDriver->Create("", 0, 0, 0, GDT_Unknown, NULL); OGRLayer* poSrcLyr = poTmpDS->GetLayer(i); const char* pszLayerName; pszLayerName = CPLSPrintf("Annotation_%d_%s", ++nAnnotations, poSrcLyr->GetName()); poMemDS->CopyLayer(poSrcLyr, pszLayerName, NULL); } GDALClose(poTmpDS); } else { CPLDebug("GMLJP2", "No KML/LIBKML driver found to read annotation"); } VSIUnlink(osKMLTmpFile); } } CPLDestroyXMLNode(psRoot); }
int GMLReader::ResolveXlinks( const char *pszFile, int* pbOutIsTempFile, char **papszSkip, const int bStrict) { *pbOutIsTempFile = FALSE; // Check if the original source file is set. if( m_pszFilename == NULL ) { CPLError( CE_Failure, CPLE_NotSupported, "GML source file needs to be set first with " "GMLReader::SetSourceFile()." ); return FALSE; } /* -------------------------------------------------------------------- */ /* Load the raw XML file into a XML Node tree. */ /* -------------------------------------------------------------------- */ CPLXMLNode **papsSrcTree; papsSrcTree = (CPLXMLNode **)CPLCalloc( 2, sizeof(CPLXMLNode *)); papsSrcTree[0] = CPLParseXMLFile( m_pszFilename ); if( papsSrcTree[0] == NULL ) { CPLFree(papsSrcTree); return FALSE; } //make all the URLs absolute CPLXMLNode *psSibling = NULL; for( psSibling = papsSrcTree[0]; psSibling != NULL; psSibling = psSibling->psNext ) CorrectURLs( psSibling, m_pszFilename ); //setup resource data structure char **papszResourceHREF = NULL; // "" is the href of the original source file papszResourceHREF = CSLAddString( papszResourceHREF, m_pszFilename ); //call resolver CPLErr eReturned = CE_None; eReturned = Resolve( papsSrcTree[0], &papsSrcTree, &papszResourceHREF, papszSkip, bStrict ); int bReturn = TRUE; if( eReturned != CE_Failure ) { char *pszTmpName = NULL; int bTryWithTempFile = FALSE; if( EQUALN(pszFile, "/vsitar/", strlen("/vsitar/")) || EQUALN(pszFile, "/vsigzip/", strlen("/vsigzip/")) || EQUALN(pszFile, "/vsizip/", strlen("/vsizip/")) ) { bTryWithTempFile = TRUE; } else if( !CPLSerializeXMLTreeToFile( papsSrcTree[0], pszFile ) ) { CPLError( CE_Failure, CPLE_FileIO, "Cannot serialize resolved file %s to %s.", m_pszFilename, pszFile ); bTryWithTempFile = TRUE; } if (bTryWithTempFile) { pszTmpName = CPLStrdup( CPLGenerateTempFilename( "ResolvedGML" ) ); if( !CPLSerializeXMLTreeToFile( papsSrcTree[0], pszTmpName ) ) { CPLError( CE_Failure, CPLE_FileIO, "Cannot serialize resolved file %s to %s either.", m_pszFilename, pszTmpName ); CPLFree( pszTmpName ); bReturn = FALSE; } else { //set the source file to the resolved file CPLFree( m_pszFilename ); m_pszFilename = pszTmpName; *pbOutIsTempFile = TRUE; } } else { //set the source file to the resolved file CPLFree( m_pszFilename ); m_pszFilename = CPLStrdup( pszFile ); } } else { bReturn = FALSE; } int nItems = CSLCount( papszResourceHREF ); CSLDestroy( papszResourceHREF ); while( nItems > 0 ) CPLDestroyXMLNode( papsSrcTree[--nItems] ); CPLFree( papsSrcTree ); return bReturn; }
static void CPLXMLSchemaResolveInclude( const char* pszMainSchemaLocation, CPLXMLNode *psSchemaNode ) { std::set<CPLString> osAlreadyIncluded; bool bTryAgain; do { CPLXMLNode *psLast = NULL; bTryAgain = false; CPLXMLNode *psThis = psSchemaNode->psChild; for( ; psThis != NULL; psThis = psThis->psNext ) { if( psThis->eType == CXT_Element && EQUAL(psThis->pszValue,"include") ) { const char* pszSchemaLocation = CPLGetXMLValue(psThis, "schemaLocation", NULL); if( pszSchemaLocation != NULL && osAlreadyIncluded.count( pszSchemaLocation) == 0 ) { osAlreadyIncluded.insert( pszSchemaLocation ); if( !STARTS_WITH(pszSchemaLocation, "http://") && !STARTS_WITH(pszSchemaLocation, "https://") && CPLIsFilenameRelative(pszSchemaLocation ) ) { pszSchemaLocation = CPLFormFilename( CPLGetPath(pszMainSchemaLocation), pszSchemaLocation, NULL ); } CPLXMLNode *psIncludedXSDTree = GMLParseXMLFile( pszSchemaLocation ); if( psIncludedXSDTree != NULL ) { CPLStripXMLNamespace( psIncludedXSDTree, NULL, TRUE ); CPLXMLNode *psIncludedSchemaNode = CPLGetXMLNode( psIncludedXSDTree, "=schema" ); if( psIncludedSchemaNode != NULL ) { /* Substitute de <include> node by its content */ CPLXMLNode* psFirstChildElement = CPLGetFirstChildNode(psIncludedSchemaNode); if( psFirstChildElement != NULL ) { CPLXMLNode* psCopy = CPLCloneXMLTree(psFirstChildElement); if( psLast != NULL ) psLast->psNext = psCopy; else psSchemaNode->psChild = psCopy; CPLXMLNode* psNext = psThis->psNext; psThis->psNext = NULL; CPLDestroyXMLNode(psThis); psThis = CPLGetLastNode(psCopy); psThis->psNext = psNext; /* In case the included schema also contains */ /* includes */ bTryAgain = true; } } CPLDestroyXMLNode( psIncludedXSDTree ); } } } psLast = psThis; } } while( bTryAgain ); const char* pszSchemaOutputName = CPLGetConfigOption("GML_SCHEMA_OUTPUT_NAME", NULL); if( pszSchemaOutputName != NULL ) { CPLSerializeXMLTreeToFile( psSchemaNode, pszSchemaOutputName ); } }
CPLErr GDALPamDataset::TrySaveXML() { CPLXMLNode *psTree; CPLErr eErr = CE_None; nPamFlags &= ~GPF_DIRTY; if( psPam == NULL || (nPamFlags & GPF_NOSAVE) ) return CE_None; /* -------------------------------------------------------------------- */ /* Make sure we know the filename we want to store in. */ /* -------------------------------------------------------------------- */ if( !BuildPamFilename() ) return CE_None; /* -------------------------------------------------------------------- */ /* Build the XML representation of the auxilary metadata. */ /* -------------------------------------------------------------------- */ CPLString osVRTPath = CPLGetPath(psPam->pszPamFilename); psTree = SerializeToXML( osVRTPath ); if( psTree == NULL ) return CE_None; /* -------------------------------------------------------------------- */ /* If we are working with a subdataset, we need to integrate */ /* the subdataset tree within the whole existing pam tree, */ /* after removing any old version of the same subdataset. */ /* -------------------------------------------------------------------- */ if( psPam->osSubdatasetName.size() != 0 ) { CPLXMLNode *psOldTree, *psSubTree; CPLErrorReset(); CPLPushErrorHandler( CPLQuietErrorHandler ); psOldTree = CPLParseXMLFile( psPam->pszPamFilename ); CPLPopErrorHandler(); if( psOldTree == NULL ) psOldTree = CPLCreateXMLNode( NULL, CXT_Element, "PAMDataset" ); for( psSubTree = psTree->psChild; psSubTree != NULL; psSubTree = psSubTree->psNext ) { if( psSubTree->eType != CXT_Element || !EQUAL(psSubTree->pszValue,"Subdataset") ) continue; if( !EQUAL(CPLGetXMLValue( psSubTree, "name", "" ), psPam->osSubdatasetName) ) continue; break; } if( psSubTree == NULL ) { psSubTree = CPLCreateXMLNode( psOldTree, CXT_Element, "Subdataset" ); CPLCreateXMLNode( CPLCreateXMLNode( psSubTree, CXT_Attribute, "name" ), CXT_Text, psPam->osSubdatasetName ); } CPLXMLNode *psOldPamDataset = CPLGetXMLNode( psSubTree, "PAMDataset"); if( psOldPamDataset != NULL ) { CPLRemoveXMLChild( psSubTree, psOldPamDataset ); CPLDestroyXMLNode( psOldPamDataset ); } CPLAddXMLChild( psSubTree, psTree ); psTree = psOldTree; } /* -------------------------------------------------------------------- */ /* Try saving the auxilary metadata. */ /* -------------------------------------------------------------------- */ const char *pszNewPam; int bSaved; CPLPushErrorHandler( CPLQuietErrorHandler ); bSaved = CPLSerializeXMLTreeToFile( psTree, psPam->pszPamFilename ); CPLPopErrorHandler(); /* -------------------------------------------------------------------- */ /* If it fails, check if we have a proxy directory for auxilary */ /* metadata to be stored in, and try to save there. */ /* -------------------------------------------------------------------- */ if( bSaved ) eErr = CE_None; else if( PamGetProxy(GetDescription()) == NULL && ((pszNewPam = PamAllocateProxy(GetDescription())) != NULL)) { CPLErrorReset(); CPLFree( psPam->pszPamFilename ); psPam->pszPamFilename = CPLStrdup(pszNewPam); eErr = TrySaveXML(); } else { CPLError( CE_Warning, CPLE_AppDefined, "Unable to save auxilary information in %s.", psPam->pszPamFilename ); eErr = CE_Warning; } /* -------------------------------------------------------------------- */ /* Cleanup */ /* -------------------------------------------------------------------- */ CPLDestroyXMLNode( psTree ); return eErr; }
GDALDataset *ISCEDataset::Create( const char *pszFilename, int nXSize, int nYSize, int nBands, GDALDataType eType, char **papszOptions ) { const char *sType = GDALGetDataTypeName( eType ); const char *sScheme = CSLFetchNameValueDef( papszOptions, "SCHEME", "BIP" ); /* -------------------------------------------------------------------- */ /* Try to create the file. */ /* -------------------------------------------------------------------- */ VSILFILE *fp = VSIFOpenL( pszFilename, "wb" ); if( fp == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Attempt to create file `%s' failed.\n", pszFilename ); return NULL; } /* -------------------------------------------------------------------- */ /* Just write out a couple of bytes to establish the binary */ /* file, and then close it. */ /* -------------------------------------------------------------------- */ CPL_IGNORE_RET_VAL(VSIFWriteL( (void *) "\0\0", 2, 1, fp )); CPL_IGNORE_RET_VAL(VSIFCloseL( fp )); /* -------------------------------------------------------------------- */ /* Create a minimal XML document. */ /* -------------------------------------------------------------------- */ CPLXMLNode *psDocNode = CPLCreateXMLNode( NULL, CXT_Element, "imageFile" ); CPLXMLNode *psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "WIDTH" ); char sBuf[64]; snprintf(sBuf, sizeof(sBuf), "%d", nXSize); CPLCreateXMLElementAndValue( psTmpNode, "value", sBuf ); psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "LENGTH" ); snprintf(sBuf, sizeof(sBuf), "%d", nYSize); CPLCreateXMLElementAndValue( psTmpNode, "value", sBuf ); psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "NUMBER_BANDS" ); snprintf(sBuf, sizeof(sBuf), "%d", nBands); CPLCreateXMLElementAndValue( psTmpNode, "value", sBuf ); psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "DATA_TYPE" ); CPLCreateXMLElementAndValue( psTmpNode, "value", CSLFetchNameValue( (char **)apszGDAL2ISCEDatatypes, sType )); psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "SCHEME" ); CPLCreateXMLElementAndValue( psTmpNode, "value", sScheme ); psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "BYTE_ORDER" ); #ifdef CPL_LSB CPLCreateXMLElementAndValue( psTmpNode, "value", "l" ); #else CPLCreateXMLElementAndValue( psTmpNode, "value", "b" ); #endif /* -------------------------------------------------------------------- */ /* Write the XML file. */ /* -------------------------------------------------------------------- */ const char *pszXMLFilename = CPLFormFilename( NULL, pszFilename, "xml" ); CPLSerializeXMLTreeToFile( psDocNode, pszXMLFilename ); /* -------------------------------------------------------------------- */ /* Free the XML Doc. */ /* -------------------------------------------------------------------- */ CPLDestroyXMLNode( psDocNode ); return (GDALDataset *) GDALOpen( pszFilename, GA_Update ); }
void ISCEDataset::FlushCache( void ) { RawDataset::FlushCache(); GDALRasterBand *band = (GetRasterCount() > 0) ? GetRasterBand(1) : NULL; if ( eAccess == GA_ReadOnly || band == NULL ) return; /* -------------------------------------------------------------------- */ /* Recreate a XML doc with the dataset information. */ /* -------------------------------------------------------------------- */ char sBuf[64]; CPLXMLNode *psDocNode = CPLCreateXMLNode( NULL, CXT_Element, "imageFile" ); CPLXMLNode *psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "WIDTH" ); snprintf(sBuf, sizeof(sBuf), "%d", nRasterXSize); CPLCreateXMLElementAndValue( psTmpNode, "value", sBuf ); psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "LENGTH" ); snprintf(sBuf, sizeof(sBuf), "%d", nRasterYSize); CPLCreateXMLElementAndValue( psTmpNode, "value", sBuf ); psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "NUMBER_BANDS" ); snprintf(sBuf, sizeof(sBuf), "%d", nBands); CPLCreateXMLElementAndValue( psTmpNode, "value", sBuf ); const char *sType = GDALGetDataTypeName( band->GetRasterDataType() ); psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "DATA_TYPE" ); CPLCreateXMLElementAndValue( psTmpNode, "value", CSLFetchNameValue( (char **)apszGDAL2ISCEDatatypes, sType ) ); const char *sScheme = apszSchemeNames[eScheme]; psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "SCHEME" ); CPLCreateXMLElementAndValue( psTmpNode, "value", sScheme ); psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", "BYTE_ORDER" ); #ifdef CPL_LSB CPLCreateXMLElementAndValue( psTmpNode, "value", "l" ); #else CPLCreateXMLElementAndValue( psTmpNode, "value", "b" ); #endif /* -------------------------------------------------------------------- */ /* Then, add the ISCE domain metadata. */ /* -------------------------------------------------------------------- */ char **papszISCEMetadata = GetMetadata( "ISCE" ); for (int i = 0; i < CSLCount( papszISCEMetadata ); i++) { /* Get the tokens from the metadata item */ char **papszTokens = CSLTokenizeString2( papszISCEMetadata[i], "=", CSLT_STRIPLEADSPACES | CSLT_STRIPENDSPACES); if ( CSLCount( papszTokens ) != 2 ) { CPLDebug( "ISCE", "Line of header file could not be split at = into two" " elements: %s", papszISCEMetadata[i] ); CSLDestroy( papszTokens ); continue; } /* Don't write it out if it is one of the bits of metadata that is * written out elsewhere in this routine */ if ( strcmp( papszTokens[0], "WIDTH" ) == 0 || strcmp( papszTokens[0], "LENGTH" ) == 0 || strcmp( papszTokens[0], "NUMBER_BANDS" ) == 0 || strcmp( papszTokens[0], "DATA_TYPE" ) == 0 || strcmp( papszTokens[0], "SCHEME" ) == 0 || strcmp( papszTokens[0], "BYTE_ORDER" ) == 0 ) { CSLDestroy( papszTokens ); continue; } psTmpNode = CPLCreateXMLNode( psDocNode, CXT_Element, "property" ); CPLAddXMLAttributeAndValue( psTmpNode, "name", papszTokens[0] ); CPLCreateXMLElementAndValue( psTmpNode, "value", papszTokens[1] ); CSLDestroy( papszTokens ); } /* -------------------------------------------------------------------- */ /* Write the XML file. */ /* -------------------------------------------------------------------- */ CPLSerializeXMLTreeToFile( psDocNode, pszXMLFilename ); /* -------------------------------------------------------------------- */ /* Free the XML Doc. */ /* -------------------------------------------------------------------- */ CPLDestroyXMLNode( psDocNode ); }