int ERSHdrNode::WriteSelf( VSILFILE * fp, int nIndent ) { CPLString oIndent; oIndent.assign( nIndent, '\t' ); for( int i = 0; i < nItemCount; i++ ) { if( papszItemValue[i] != nullptr ) { if( VSIFPrintfL( fp, "%s%s\t= %s\n", oIndent.c_str(), papszItemName[i], papszItemValue[i] ) < 1 ) return FALSE; } else { VSIFPrintfL( fp, "%s%s Begin\n", oIndent.c_str(), papszItemName[i] ); if( !papoItemChild[i]->WriteSelf( fp, nIndent+1 ) ) return FALSE; if( VSIFPrintfL( fp, "%s%s End\n", oIndent.c_str(), papszItemName[i] ) < 1 ) return FALSE; } } return TRUE; }
void OGRJMLWriterLayer::WriteColumnDeclaration( const char* pszName, const char* pszType ) { char* pszEscapedName = OGRGetXML_UTF8_EscapedString( pszName ); if( bClassicGML ) { VSIFPrintfL(fp, " <column>\n" " <name>%s</name>\n" " <type>%s</type>\n" " <valueElement elementName=\"%s\"/>\n" " <valueLocation position=\"body\"/>\n" " </column>\n", pszEscapedName, pszType, pszEscapedName); } else { VSIFPrintfL(fp, " <column>\n" " <name>%s</name>\n" " <type>%s</type>\n" " <valueElement elementName=\"property\" attributeName=\"name\" attributeValue=\"%s\"/>\n" " <valueLocation position=\"body\"/>\n" " </column>\n", pszEscapedName, pszType, pszEscapedName); } CPLFree(pszEscapedName); }
OGRJMLWriterLayer::~OGRJMLWriterLayer() { if( !bFeaturesWritten ) VSIFPrintfL(fp, "</ColumnDefinitions>\n</JCSGMLInputTemplate>\n<featureCollection>\n"); VSIFPrintfL(fp, "</featureCollection>\n</JCSDataFile>\n"); poFeatureDefn->Release(); }
OGRGeoRSSDataSource::~OGRGeoRSSDataSource() { if ( fpOutput != NULL ) { if (bWriteHeaderAndFooter) { if (eFormat == GEORSS_RSS) { VSIFPrintfL(fpOutput, " </channel>\n"); VSIFPrintfL(fpOutput, "</rss>\n"); } else { VSIFPrintfL(fpOutput, "</feed>\n"); } } VSIFCloseL( fpOutput); } for( int i = 0; i < nLayers; i++ ) delete papoLayers[i]; CPLFree( papoLayers ); CPLFree( pszName ); }
void OGRBNALayer::WriteCoord(VSILFILE* fp, double dfX, double dfY) { char szBuffer[64]; OGRFormatDouble(szBuffer, sizeof(szBuffer), dfX, '.', poDS->GetCoordinatePrecision()); VSIFPrintfL( fp, "%s", szBuffer); VSIFPrintfL( fp, "%s", poDS->GetCoordinateSeparator()); OGRFormatDouble(szBuffer, sizeof(szBuffer), dfY, '.', poDS->GetCoordinatePrecision()); VSIFPrintfL( fp, "%s", szBuffer); }
OGRErr OGRILI2Layer::ICreateFeature( OGRFeature *poFeature ) { char szTempBuffer[80]; const char* tid; int iField = 0; if( poFeatureDefn->GetFieldCount() && EQUAL(poFeatureDefn->GetFieldDefn(iField)->GetNameRef(), "TID") ) { tid = poFeature->GetFieldAsString(0); ++iField; } else { snprintf( szTempBuffer, sizeof(szTempBuffer), CPL_FRMT_GIB, poFeature->GetFID() ); tid = szTempBuffer; } VSILFILE* fp = poDS->GetOutputFP(); if (fp == NULL) return OGRERR_FAILURE; VSIFPrintfL(fp, "<%s TID=\"%s\">\n", poFeatureDefn->GetName(), tid); // Write out Geometries for( int iGeomField = 0; iGeomField < poFeatureDefn->GetGeomFieldCount(); iGeomField++ ) { OGRGeomFieldDefn *poFieldDefn = poFeatureDefn->GetGeomFieldDefn(iGeomField); OGRGeometry* poGeom = poFeature->GetGeomFieldRef(iGeomField); if( poGeom != NULL ) { CPLString iliGeomType = GetIliGeomType(poFieldDefn->GetNameRef()); OGR2ILIGeometryAppend( poGeom, fp, poFieldDefn->GetNameRef(), iliGeomType ); } } // Write all "set" fields. for( ; iField < poFeatureDefn->GetFieldCount(); iField++ ) { OGRFieldDefn *poField = poFeatureDefn->GetFieldDefn( iField ); if( poFeature->IsFieldSet( iField ) ) { const char *pszRaw = poFeature->GetFieldAsString( iField ); VSIFPrintfL(fp, "<%s>%s</%s>\n", poField->GetNameRef(), pszRaw, poField->GetNameRef()); } } VSIFPrintfL(fp, "</%s>\n", poFeatureDefn->GetName()); return OGRERR_NONE; }
OGRGeoJSONWriteLayer::~OGRGeoJSONWriteLayer() { VSILFILE* fp = poDS_->GetOutputFile(); VSIFPrintfL( fp, "\n]" ); if( bWriteFC_BBOX && sEnvelopeLayer.IsInit() ) { CPLString osBBOX = "[ "; if( bRFC7946_ ) { osBBOX += CPLSPrintf("%.*f, ", nCoordPrecision_, sEnvelopeLayer.MinX); osBBOX += CPLSPrintf("%.*f, ", nCoordPrecision_, sEnvelopeLayer.MinY); if( bBBOX3D ) osBBOX += CPLSPrintf("%.*f, ", nCoordPrecision_, sEnvelopeLayer.MinZ); osBBOX += CPLSPrintf("%.*f, ", nCoordPrecision_, sEnvelopeLayer.MaxX); osBBOX += CPLSPrintf("%.*f", nCoordPrecision_, sEnvelopeLayer.MaxY); if( bBBOX3D ) osBBOX += CPLSPrintf(", %.*f", nCoordPrecision_, sEnvelopeLayer.MaxZ); } else { osBBOX += CPLSPrintf("%.15g, ", sEnvelopeLayer.MinX); osBBOX += CPLSPrintf("%.15g, ", sEnvelopeLayer.MinY); if( bBBOX3D ) osBBOX += CPLSPrintf("%.15g, ", sEnvelopeLayer.MinZ); osBBOX += CPLSPrintf("%.15g, ", sEnvelopeLayer.MaxX); osBBOX += CPLSPrintf("%.15g", sEnvelopeLayer.MaxY); if( bBBOX3D ) osBBOX += CPLSPrintf(", %.15g", sEnvelopeLayer.MaxZ); } osBBOX += " ]"; if( poDS_->GetFpOutputIsSeekable() && osBBOX.size() + 9 < OGRGeoJSONDataSource::SPACE_FOR_BBOX ) { VSIFSeekL(fp, poDS_->GetBBOXInsertLocation(), SEEK_SET); VSIFPrintfL( fp, "\"bbox\": %s,", osBBOX.c_str() ); VSIFSeekL(fp, 0, SEEK_END); } else { VSIFPrintfL( fp, ",\n\"bbox\": %s", osBBOX.c_str() ); } } VSIFPrintfL( fp, "\n}\n" ); if( nullptr != poFeatureDefn_ ) { poFeatureDefn_->Release(); } delete poCT_; }
OGRErr OGRGeoJSONSeqWriteLayer::ICreateFeature( OGRFeature* poFeature ) { VSILFILE* fp = m_poDS->GetOutputFile(); std::unique_ptr<OGRFeature> poFeatureToWrite; if( m_poCT != nullptr ) { poFeatureToWrite.reset(new OGRFeature(m_poFeatureDefn)); poFeatureToWrite->SetFrom( poFeature ); poFeatureToWrite->SetFID( poFeature->GetFID() ); OGRGeometry* poGeometry = poFeatureToWrite->GetGeometryRef(); if( poGeometry ) { const char* const apszOptions[] = { "WRAPDATELINE=YES", nullptr }; OGRGeometry* poNewGeom = OGRGeometryFactory::transformWithOptions( poGeometry, m_poCT, const_cast<char**>(apszOptions)); if( poNewGeom == nullptr ) { return OGRERR_FAILURE; } OGREnvelope sEnvelope; poNewGeom->getEnvelope(&sEnvelope); if( sEnvelope.MinX < -180.0 || sEnvelope.MaxX > 180.0 || sEnvelope.MinY < -90.0 || sEnvelope.MaxY > 90.0 ) { CPLError(CE_Failure, CPLE_AppDefined, "Geometry extent outside of [-180.0,180.0]x[-90.0,90.0] bounds"); return OGRERR_FAILURE; } poFeatureToWrite->SetGeometryDirectly( poNewGeom ); } } json_object* poObj = OGRGeoJSONWriteFeature( poFeatureToWrite.get() ? poFeatureToWrite.get() : poFeature, m_oWriteOptions ); CPLAssert( nullptr != poObj ); if( m_bRS ) { VSIFPrintfL( fp, "%c", RS); } VSIFPrintfL( fp, "%s\n", json_object_to_json_string( poObj ) ); json_object_put( poObj ); return OGRERR_NONE; }
static void AppendCoordinateList( OGRLineString *poLine, VSILFILE* fp ) { int b3D = wkbHasZ(poLine->getGeometryType()); for( int iPoint = 0; iPoint < poLine->getNumPoints(); iPoint++ ) { VSIFPrintfL(fp, "<COORD>"); VSIFPrintfL(fp, "<C1>%s</C1>", d2str(poLine->getX(iPoint))); VSIFPrintfL(fp, "<C2>%s</C2>", d2str(poLine->getY(iPoint))); if (b3D) VSIFPrintfL(fp, "<C3>%s</C3>", d2str(poLine->getZ(iPoint))); VSIFPrintfL(fp, "</COORD>\n"); } }
static void AppendCoumpoundCurve( OGRCompoundCurve *poCC, OGRILI1DataSource *poDS ) { for( int iMember = 0; iMember < poCC->getNumCurves(); iMember++) { OGRCurve *poGeometry = poCC->getCurve( iMember ); int b3D = wkbHasZ(poGeometry->getGeometryType()); int bIsArc = (poGeometry->getGeometryType() == wkbCircularString || poGeometry->getGeometryType() == wkbCircularStringZ ); OGRSimpleCurve *poLine = (OGRSimpleCurve *)poGeometry; for( int iPoint = 0; iPoint < poLine->getNumPoints(); iPoint++ ) { //Skip last point in curve member if (iPoint == poLine->getNumPoints()-1 && iMember < poCC->getNumCurves()-1) continue; if (iMember == 0 && iPoint == 0) VSIFPrintfL( poDS->GetTransferFile(), "STPT" ); else if (bIsArc && iPoint == 1) VSIFPrintfL( poDS->GetTransferFile(), "ARCP" ); else VSIFPrintfL( poDS->GetTransferFile(), "LIPT" ); VSIFPrintfL( poDS->GetTransferFile(), " %s", d2str(poLine->getX(iPoint)) ); VSIFPrintfL( poDS->GetTransferFile(), " %s", d2str(poLine->getY(iPoint)) ); if (b3D) VSIFPrintfL( poDS->GetTransferFile(), " %s", d2str(poLine->getZ(iPoint)) ); VSIFPrintfL( poDS->GetTransferFile(), "\n" ); } } VSIFPrintfL( poDS->GetTransferFile(), "ELIN\n" ); }
int main(int argc, char* argv[]) { OSMContext* psContext; const char* pszSrcFilename; const char* pszDstFilename; VSILFILE* fp; if( argc != 3 ) { fprintf(stderr, "Usage: osm2osm input.pbf output.osm\n"); exit(1); } pszSrcFilename = argv[1]; pszDstFilename = argv[2]; fp = VSIFOpenL(pszDstFilename, "wt"); if( fp == NULL ) { fprintf(stderr, "Cannot create %s.\n", pszDstFilename); exit(1); } psContext = OSM_Open( pszSrcFilename, myNotifyNodesFunc, myNotifyWayFunc, myNotifyRelationFunc, myNotifyBoundsFunc, fp ); if( psContext == NULL ) { fprintf(stderr, "Cannot process %s.\n", pszSrcFilename); exit(1); } VSIFPrintfL(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); VSIFPrintfL(fp, "<osm version=\"0.6\" generator=\"pbttoosm\">\n"); while( OSM_ProcessBlock(psContext) == OSM_OK ); VSIFPrintfL(fp, "</osm>\n"); OSM_Close( psContext ); VSIFCloseL(fp); return 0; }
static void GMLWriteField(OGRGMLDataSource* poDS, VSILFILE *fp, int bWriteSpaceIndentation, const char* pszPrefix, int bRemoveAppPrefix, OGRFieldDefn* poFieldDefn, const char* pszVal ) { const char* pszFieldName = poFieldDefn->GetNameRef(); while( *pszVal == ' ' ) pszVal++; if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); if( bRemoveAppPrefix ) poDS->PrintLine( fp, "<%s>%s</%s>", pszFieldName, pszVal, pszFieldName); else poDS->PrintLine( fp, "<%s:%s>%s</%s:%s>", pszPrefix, pszFieldName, pszVal, pszPrefix, pszFieldName); }
OGRJMLWriterLayer::OGRJMLWriterLayer( const char* pszLayerName, OGRJMLDataset* poDS, VSILFILE* fp, int bAddRGBField, int bAddOGRStyleField, int bClassicGML ) { this->poDS = poDS; this->fp = fp; bFeaturesWritten = FALSE; this->bAddRGBField = bAddRGBField; this->bAddOGRStyleField = bAddOGRStyleField; this->bClassicGML = bClassicGML; nNextFID = 0; poFeatureDefn = new OGRFeatureDefn( pszLayerName ); SetDescription( poFeatureDefn->GetName() ); poFeatureDefn->Reference(); VSIFPrintfL(fp, "<?xml version='1.0' encoding='UTF-8'?>\n" "<JCSDataFile xmlns:gml=\"http://www.opengis.net/gml\" " "xmlns:xsi=\"http://www.w3.org/2000/10/XMLSchema-instance\" >\n" "<JCSGMLInputTemplate>\n" "<CollectionElement>featureCollection</CollectionElement>\n" "<FeatureElement>feature</FeatureElement>\n" "<GeometryElement>geometry</GeometryElement>\n" "<ColumnDefinitions>\n"); }
OGRKMLDataSource::~OGRKMLDataSource() { if( fpOutput_ != NULL ) { VSIFPrintfL( fpOutput_, "%s", "</Folder></Document></kml>\n" ); VSIFCloseL( fpOutput_ ); } CSLDestroy( papszCreateOptions_ ); CPLFree( pszName_ ); CPLFree( pszNameField_ ); CPLFree( pszDescriptionField_ ); CPLFree( pszAltitudeMode_ ); for( int i = 0; i < nLayers_; i++ ) { delete papoLayers_[i]; } CPLFree( papoLayers_ ); #ifdef HAVE_EXPAT delete poKMLFile_; #endif }
OGRJMLWriterLayer::OGRJMLWriterLayer( const char* pszLayerName, OGRJMLDataset * /* poDSIn */, VSILFILE* fpIn, bool bAddRGBFieldIn, bool bAddOGRStyleFieldIn, bool bClassicGMLIn ) : poFeatureDefn(new OGRFeatureDefn( pszLayerName )), fp(fpIn), bFeaturesWritten(false), bAddRGBField(bAddRGBFieldIn), bAddOGRStyleField(bAddOGRStyleFieldIn), bClassicGML(bClassicGMLIn), nNextFID(0) { SetDescription( poFeatureDefn->GetName() ); poFeatureDefn->Reference(); VSIFPrintfL(fp, "<?xml version='1.0' encoding='UTF-8'?>\n" "<JCSDataFile xmlns:gml=\"http://www.opengis.net/gml\" " "xmlns:xsi=\"http://www.w3.org/2000/10/XMLSchema-instance\" >\n" "<JCSGMLInputTemplate>\n" "<CollectionElement>featureCollection</CollectionElement>\n" "<FeatureElement>feature</FeatureElement>\n" "<GeometryElement>geometry</GeometryElement>\n" "<ColumnDefinitions>\n"); }
OGRKMLDataSource::~OGRKMLDataSource() { if( fpOutput_ != NULL ) { if( nLayers_ > 0 ) { if( nLayers_ == 1 && papoLayers_[0]->nWroteFeatureCount_ == 0 ) { VSIFPrintfL( fpOutput_, "<Folder><name>%s</name>\n", papoLayers_[0]->GetName() ); } VSIFPrintfL( fpOutput_, "%s", "</Folder>\n"); for( int i = 0; i < nLayers_; i++ ) { if( !(papoLayers_[i]->bSchemaWritten_) && papoLayers_[i]->nWroteFeatureCount_ != 0 ) { CPLString osRet = papoLayers_[i]->WriteSchema(); if( osRet.size() ) VSIFPrintfL( fpOutput_, "%s", osRet.c_str() ); } } } VSIFPrintfL( fpOutput_, "%s", "</Document></kml>\n" ); VSIFCloseL( fpOutput_ ); } CSLDestroy( papszCreateOptions_ ); CPLFree( pszName_ ); CPLFree( pszNameField_ ); CPLFree( pszDescriptionField_ ); CPLFree( pszAltitudeMode_ ); for( int i = 0; i < nLayers_; i++ ) { delete papoLayers_[i]; } CPLFree( papoLayers_ ); #ifdef HAVE_EXPAT delete poKMLFile_; #endif }
static void GDALWriteIMDMultiLine( VSILFILE *fp, const char *pszValue ) { char **papszItems = CSLTokenizeStringComplex( pszValue, "(,) ", FALSE, FALSE ); const int nItemCount = CSLCount(papszItems); CPL_IGNORE_RET_VAL(VSIFPrintfL( fp, "(\n" )); for( int i = 0; i < nItemCount; i++ ) { if( i == nItemCount-1 ) CPL_IGNORE_RET_VAL(VSIFPrintfL( fp, "\t%s );\n", papszItems[i] )); else CPL_IGNORE_RET_VAL(VSIFPrintfL( fp, "\t%s,\n", papszItems[i] )); } CSLDestroy( papszItems ); }
unsigned int ISIS2Dataset::WriteKeyword( VSILFILE *fpLabel, unsigned int iLevel, CPLString key, CPLString value) { CPLString tab = ""; iLevel *= 4; // each struct is idented by 4 spaces int ret = VSIFPrintfL(fpLabel,"%*s%s=%s\n", iLevel, tab.c_str(), key.c_str(), value.c_str()); return ret; }
void OGRPGDumpDataSource::Log(const char* pszStr, int bAddSemiColumn) { if (fp == NULL) { if (bTriedOpen) return; bTriedOpen = TRUE; fp = VSIFOpenL(pszName, "wb"); if (fp == NULL) { CPLError(CE_Failure, CPLE_FileIO, "Cannot create %s", pszName); return; } } if (bAddSemiColumn) VSIFPrintfL(fp, "%s;%s", pszStr, pszEOL); else VSIFPrintfL(fp, "%s%s", pszStr, pszEOL); }
void OGRGPXDataSource::PrintLine(const char *fmt, ...) { CPLString osWork; va_list args; va_start( args, fmt ); osWork.vPrintf( fmt, args ); va_end( args ); VSIFPrintfL(fpOutput, "%s%s", osWork.c_str(), pszEOL); }
OGRGeoJSONWriteLayer::~OGRGeoJSONWriteLayer() { VSILFILE* fp = poDS_->GetOutputFile(); VSIFPrintfL( fp, "\n]" ); if( bWriteBBOX && sEnvelopeLayer.IsInit() ) { CPLString osBBOX = "[ "; osBBOX += CPLSPrintf("%.15g, ", sEnvelopeLayer.MinX); osBBOX += CPLSPrintf("%.15g, ", sEnvelopeLayer.MinY); if( bBBOX3D ) osBBOX += CPLSPrintf("%.15g, ", sEnvelopeLayer.MinZ); osBBOX += CPLSPrintf("%.15g, ", sEnvelopeLayer.MaxX); osBBOX += CPLSPrintf("%.15g", sEnvelopeLayer.MaxY); if( bBBOX3D ) osBBOX += CPLSPrintf(", %.15g", sEnvelopeLayer.MaxZ); osBBOX += " ]"; if( poDS_->GetFpOutputIsSeekable() && osBBOX.size() + 9 < SPACE_FOR_BBOX ) { VSIFSeekL(fp, poDS_->GetBBOXInsertLocation(), SEEK_SET); VSIFPrintfL( fp, "\"bbox\": %s,", osBBOX.c_str() ); VSIFSeekL(fp, 0, SEEK_END); } else { VSIFPrintfL( fp, ",\n\"bbox\": %s", osBBOX.c_str() ); } } VSIFPrintfL( fp, "\n}\n" ); if( NULL != poFeatureDefn_ ) { poFeatureDefn_->Release(); } }
void OGRBNALayer::WriteFeatureAttributes(VSILFILE* fp, OGRFeature *poFeature ) { int i; OGRFieldDefn *poFieldDefn; int nbOutID = poDS->GetNbOutId(); if (nbOutID < 0) nbOutID = poFeatureDefn->GetFieldCount(); for(i=0;i<nbOutID;i++) { if (i < poFeatureDefn->GetFieldCount()) { poFieldDefn = poFeatureDefn->GetFieldDefn( i ); if( poFeature->IsFieldSet( i ) ) { if (poFieldDefn->GetType() == OFTReal) { char szBuffer[64]; OGRFormatDouble(szBuffer, sizeof(szBuffer), poFeature->GetFieldAsDouble(i), '.'); VSIFPrintfL( fp, "\"%s\",", szBuffer); } else { const char *pszRaw = poFeature->GetFieldAsString( i ); VSIFPrintfL( fp, "\"%s\",", pszRaw); } } else { VSIFPrintfL( fp, "\"\","); } } else { VSIFPrintfL( fp, "\"\","); } } }
static void WriteEscaped(const char* pszStr, VSILFILE* fp) { GByte ch; while((ch = *(pszStr ++)) != 0) { if( ch == '<' ) { /* printf("<"); */ VSIFPrintfL(fp, "<"); } else if( ch == '>' ) { /* printf(">"); */ VSIFPrintfL(fp, ">"); } else if( ch == '&' ) { /* printf("&"); */ VSIFPrintfL(fp, "&"); } else if( ch == '"' ) { /* printf("""); */ VSIFPrintfL(fp, """); } else if( ch == '\'' ) { VSIFPrintfL(fp, "'"); } else if( ch < 0x20 && ch != 0x9 && ch != 0xA && ch != 0xD ) { /* These control characters are unrepresentable in XML format, */ /* so we just drop them. #4117 */ } else VSIFWriteL(&ch, 1, 1, fp); } }
OGRErr OGRGeoJSONWriteLayer::ICreateFeature( OGRFeature* poFeature ) { VSILFILE* fp = poDS_->GetOutputFile(); if( NULL == poFeature ) { CPLDebug( "GeoJSON", "Feature is null" ); return OGRERR_INVALID_HANDLE; } json_object* poObj = OGRGeoJSONWriteFeature( poFeature, bWriteBBOX, nCoordPrecision ); CPLAssert( NULL != poObj ); if( nOutCounter_ > 0 ) { /* Separate "Feature" entries in "FeatureCollection" object. */ VSIFPrintfL( fp, ",\n" ); } VSIFPrintfL( fp, "%s", json_object_to_json_string( poObj ) ); json_object_put( poObj ); ++nOutCounter_; OGRGeometry* poGeometry = poFeature->GetGeometryRef(); if ( bWriteBBOX && !poGeometry->IsEmpty() ) { OGREnvelope3D sEnvelope; poGeometry->getEnvelope(&sEnvelope); if( poGeometry->getCoordinateDimension() == 3 ) bBBOX3D = TRUE; sEnvelopeLayer.Merge(sEnvelope); } return OGRERR_NONE; }
void ERSDataset::FlushCache() { if( bHDRDirty ) { VSILFILE * fpERS = VSIFOpenL( GetDescription(), "w" ); if( fpERS == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Unable to rewrite %s header.", GetDescription() ); } else { VSIFPrintfL( fpERS, "DatasetHeader Begin\n" ); poHeader->WriteSelf( fpERS, 1 ); VSIFPrintfL( fpERS, "DatasetHeader End\n" ); VSIFCloseL( fpERS ); } } RawDataset::FlushCache(); }
void myNotifyWayFunc (OSMWay* psWay, OSMContext* psOSMContext, void* user_data) { VSILFILE* fp = (VSILFILE*) user_data; int l; struct tm mytm; WRITE_STR(" <way id=\""); VSIFPrintfL(fp, "%d", (int)psWay->nID); WRITE_STR("\" version=\""); VSIFPrintfL(fp, "%d", psWay->sInfo.nVersion); WRITE_STR("\" changeset=\""); VSIFPrintfL(fp, "%d", (int) psWay->sInfo.nChangeset); if (psWay->sInfo.nUID >= 0) { WRITE_STR("\" uid=\""); VSIFPrintfL(fp, "%d", psWay->sInfo.nUID); WRITE_STR("\" user=\""); WRITE_ESCAPED(psWay->sInfo.pszUserSID); } if( !(psWay->sInfo.bTimeStampIsStr) ) { WRITE_STR("\" timestamp=\""); myCPLUnixTimeToYMDHMS(psWay->sInfo.ts.nTimeStamp, &mytm); VSIFPrintfL(fp, "%04d-%02d-%02dT%02d:%02d:%02dZ", 1900 + mytm.tm_year, mytm.tm_mon + 1, mytm.tm_mday, mytm.tm_hour, mytm.tm_min, mytm.tm_sec); } else if (psWay->sInfo.ts.pszTimeStamp != NULL && psWay->sInfo.ts.pszTimeStamp[0] != '\0') { WRITE_STR("\" timestamp=\""); WRITE_STR(psWay->sInfo.ts.pszTimeStamp); } WRITE_STR("\">\n"); for(l=0;l<psWay->nRefs;l++) VSIFPrintfL(fp, " <nd ref=\"%d\"/>\n", (int)psWay->panNodeRefs[l]); for(l=0;l<psWay->nTags;l++) { WRITE_STR(" <tag k=\""); WRITE_ESCAPED(psWay->pasTags[l].pszK); WRITE_STR("\" v=\""); WRITE_ESCAPED(psWay->pasTags[l].pszV); WRITE_STR("\" />\n"); } VSIFPrintfL(fp, " </way>\n"); }
static void AppendCoordinateList( OGRLineString *poLine, OGRILI1DataSource *poDS ) { const bool b3D = CPL_TO_BOOL(wkbHasZ(poLine->getGeometryType())); for( int iPoint = 0; iPoint < poLine->getNumPoints(); iPoint++ ) { if (iPoint == 0) VSIFPrintfL( poDS->GetTransferFile(), "STPT" ); else VSIFPrintfL( poDS->GetTransferFile(), "LIPT" ); VSIFPrintfL( poDS->GetTransferFile(), " %s", d2str(poLine->getX(iPoint)) ); VSIFPrintfL( poDS->GetTransferFile(), " %s", d2str(poLine->getY(iPoint)) ); if( b3D ) VSIFPrintfL( poDS->GetTransferFile(), " %s", d2str(poLine->getZ(iPoint)) ); VSIFPrintfL( poDS->GetTransferFile(), "\n" ); } VSIFPrintfL( poDS->GetTransferFile(), "ELIN\n" ); }
OGRGmtLayer::~OGRGmtLayer() { if( m_nFeaturesRead > 0 && poFeatureDefn != NULL ) { CPLDebug( "Gmt", "%d features read on layer '%s'.", (int) m_nFeaturesRead, poFeatureDefn->GetName() ); } /* -------------------------------------------------------------------- */ /* Write out the region bounds if we know where they go, and we */ /* are in update mode. */ /* -------------------------------------------------------------------- */ if( nRegionOffset != 0 && bUpdate ) { VSIFSeekL( fp, nRegionOffset, SEEK_SET ); VSIFPrintfL( fp, "# @R%.12g/%.12g/%.12g/%.12g", sRegion.MinX, sRegion.MaxX, sRegion.MinY, sRegion.MaxY ); } /* -------------------------------------------------------------------- */ /* Clean up. */ /* -------------------------------------------------------------------- */ CSLDestroy( papszKeyedValues ); if( poFeatureDefn ) poFeatureDefn->Release(); if( poSRS ) poSRS->Release(); if( fp != NULL ) VSIFCloseL( fp ); }
CPLErr GDALWriteRPBFile( const char *pszFilename, char **papszMD ) { CPLString osRPBFilename = CPLResetExtension( pszFilename, "RPB" ); /* -------------------------------------------------------------------- */ /* Read file and parse. */ /* -------------------------------------------------------------------- */ VSILFILE *fp = VSIFOpenL( osRPBFilename, "w" ); if( fp == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Unable to create %s for writing.\n%s", osRPBFilename.c_str(), CPLGetLastErrorMsg() ); return CE_Failure; } /* -------------------------------------------------------------------- */ /* Write the prefix information. */ /* -------------------------------------------------------------------- */ VSIFPrintfL( fp, "%s", "satId = \"QB02\";\n" ); VSIFPrintfL( fp, "%s", "bandId = \"P\";\n" ); VSIFPrintfL( fp, "%s", "SpecId = \"RPC00B\";\n" ); VSIFPrintfL( fp, "%s", "BEGIN_GROUP = IMAGE\n" ); VSIFPrintfL( fp, "%s", "\terrBias = 0.0;\n" ); VSIFPrintfL( fp, "%s", "\terrRand = 0.0;\n" ); /* -------------------------------------------------------------------- */ /* Write RPC values from our RPC metadata. */ /* -------------------------------------------------------------------- */ int i; for( i = 0; apszRPBMap[i] != NULL; i += 2 ) { const char *pszRPBVal = CSLFetchNameValue( papszMD, apszRPBMap[i] ); const char *pszRPBTag; if( pszRPBVal == NULL ) { CPLError( CE_Failure, CPLE_AppDefined, "%s field missing in metadata, %s file not written.", apszRPBMap[i], osRPBFilename.c_str() ); VSIFCloseL( fp ); VSIUnlink( osRPBFilename ); return CE_Failure; } pszRPBTag = apszRPBMap[i+1]; if( EQUALN(pszRPBTag,"IMAGE.",6) ) pszRPBTag += 6; if( strstr(apszRPBMap[i], "COEF" ) == NULL ) { VSIFPrintfL( fp, "\t%s = %s;\n", pszRPBTag, pszRPBVal ); } else { // Reformat in brackets with commas over multiple lines. VSIFPrintfL( fp, "\t%s = (\n", pszRPBTag ); char **papszItems = CSLTokenizeStringComplex( pszRPBVal, " ,", FALSE, FALSE ); if( CSLCount(papszItems) != 20 ) { CPLError( CE_Failure, CPLE_AppDefined, "%s field is corrupt (not 20 values), %s file not written.\n%s = %s", apszRPBMap[i], osRPBFilename.c_str(), apszRPBMap[i], pszRPBVal ); VSIFCloseL( fp ); VSIUnlink( osRPBFilename ); CSLDestroy( papszItems ); return CE_Failure; } int j; for( j = 0; j < 20; j++ ) { if( j < 19 ) VSIFPrintfL( fp, "\t\t\t%s,\n", papszItems[j] ); else VSIFPrintfL( fp, "\t\t\t%s);\n", papszItems[j] ); } CSLDestroy( papszItems ); } } /* -------------------------------------------------------------------- */ /* Write end part */ /* -------------------------------------------------------------------- */ VSIFPrintfL( fp, "%s", "END_GROUP = IMAGE\n" ); VSIFPrintfL( fp, "END;\n" ); VSIFCloseL( fp ); return CE_None; }
CPLErr GDALWriteRPCTXTFile( const char *pszFilename, char **papszMD ) { CPLString osRPCFilename = pszFilename; CPLString soPt("."); size_t found = osRPCFilename.rfind(soPt); if (found == CPLString::npos) return CE_Failure; osRPCFilename.replace (found, osRPCFilename.size() - found, "_RPC.TXT"); /* -------------------------------------------------------------------- */ /* Read file and parse. */ /* -------------------------------------------------------------------- */ VSILFILE *fp = VSIFOpenL( osRPCFilename, "w" ); if( fp == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Unable to create %s for writing.\n%s", osRPCFilename.c_str(), CPLGetLastErrorMsg() ); return CE_Failure; } /* -------------------------------------------------------------------- */ /* Write RPC values from our RPC metadata. */ /* -------------------------------------------------------------------- */ int i; for( i = 0; apszRPCTXTSingleValItems[i] != NULL; i ++ ) { const char *pszRPCVal = CSLFetchNameValue( papszMD, apszRPCTXTSingleValItems[i] ); if( pszRPCVal == NULL ) { CPLError( CE_Failure, CPLE_AppDefined, "%s field missing in metadata, %s file not written.", apszRPCTXTSingleValItems[i], osRPCFilename.c_str() ); VSIFCloseL( fp ); VSIUnlink( osRPCFilename ); return CE_Failure; } VSIFPrintfL( fp, "%s: %s\n", apszRPCTXTSingleValItems[i], pszRPCVal ); } for( i = 0; apszRPCTXT20ValItems[i] != NULL; i ++ ) { const char *pszRPCVal = CSLFetchNameValue( papszMD, apszRPCTXT20ValItems[i] ); if( pszRPCVal == NULL ) { CPLError( CE_Failure, CPLE_AppDefined, "%s field missing in metadata, %s file not written.", apszRPCTXTSingleValItems[i], osRPCFilename.c_str() ); VSIFCloseL( fp ); VSIUnlink( osRPCFilename ); return CE_Failure; } char **papszItems = CSLTokenizeStringComplex( pszRPCVal, " ,", FALSE, FALSE ); if( CSLCount(papszItems) != 20 ) { CPLError( CE_Failure, CPLE_AppDefined, "%s field is corrupt (not 20 values), %s file not written.\n%s = %s", apszRPCTXT20ValItems[i], osRPCFilename.c_str(), apszRPCTXT20ValItems[i], pszRPCVal ); VSIFCloseL( fp ); VSIUnlink( osRPCFilename ); CSLDestroy( papszItems ); return CE_Failure; } int j; for( j = 0; j < 20; j++ ) { VSIFPrintfL( fp, "%s_%d: %s\n", apszRPCTXT20ValItems[i], j+1, papszItems[j] ); } CSLDestroy( papszItems ); } VSIFCloseL( fp ); return CE_None; }