geos::geom::Polygon* GeoJSONReader::getPolygon(Handle<Value> coords) { if (coords->IsArray()) { Handle<Array> array = Handle<Array>::Cast(coords); if (array->Length() == 0) throw "The number of the linear rings must be >= 1"; geos::geom::LinearRing* shell = getLinearRing(array->Get(0)); uint32_t length = array->Length(); std::vector<geos::geom::Geometry*>* holes = new std::vector<geos::geom::Geometry*>(); try { for (uint32_t i = 1; i < length; i++) { geos::geom::LinearRing* g = getLinearRing(array->Get(i)); holes->push_back(g); } } catch (...) { delete shell; unsigned size = holes->size(); for (unsigned int i = 0; i < size; i++) delete (*holes)[i]; delete holes; throw; } return geometryFactory->createPolygon(shell, holes); } return geometryFactory->createPolygon(); }
/*public*/ Polygon* EdgeRing::toPolygon(const GeometryFactory* geometryFactory) { testInvariant(); size_t nholes=holes.size(); vector<Geometry *> *holeLR=new vector<Geometry *>(nholes); for (size_t i=0; i<nholes; ++i) { Geometry *hole=holes[i]->getLinearRing()->clone(); (*holeLR)[i]=hole; } // We don't use "clone" here because // GeometryFactory::createPolygon really // wants a LinearRing // LinearRing *shellLR=new LinearRing(*(getLinearRing())); return geometryFactory->createPolygon(shellLR, holeLR); }