[geos-commits] r2624 - trunk/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Sep 11 14:47:34 EDT 2009


Author: pramsey
Date: 2009-09-11 14:47:32 -0400 (Fri, 11 Sep 2009)
New Revision: 2624

Modified:
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
Log:
Patch for #285, C api for project and interpolate, from David Turner (novalis)


Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2009-08-21 09:54:58 UTC (rev 2623)
+++ trunk/capi/geos_c.cpp	2009-09-11 18:47:32 UTC (rev 2624)
@@ -883,4 +883,33 @@
     GEOSSTRtree_destroy_r( handle, tree );
 }
 
+double
+GEOSProject (const geos::geom::Geometry *g,
+             const geos::geom::Geometry *p)
+{
+    return GEOSProject_r (handle, g, p);
+}
+
+geos::geom::Geometry *
+GEOSInterpolate (const geos::geom::Geometry *g,
+                 double d)
+{
+    return GEOSInterpolate_r(handle, g, d);
+}
+
+double
+GEOSProjectNormalized (const geos::geom::Geometry *g,
+                       const geos::geom::Geometry *p)
+{
+    return GEOSProjectNormalized_r (handle, g, p);
+}
+
+geos::geom::Geometry *
+GEOSInterpolateNormalized (const geos::geom::Geometry *g,
+                           double d)
+{
+    return GEOSInterpolateNormalized_r(handle, g, d);
+}
+
+
 } /* extern "C" */

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2009-08-21 09:54:58 UTC (rev 2623)
+++ trunk/capi/geos_c.h.in	2009-09-11 18:47:32 UTC (rev 2624)
@@ -319,6 +319,43 @@
 
 /************************************************************************
  *
+ *  Linearref functions -- there are more, but these two are probably
+ *  sufficient for most purposes
+ *
+ ***********************************************************************/
+
+/* 
+ * GEOSGeometry ownership is retained by caller
+ */
+
+
+extern double GEOS_DLL GEOSProject(const GEOSGeometry *g,
+                                   const GEOSGeometry* p);
+extern double GEOS_DLL GEOSProject_r(GEOSContextHandle_t handle,
+                                     const GEOSGeometry *g,
+                                     const GEOSGeometry *p);
+
+extern GEOSGeometry* GEOS_DLL GEOSInterpolate(const GEOSGeometry *g,
+                                              double d);
+extern GEOSGeometry* GEOS_DLL GEOSInterpolate_r(GEOSContextHandle_t handle,
+                                                const GEOSGeometry *g,
+                                                double d);
+
+extern double GEOS_DLL GEOSProjectNormalized(const GEOSGeometry *g,
+                                             const GEOSGeometry* p);
+extern double GEOS_DLL GEOSProjectNormalized_r(GEOSContextHandle_t handle,
+                                               const GEOSGeometry *g,
+                                               const GEOSGeometry *p);
+
+extern GEOSGeometry* GEOS_DLL GEOSInterpolateNormalized(const GEOSGeometry *g,
+                                                        double d);
+extern GEOSGeometry* GEOS_DLL GEOSInterpolateNormalized_r(
+                                                GEOSContextHandle_t handle,
+                                                const GEOSGeometry *g,
+                                                double d);
+
+/************************************************************************
+ *
  * Buffer related functions
  *
  ***********************************************************************/

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2009-08-21 09:54:58 UTC (rev 2623)
+++ trunk/capi/geos_ts_c.cpp	2009-09-11 18:47:32 UTC (rev 2624)
@@ -48,6 +48,7 @@
 #include <geos/operation/union/CascadedPolygonUnion.h>
 #include <geos/operation/buffer/BufferOp.h>
 #include <geos/operation/buffer/BufferParameters.h>
+#include <geos/linearref/LengthIndexedLine.h>
 #include <geos/geom/BinaryOp.h>
 #include <geos/util/IllegalArgumentException.h>
 #include <geos/version.h> 
@@ -4299,5 +4300,64 @@
     }
 }
 
+double
+GEOSProject_r(GEOSContextHandle_t extHandle,
+              const Geometry *g,
+              const Geometry *p)
+{
+
+    const geos::geom::Point* point = dynamic_cast<const geos::geom::Point*>(p);
+    if (!point) {
+        if ( 0 == extHandle )
+        {
+            return -1.0;
+        }
+        GEOSContextHandleInternal_t *handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+        if ( 0 == handle->initialized )
+        {
+            return -1.0;
+        }
+
+        handle->ERROR_MESSAGE("third argument of GEOSProject_r must be Point*");
+        return -1.0;
+    }
+    const geos::geom::Coordinate* inputPt = p->getCoordinate();
+    return geos::linearref::LengthIndexedLine(g).project(*inputPt);
+}
+
+
+Geometry*
+GEOSInterpolate_r(GEOSContextHandle_t extHandle, const Geometry *g, double d)
+{
+    geos::linearref::LengthIndexedLine lil(g);
+    geos::geom::Coordinate coord = lil.extractPoint(d);
+    GEOSContextHandleInternal_t *handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    const GeometryFactory *gf = handle->geomFactory;
+    Geometry* point = gf->createPoint(coord);
+    return point;
+}
+
+
+double
+GEOSProjectNormalized_r(GEOSContextHandle_t extHandle, const Geometry *g,
+                        const Geometry *p)
+{
+
+    double length;
+    GEOSLength_r(extHandle, g, &length);
+    return GEOSProject_r(extHandle, g, p) / length;
+}
+
+
+Geometry*
+GEOSInterpolateNormalized_r(GEOSContextHandle_t extHandle, const Geometry *g,
+                            double d)
+{
+    double length;
+    GEOSLength_r(extHandle, g, &length);
+    return GEOSInterpolate_r(extHandle, g, d * length);
+}
+
+
 } /* extern "C" */
 



More information about the geos-commits mailing list