14 #include <geos/geom/Coordinate.h> 15 #include <geos/geom/CoordinateArraySequence.h> 16 #include <geos/geom/GeometryFactory.h> 17 #include <geos/geom/LinearRing.h> 18 #include <geos/opBuffer.h> 19 #include <geos/geom/Point.h> 20 #include <geos/geom/Polygon.h> 21 #include <geos/geom/MultiPolygon.h> 22 #include <geos/geom/PrecisionModel.h> 23 #include <geos/io/WKTReader.h> 24 #include <geos/io/WKTWriter.h> 25 #include <geos/util/GEOSException.h> 26 #include <geos/operation/valid/IsValidOp.h> 27 #include <geos/opBuffer.h> 37 geos::geom::GeometryFactory(new
geos::geom::PrecisionModel(
geos::geom::PrecisionModel::FLOATING),
80 static std::mutex globalFactoryMutex;
83 std::lock_guard<std::mutex> lock(globalFactoryMutex);
97 const ossimPolygon& exteriorRing,
const vector<ossimPolygon>& interiorRings)
101 geos::geom::CoordinateArraySequence *cas =
new geos::geom::CoordinateArraySequence();
103 const std::vector<ossimDpt>& pts = exteriorRing.
getVertexList();
106 int n = (int)pts.size();
111 for (idx = 0; idx <
n; idx++)
113 cas->add(geos::geom::Coordinate(pts[idx].
x, pts[idx].
y));
117 if((pts[0].
x != pts[
n-1].
x) || (pts[0].
y!=pts[
n-1].
y))
119 cas->add(geos::geom::Coordinate(pts[0].
x, pts[0].
y));
123 vector<geos::geom::Geometry*> *holes =
new vector<geos::geom::Geometry*>();
124 for (
ossim_uint32 interiorRingIdx = 0; interiorRingIdx < interiorRings.size(); ++interiorRingIdx)
126 geos::geom::CoordinateArraySequence *interiorCas =
127 new geos::geom::CoordinateArraySequence();
128 const std::vector<ossimDpt>& vertexPts = interiorRings[interiorRingIdx].getVertexList();
129 for(
ossim_uint32 vertexIndex=0; vertexIndex < vertexPts.size(); ++vertexIndex)
131 interiorCas->add(geos::geom::Coordinate(vertexPts[vertexIndex].
x,
132 vertexPts[vertexIndex].
y));
136 if((vertexPts[0].
x != vertexPts[vertexPts.size()-1].x) ||
137 (vertexPts[0].
y!=vertexPts[vertexPts.size()-1].y))
139 interiorCas->add(geos::geom::Coordinate(vertexPts[0].
x, vertexPts[0].
y));
142 geos::geom::LinearRing *hole =
geomFactory()->createLinearRing(interiorCas);
143 holes->push_back(hole);
146 geos::geom::LinearRing* shell =
geomFactory()->createLinearRing(cas);
159 std::vector<ossimPolygon>& polyList,
const geos::geom::Geometry* geom)
const 161 int nGeoms = (int)geom->getNumGeometries();
165 const geos::geom::Polygon* poly =
dynamic_cast<const geos::geom::Polygon*
> (geom);
169 const geos::geom::LineString* lineString =
dynamic_cast<const geos::geom::LineString*
> (poly->getExteriorRing());
172 int currentPolyIdx = (int)polyList.size();
173 int nPoints = (int)lineString->getNumPoints();
178 for (idx=0; idx<nPoints; idx++)
180 std::auto_ptr<const geos::geom::Point> point(lineString->getPointN(idx));
181 polyList[currentPolyIdx].addPoint(point->getX(), point->getY());
188 for (
int idx=0; idx < nGeoms; ++idx)
196 const geos::geom::Geometry* geom)
const 198 int nGeoms = (int)geom->getNumGeometries();
202 const geos::geom::Polygon* poly =
dynamic_cast<const geos::geom::Polygon*
> (geom);
209 for(idx = 0; idx < nInteriorRings; ++idx)
211 const geos::geom::LineString* lineString = poly->getInteriorRingN(idx);
214 int currentPolyIdx = (int)polyList.size();
215 int nPoints = (int)lineString->getNumPoints();
220 for (idx=0; idx<nPoints; idx++)
222 std::auto_ptr<const geos::geom::Point> point(lineString->getPointN(idx));
223 polyList[currentPolyIdx].addPoint(point->getX(), point->getY());
233 for (idx=0; idx < nGeoms; idx++)
241 const geos::geom::Geometry* geom)
const 243 int nGeoms = (int)geom->getNumGeometries();
246 const geos::geom::Polygon* poly =
dynamic_cast<const geos::geom::Polygon*
> (geom);
252 const geos::geom::LineString* lineString =
253 dynamic_cast<const geos::geom::LineString*
> (poly->getExteriorRing());
256 int nPoints = (int)lineString->getNumPoints();
257 for (
int idx = 0; idx<nPoints; idx++)
259 std::auto_ptr<const geos::geom::Point> point(lineString->getPointN(idx));
260 shell.
addPoint(point->getX(), point->getY());
265 std::size_t nInteriorRings = poly->getNumInteriorRing();
266 vector<ossimPolygon> holes(nInteriorRings);
267 for(std::size_t holeIdx = 0; holeIdx < nInteriorRings; ++holeIdx)
269 const geos::geom::LineString* lineString = poly->getInteriorRingN(holeIdx);
272 std::size_t nPoints = lineString->getNumPoints();
273 for (std::size_t idx = 0; idx<nPoints; ++idx)
275 std::auto_ptr<const geos::geom::Point> point(lineString->getPointN(idx));
276 holes[holeIdx].addPoint(point->getX(), point->getY());
287 for (idx=0; idx < nGeoms; idx++)
401 std::vector<ossimDpt> pts;
403 int n = (int)polygon.size();
404 for(idx = 0; idx <
n;++idx)
406 pts.push_back(polygon[idx]);
439 catch(
const std::exception& e )
442 <<
"ossimPolyArea2d::operator& Caught exception: " << e.what() << std::endl;
448 <<
"ossimPolyArea2d::operator& Caught exception!" << std::endl;
466 catch(
const std::exception& e )
469 <<
"ossimPolyArea2d::operator+ Caught exception: " << e.what() << std::endl;
475 <<
"ossimPolyArea2d::operator+ Caught exception!" << std::endl;
492 catch(
const std::exception& e )
495 <<
"ossimPolyArea2d::operator- Caught exception: " << e.what() << std::endl;
501 <<
"ossimPolyArea2d::operator- Caught exception!" << std::endl;
518 catch(
const std::exception& e )
521 <<
"ossimPolyArea2d::operator&= Caught exception: " << e.what() << std::endl;
527 <<
"ossimPolyArea2d::operator&= Caught exception!" << std::endl;
543 catch(
const std::exception& e )
546 <<
"ossimPolyArea2d::operator+= Caught exception: " << e.what() << std::endl;
552 <<
"ossimPolyArea2d::operator+= Caught exception!" << std::endl;
568 catch(
const std::exception& e )
571 <<
"ossimPolyArea2d::operator-= Caught exception: " << e.what() << std::endl;
577 <<
"ossimPolyArea2d::operator-= Caught exception!" << std::endl;
607 bool foundPolys =
false;
612 foundPolys = (sizeBefore != polyList.size());
620 bool foundPolys =
false;
625 foundPolys = (sizeBefore != polyList.size());
633 bool foundPolys =
false;
637 foundPolys = (sizeBefore != polyList.size());
659 if(displayValidationError)
662 geos::operation::valid::TopologyValidationError*
663 topologyValidationError(validityCheck.getValidationError());
665 if(topologyValidationError == 0)
672 <<
"ossimPolyArea2d::isValid: " << topologyValidationError->toString() << std::endl;
695 geos::geom::Coordinate c(
x,
y);
714 rect =
ossimDrect(envelope->getMinX(), envelope->getMinY(), envelope->getMaxX(), envelope->getMaxY());
720 std::string result =
"";
735 }
catch(
const std::exception& e ){
737 <<
"ossimPolyArea2d::getBufferedShape Caught exception: " << e.what() << std::endl;
741 <<
"ossimPolyArea2d::getBufferedShape Caught exception!" << std::endl;
751 }
catch(
const std::exception& e ){
753 <<
"ossimPolyArea2d::getBufferedShape Caught exception: " << e.what() << std::endl;
756 <<
"ossimPolyArea2d::getBufferedShape Caught exception!" << std::endl;
770 case geos::geom::GEOS_POLYGON:
772 std::vector<geos::geom::Geometry*> values;
778 case geos::geom::GEOS_MULTIPOLYGON:
787 <<
"ossimPolyArea2d::toMultiPolygon Geometry type can not be converted to a multi polygon: " <<
m_privateData->
m_geometry->getGeometryType()<< std::endl;
794 catch(
const std::exception& e)
797 <<
"ossimPolyArea2d::toMultiPolygon Caught exception: " << e.what() << std::endl;
802 <<
"ossimPolyArea2d::toMultiPolygon Caught exception!" << std::endl;
809 const char* prefix)
const 818 geos::io::WKTWriter writer;
847 catch(
const std::exception& e )
850 <<
"ossimPolyArea2d::loadState Caught exception: " << e.what() << std::endl;
856 <<
"ossimPolyArea2d::loadState Caught exception!" << std::endl;
bool isPointWithin(const ossimDpt &point) const
ossimPolyArea2d operator+(const ossimPolyArea2d &rhs) const
std::ostream & operator<<(std::ostream &out, const ossimPolyArea2d &rhs)
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimPolyArea2d operator&(const ossimPolyArea2d &rhs) const
void getBoundingRect(ossimDrect &rect)
ossimPolyArea2d getBufferedShape(double distance=FLT_EPSILON) const
Buffers the ossimPolyArea2d shape and returns a copy.
ossimPolyArea2d operator-(const ossimPolyArea2d &rhs) const
Represents serializable keyword/value map.
const ossimPolyArea2d & operator-=(const ossimPolyArea2d &rhs)
bool isValid(bool displayValidationError=false) const
const char * find(const char *key) const
ossimReferenced allows for shared object ref counting if the reference count ever gets to 0 or less i...
void addPoint(const ossimDpt &pt)
const geos::geom::Geometry * ConstGeometryPtr
void recurseVisibleGeometries(ossimPolygon::Vector &polyList, const geos::geom::Geometry *geom) const
std::string toString() const
Returns the Well Known Text string.
bool intersects(const ossimPolyArea2d &rhs) const
MyGeomFactory * m_geomFactory
OssimPolyArea2dPrivate * m_privateData
void recurseCompleteGeometries(std::vector< ossimPolyArea2d > &polyList, const geos::geom::Geometry *geom) const
Recurses over the Geometry object to load all complete polygons (a shell and any internal holes) into...
void setGeometry(const ossimPolygon &polygon, const vector< ossimPolygon > &holes=vector< ossimPolygon >())
void setGeometry(GeometryPtr geom)
static const char * TYPE_KW
bool getCompletePolygons(vector< ossimPolyArea2d > &polyList) const
Gets all of the polygons stored with their holes embedded.
geos::geom::Geometry * GeometryPtr
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossimPolyArea2d & toMultiPolygon()
const ossimPolyArea2d & operator&=(const ossimPolyArea2d &rhs)
os2<< "> n<< " > nendobj n
unsigned int ossim_uint32
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
static ossimRefPtr< ossimGeometryFactoryWrapper > m_globalFactory
void add(const ossimPolyArea2d &rhs)
const vector< ossimDpt > & getVertexList() const
bool getPolygonHoles(vector< ossimPolygon > &polyList) const
ossimGeometryFactoryWrapper()
const ossimPolyArea2d & operator=(const ossimPolyArea2d &rhs)
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
ossimPolyArea2d & setToBufferedShape(double distance=FLT_EPSILON)
~OssimPolyArea2dPrivate()
const ossimPolyArea2d & operator+=(const ossimPolyArea2d &rhs)
float distance(double lat1, double lon1, double lat2, double lon2, int units)
bool getVisiblePolygons(vector< ossimPolygon > &polyList) const
geos::geom::GeometryFactory * geomFactory()
void recurseHoles(ossimPolygon::Vector &polyList, const geos::geom::Geometry *geom) const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
virtual ~ossimGeometryFactoryWrapper()
OssimPolyArea2dPrivate(GeometryPtr geom=0)