Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Dec 2019 17:16:20 +0000 (UTC)
From:      Sunpoet Po-Chuan Hsieh <sunpoet@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r519760 - head/graphics/ossim/files
Message-ID:  <201912101716.xBAHGKWj008893@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sunpoet
Date: Tue Dec 10 17:16:20 2019
New Revision: 519760
URL: https://svnweb.freebsd.org/changeset/ports/519760

Log:
  Fix build with geos 3.8.0
  
  Obtained from:	https://github.com/ossimlabs/ossim/commit/c456397821cf369af4d9ff1fb60a5dfd1bcefc24
  		https://github.com/ossimlabs/ossim/commit/0498f71e811ff3068ba491929c09aa5137ea0cca
  		https://github.com/ossimlabs/ossim/commit/c0d97536f9ac967941b6ca48a6a7a4dde44f4ee3

Added:
  head/graphics/ossim/files/
  head/graphics/ossim/files/patch-include-ossim-base-ossimPolyArea2d.h   (contents, props changed)
  head/graphics/ossim/files/patch-src-base-ossimPolyArea2d.cpp   (contents, props changed)
  head/graphics/ossim/files/patch-src-imaging-ossimImageGeometry.cpp   (contents, props changed)
  head/graphics/ossim/files/patch-src-init-ossimInit.cpp   (contents, props changed)

