OGRErr OGRMemLayer::ISetFeature( OGRFeature *poFeature ) { if (!bUpdatable) return OGRERR_FAILURE; if( poFeature == NULL ) return OGRERR_FAILURE; if( poFeature->GetFID() == OGRNullFID ) { while( iNextCreateFID < nMaxFeatureCount && papoFeatures[iNextCreateFID] != NULL ) iNextCreateFID++; poFeature->SetFID( iNextCreateFID++ ); } else if ( poFeature->GetFID() < OGRNullFID ) { CPLError(CE_Failure, CPLE_NotSupported, "negative FID are not supported"); return OGRERR_FAILURE; } if( poFeature->GetFID() >= nMaxFeatureCount ) { GIntBig nNewCount = MAX(2*nMaxFeatureCount+10, poFeature->GetFID() + 1 ); if( (GIntBig)(size_t)(sizeof(OGRFeature *) * nNewCount) != (GIntBig)sizeof(OGRFeature *) * nNewCount ) { CPLError(CE_Failure, CPLE_OutOfMemory, "Cannot allocate array of " CPL_FRMT_GIB " elements", nNewCount); return OGRERR_FAILURE; } OGRFeature** papoNewFeatures = (OGRFeature **) VSIRealloc( papoFeatures, (size_t)(sizeof(OGRFeature *) * nNewCount) ); if (papoNewFeatures == NULL) { CPLError(CE_Failure, CPLE_OutOfMemory, "Cannot allocate array of " CPL_FRMT_GIB " elements", nNewCount); return OGRERR_FAILURE; } papoFeatures = papoNewFeatures; memset( papoFeatures + nMaxFeatureCount, 0, sizeof(OGRFeature *) * (size_t)(nNewCount - nMaxFeatureCount) ); nMaxFeatureCount = nNewCount; } if( papoFeatures[poFeature->GetFID()] != NULL ) { delete papoFeatures[poFeature->GetFID()]; papoFeatures[poFeature->GetFID()] = NULL; nFeatureCount--; } papoFeatures[poFeature->GetFID()] = poFeature->Clone(); int i; for(i = 0; i < poFeatureDefn->GetGeomFieldCount(); i ++) { OGRGeometry* poGeom = papoFeatures[poFeature->GetFID()]->GetGeomFieldRef(i); if( poGeom != NULL && poGeom->getSpatialReference() == NULL ) { poGeom->assignSpatialReference( poFeatureDefn->GetGeomFieldDefn(i)->GetSpatialRef()); } } nFeatureCount++; return OGRERR_NONE; }
OGRErr OGRGFTTableLayer::ISetFeature( OGRFeature *poFeature ) { GetLayerDefn(); if (!poDS->IsReadWrite()) { CPLError(CE_Failure, CPLE_AppDefined, "Operation not available in read-only mode"); return OGRERR_FAILURE; } if (osTableId.size() == 0) { CPLError(CE_Failure, CPLE_NotSupported, "Cannot set feature to non-created table"); return OGRERR_FAILURE; } if (poDS->GetAccessToken().size() == 0) { CPLError(CE_Failure, CPLE_AppDefined, "Operation not available in unauthenticated mode"); return OGRERR_FAILURE; } if (poFeature->GetFID() == OGRNullFID) { CPLError( CE_Failure, CPLE_AppDefined, "FID required on features given to SetFeature()." ); return OGRERR_FAILURE; } CPLString osCommand; osCommand += "UPDATE "; osCommand += osTableId; osCommand += " SET "; int iField; int nFieldCount = poFeatureDefn->GetFieldCount(); for(iField = 0; iField < nFieldCount + bHiddenGeometryField; iField++) { if (iField > 0) osCommand += ", "; if (iField == nFieldCount) { osCommand += EscapeAndQuote(GetGeometryColumn()); } else { const char* pszFieldName = poFeatureDefn->GetFieldDefn(iField)->GetNameRef(); osCommand += EscapeAndQuote(pszFieldName); } osCommand += " = "; OGRGeometry* poGeom = poFeature->GetGeometryRef(); if (iGeometryField != iLatitudeField && iField == iGeometryField && (iField == nFieldCount || poGeom != NULL || !poFeature->IsFieldSet( iField ))) { if (poGeom == NULL) osCommand += "''"; else { char* pszKML; if (poGeom->getSpatialReference() != NULL && !poGeom->getSpatialReference()->IsSame(poSRS)) { OGRGeometry* poGeom4326 = poGeom->clone(); poGeom4326->transformTo(poSRS); pszKML = poGeom4326->exportToKML(); delete poGeom4326; } else { pszKML = poGeom->exportToKML(); } osCommand += "'"; osCommand += pszKML; osCommand += "'"; CPLFree(pszKML); } continue; } if( !poFeature->IsFieldSet( iField ) ) { osCommand += "''"; } else { OGRFieldType eType = poFeatureDefn->GetFieldDefn(iField)->GetType(); if (eType != OFTInteger && eType != OFTReal) { CPLString osTmp; const char* pszVal = poFeature->GetFieldAsString(iField); if (!CPLIsUTF8(pszVal, -1)) { static int bFirstTime = TRUE; if (bFirstTime) { bFirstTime = FALSE; CPLError(CE_Warning, CPLE_AppDefined, "%s is not a valid UTF-8 string. Forcing it to ASCII.\n" "This warning won't be issued anymore", pszVal); } else { CPLDebug("OGR", "%s is not a valid UTF-8 string. Forcing it to ASCII", pszVal); } char* pszEscaped = CPLForceToASCII(pszVal, -1, '?'); osTmp = pszEscaped; CPLFree(pszEscaped); pszVal = osTmp.c_str(); } osCommand += EscapeAndQuote(pszVal); } else osCommand += poFeature->GetFieldAsString(iField); } } osCommand += " WHERE ROWID = '"; osCommand += CPLSPrintf(CPL_FRMT_GIB, poFeature->GetFID()); osCommand += "'"; CPLHTTPResult * psResult = poDS->RunSQL(osCommand); if (psResult == NULL) { CPLError(CE_Failure, CPLE_AppDefined, "Feature update failed (1)"); return OGRERR_FAILURE; } /* -------------------------------------------------------------------- */ /* We expect a response like "affected_rows\n1". */ /* -------------------------------------------------------------------- */ char* pszLine = (char*) psResult->pabyData; if (pszLine == NULL || strncmp(pszLine, "affected_rows\n1\n", 16) != 0 || psResult->pszErrBuf != NULL) { CPLDebug( "GFT", "%s/%s", pszLine ? pszLine : "null", psResult->pszErrBuf ? psResult->pszErrBuf : "null"); CPLError(CE_Failure, CPLE_AppDefined, "Feature update failed (2)"); CPLHTTPDestroyResult(psResult); return OGRERR_FAILURE; } CPLHTTPDestroyResult(psResult); return OGRERR_NONE; }
OGRErr OGRGMLLayer::CreateFeature( OGRFeature *poFeature ) { int bIsGML3Output = poDS->IsGML3Output(); VSILFILE *fp = poDS->GetOutputFP(); int bWriteSpaceIndentation = poDS->WriteSpaceIndentation(); if( !bWriter ) return OGRERR_FAILURE; if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); if (bIsGML3Output) poDS->PrintLine( fp, "<ogr:featureMember>" ); else poDS->PrintLine( fp, "<gml:featureMember>" ); if( poFeature->GetFID() == OGRNullFID ) poFeature->SetFID( iNextGMLId++ ); int nGMLIdIndex = -1; if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); if (bIsGML3Output) { nGMLIdIndex = poFeatureDefn->GetFieldIndex("gml_id"); if (nGMLIdIndex >= 0 && poFeature->IsFieldSet( nGMLIdIndex ) ) poDS->PrintLine( fp, "<ogr:%s gml:id=\"%s\">", poFeatureDefn->GetName(), poFeature->GetFieldAsString(nGMLIdIndex) ); else poDS->PrintLine( fp, "<ogr:%s gml:id=\"%s.%ld\">", poFeatureDefn->GetName(), poFeatureDefn->GetName(), poFeature->GetFID() ); } else poDS->PrintLine( fp, "<ogr:%s fid=\"F%ld\">", poFeatureDefn->GetName(), poFeature->GetFID() ); // Write out Geometry - for now it isn't indented properly. /* GML geometries don't like very much the concept of empty geometry */ OGRGeometry* poGeom = poFeature->GetGeometryRef(); if( poGeom != NULL && !poGeom->IsEmpty()) { char *pszGeometry; OGREnvelope sGeomBounds; poGeom->getEnvelope( &sGeomBounds ); poDS->GrowExtents( &sGeomBounds ); if (bIsGML3Output) { int bCoordSwap; if (poGeom->getSpatialReference() == NULL && poSRS != NULL) poGeom->assignSpatialReference(poSRS); char* pszSRSName = GML_GetSRSName(poGeom->getSpatialReference(), poDS->IsLongSRSRequired(), &bCoordSwap); char szLowerCorner[75], szUpperCorner[75]; if (bCoordSwap) { OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinY, sGeomBounds.MinX, 0, 2); OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxY, sGeomBounds.MaxX, 0, 2); } else { OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinX, sGeomBounds.MinY, 0, 2); OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxX, sGeomBounds.MaxY, 0, 2); } if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); poDS->PrintLine( fp, "<gml:boundedBy><gml:Envelope%s><gml:lowerCorner>%s</gml:lowerCorner><gml:upperCorner>%s</gml:upperCorner></gml:Envelope></gml:boundedBy>", pszSRSName, szLowerCorner, szUpperCorner); CPLFree(pszSRSName); } char** papszOptions = (bIsGML3Output) ? CSLAddString(NULL, "FORMAT=GML3") : NULL; if (bIsGML3Output && !poDS->IsLongSRSRequired()) papszOptions = CSLAddString(papszOptions, "GML3_LONGSRS=NO"); pszGeometry = poGeom->exportToGML(papszOptions); CSLDestroy(papszOptions); if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); poDS->PrintLine( fp, "<ogr:geometryProperty>%s</ogr:geometryProperty>", pszGeometry ); CPLFree( pszGeometry ); } // Write all "set" fields. for( int iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ ) { OGRFieldDefn *poFieldDefn = poFeatureDefn->GetFieldDefn( iField ); if( poFeature->IsFieldSet( iField ) && iField != nGMLIdIndex ) { const char *pszRaw = poFeature->GetFieldAsString( iField ); while( *pszRaw == ' ' ) pszRaw++; char *pszEscaped = OGRGetXML_UTF8_EscapedString( pszRaw ); if (poFieldDefn->GetType() == OFTReal) { /* Use point as decimal separator */ char* pszComma = strchr(pszEscaped, ','); if (pszComma) *pszComma = '.'; } if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); poDS->PrintLine( fp, "<ogr:%s>%s</ogr:%s>", poFieldDefn->GetNameRef(), pszEscaped, poFieldDefn->GetNameRef() ); CPLFree( pszEscaped ); } } if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); poDS->PrintLine( fp, "</ogr:%s>", poFeatureDefn->GetName() ); if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); if (bIsGML3Output) poDS->PrintLine( fp, "</ogr:featureMember>" ); else poDS->PrintLine( fp, "</gml:featureMember>" ); return OGRERR_NONE; }
OGRErr OGRGFTTableLayer::ICreateFeature( OGRFeature *poFeature ) { if (!poDS->IsReadWrite()) { CPLError(CE_Failure, CPLE_AppDefined, "Operation not available in read-only mode"); return OGRERR_FAILURE; } if (osTableId.size() == 0) { CreateTableIfNecessary(); if (osTableId.size() == 0) { CPLError(CE_Failure, CPLE_NotSupported, "Cannot add feature to non-created table"); return OGRERR_FAILURE; } } if (poDS->GetAccessToken().size() == 0) { CPLError(CE_Failure, CPLE_AppDefined, "Operation not available in unauthenticated mode"); return OGRERR_FAILURE; } CPLString osCommand; osCommand += "INSERT INTO "; osCommand += osTableId; osCommand += " ("; int iField; int nFieldCount = poFeatureDefn->GetFieldCount(); for(iField = 0; iField < nFieldCount; iField++) { if (iField > 0) osCommand += ", "; const char* pszFieldName = poFeatureDefn->GetFieldDefn(iField)->GetNameRef(); osCommand += EscapeAndQuote(pszFieldName); } if (bHiddenGeometryField) { if (iField > 0) osCommand += ", "; osCommand += EscapeAndQuote(GetGeometryColumn()); } osCommand += ") VALUES ("; for(iField = 0; iField < nFieldCount + bHiddenGeometryField; iField++) { if (iField > 0) osCommand += ", "; OGRGeometry* poGeom = poFeature->GetGeometryRef(); /* If there's a geometry, let's use it in priority over the textual */ /* content of the field. */ if (iGeometryField != iLatitudeField && iField == iGeometryField && (iField == nFieldCount || poGeom != NULL || !poFeature->IsFieldSet( iField ))) { if (poGeom == NULL) osCommand += "''"; else { char* pszKML; if (poGeom->getSpatialReference() != NULL && !poGeom->getSpatialReference()->IsSame(poSRS)) { OGRGeometry* poGeom4326 = poGeom->clone(); poGeom4326->transformTo(poSRS); pszKML = poGeom4326->exportToKML(); delete poGeom4326; } else { pszKML = poGeom->exportToKML(); } osCommand += "'"; osCommand += pszKML; osCommand += "'"; CPLFree(pszKML); } continue; } if( !poFeature->IsFieldSet( iField ) ) { osCommand += "''"; } else { OGRFieldType eType = poFeatureDefn->GetFieldDefn(iField)->GetType(); if (eType != OFTInteger && eType != OFTReal) { CPLString osTmp; const char* pszVal = poFeature->GetFieldAsString(iField); if (!CPLIsUTF8(pszVal, -1)) { static int bFirstTime = TRUE; if (bFirstTime) { bFirstTime = FALSE; CPLError(CE_Warning, CPLE_AppDefined, "%s is not a valid UTF-8 string. Forcing it to ASCII.\n" "This warning won't be issued anymore", pszVal); } else { CPLDebug("OGR", "%s is not a valid UTF-8 string. Forcing it to ASCII", pszVal); } char* pszEscaped = CPLForceToASCII(pszVal, -1, '?'); osTmp = pszEscaped; CPLFree(pszEscaped); pszVal = osTmp.c_str(); } osCommand += EscapeAndQuote(pszVal); } else osCommand += poFeature->GetFieldAsString(iField); } } osCommand += ")"; //CPLDebug("GFT", "%s", osCommand.c_str()); if (bInTransaction) { nFeaturesInTransaction ++; if (nFeaturesInTransaction > 1) osTransaction += "; "; osTransaction += osCommand; return OGRERR_NONE; } CPLHTTPResult * psResult = poDS->RunSQL(osCommand); if (psResult == NULL) { CPLError(CE_Failure, CPLE_AppDefined, "Feature creation failed"); return OGRERR_FAILURE; } char* pszLine = (char*) psResult->pabyData; if (pszLine == NULL || strncmp(pszLine, "rowid", 5) != 0 || psResult->pszErrBuf != NULL) { CPLError(CE_Failure, CPLE_AppDefined, "Feature creation failed"); CPLHTTPDestroyResult(psResult); return OGRERR_FAILURE; } pszLine = OGRGFTGotoNextLine(pszLine); if (pszLine == NULL) { CPLError(CE_Failure, CPLE_AppDefined, "Feature creation failed"); CPLHTTPDestroyResult(psResult); return OGRERR_FAILURE; } char* pszNextLine = OGRGFTGotoNextLine(pszLine); if (pszNextLine) pszNextLine[-1] = 0; CPLDebug("GFT", "Feature id = %s", pszLine); int nFID = atoi(pszLine); if (strcmp(CPLSPrintf("%d", nFID), pszLine) == 0) poFeature->SetFID(nFID); CPLHTTPDestroyResult(psResult); return OGRERR_NONE; }
OGRErr OGRGMLLayer::ICreateFeature( OGRFeature *poFeature ) { int bIsGML3Output = poDS->IsGML3Output(); VSILFILE *fp = poDS->GetOutputFP(); int bWriteSpaceIndentation = poDS->WriteSpaceIndentation(); const char* pszPrefix = poDS->GetAppPrefix(); int bRemoveAppPrefix = poDS->RemoveAppPrefix(); if( !bWriter ) return OGRERR_FAILURE; poFeature->FillUnsetWithDefault(TRUE, NULL); if( !poFeature->Validate( OGR_F_VAL_ALL & ~OGR_F_VAL_GEOM_TYPE & ~OGR_F_VAL_ALLOW_NULL_WHEN_DEFAULT, TRUE ) ) return OGRERR_FAILURE; if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); if (bIsGML3Output) { if( bRemoveAppPrefix ) poDS->PrintLine( fp, "<featureMember>" ); else poDS->PrintLine( fp, "<%s:featureMember>", pszPrefix ); } else poDS->PrintLine( fp, "<gml:featureMember>" ); if( iNextGMLId == 0 ) { bSameSRS = true; for( int iGeomField = 1; iGeomField < poFeatureDefn->GetGeomFieldCount(); iGeomField++ ) { OGRGeomFieldDefn *poFieldDefn0 = poFeatureDefn->GetGeomFieldDefn(0); OGRGeomFieldDefn *poFieldDefn = poFeatureDefn->GetGeomFieldDefn(iGeomField); OGRSpatialReference* poSRS0 = poFieldDefn0->GetSpatialRef(); OGRSpatialReference* poSRS = poFieldDefn->GetSpatialRef(); if( poSRS0 != NULL && poSRS == NULL ) bSameSRS = false; else if( poSRS0 == NULL && poSRS != NULL ) bSameSRS = false; else if( poSRS0 != NULL && poSRS != NULL && poSRS0 != poSRS && !poSRS0->IsSame(poSRS) ) { bSameSRS = false; } } } if( poFeature->GetFID() == OGRNullFID ) poFeature->SetFID( iNextGMLId++ ); int nGMLIdIndex = -1; if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); VSIFPrintfL(fp, "<"); if( !bRemoveAppPrefix ) VSIFPrintfL(fp, "%s:", pszPrefix); if (bIsGML3Output) { nGMLIdIndex = poFeatureDefn->GetFieldIndex("gml_id"); if (nGMLIdIndex >= 0 && poFeature->IsFieldSet( nGMLIdIndex ) ) poDS->PrintLine( fp, "%s gml:id=\"%s\">", poFeatureDefn->GetName(), poFeature->GetFieldAsString(nGMLIdIndex) ); else poDS->PrintLine( fp, "%s gml:id=\"%s." CPL_FRMT_GIB "\">", poFeatureDefn->GetName(), poFeatureDefn->GetName(), poFeature->GetFID() ); } else { nGMLIdIndex = poFeatureDefn->GetFieldIndex("fid"); if (bUseOldFIDFormat) { poDS->PrintLine( fp, "%s fid=\"F" CPL_FRMT_GIB "\">", poFeatureDefn->GetName(), poFeature->GetFID() ); } else if (nGMLIdIndex >= 0 && poFeature->IsFieldSet( nGMLIdIndex ) ) { poDS->PrintLine( fp, "%s fid=\"%s\">", poFeatureDefn->GetName(), poFeature->GetFieldAsString(nGMLIdIndex) ); } else { poDS->PrintLine( fp, "%s fid=\"%s." CPL_FRMT_GIB "\">", poFeatureDefn->GetName(), poFeatureDefn->GetName(), poFeature->GetFID() ); } } for( int iGeomField = 0; iGeomField < poFeatureDefn->GetGeomFieldCount(); iGeomField++ ) { OGRGeomFieldDefn *poFieldDefn = poFeatureDefn->GetGeomFieldDefn(iGeomField); // Write out Geometry - for now it isn't indented properly. /* GML geometries don't like very much the concept of empty geometry */ OGRGeometry* poGeom = poFeature->GetGeomFieldRef(iGeomField); if( poGeom != NULL && !poGeom->IsEmpty()) { char *pszGeometry; OGREnvelope3D sGeomBounds; int nCoordDimension = poGeom->getCoordinateDimension(); poGeom->getEnvelope( &sGeomBounds ); if( bSameSRS ) poDS->GrowExtents( &sGeomBounds, nCoordDimension ); if (poGeom->getSpatialReference() == NULL && poFieldDefn->GetSpatialRef() != NULL) poGeom->assignSpatialReference(poFieldDefn->GetSpatialRef()); if (bIsGML3Output && poDS->WriteFeatureBoundedBy()) { bool bCoordSwap; char* pszSRSName = GML_GetSRSName(poGeom->getSpatialReference(), poDS->IsLongSRSRequired(), &bCoordSwap); char szLowerCorner[75], szUpperCorner[75]; if (bCoordSwap) { OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinY, sGeomBounds.MinX, sGeomBounds.MinZ, nCoordDimension); OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxY, sGeomBounds.MaxX, sGeomBounds.MaxZ, nCoordDimension); } else { OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinX, sGeomBounds.MinY, sGeomBounds.MinZ, nCoordDimension); OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxX, sGeomBounds.MaxY, sGeomBounds.MaxZ, nCoordDimension); } if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); poDS->PrintLine( fp, "<gml:boundedBy><gml:Envelope%s%s><gml:lowerCorner>%s</gml:lowerCorner><gml:upperCorner>%s</gml:upperCorner></gml:Envelope></gml:boundedBy>", (nCoordDimension == 3) ? " srsDimension=\"3\"" : "",pszSRSName, szLowerCorner, szUpperCorner); CPLFree(pszSRSName); } char** papszOptions = (bIsGML3Output) ? CSLAddString(NULL, "FORMAT=GML3") : NULL; if (bIsGML3Output && !poDS->IsLongSRSRequired()) papszOptions = CSLAddString(papszOptions, "GML3_LONGSRS=NO"); const char* pszSRSDimensionLoc = poDS->GetSRSDimensionLoc(); if( pszSRSDimensionLoc != NULL ) papszOptions = CSLSetNameValue(papszOptions, "SRSDIMENSION_LOC", pszSRSDimensionLoc); if (poDS->IsGML32Output()) { if( poFeatureDefn->GetGeomFieldCount() > 1 ) papszOptions = CSLAddString(papszOptions, CPLSPrintf("GMLID=%s.%s." CPL_FRMT_GIB, poFeatureDefn->GetName(), poFieldDefn->GetNameRef(), poFeature->GetFID())); else papszOptions = CSLAddString(papszOptions, CPLSPrintf("GMLID=%s.geom." CPL_FRMT_GIB, poFeatureDefn->GetName(), poFeature->GetFID())); } if( !bIsGML3Output && OGR_GT_IsNonLinear(poGeom->getGeometryType()) ) { OGRGeometry* poGeomTmp = OGRGeometryFactory::forceTo( poGeom->clone(),OGR_GT_GetLinear(poGeom->getGeometryType())); pszGeometry = poGeomTmp->exportToGML(papszOptions); delete poGeomTmp; } else pszGeometry = poGeom->exportToGML(papszOptions); CSLDestroy(papszOptions); if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); if( bRemoveAppPrefix ) poDS->PrintLine( fp, "<%s>%s</%s>", poFieldDefn->GetNameRef(), pszGeometry, poFieldDefn->GetNameRef() ); else poDS->PrintLine( fp, "<%s:%s>%s</%s:%s>", pszPrefix, poFieldDefn->GetNameRef(), pszGeometry, pszPrefix, poFieldDefn->GetNameRef() ); CPLFree( pszGeometry ); } } // Write all "set" fields. for( int iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ ) { OGRFieldDefn *poFieldDefn = poFeatureDefn->GetFieldDefn( iField ); if( poFeature->IsFieldSet( iField ) && iField != nGMLIdIndex ) { OGRFieldType eType = poFieldDefn->GetType(); if (eType == OFTStringList ) { char ** papszIter = poFeature->GetFieldAsStringList( iField ); while( papszIter != NULL && *papszIter != NULL ) { char *pszEscaped = OGRGetXML_UTF8_EscapedString( *papszIter ); GMLWriteField(poDS, fp, bWriteSpaceIndentation, pszPrefix, bRemoveAppPrefix, poFieldDefn, pszEscaped); CPLFree( pszEscaped ); papszIter ++; } } else if (eType == OFTIntegerList ) { int nCount = 0; const int* panVals = poFeature->GetFieldAsIntegerList( iField, &nCount ); if( poFieldDefn->GetSubType() == OFSTBoolean ) { for(int i = 0; i < nCount; i++) { /* 0 and 1 are OK, but the canonical representation is false and true */ GMLWriteField(poDS, fp, bWriteSpaceIndentation, pszPrefix, bRemoveAppPrefix, poFieldDefn, panVals[i] ? "true" : "false"); } } else { for(int i = 0; i < nCount; i++) { GMLWriteField(poDS, fp, bWriteSpaceIndentation, pszPrefix, bRemoveAppPrefix, poFieldDefn, CPLSPrintf("%d", panVals[i])); } } } else if (eType == OFTInteger64List ) { int nCount = 0; const GIntBig* panVals = poFeature->GetFieldAsInteger64List( iField, &nCount ); if( poFieldDefn->GetSubType() == OFSTBoolean ) { for(int i = 0; i < nCount; i++) { /* 0 and 1 are OK, but the canonical representation is false and true */ GMLWriteField(poDS, fp, bWriteSpaceIndentation, pszPrefix, bRemoveAppPrefix, poFieldDefn, panVals[i] ? "true" : "false"); } } else { for(int i = 0; i < nCount; i++) { GMLWriteField(poDS, fp, bWriteSpaceIndentation, pszPrefix, bRemoveAppPrefix, poFieldDefn, CPLSPrintf(CPL_FRMT_GIB, panVals[i])); } } } else if (eType == OFTRealList ) { int nCount = 0; const double* padfVals = poFeature->GetFieldAsDoubleList( iField, &nCount ); for(int i = 0; i < nCount; i++) { char szBuffer[80]; CPLsnprintf( szBuffer, sizeof(szBuffer), "%.15g", padfVals[i]); GMLWriteField(poDS, fp, bWriteSpaceIndentation, pszPrefix, bRemoveAppPrefix, poFieldDefn, szBuffer); } } else if ((eType == OFTInteger || eType == OFTInteger64) && poFieldDefn->GetSubType() == OFSTBoolean ) { /* 0 and 1 are OK, but the canonical representation is false and true */ GMLWriteField(poDS, fp, bWriteSpaceIndentation, pszPrefix, bRemoveAppPrefix, poFieldDefn, (poFeature->GetFieldAsInteger(iField)) ? "true" : "false"); } else { const char *pszRaw = poFeature->GetFieldAsString( iField ); char *pszEscaped = OGRGetXML_UTF8_EscapedString( pszRaw ); GMLWriteField(poDS, fp, bWriteSpaceIndentation, pszPrefix, bRemoveAppPrefix, poFieldDefn, pszEscaped); CPLFree( pszEscaped ); } } } if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); if( bRemoveAppPrefix ) poDS->PrintLine( fp, "</%s>", poFeatureDefn->GetName() ); else poDS->PrintLine( fp, "</%s:%s>", pszPrefix, poFeatureDefn->GetName() ); if (bWriteSpaceIndentation) VSIFPrintfL(fp, " "); if (bIsGML3Output) { if( bRemoveAppPrefix ) poDS->PrintLine( fp, "</featureMember>" ); else poDS->PrintLine( fp, "</%s:featureMember>", pszPrefix ); } else poDS->PrintLine( fp, "</gml:featureMember>" ); return OGRERR_NONE; }