Geometry::AutoPtr GeometryTransformer::transformGeometryCollection( const GeometryCollection* geom, const Geometry* parent) { UNREFERENCED_PARAMETER(parent); #if GEOS_DEBUG std::cerr << "GeometryTransformer::transformGeometryCollection(GeometryCollection " << geom <<", Geometry " << parent << ");" << std::endl; #endif vector<Geometry*>* transGeomList = new vector<Geometry*>(); for (unsigned int i=0, n=geom->getNumGeometries(); i<n; i++) { Geometry::AutoPtr transformGeom = transform( geom->getGeometryN(i)); // no parent ? if ( transformGeom.get() == NULL ) continue; if ( pruneEmptyGeometry && transformGeom->isEmpty() ) continue; // If an exception is thrown we'll leak transGeomList->push_back(transformGeom.release()); } if ( preserveGeometryCollectionType ) { return Geometry::AutoPtr(factory->createGeometryCollection( transGeomList)); } else { return Geometry::AutoPtr(factory->buildGeometry(transGeomList)); } }
Geometry::AutoPtr GeometryTransformer::transformMultiPolygon( const MultiPolygon* geom, const Geometry* parent) { UNREFERENCED_PARAMETER(parent); #if GEOS_DEBUG std::cerr << "GeometryTransformer::transformMultiPolygon(MultiPolygon " << geom <<", Geometry " << parent << ");" << std::endl; #endif auto_ptr< vector<Geometry*> > transGeomList( new vector<Geometry*>() ); for (unsigned int i=0, n=geom->getNumGeometries(); i<n; i++) { assert(dynamic_cast<const Polygon*>(geom->getGeometryN(i))); const Polygon* p = static_cast<const Polygon*>( geom->getGeometryN(i)); Geometry::AutoPtr transformGeom = transformPolygon(p, geom); if ( transformGeom.get() == NULL ) continue; if ( transformGeom->isEmpty() ) continue; // If an exception is thrown we'll leak transGeomList->push_back(transformGeom.release()); } return Geometry::AutoPtr(factory->buildGeometry(transGeomList.release())); }
Geometry::AutoPtr GeometryTransformer::transformMultiLineString( const MultiLineString* geom, const Geometry* parent) { #if GEOS_DEBUG std::cerr << "GeometryTransformer::transformMultiLineString(MultiLineString " << geom <<", Geometry " << parent << ");" << std::endl; #endif vector<Geometry*>* transGeomList = new vector<Geometry*>(); for (unsigned int i=0, n=geom->getNumGeometries(); i<n; i++) { assert(dynamic_cast<const LineString*>(geom->getGeometryN(i))); const LineString* l = static_cast<const LineString*>( geom->getGeometryN(i)); Geometry::AutoPtr transformGeom = transformLineString(l, geom); if ( transformGeom.get() == NULL ) continue; if ( transformGeom->isEmpty() ) continue; // If an exception is thrown we'll leak transGeomList->push_back(transformGeom.release()); } return Geometry::AutoPtr(factory->buildGeometry(transGeomList)); }
Geometry::AutoPtr GeometryTransformer::transformPolygon( const Polygon* geom, const Geometry* parent) { UNREFERENCED_PARAMETER(parent); #if GEOS_DEBUG std::cerr << "GeometryTransformer::transformPolygon(Polygon " << geom <<", Geometry " << parent << ");" << std::endl; #endif bool isAllValidLinearRings = true; assert(dynamic_cast<const LinearRing*>(geom->getExteriorRing())); const LinearRing* lr = static_cast<const LinearRing*>( geom->getExteriorRing()); Geometry::AutoPtr shell = transformLinearRing(lr, geom); if ( shell.get() == NULL || ! dynamic_cast<LinearRing*>(shell.get()) || shell->isEmpty() ) { isAllValidLinearRings = false; } vector<Geometry*>* holes = new vector<Geometry*>(); for (unsigned int i=0, n=geom->getNumInteriorRing(); i<n; i++) { assert(dynamic_cast<const LinearRing*>( geom->getInteriorRingN(i))); const LinearRing* lr = static_cast<const LinearRing*>( geom->getInteriorRingN(i)); Geometry::AutoPtr hole(transformLinearRing(lr, geom)); if ( hole.get() == NULL || hole->isEmpty() ) { continue; } if ( ! dynamic_cast<LinearRing*>(hole.get()) ) { isAllValidLinearRings = false; } holes->push_back(hole.release()); } if ( isAllValidLinearRings) { Geometry* sh = shell.release(); assert(dynamic_cast<LinearRing*>(sh)); return Geometry::AutoPtr(factory->createPolygon( static_cast<LinearRing*>(sh), holes)); } else { // would like to use a manager constructor here vector<Geometry*>* components = new vector<Geometry*>(); if ( shell.get() != NULL ) { components->push_back(shell.release()); } components->insert(components->end(), holes->begin(), holes->end()); delete holes; // :( return Geometry::AutoPtr(factory->buildGeometry(components)); } }