[geos-commits] r2997 - trunk/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Sun May 30 22:57:53 EDT 2010


Author: warmerdam
Date: 2010-05-30 22:57:51 -0400 (Sun, 30 May 2010)
New Revision: 2997

Modified:
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
Log:
Addition of getCoordinateDimension() on GEOSGeom (#311)
Addition of setOutputDimension, setOld3D on WKTWriter (#292)


Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2010-05-28 20:44:05 UTC (rev 2996)
+++ trunk/capi/geos_c.cpp	2010-05-31 02:57:51 UTC (rev 2997)
@@ -765,6 +765,12 @@
     return GEOSGeom_getDimensions_r( handle, g );
 }
 
+int
+GEOSGeom_getCoordinateDimension(const Geometry *g)
+{
+    return GEOSGeom_getCoordinateDimension_r( handle, g );
+}
+
 Geometry *
 GEOSSimplify(const Geometry *g1, double tolerance)
 {
@@ -829,6 +835,18 @@
 	return GEOSWKTWriter_setRoundingPrecision_r(handle, writer, precision);
 }
 
+void
+GEOSWKTWriter_setOutputDimension(WKTWriter *writer, int dim)
+{
+	GEOSWKTWriter_setOutputDimension_r(handle, writer, dim);
+}
+
+void
+GEOSWKTWriter_setOld3D(WKTWriter *writer, int useOld3D)
+{
+	GEOSWKTWriter_setOld3D_r(handle, writer, useOld3D);
+}
+
 /* WKB Reader */
 WKBReader *
 GEOSWKBReader_create()

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2010-05-28 20:44:05 UTC (rev 2996)
+++ trunk/capi/geos_c.h.in	2010-05-31 02:57:51 UTC (rev 2997)
@@ -891,7 +891,6 @@
 
 /*
  * Return 0 on exception (or empty geometry)
- * See also GEOSCoordSeq_getDimensions 
  */
 extern int GEOS_DLL GEOSGeom_getDimensions(const GEOSGeometry* g);
 
@@ -899,6 +898,14 @@
                                              const GEOSGeometry* g);
 
 /*
+ * Return 2 or 3.
+ */
+extern int GEOS_DLL GEOSGeom_getCoordinateDimension(const GEOSGeometry* g);
+
+extern int GEOS_DLL GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t handle,
+                                                      const GEOSGeometry* g);
+
+/*
  * Return NULL on exception.
  * Must be LineString and must be freed by called.
  */
@@ -995,6 +1002,8 @@
 extern char GEOS_DLL *GEOSWKTWriter_write(GEOSWKTWriter* reader, const GEOSGeometry* g);
 extern void GEOS_DLL GEOSWKTWriter_setTrim(GEOSWKTWriter *writer, char trim);
 extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision(GEOSWKTWriter *writer, int precision);
+extern void GEOS_DLL GEOSWKTWriter_setOutputDimension(GEOSWKTWriter *writer, int dim);
+extern void GEOS_DLL GEOSWKTWriter_setOld3D(GEOSWKTWriter *writer, int useOld3D);
 
 extern GEOSWKTWriter GEOS_DLL *GEOSWKTWriter_create_r(
                                              GEOSContextHandle_t handle);
@@ -1009,6 +1018,12 @@
 extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t handle,
                                             GEOSWKTWriter *writer,
                                             int precision);
+extern void GEOS_DLL GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t handle,
+                                                        GEOSWKTWriter *writer,
+                                                        int dim);
+extern void GEOS_DLL GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t handle,
+                                              GEOSWKTWriter *writer,
+                                              int useOld3D);
 
 /* WKB Reader */
 extern GEOSWKBReader GEOS_DLL *GEOSWKBReader_create();

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2010-05-28 20:44:05 UTC (rev 2996)
+++ trunk/capi/geos_ts_c.cpp	2010-05-31 02:57:51 UTC (rev 2997)
@@ -3727,44 +3727,39 @@
 
     try
     {
-        using geos::geom::Point;
-        using geos::geom::GeometryCollection;
+        return (int) g->getDimension();
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+    }
+    
+    return 0;
+}
 
-	if ( g->isEmpty() )
-	{
-		return 0;
-	}
+int
+GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t extHandle, const Geometry *g)
+{
+    if ( 0 == extHandle )
+    {
+        return 0;
+    }
 
-        std::size_t dim = 0;
-        const LineString *ls = dynamic_cast<const LineString *>(g);
-        if ( ls )
-        {
-            dim = ls->getCoordinatesRO()->getDimension();
-            return static_cast<int>(dim);
-        }
-
-        const Point *p = dynamic_cast<const Point *>(g);
-        if ( p )
-        {
-            dim = p->getCoordinatesRO()->getDimension();
-            return static_cast<int>(dim);
-        }
-
-        const Polygon *poly = dynamic_cast<const Polygon *>(g);
-        if ( poly )
-        {
-            return GEOSGeom_getDimensions_r(extHandle, poly->getExteriorRing());
-        }
-
-        const GeometryCollection *coll = dynamic_cast<const GeometryCollection *>(g);
-        if ( coll )
-        {
-            return GEOSGeom_getDimensions_r(extHandle, coll->getGeometryN(0));
-        }
-
-        handle->ERROR_MESSAGE("Unknown geometry type");
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
         return 0;
     }
+
+    try
+    {
+        return g->getCoordinateDimension();
+    }
     catch (const std::exception &e)
     {
         handle->ERROR_MESSAGE("%s", e.what());
@@ -4105,6 +4100,46 @@
     writer->setRoundingPrecision(precision);
 }
 
+void
+GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t extHandle, WKTWriter *writer, int dim)
+{
+    assert(0 != writer);
+
+    if ( 0 == extHandle )
+    {
+        return;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return;
+    }
+
+    writer->setOutputDimension(dim);
+}
+
+void
+GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t extHandle, WKTWriter *writer, int useOld3D)
+{
+    assert(0 != writer);
+
+    if ( 0 == extHandle )
+    {
+        return;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return;
+    }
+
+    writer->setOld3D(useOld3D);
+}
+
 /* WKB Reader */
 WKBReader *
 GEOSWKBReader_create_r(GEOSContextHandle_t extHandle)



More information about the geos-commits mailing list