OGRGeometry *OGRGeometryFactory::forceToMultiPolygon( OGRGeometry *poGeom ) { if( poGeom == NULL ) return NULL; /* -------------------------------------------------------------------- */ /* Check for the case of a geometrycollection that can be */ /* promoted to MultiPolygon. */ /* -------------------------------------------------------------------- */ if( wkbFlatten(poGeom->getGeometryType()) == wkbGeometryCollection ) { int iGeom; int bAllPoly = TRUE; OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeom; for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ ) { if( wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType()) != wkbPolygon ) bAllPoly = FALSE; } if( !bAllPoly ) return poGeom; OGRMultiPolygon *poMP = new OGRMultiPolygon(); while( poGC->getNumGeometries() > 0 ) { poMP->addGeometryDirectly( poGC->getGeometryRef(0) ); poGC->removeGeometry( 0, FALSE ); } delete poGC; return poMP; } /* -------------------------------------------------------------------- */ /* Eventually we should try to split the polygon into component */ /* island polygons. But thats alot of work and can be put off. */ /* -------------------------------------------------------------------- */ if( wkbFlatten(poGeom->getGeometryType()) != wkbPolygon ) return poGeom; OGRMultiPolygon *poMP = new OGRMultiPolygon(); poMP->addGeometryDirectly( poGeom ); return poMP; }
OGRGeometry *OGRGeometryFactory::forceToMultiLineString( OGRGeometry *poGeom ) { if( poGeom == NULL ) return NULL; /* -------------------------------------------------------------------- */ /* Check for the case of a geometrycollection that can be */ /* promoted to MultiLineString. */ /* -------------------------------------------------------------------- */ if( wkbFlatten(poGeom->getGeometryType()) == wkbGeometryCollection ) { int iGeom; int bAllLines = TRUE; OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeom; for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ ) { if( wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType()) != wkbLineString ) bAllLines = FALSE; } if( !bAllLines ) return poGeom; OGRMultiLineString *poMP = new OGRMultiLineString(); while( poGC->getNumGeometries() > 0 ) { poMP->addGeometryDirectly( poGC->getGeometryRef(0) ); poGC->removeGeometry( 0, FALSE ); } delete poGC; return poMP; } if( wkbFlatten(poGeom->getGeometryType()) != wkbLineString ) return poGeom; OGRMultiLineString *poMP = new OGRMultiLineString(); poMP->addGeometryDirectly( poGeom ); return poMP; }