OGRGeometryCollection* OGRGeometryCollection::CastToGeometryCollection( OGRGeometryCollection* poSrc ) { if( wkbFlatten(poSrc->getGeometryType()) == wkbGeometryCollection ) return poSrc; return TransferMembersAndDestroy(poSrc, new OGRGeometryCollection()); }
OGRMultiPolygon* OGRMultiSurface::CastToMultiPolygon( OGRMultiSurface* poMS ) { for( int i = 0; i < poMS->nGeomCount; i++ ) { OGRSurface* poSurface = dynamic_cast<OGRSurface *>(poMS->papoGeoms[i]); if( poSurface == NULL ) { CPLError(CE_Fatal, CPLE_AppDefined, "dynamic_cast failed. Expected OGRSurface."); delete poMS; return NULL; } poMS->papoGeoms[i] = OGRSurface::CastToPolygon(poSurface); if( poMS->papoGeoms[i] == NULL ) { delete poMS; return NULL; } } OGRGeometryCollection *poGC = TransferMembersAndDestroy(poMS, new OGRMultiPolygon()); OGRMultiPolygon* poMultiPolygon = dynamic_cast<OGRMultiPolygon *>(poGC); if( poMultiPolygon == NULL ) { CPLError(CE_Fatal, CPLE_AppDefined, "dynamic_cast failed. Expected OGRMultiPolygon."); } return poMultiPolygon; }
OGRMultiPolygon* OGRMultiSurface::CastToMultiPolygon(OGRMultiSurface* poMS) { for(int i=0;i<poMS->nGeomCount;i++) { poMS->papoGeoms[i] = OGRSurface::CastToPolygon( (OGRSurface*)poMS->papoGeoms[i] ); if( poMS->papoGeoms[i] == NULL ) { delete poMS; return NULL; } } return (OGRMultiPolygon*) TransferMembersAndDestroy(poMS, new OGRMultiPolygon()); }
OGRMultiLineString* OGRMultiCurve::CastToMultiLineString(OGRMultiCurve* poMC) { for(int i=0;i<poMC->nGeomCount;i++) { poMC->papoGeoms[i] = OGRCurve::CastToLineString( (OGRCurve*)poMC->papoGeoms[i] ); if( poMC->papoGeoms[i] == NULL ) { delete poMC; return NULL; } } return (OGRMultiLineString*) TransferMembersAndDestroy(poMC, new OGRMultiLineString()); }
OGRMultiPolygon* OGRMultiSurface::CastToMultiPolygon( OGRMultiSurface* poMS ) { for( auto&& poSubGeom: *poMS ) { poSubGeom = OGRSurface::CastToPolygon(poSubGeom); if( poSubGeom == nullptr ) { delete poMS; return nullptr; } } OGRMultiPolygon* poMP = new OGRMultiPolygon(); TransferMembersAndDestroy(poMS, poMP); return poMP; }
OGRMultiLineString* OGRMultiCurve::CastToMultiLineString( OGRMultiCurve* poMC ) { for( int i = 0; i < poMC->nGeomCount; ++i ) { OGRCurve * const poCurve = dynamic_cast<OGRCurve *>(poMC->papoGeoms[i]); if( poCurve == NULL ) { CPLError( CE_Fatal, CPLE_AssertionFailed, "dynamic_cast failed." ); continue; } poMC->papoGeoms[i] = OGRCurve::CastToLineString( poCurve ); if( poMC->papoGeoms[i] == NULL ) { delete poMC; return NULL; } } return dynamic_cast<OGRMultiLineString *>( TransferMembersAndDestroy(poMC, new OGRMultiLineString()) ); }
OGRMultiCurve* OGRMultiLineString::CastToMultiCurve(OGRMultiLineString* poMLS) { return (OGRMultiCurve*) TransferMembersAndDestroy(poMLS, new OGRMultiCurve()); }
OGRLineString* OGRLinearRing::CastToLineString( OGRLinearRing* poLR ) { return TransferMembersAndDestroy(poLR, new OGRLineString()); }
OGRMultiSurface* OGRMultiPolygon::CastToMultiSurface(OGRMultiPolygon* poMP) { return (OGRMultiSurface*) TransferMembersAndDestroy(poMP, new OGRMultiSurface()); }