OGRGeometry* GML_BuildOGRGeometryFromList(const CPLXMLNode* const * papsGeometry, int bTryToMakeMultipolygons, int bInvertAxisOrderIfLatLong, const char* pszDefaultSRSName, int bConsiderEPSGAsURN, int bGetSecondaryGeometryOption, void* hCacheSRS) { OGRGeometry* poGeom = NULL; int i; OGRGeometryCollection* poCollection = NULL; for(i=0;papsGeometry[i] != NULL;i++) { OGRGeometry* poSubGeom = GML2OGRGeometry_XMLNode( papsGeometry[i], bGetSecondaryGeometryOption ); if (poSubGeom) { if (poGeom == NULL) poGeom = poSubGeom; else { if (poCollection == NULL) { if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon && wkbFlatten(poSubGeom->getGeometryType()) == wkbPolygon) { OGRGeometryCollection* poGeomColl = new OGRMultiPolygon(); poGeomColl->addGeometryDirectly(poGeom); poGeomColl->addGeometryDirectly(poSubGeom); poGeom = poGeomColl; } else if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon && wkbFlatten(poSubGeom->getGeometryType()) == wkbPolygon) { OGRGeometryCollection* poGeomColl = (OGRGeometryCollection* )poGeom; poGeomColl->addGeometryDirectly(poSubGeom); } else if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon && wkbFlatten(poSubGeom->getGeometryType()) == wkbMultiPolygon) { OGRGeometryCollection* poGeomColl = (OGRGeometryCollection* )poGeom; OGRGeometryCollection* poGeomColl2 = (OGRGeometryCollection* )poSubGeom; int nCount = poGeomColl2->getNumGeometries(); int i; for(i=0;i<nCount;i++) { poGeomColl->addGeometry(poGeomColl2->getGeometryRef(i)); } delete poSubGeom; } else if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon) { delete poGeom; delete poSubGeom; return GML_BuildOGRGeometryFromList(papsGeometry, FALSE, bInvertAxisOrderIfLatLong, pszDefaultSRSName, bConsiderEPSGAsURN, bGetSecondaryGeometryOption, hCacheSRS); } else { poCollection = new OGRGeometryCollection(); poCollection->addGeometryDirectly(poGeom); poGeom = poCollection; } } if (poCollection != NULL) { poCollection->addGeometryDirectly(poSubGeom); } } } } if ( poGeom != NULL && bInvertAxisOrderIfLatLong ) { std::string osWork; const char* pszSRSName = GML_ExtractSrsNameFromGeometry(papsGeometry, osWork, bConsiderEPSGAsURN); const char* pszNameLookup = pszSRSName ? pszSRSName : pszDefaultSRSName; if (pszNameLookup != NULL) { SRSCache* poSRSCache = (SRSCache*)hCacheSRS; int bSwap; if (strcmp(poSRSCache->osLastSRSName.c_str(), pszNameLookup) == 0) { bSwap = poSRSCache->bAxisInvertLastSRSName; } else { bSwap = GML_IsSRSLatLongOrder(pszNameLookup); poSRSCache->osLastSRSName = pszNameLookup; poSRSCache->bAxisInvertLastSRSName= bSwap; } if (bSwap) poGeom->swapXY(); } } return poGeom; }
OGRGeometry* GML_BuildOGRGeometryFromList(const CPLXMLNode* const * papsGeometry, int bTryToMakeMultipolygons, int bInvertAxisOrderIfLatLong, const char* pszDefaultSRSName, int bConsiderEPSGAsURN, int bGetSecondaryGeometryOption, void* hCacheSRS, int bFaceHoleNegative) { OGRGeometry* poGeom = NULL; int i; OGRGeometryCollection* poCollection = NULL; for(i=0;papsGeometry[i] != NULL;i++) { OGRGeometry* poSubGeom = GML2OGRGeometry_XMLNode( papsGeometry[i], bGetSecondaryGeometryOption, 0, 0, FALSE, TRUE, bFaceHoleNegative ); if (poSubGeom) { if (poGeom == NULL) poGeom = poSubGeom; else { if (poCollection == NULL) { if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon && wkbFlatten(poSubGeom->getGeometryType()) == wkbPolygon) { OGRGeometryCollection* poGeomColl = new OGRMultiPolygon(); poGeomColl->addGeometryDirectly(poGeom); poGeomColl->addGeometryDirectly(poSubGeom); poGeom = poGeomColl; } else if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon && wkbFlatten(poSubGeom->getGeometryType()) == wkbPolygon) { OGRGeometryCollection* poGeomColl = (OGRGeometryCollection* )poGeom; poGeomColl->addGeometryDirectly(poSubGeom); } else if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon && wkbFlatten(poSubGeom->getGeometryType()) == wkbMultiPolygon) { OGRGeometryCollection* poGeomColl = (OGRGeometryCollection* )poGeom; OGRGeometryCollection* poGeomColl2 = (OGRGeometryCollection* )poSubGeom; int nCount = poGeomColl2->getNumGeometries(); int i; for(i=0;i<nCount;i++) { poGeomColl->addGeometry(poGeomColl2->getGeometryRef(i)); } delete poSubGeom; } else if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon) { delete poGeom; delete poSubGeom; return GML_BuildOGRGeometryFromList(papsGeometry, FALSE, bInvertAxisOrderIfLatLong, pszDefaultSRSName, bConsiderEPSGAsURN, bGetSecondaryGeometryOption, hCacheSRS); } else { poCollection = new OGRGeometryCollection(); poCollection->addGeometryDirectly(poGeom); poGeom = poCollection; } } if (poCollection != NULL) { poCollection->addGeometryDirectly(poSubGeom); } } } } if( poGeom == NULL ) return NULL; std::string osWork; const char* pszSRSName = GML_ExtractSrsNameFromGeometry(papsGeometry, osWork, bConsiderEPSGAsURN); const char* pszNameLookup = pszSRSName; if( pszNameLookup == NULL ) pszNameLookup = pszDefaultSRSName; if (pszNameLookup != NULL) { SRSCache* poSRSCache = (SRSCache*)hCacheSRS; SRSDesc& oSRSDesc = poSRSCache->Get(pszNameLookup); poGeom->assignSpatialReference(oSRSDesc.poSRS); if (oSRSDesc.bAxisInvert && bInvertAxisOrderIfLatLong) poGeom->swapXY(); } return poGeom; }
OGRGeometry* GML_BuildOGRGeometryFromList(char** papszGeometryList, int bTryToMakeMultipolygons, int bInvertAxisOrderIfLatLong, const char* pszDefaultSRSName) { OGRGeometry* poGeom = NULL; if( papszGeometryList != NULL ) { char** papszIter = papszGeometryList; OGRGeometryCollection* poCollection = NULL; while(*papszIter) { OGRGeometry* poSubGeom = OGRGeometryFactory::createFromGML( *papszIter ); if (poSubGeom) { if (poGeom == NULL) poGeom = poSubGeom; else { if (poCollection == NULL) { if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon && wkbFlatten(poSubGeom->getGeometryType()) == wkbPolygon) { OGRGeometryCollection* poGeomColl = new OGRMultiPolygon(); poGeomColl->addGeometryDirectly(poGeom); poGeomColl->addGeometryDirectly(poSubGeom); poGeom = poGeomColl; } else if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon && wkbFlatten(poSubGeom->getGeometryType()) == wkbPolygon) { OGRGeometryCollection* poGeomColl = (OGRGeometryCollection* )poGeom; poGeomColl->addGeometryDirectly(poSubGeom); } else if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon && wkbFlatten(poSubGeom->getGeometryType()) == wkbMultiPolygon) { OGRGeometryCollection* poGeomColl = (OGRGeometryCollection* )poGeom; OGRGeometryCollection* poGeomColl2 = (OGRGeometryCollection* )poSubGeom; int nCount = poGeomColl2->getNumGeometries(); int i; for(i=0;i<nCount;i++) { poGeomColl->addGeometry(poGeomColl2->getGeometryRef(i)); } delete poSubGeom; } else if (bTryToMakeMultipolygons && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon) { delete poGeom; delete poSubGeom; return GML_BuildOGRGeometryFromList(papszGeometryList, FALSE, bInvertAxisOrderIfLatLong, pszDefaultSRSName); } else { poCollection = new OGRGeometryCollection(); poCollection->addGeometryDirectly(poGeom); poGeom = poCollection; } } if (poCollection != NULL) { poCollection->addGeometryDirectly(poSubGeom); } } } papszIter ++; } } if (bInvertAxisOrderIfLatLong) { char* pszSRSName = GML_ExtractSrsNameFromGeometry(papszGeometryList); if (GML_IsSRSLatLongOrder(pszSRSName ? pszSRSName : pszDefaultSRSName)) poGeom->swapXY(); CPLFree(pszSRSName); } return poGeom; }