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; }
static int OGR2ILIGeometryAppend( OGRGeometry *poGeometry, VSILFILE* fp, const char *attrname, CPLString iliGeomType ) { //CPLDebug( "OGR_ILI", "OGR2ILIGeometryAppend getGeometryType %s iliGeomType %s", poGeometry->getGeometryName(), iliGeomType.c_str()); /* -------------------------------------------------------------------- */ /* 2D/3D Point */ /* -------------------------------------------------------------------- */ if( poGeometry->getGeometryType() == wkbPoint || poGeometry->getGeometryType() == wkbPoint25D ) { OGRPoint *poPoint = (OGRPoint *) poGeometry; VSIFPrintfL(fp, "<%s>\n", attrname); VSIFPrintfL(fp, "<COORD>"); VSIFPrintfL(fp, "<C1>%s</C1>", d2str(poPoint->getX())); VSIFPrintfL(fp, "<C2>%s</C2>", d2str(poPoint->getY())); if( poGeometry->getGeometryType() == wkbPoint25D ) VSIFPrintfL(fp, "<C3>%s</C3>", d2str(poPoint->getZ())); VSIFPrintfL(fp, "</COORD>\n"); VSIFPrintfL(fp, "</%s>\n", attrname); } /* -------------------------------------------------------------------- */ /* LineString and LinearRing */ /* -------------------------------------------------------------------- */ else if( poGeometry->getGeometryType() == wkbLineString || poGeometry->getGeometryType() == wkbLineString25D ) { if (attrname) VSIFPrintfL(fp, "<%s>\n", attrname); VSIFPrintfL(fp, "<POLYLINE>\n"); // unclipped polyline, add one sequence // VSIFPrintfL(fp, "<SEGMENTS>\n"); AppendCoordinateList( (OGRLineString *) poGeometry, fp ); // VSIFPrintfL(fp, "</SEGMENTS>\n"); VSIFPrintfL(fp, "</POLYLINE>\n"); if (attrname) VSIFPrintfL(fp, "</%s>\n", attrname); } /* -------------------------------------------------------------------- */ /* Polygon */ /* -------------------------------------------------------------------- */ else if( poGeometry->getGeometryType() == wkbPolygon || poGeometry->getGeometryType() == wkbPolygon25D ) { OGRPolygon *poPolygon = (OGRPolygon *) poGeometry; if (attrname) VSIFPrintfL(fp, "<%s>\n", attrname); if( iliGeomType == "Surface" || iliGeomType == "Area" ) { //VSIFPrintfL(fp, "<MULTISURFACE>\n"); VSIFPrintfL(fp, "<SURFACE>\n"); VSIFPrintfL(fp, "<BOUNDARY>\n"); } if( poPolygon->getExteriorRing() != NULL ) { if( !OGR2ILIGeometryAppend( poPolygon->getExteriorRing(), fp, NULL, "" ) ) return FALSE; } for( int iRing = 0; iRing < poPolygon->getNumInteriorRings(); iRing++ ) { OGRLinearRing *poRing = poPolygon->getInteriorRing(iRing); if( !OGR2ILIGeometryAppend( poRing, fp, NULL, "" ) ) return FALSE; } if( iliGeomType == "Surface" || iliGeomType == "Area" ) { VSIFPrintfL(fp, "</BOUNDARY>\n"); VSIFPrintfL(fp, "</SURFACE>\n"); //VSIFPrintfL(fp, "</MULTISURFACE>\n"); } if (attrname) VSIFPrintfL(fp, "</%s>\n", attrname); } /* -------------------------------------------------------------------- */ /* MultiPolygon */ /* -------------------------------------------------------------------- */ else if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon || wkbFlatten(poGeometry->getGeometryType()) == wkbMultiLineString || wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPoint || wkbFlatten(poGeometry->getGeometryType()) == wkbGeometryCollection ) { OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeometry; int iMember; if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon ) { } else if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiLineString ) { } else if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPoint ) { } else { } for( iMember = 0; iMember < poGC->getNumGeometries(); iMember++) { OGRGeometry *poMember = poGC->getGeometryRef( iMember ); if( !OGR2ILIGeometryAppend( poMember, fp, NULL, "" ) ) return FALSE; } } else return FALSE; return TRUE; }