Added: head/graphics/ossim/files/patch-include-ossim-base-ossimPolyArea2d.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/graphics/ossim/files/patch-include-ossim-base-ossimPolyArea2d.h	Tue Dec 10 17:16:20 2019	(r519760)
@@ -0,0 +1,207 @@
+Obtained from:	https://github.com/ossimlabs/ossim/commit/c456397821cf369af4d9ff1fb60a5dfd1bcefc24
+
+--- include/ossim/base/ossimPolyArea2d.h.orig	2019-10-17 21:54:21 UTC
++++ include/ossim/base/ossimPolyArea2d.h
+@@ -5,10 +5,8 @@
+ // Author: Garrett Potts
+ //*******************************************************************
+ //$Id: ossimPolyArea2d.h 23608 2015-10-28 13:51:35Z gpotts $
+-
+ #ifndef ossimPolyArea2d_HEADER
+ #define ossimPolyArea2d_HEADER 1
+-
+ #include <ossim/base/ossimDpt.h>
+ #include <ossim/base/ossimGpt.h>
+ #include <ossim/base/ossimKeywordlist.h>
+@@ -16,137 +14,76 @@
+ #include <ossim/base/ossimReferenced.h>
+ #include <vector>
+ 
+-class ossimDrect;
+-class ossimIrect;
+-class OssimPolyArea2dPrivate;
+-
+-namespace geos
+-{
+-   namespace geom
+-   {
+-      class Geometry;
+-   }
+-}
++class ossimPolyArea2dPrivate;
+ 
+-class OSSIM_DLL ossimPolyArea2d : public ossimReferenced
++class OSSIM_DLL ossimPolyArea2d
+ {
+ public:
+-   friend class OssimPolyArea2dPrivate;
+-   friend OSSIM_DLL std::ostream& operator <<(std::ostream& out, const ossimPolyArea2d& data);
+-   
++   friend OSSIM_DLL std::ostream &operator<<(std::ostream &out, const ossimPolyArea2d &data);
++   friend class ossimPolyArea2dPrivate;
+    ossimPolyArea2d();
+-   ossimPolyArea2d(const std::vector<ossimGpt>& polygon);
+-   ossimPolyArea2d(const std::vector<ossimDpt>& polygon);
+-   ossimPolyArea2d(const ossimPolygon& shell, const std::vector<ossimPolygon>& holes);
+-   
+-   ossimPolyArea2d(const ossimDpt& p1,
+-                   const ossimDpt& p2,
+-                   const ossimDpt& p3,
+-                   const ossimDpt& p4);
+-   ossimPolyArea2d(const ossimPolyArea2d& rhs);
+-   
+-   ossimPolyArea2d(const ossimIrect& rect);
+-   ossimPolyArea2d(const ossimDrect& rect);
+-   ossimPolyArea2d(const ossimPolygon& polygon);
++   ossimPolyArea2d(const std::vector<ossimGpt> &polygon);
++   ossimPolyArea2d(const std::vector<ossimDpt> &polygon);
++   ossimPolyArea2d(const ossimPolygon &shell, const std::vector<ossimPolygon> &holes);
++
++   ossimPolyArea2d(const ossimDpt &p1,
++                   const ossimDpt &p2,
++                   const ossimDpt &p3,
++                   const ossimDpt &p4);
++   ossimPolyArea2d(const ossimPolyArea2d &rhs);
++
++   ossimPolyArea2d(const ossimIrect &rect);
++   ossimPolyArea2d(const ossimDrect &rect);
++   ossimPolyArea2d(const ossimPolygon &polygon);
+    ~ossimPolyArea2d();
+-   
++
+    void clear()
+    {
+       clearPolygons();
+    }
+-   const ossimPolyArea2d& operator =(const ossimPolyArea2d& rhs);
+-   const ossimPolyArea2d& operator =(const ossimPolygon& rhs);
+-   const ossimPolyArea2d& operator =(const ossimIrect& rect);
+-   const ossimPolyArea2d& operator =(const ossimDrect& rect);
+-   const ossimPolyArea2d& operator =(const std::vector<ossimGpt>& polygon);
+-   const ossimPolyArea2d& operator =(const std::vector<ossimDpt>& polygon);
+-   const ossimPolyArea2d& operator &=(const ossimPolyArea2d& rhs);
+-   ossimPolyArea2d operator &(const ossimPolyArea2d& rhs)const;
+-   ossimPolyArea2d operator +(const ossimPolyArea2d& rhs)const;
+-   const ossimPolyArea2d& operator +=(const ossimPolyArea2d& rhs);
+-   ossimPolyArea2d operator -(const ossimPolyArea2d& rhs)const;
+-   const ossimPolyArea2d& operator -=(const ossimPolyArea2d& rhs);
+-   
+-   bool intersects(const ossimPolyArea2d& rhs)const;
+-   
+-   void add(const ossimPolyArea2d& rhs);
+-   bool getVisiblePolygons(std::vector<ossimPolygon>& polyList)const;
+-   bool getPolygonHoles(std::vector<ossimPolygon>& polyList)const;
+-   
+-   /**
+-    * @brief Gets all of the polygons stored with their holes embedded. This
+-    * may be useful if an operation was performed on the original ossimPolyArea2d 
+-    * that caused multiple polygons to be created internally.
+-    *	 
+-    * For example, if a rectangle is intersected with a U shape, the two top
+-    * portions of the U would be their own separate polygon. It's also possible 
+-    * for these polygons to contain their own holes. This function will return 
+-    * the two top polygons as separate ossimPolyArea2d objects (with any of 
+-    * their holes embedded inside them).
+-    *
+-    *  --------------------------------		 
+-    * |                                |
+-    * |                                |
+-    * | ........           .........   |
+-    * | .      .           .       .   |
+-    *  -.------.-----------.-------.---
+-    *   .      .           .       .
+-    *   .      .............       .
+-    *   .                          .
+-    *   ............................
+-    *   
+-    * @param polylist an empty vector of ossimPolyArea2d that will be filled
+-    * @return returns true if it successfully places polygons in the input vector
+-    */
+-   bool getCompletePolygons(std::vector<ossimPolyArea2d>& polyList)const;
+-   
+-   bool isEmpty()const;
+-   bool isValid(bool displayValidationError = false)const;
+-   bool isPointWithin(const ossimDpt& point)const;
+-   bool isPointWithin(double x, double y)const;
+-   void getBoundingRect(ossimDrect& rect);
+-   
++   const ossimPolyArea2d &operator=(const ossimPolyArea2d &rhs);
++   const ossimPolyArea2d &operator=(const ossimPolygon &rhs);
++   const ossimPolyArea2d &operator=(const ossimIrect &rect);
++   const ossimPolyArea2d &operator=(const ossimDrect &rect);
++   const ossimPolyArea2d &operator=(const std::vector<ossimGpt> &polygon);
++   const ossimPolyArea2d &operator=(const std::vector<ossimDpt> &polygon);
++   const ossimPolyArea2d &operator&=(const ossimPolyArea2d &rhs);
++   ossimPolyArea2d operator&(const ossimPolyArea2d &rhs) const;
++   ossimPolyArea2d operator+(const ossimPolyArea2d &rhs) const;
++   const ossimPolyArea2d &operator+=(const ossimPolyArea2d &rhs);
++   ossimPolyArea2d operator-(const ossimPolyArea2d &rhs) const;
++   const ossimPolyArea2d &operator-=(const ossimPolyArea2d &rhs);
++
++   ossim_float64 getArea()const;
++   bool isEmpty() const;
++   void makeValid();
++   bool isValid(bool displayValidationError = false) const;
++   bool isPointWithin(const ossimDpt &point) const;
++   bool isPointWithin(double x, double y) const;
++   void getBoundingRect(ossimDrect &rect) const;
++
++   bool intersects(const ossimPolyArea2d &rhs) const;
++   void add(const ossimPolyArea2d &rhs);
++   bool getVisiblePolygons(std::vector<ossimPolygon> &polyList) const;
++   bool getPolygonHoles(std::vector<ossimPolygon> &polyList) const;
++
++   ossimPolyArea2d &toMultiPolygon();
++
+    /**
+    * Returns the Well Known Text string
+    */
+-   std::string toString()const;
++   std::string toString() const;
++   bool setFromWkt(const std::string &s);
+ 
+-   /**
+-    * @brief Buffers the ossimPolyArea2d shape and returns a copy. This method
+-    * does not alter polygon.
+-    *  
+-    * @param distance is the distance to buffer the shape by. Positive values
+-    * will expand the shape, and negative values will shrink the shape.
+-    * @return A shape that is a buffered (expanded/contracted) version of this
+-    * shape
+-    */
+-   ossimPolyArea2d getBufferedShape(double distance=FLT_EPSILON) const;
+-   
+-   ossimPolyArea2d& setToBufferedShape(double distance=FLT_EPSILON);
++   bool saveState(ossimKeywordlist &kwl,
++                  const char *prefix = 0) const;
++   bool loadState(const ossimKeywordlist &kwl,
++                  const char *prefix = 0);
+ 
+-   ossimPolyArea2d& toMultiPolygon();
+-   bool saveState(ossimKeywordlist& kwl,
+-                  const char* prefix=0)const;
+-   bool loadState(const ossimKeywordlist& kwl,
+-                  const char* prefix=0);
+-   
+ protected:
+-   
++   ossimPolyArea2dPrivate *m_privateData;
++
+    void clearPolygons();
+-   void recurseVisibleGeometries(ossimPolygon::Vector& polyList,
+-                                 const geos::geom::Geometry* geom) const;
+-   
+-   void recurseHoles(ossimPolygon::Vector& polyList,
+-                     const geos::geom::Geometry* geom) const;
+-   
+-   /**
+-    * @brief Recurses over the Geometry object to load all complete polygons
+-    * (a shell and any internal holes) into the ossimPolyArea2d.
+-    */
+-   void recurseCompleteGeometries(std::vector<ossimPolyArea2d>& polyList,
+-                                  const geos::geom::Geometry* geom) const;
+-   
+-   OssimPolyArea2dPrivate* m_privateData;
+ };
+ 
+ #endif /* #ifndef ossimPolyArea2d_HEADER */

Added: head/graphics/ossim/files/patch-src-base-ossimPolyArea2d.cpp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/graphics/ossim/files/patch-src-base-ossimPolyArea2d.cpp	Tue Dec 10 17:16:20 2019	(r519760)
@@ -0,0 +1,1336 @@
+Obtained from:	https://github.com/ossimlabs/ossim/commit/c456397821cf369af4d9ff1fb60a5dfd1bcefc24
+		https://github.com/ossimlabs/ossim/commit/c0d97536f9ac967941b6ca48a6a7a4dde44f4ee3
+
+--- src/base/ossimPolyArea2d.cpp.orig	2019-10-17 21:54:21 UTC
++++ src/base/ossimPolyArea2d.cpp
+@@ -3,153 +3,169 @@
+ //
+ // $Id: ossimPolyArea2d.cpp 23623 2015-11-13 18:24:28Z gpotts $
+ //---
+-
+ #include <ossim/base/ossimPolyArea2d.h>
+-#include <ossim/base/ossimDrect.h>
+-#include <ossim/base/ossimIrect.h>
++#include <ossim/base/ossimReferenced.h>
++#include <ossim/base/ossimPolygon.h>
++#include <ossim/base/ossimNotifyContext.h>
++#include <ossim/base/ossimKeywordlist.h>
+ #include <ossim/base/ossimKeywordNames.h>
+-#include <ossim/base/ossimNotify.h>
+-#include <ossim/base/ossimRefPtr.h>
+-#include <ossim/base/ossimString.h>
+-#include <geos/geom/Coordinate.h>
+-#include <geos/geom/CoordinateArraySequence.h>
+-#include <geos/geom/GeometryFactory.h>
+-#include <geos/geom/LinearRing.h>
+-#include <geos/opBuffer.h>
+-#include <geos/geom/Point.h>
+-#include <geos/geom/Polygon.h>
+-#include <geos/geom/MultiPolygon.h>
+-#include <geos/geom/PrecisionModel.h>
+-#include <geos/io/WKTReader.h>
+-#include <geos/io/WKTWriter.h>
+-#include <geos/util/GEOSException.h>
+-#include <geos/operation/valid/IsValidOp.h>
+-#include <geos/opBuffer.h>
+-#include <cstdlib>
+-#include <exception>
+-#include <memory>
+ #include <vector>
+-#include <mutex>
+-
+-using namespace std;
++#include <cstdio>
++#include <cstdarg>
++#include <geos_c.h>
+ 
+-class MyGeomFactory : public geos::geom::GeometryFactory
++class ossimPolyArea2dPrivate
+ {
+ public:
+-   MyGeomFactory():
+-   geos::geom::GeometryFactory(new geos::geom::PrecisionModel(geos::geom::PrecisionModel::FLOATING),
+-                             -1)
++   typedef GEOSGeometry *GEOSGeometryPtr;
++   typedef const GEOSGeometry *ConstGEOSGeometryPtr;
++   ossimPolyArea2dPrivate() : m_geometry(GEOSGeom_createEmptyPolygon()) {}
++   virtual ~ossimPolyArea2dPrivate() { deleteGeometry(); }
++   void deleteGeometry()
+    {
++      if (m_geometry)
++         GEOSGeom_destroy(m_geometry);
++      m_geometry = 0;
++   }
+ 
++   void setGeometry(GEOSGeometryPtr geom)
++   {
++      if(geom != m_geometry)
++      {
++         deleteGeometry();
++         m_geometry = geom;
++      }
+    }
+-}; 
+-class ossimGeometryFactoryWrapper : public ossimReferenced
+-{
+-public:
+-   ossimGeometryFactoryWrapper()
+-      : m_geomFactory(0)
++   void setGeometry(const ossimPolygon &polygon, const std::vector<ossimPolygon> &holes = std::vector<ossimPolygon>());
++
++   void ringToPoints(const ConstGEOSGeometryPtr geom, std::vector<ossimDpt> &points) const;
++   void recurseVisibleGeometries(ossimPolygon::Vector &polyList) const
+    {
+-      //geos::geom::PrecisionModel *pm =
+-      //   new geos::geom::PrecisionModel(geos::geom::PrecisionModel::FLOATING);
+-      m_geomFactory = new MyGeomFactory();//new geos::geom::GeometryFactory(pm, -1); 
++      recurseVisibleGeometries(m_geometry, polyList);
+    }
+-   virtual ~ossimGeometryFactoryWrapper(){if(m_geomFactory) delete m_geomFactory;m_geomFactory=0;}
+-   
+-   MyGeomFactory* m_geomFactory;
+-};
+ 
+-class OssimPolyArea2dPrivate
+-{
+-public:
+-   typedef geos::geom::Geometry* GeometryPtr;
+-   typedef const geos::geom::Geometry* ConstGeometryPtr;
+-   
+-   OssimPolyArea2dPrivate(GeometryPtr geom=0);
+-   ~OssimPolyArea2dPrivate();
+-   
+-   void deleteGeometry() { if(m_geometry) { delete m_geometry; m_geometry = 0; }}
+-   void setGeometry(const ossimPolygon& polygon, const vector<ossimPolygon>& holes = vector<ossimPolygon>());
+-   void setGeometry(GeometryPtr geom){deleteGeometry();m_geometry=geom;}
+-   geos::geom::GeometryFactory* geomFactory(){{return m_globalFactory.valid()?m_globalFactory->m_geomFactory:0;}}
+-   GeometryPtr m_geometry;
+-   static ossimRefPtr<ossimGeometryFactoryWrapper> m_globalFactory; 
+-};
++   void recurseVisibleGeometries(ConstGEOSGeometryPtr geom,
++                                 ossimPolygon::Vector &polygons) const;
+ 
+-ossimRefPtr<ossimGeometryFactoryWrapper> OssimPolyArea2dPrivate::m_globalFactory;
++   void getVisiblePolygons(ConstGEOSGeometryPtr geom,
++                           ossimPolygon::Vector &polygons) const;
+ 
+-OssimPolyArea2dPrivate::OssimPolyArea2dPrivate(GeometryPtr geom)
+-:m_geometry(geom)
+-{
+-   static std::mutex globalFactoryMutex;
+-   
++   bool getVisiblePolygons(ossimPolygon::Vector &polygons) const;
++
++   void getHoles(ConstGEOSGeometryPtr geom,
++                 ossimPolygon::Vector &polygons) const;
++   bool getPolygonHoles(ossimPolygon::Vector &polygons) const;
++   bool getPolygonHoles(ConstGEOSGeometryPtr geom,
++                        ossimPolygon::Vector &polygons) const;
++   void recurseGeometryHoles(ConstGEOSGeometryPtr geom,
++                             ossimPolygon::Vector &polygons) const;
++   void getBoundingRect(ossimDrect &bounds) const
+    {
+-      std::lock_guard<std::mutex> lock(globalFactoryMutex);
+-      if(!m_globalFactory.valid())
++      bounds.makeNan();
++      if (!isEmpty())
+       {
+-         m_globalFactory = new ossimGeometryFactoryWrapper();
+-      }    
++         GEOSGeometry *geom = GEOSEnvelope(m_geometry);
++
++         if (geom)
++         {
++            ossimPolygon::Vector polys;
++            getVisiblePolygons(geom, polys);
++            for (ossim_int32 idx = 0; idx < polys.size(); ++idx)
++            {
++               if (bounds.isNan())
++               {
++                  polys[idx].getBoundingRect(bounds);
++               }
++               else
++               {
++                  ossimDrect tempRect;
++                  polys[idx].getBoundingRect(tempRect);
++                  bounds = bounds.combine(tempRect);
++               }
++            }
++            GEOSGeom_destroy(geom);
++            geom = 0;
++         }
++      }
+    }
+-}
++   std::string toString() const;
++   bool setFromWkt(const std::string &s);
+ 
+-OssimPolyArea2dPrivate::~OssimPolyArea2dPrivate()
+-{
+-   deleteGeometry();
+-}
++   bool isEmpty() const;
++   bool isValid(bool displayValidationError = false) const;
++   bool isPointWithin(const ossimDpt &pt) const;
++   GEOSGeometryPtr m_geometry;
++};
+ 
+-void OssimPolyArea2dPrivate::setGeometry(
+-   const ossimPolygon& exteriorRing, const vector<ossimPolygon>& interiorRings)
++void ossimPolyArea2dPrivate::setGeometry(const ossimPolygon &exteriorRing,
++                                         const std::vector<ossimPolygon> &interiorRings)
+ {
++
+    deleteGeometry();
+-   
+-   geos::geom::CoordinateArraySequence *cas = new geos::geom::CoordinateArraySequence();
+-   
+-   const std::vector<ossimDpt>& pts = exteriorRing.getVertexList();
+ 
+-   int idx = 0;
+-   int n = (int)pts.size();
+-   
+-   if(n > 0)
++   if (exteriorRing.getNumberOfVertices() < 1)
++      return;
++   GEOSGeometryPtr shell = 0;
++   std::vector<GEOSGeometryPtr> holes;
++   const std::vector<ossimDpt> &pts = exteriorRing.getVertexList();
++   ossim_int32 idx = 0;
++   ossim_int32 n = (int)pts.size();
++
++   bool firstAndLastSame = ((pts[0].x == pts[n - 1].x) && (pts[0].y == pts[n - 1].y));
++   if (n > 0)
+    {
++      GEOSCoordSequence *shellSeq = GEOSCoordSeq_create(
++          n + ((firstAndLastSame) ? 0 : 1), 2);
++
+       //fill the exterior ring
+       for (idx = 0; idx < n; idx++)
+       {
+-         cas->add(geos::geom::Coordinate(pts[idx].x, pts[idx].y));
++         GEOSCoordSeq_setXY(shellSeq, idx, pts[idx].x, pts[idx].y);
+       }
+-      
+       //if the original polygon didn't have the first and last point the same, make it so
+-      if((pts[0].x != pts[n-1].x) || (pts[0].y!=pts[n-1].y))
++      if (!firstAndLastSame)
+       {
+-         cas->add(geos::geom::Coordinate(pts[0].x, pts[0].y));
++         GEOSCoordSeq_setXY(shellSeq, n, pts[0].x, pts[0].y);
+       }
+-      
++      shell = GEOSGeom_createLinearRing(shellSeq);
+       //fill the interior rings
+-      vector<geos::geom::Geometry*> *holes = new vector<geos::geom::Geometry*>();
+-      for (ossim_uint32 interiorRingIdx = 0; interiorRingIdx < interiorRings.size(); ++interiorRingIdx)
++      if (!interiorRings.empty())
+       {
+-         geos::geom::CoordinateArraySequence *interiorCas =
+-            new geos::geom::CoordinateArraySequence();
+-         const std::vector<ossimDpt>& vertexPts = interiorRings[interiorRingIdx].getVertexList();
+-         for(ossim_uint32 vertexIndex=0; vertexIndex < vertexPts.size(); ++vertexIndex)
+-         {
+-            interiorCas->add(geos::geom::Coordinate(vertexPts[vertexIndex].x,
+-                                                    vertexPts[vertexIndex].y));
+-         }
+-         
+-         //if the original polygon didn't have the first and last point the same, make it so
+-         if((vertexPts[0].x != vertexPts[vertexPts.size()-1].x) ||
+-            (vertexPts[0].y!=vertexPts[vertexPts.size()-1].y))
++         for (ossim_uint32 interiorRingIdx = 0; interiorRingIdx < interiorRings.size(); ++interiorRingIdx)
+          {
+-            interiorCas->add(geos::geom::Coordinate(vertexPts[0].x, vertexPts[0].y));
++            if (interiorRings[interiorRingIdx].getNumberOfVertices() > 0)
++            {
++               const std::vector<ossimDpt> &vertexPts = interiorRings[interiorRingIdx].getVertexList();
++               firstAndLastSame = ((vertexPts[0].x == vertexPts[n - 1].x) && (vertexPts[0].y == vertexPts[n - 1].y));
++
++               GEOSCoordSequence *ring = GEOSCoordSeq_create(
++                   vertexPts.size() + ((firstAndLastSame) ? 0 : 1), 2);
++               for (ossim_uint32 vertexIndex = 0; vertexIndex < vertexPts.size(); ++vertexIndex)
++               {
++                  GEOSCoordSeq_setXY(ring, vertexIndex, vertexPts[vertexIndex].x, vertexPts[vertexIndex].y);
++               }
++
++               //if the original polygon didn't have the first and last point the same, make it so
++               if (!firstAndLastSame)
++               {
++                  GEOSCoordSeq_setXY(ring, vertexPts.size(), vertexPts[0].x, vertexPts[0].y);
++               }
++               GEOSGeometryPtr hole = GEOSGeom_createLinearRing(ring);
++               holes.push_back(hole);
++            }
+          }
+-         
+-         geos::geom::LinearRing *hole = geomFactory()->createLinearRing(interiorCas);
+-         holes->push_back(hole);
+       }
+-      
+-      geos::geom::LinearRing* shell = geomFactory()->createLinearRing(cas);
+-      if ( shell )
++
++      if (shell)
+       {
+-         m_geometry = geomFactory()->createPolygon(shell, holes);
++         if (holes.size())
++         {
++            m_geometry = GEOSGeom_createPolygon(shell, &holes.front(), holes.size());
++         }
++         else
++         {
++            m_geometry = GEOSGeom_createPolygon(shell, 0, 0);
++         }
+       }
+       else
+       {
+@@ -158,708 +174,540 @@ void OssimPolyArea2dPrivate::setGeometry
+    }
+ }
+ 
+-void ossimPolyArea2d::recurseVisibleGeometries(
+-   std::vector<ossimPolygon>& polyList, const geos::geom::Geometry* geom) const
++void ossimPolyArea2dPrivate::ringToPoints(const ConstGEOSGeometryPtr geom, std::vector<ossimDpt> &points) const
+ {
+-   int nGeoms = (int)geom->getNumGeometries();
+-   
+-   if(nGeoms < 2 )
++   double x, y;
++   if (!geom)
++      return;
++   ossim_int32 nPoints = GEOSGetNumCoordinates(geom);
++   if (nPoints > 0)
+    {
+-      const geos::geom::Polygon* poly = dynamic_cast<const geos::geom::Polygon*> (geom);
+-      
+-      if (poly)
++      const GEOSCoordSequence *seq = GEOSGeom_getCoordSeq(geom);
++      ossim_int32 i = 0;
++      for (i = 0; i < nPoints; i++)
+       {
+-         const geos::geom::LineString* lineString = dynamic_cast<const geos::geom::LineString*> (poly->getExteriorRing());
+-         if (lineString)
+-         {
+-            int currentPolyIdx = (int)polyList.size();
+-            int nPoints = (int)lineString->getNumPoints();
+-            int idx = 0;
+-            
+-            polyList.push_back(ossimPolygon());
+-            
+-            for (idx=0; idx<nPoints; idx++)
+-            {
+-               std::unique_ptr<const geos::geom::Point> point(lineString->getPointN(idx));
+-               polyList[currentPolyIdx].addPoint(point->getX(), point->getY());
+-            }
+-         }
++         GEOSCoordSeq_getX(seq, i, &x);
++         GEOSCoordSeq_getY(seq, i, &y);
++         points.push_back(ossimDpt(x, y));
+       }
+    }
+-   else
++}
++
++void ossimPolyArea2dPrivate::getHoles(ConstGEOSGeometryPtr geom,
++                                      ossimPolygon::Vector &polygons) const
++{
++   int geomType = GEOSGeomTypeId(geom);
++   std::vector<ossimDpt> points;
++   switch (geomType)
+    {
+-      for (int idx=0; idx < nGeoms; ++idx)
+-      {
+-         recurseVisibleGeometries(polyList, geom->getGeometryN(idx));
+-      }
++   case GEOS_LINESTRING:
++   case GEOS_LINEARRING:
++   {
++      ringToPoints(geom, points);
++      polygons.push_back(ossimPolygon(points));
++      break;
++   }
+    }
+ }
+ 
+-void ossimPolyArea2d::recurseHoles(std::vector<ossimPolygon>& polyList,
+-                                   const geos::geom::Geometry* geom) const
++void ossimPolyArea2dPrivate::getVisiblePolygons(ConstGEOSGeometryPtr geom,
++                                                ossimPolygon::Vector &polygons) const
+ {
+-   int nGeoms = (int)geom->getNumGeometries();
+-   
+-   if(nGeoms < 2 )
++   int geomType = GEOSGeomTypeId(geom);
++   std::vector<ossimDpt> points;
++
++   switch (geomType)
+    {
+-      const geos::geom::Polygon* poly = dynamic_cast<const geos::geom::Polygon*> (geom);
++   case GEOS_LINESTRING:
++   case GEOS_LINEARRING:
++   {
++      ringToPoints(geom, points);
++      polygons.push_back(ossimPolygon(points));
++      break;
++   }
++   case GEOS_POLYGON:
++   {
++      ConstGEOSGeometryPtr geom2 = GEOSGetExteriorRing(geom);
++      ringToPoints(geom2, points);
++      polygons.push_back(ossimPolygon(points));
+ 
+-      if (poly)
++      break;
++   }
++   }
++}
++void ossimPolyArea2dPrivate::recurseVisibleGeometries(ConstGEOSGeometryPtr geom,
++                                                      ossimPolygon::Vector &polygons) const
++{
++   ossim_int32 nGeoms = GEOSGetNumGeometries(geom);
++   ConstGEOSGeometryPtr geomPtr = 0;
++   if (nGeoms < 2)
++   {
++      geomPtr = GEOSGetGeometryN(geom, 0);
++      if (geomPtr)
+       {
+-         ossim_uint32 nInteriorRings = (ossim_uint32)poly->getNumInteriorRing();
+-         ossim_uint32 idx = 0;
+-         
+-         for(idx = 0; idx < nInteriorRings; ++idx)
+-         {
+-            const geos::geom::LineString* lineString = poly->getInteriorRingN(idx);
+-            if (lineString)
+-            {
+-               int currentPolyIdx = (int)polyList.size();
+-               int nPoints = (int)lineString->getNumPoints();
+-               int idx = 0;
+-
+-               polyList.push_back(ossimPolygon());
+-
+-               for (idx=0; idx<nPoints; idx++)
+-               {
+-                  std::unique_ptr<const geos::geom::Point> point(lineString->getPointN(idx));
+-                  polyList[currentPolyIdx].addPoint(point->getX(), point->getY());
+-               }
+-            }
+-         }
++         getVisiblePolygons(geomPtr, polygons);
+       }
+    }
+    else
+    {
+-      int idx = 0;
+-      
+-      for (idx=0; idx < nGeoms; idx++)
++      for (int idx = 0; idx < nGeoms; ++idx)
+       {
+-         recurseHoles(polyList, geom->getGeometryN(idx));
++         geomPtr = GEOSGetGeometryN(geom, idx);
++         recurseVisibleGeometries(geomPtr, polygons);
+       }
+    }
+ }
+ 
+-void ossimPolyArea2d::recurseCompleteGeometries(std::vector<ossimPolyArea2d>& polyList,
+-                                                const geos::geom::Geometry* geom) const
++void ossimPolyArea2dPrivate::recurseGeometryHoles(ConstGEOSGeometryPtr geom,
++                                                  ossimPolygon::Vector &polygons) const
+ {
+-   int nGeoms = (int)geom->getNumGeometries();
+-   if(nGeoms < 2 )
++   ossim_int32 nGeoms = GEOSGetNumGeometries(geom);
++   ConstGEOSGeometryPtr geomPtr = 0;
++   if (nGeoms < 2)
+    {
+-      const geos::geom::Polygon* poly = dynamic_cast<const geos::geom::Polygon*> (geom);
++      ossim_int32 nInteriorRings = GEOSGetNumInteriorRings(geom);
++      ossim_int32 idx = 0;
+ 
+-      if (poly)
++      for (idx = 0; idx < nInteriorRings; ++idx)
+       {
+-         //get exterior shell for the geometry
+-         ossimPolygon shell;
+-         const geos::geom::LineString* lineString =
+-            dynamic_cast<const geos::geom::LineString*> (poly->getExteriorRing());
+-         if (lineString)
+-         {
+-            int nPoints = (int)lineString->getNumPoints();
+-            for (int idx = 0; idx<nPoints; idx++)
+-            {
+-               std::unique_ptr<const geos::geom::Point> point(lineString->getPointN(idx));
+-               shell.addPoint(point->getX(), point->getY());
+-            }
+-         }
+-         
+-         // Get interior rings for the geometry.
+-         std::size_t nInteriorRings = poly->getNumInteriorRing();
+-         vector<ossimPolygon> holes(nInteriorRings);
+-         for(std::size_t holeIdx = 0; holeIdx < nInteriorRings; ++holeIdx)
+-         {
+-            const geos::geom::LineString* lineString = poly->getInteriorRingN(holeIdx);
+-            if (lineString)
+-            {
+-               std::size_t nPoints = lineString->getNumPoints();
+-               for (std::size_t idx = 0; idx<nPoints; ++idx)
+-               {
+-                  std::unique_ptr<const geos::geom::Point> point(lineString->getPointN(idx));
+-                  holes[holeIdx].addPoint(point->getX(), point->getY());
+-               }
+-            }
+-         }
+-         polyList.push_back(ossimPolyArea2d(shell, holes));
++         const GEOSGeometry *ringGeom = GEOSGetInteriorRingN(geom, idx);
++         getHoles(ringGeom, polygons);
+       }
+    }
+    else
+    {
+-      int idx = 0;
+-      
+-      for (idx=0; idx < nGeoms; idx++)
++      for (int idx = 0; idx < nGeoms; ++idx)
+       {
+-         recurseCompleteGeometries(polyList, geom->getGeometryN(idx));
++         geomPtr = GEOSGetGeometryN(geom, idx);
++         recurseGeometryHoles(geomPtr, polygons);
+       }
+    }
+ }
+ 
+-std::ostream& operator <<(std::ostream& out, const ossimPolyArea2d& rhs)
++bool ossimPolyArea2dPrivate::getVisiblePolygons(ossimPolygon::Vector &polygons) const
+ {
+-   if(rhs.m_privateData->m_geometry)
++   bool foundPolys = false;
++   if (m_geometry)
+    {
+-      out << rhs.m_privateData->m_geometry->toString();
++      ossim_uint32 sizeBefore = (ossim_uint32)polygons.size();
++      recurseVisibleGeometries(m_geometry, polygons);
++      foundPolys = (sizeBefore != polygons.size());
+    }
+-   return out;
+-}
+ 
+-ossimPolyArea2d::ossimPolyArea2d()
+-   :m_privateData(new OssimPolyArea2dPrivate)
+-{
++   return foundPolys;
+ }
+-
+-ossimPolyArea2d::ossimPolyArea2d(const vector<ossimGpt>& polygon)
+-   :m_privateData(new OssimPolyArea2dPrivate)
++bool ossimPolyArea2dPrivate::getPolygonHoles(ossimPolygon::Vector &polygons) const
+ {
+-   (*this) = polygon;
++   return getPolygonHoles(m_geometry, polygons);
+ }
+ 
+-ossimPolyArea2d::ossimPolyArea2d(const vector<ossimDpt>& polygon)
+-   :m_privateData(new OssimPolyArea2dPrivate)
++bool ossimPolyArea2dPrivate::getPolygonHoles(ConstGEOSGeometryPtr geom,
++                                             ossimPolygon::Vector &polygons) const
+ {
+-   (*this) = polygon;
+-}
++   bool foundPolys = false;
++   if (m_geometry)
++   {
++      ossim_uint32 sizeBefore = (ossim_uint32)polygons.size();
++      recurseGeometryHoles(m_geometry, polygons);
++      foundPolys = (sizeBefore != polygons.size());
++   }
+ 
+-ossimPolyArea2d::ossimPolyArea2d(const ossimIrect& rect)
+-   :m_privateData(new OssimPolyArea2dPrivate)
+-{
+-   (*this) = rect;
++   return foundPolys;
+ }
+ 
+-ossimPolyArea2d::ossimPolyArea2d(const ossimDrect& rect)
+-   :m_privateData(new OssimPolyArea2dPrivate)
++std::string ossimPolyArea2dPrivate::toString() const
+ {
+-   (*this) = rect;
+-}
++   std::string result;
+ 
+-ossimPolyArea2d::ossimPolyArea2d(const ossimPolygon& polygon)
+-   :m_privateData(new OssimPolyArea2dPrivate)
+-{
+-   (*this) = polygon;
+-}
++   if (m_geometry)
++   {
++      GEOSWKTWriter *wktWriter = GEOSWKTWriter_create();
++      GEOSWKTWriter_setRoundingPrecision(wktWriter, 20);
++      char *wkt_c = GEOSWKTWriter_write(wktWriter, m_geometry);
+ 
+-ossimPolyArea2d::ossimPolyArea2d(const ossimPolygon& exteriorRing, const vector<ossimPolygon>& interiorRings)
+-   :m_privateData(new OssimPolyArea2dPrivate)
+-{	
+-	m_privateData->setGeometry(exteriorRing, interiorRings);
+-}
++      result = wkt_c;
++      GEOSWKTWriter_destroy(wktWriter);
+ 
+-ossimPolyArea2d::ossimPolyArea2d(const ossimPolyArea2d& rhs)
+-   :m_privateData(new OssimPolyArea2dPrivate) 
+-{
+-   *this = rhs;
+-}
++      GEOSFree(wkt_c);
++   }
+ 
+-ossimPolyArea2d::ossimPolyArea2d(const ossimDpt& p1,
+-                                 const ossimDpt& p2,
+-                                 const ossimDpt& p3,
+-                                 const ossimDpt& p4)
+-   :
+-   m_privateData(new OssimPolyArea2dPrivate)
++   return result;
++}
++bool ossimPolyArea2dPrivate::setFromWkt(const std::string &s)
+ {
+-   ossimPolygon temp(p1,p2,p3,p4);
+-   *this = temp;
++   bool result = false;
++
++   GEOSWKTReader *reader = GEOSWKTReader_create();
++   GEOSGeometry *geom = GEOSWKTReader_read(reader, s.c_str());
++   result = (geom != 0);
++   setGeometry(geom);
++
++   GEOSWKTReader_destroy(reader);
++
++   return result;
+ }
+ 
+-ossimPolyArea2d::~ossimPolyArea2d()
++
++bool ossimPolyArea2dPrivate::isEmpty() const
+ {
+-   if(m_privateData)
++   bool result = true;
++   if (m_geometry)
+    {
+-      delete m_privateData;
+-      m_privateData = 0;
++      result = (GEOSisEmpty(m_geometry) == 1);
+    }
++
++   return result;
+ }
+ 
+-const ossimPolyArea2d& ossimPolyArea2d::operator =(const ossimPolyArea2d& rhs)
+-{ 
+-   if(this != &rhs)
++bool ossimPolyArea2dPrivate::isValid(bool displayValidationError) const
++{
++   bool result = false;
++
++   if (!displayValidationError)
+    {
+-      if(rhs.m_privateData->m_geometry)
++      result = GEOSisValid(m_geometry) == 1;
++   }
++   else
++   {
++      char *reason = GEOSisValidReason(m_geometry);
++      if (reason)
+       {
+-         m_privateData->setGeometry(rhs.m_privateData->m_geometry->clone());
++         ossimNotify(ossimNotifyLevel_INFO)
++             << "ossimPolyArea2dPrivate::isValid: " << reason << "\n";
++
++         GEOSFree(reason);
++         reason = 0;
+       }
+    }
+-   return *this;
++
++   return result;
+ }
++bool ossimPolyArea2dPrivate::isPointWithin(const ossimDpt &pt) const
++{
++   bool result = false;
+ 
+-const ossimPolyArea2d& ossimPolyArea2d::operator =(const ossimPolygon& polygon)
++   if (!isEmpty())
++   {
++      GEOSCoordSequence *pointSeq = GEOSCoordSeq_create(1, 2);
++      GEOSCoordSeq_setXY(pointSeq, 0, pt.x, pt.y);
++      GEOSGeometry *geom = GEOSGeom_createPoint(pointSeq);
++      result = (GEOSWithin(geom, m_geometry) == 1);
++
++      GEOSGeom_destroy(geom);
++   }
++
++   return result;
++}
++
++
++ossimPolyArea2d::ossimPolyArea2d()
++    : m_privateData(new ossimPolyArea2dPrivate())
+ {
+-   m_privateData->setGeometry(polygon);
++}
+ 
+-   return *this;
++ossimPolyArea2d::ossimPolyArea2d(const std::vector<ossimGpt> &polygon)
++    : m_privateData(new ossimPolyArea2dPrivate())
++{
++   m_privateData->setGeometry(polygon);
+ }
+ 
+-const ossimPolyArea2d& ossimPolyArea2d::operator =(const ossimIrect& rect)
++ossimPolyArea2d::ossimPolyArea2d(const std::vector<ossimDpt> &polygon)
++    : m_privateData(new ossimPolyArea2dPrivate())
+ {
+-   return (*this = ossimPolygon(rect));
++   m_privateData->setGeometry(polygon);
+ }
+ 
+-const ossimPolyArea2d& ossimPolyArea2d::operator =(const ossimDrect& rect)
++ossimPolyArea2d::ossimPolyArea2d(const ossimPolygon &shell, const std::vector<ossimPolygon> &holes)
++    : m_privateData(new ossimPolyArea2dPrivate())
+ {
+-   return (*this = ossimPolygon(rect));
++   m_privateData->setGeometry(shell, holes);
+ }
+ 
+-const ossimPolyArea2d& ossimPolyArea2d::operator =(const vector<ossimGpt>& polygon)
++ossimPolyArea2d::ossimPolyArea2d(const ossimDpt &p1,
++                                 const ossimDpt &p2,
++                                 const ossimDpt &p3,
++                                 const ossimDpt &p4)
++    : m_privateData(new ossimPolyArea2dPrivate())
+ {
+-   std::vector<ossimDpt> pts;
+-   int idx = 0;
+-   int n = (int)polygon.size();
+-   for(idx = 0; idx < n;++idx)
+-   {
+-      pts.push_back(polygon[idx]);
+-   }
+-  
+-   return (*this = ossimPolygon(pts));
++   m_privateData->setGeometry(ossimPolygon(p1, p2, p3, p4));
+ }
+ 
+-const ossimPolyArea2d& ossimPolyArea2d::operator =(const vector<ossimDpt>& polygon)
++ossimPolyArea2d::ossimPolyArea2d(const ossimPolyArea2d &rhs)
++    : m_privateData(new ossimPolyArea2dPrivate())
+ {
+-   return (*this = ossimPolygon(polygon));
++   m_privateData->deleteGeometry();
++   m_privateData->m_geometry = GEOSGeom_clone(rhs.m_privateData->m_geometry);
+ }
+ 
+-bool ossimPolyArea2d::intersects(const ossimPolyArea2d& rhs)const
++ossimPolyArea2d::ossimPolyArea2d(const ossimIrect &rect)
++    : m_privateData(new ossimPolyArea2dPrivate())
+ {
+-   bool result = false;
++   m_privateData->setGeometry(ossimPolygon(rect));
++}
+ 
+-   if(m_privateData->m_geometry&&rhs.m_privateData->m_geometry)
+-   {
+-      result = m_privateData->m_geometry->intersects(rhs.m_privateData->m_geometry); 
+-   }
++ossimPolyArea2d::ossimPolyArea2d(const ossimDrect &rect)
++    : m_privateData(new ossimPolyArea2dPrivate())
++{
++   m_privateData->setGeometry(ossimPolygon(rect));
++}
+ 
+-   return result;
++ossimPolyArea2d::ossimPolyArea2d(const ossimPolygon &polygon)
++    : m_privateData(new ossimPolyArea2dPrivate())
++{
++   m_privateData->setGeometry(polygon);
+ }
+ 
+-ossimPolyArea2d ossimPolyArea2d::operator &(const ossimPolyArea2d& rhs)const
++ossimPolyArea2d::~ossimPolyArea2d()
+ {
+-   if((this!=&rhs) && m_privateData->m_geometry && rhs.m_privateData->m_geometry)
++   if (m_privateData)
+    {
+-      ossimPolyArea2d result;
+-      try // GEOS code throws exceptions...
+-      {
+-         result.m_privateData->setGeometry(m_privateData->m_geometry->intersection(
+-                                              rhs.m_privateData->m_geometry));
+-      }
+-      catch( const std::exception& e )
+-      {
+-         ossimNotify(ossimNotifyLevel_DEBUG)
+-            << "ossimPolyArea2d::operator& Caught exception: " << e.what() << std::endl;
+-         result.clearPolygons();
+-      }
+-      catch( ... )
+-      {
+-         ossimNotify(ossimNotifyLevel_DEBUG)
+-            << "ossimPolyArea2d::operator& Caught exception!" << std::endl;
+-         result.clearPolygons();
+-      }
+-      return result;
++      delete m_privateData;
+    }
+-   return *this;
++   m_privateData = 0;
+ }

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912101716.xBAHGKWj008893>