[geos-commits] r2910 - in trunk: capi tests/unit/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Feb 11 03:33:32 EST 2010


Author: strk
Date: 2010-02-11 03:33:30 -0500 (Thu, 11 Feb 2010)
New Revision: 2910

Modified:
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
   trunk/tests/unit/capi/GEOSGeom_create.cpp
Log:
Complete set of typed-empty constructors and tests for them [RT-SIGTA]

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2010-02-11 08:18:44 UTC (rev 2909)
+++ trunk/capi/geos_c.h.in	2010-02-11 08:33:30 UTC (rev 2910)
@@ -4,6 +4,7 @@
  *
  * C-Wrapper for GEOS library
  *
+ * Copyright (C) 2010 Sandro Santilli <strk at keybit.net>
  * Copyright (C) 2005 Refractions Research Inc.
  *
  * This is free software; you can redistribute and/or modify it under
@@ -418,12 +419,16 @@
 extern GEOSGeometry GEOS_DLL *GEOSGeom_createPoint_r(
                                        GEOSContextHandle_t handle,
                                        GEOSCoordSequence* s);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPoint_r(
+                                       GEOSContextHandle_t handle);
 extern GEOSGeometry GEOS_DLL *GEOSGeom_createLinearRing_r(
                                        GEOSContextHandle_t handle,
                                        GEOSCoordSequence* s);
 extern GEOSGeometry GEOS_DLL *GEOSGeom_createLineString_r(
                                        GEOSContextHandle_t handle,
                                        GEOSCoordSequence* s);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyLineString_r(
+                                       GEOSContextHandle_t handle);
 
 /*
  * Second argument is an array of GEOSGeometry* objects.
@@ -446,6 +451,8 @@
                                        GEOSContextHandle_t handle, int type,
                                        GEOSGeometry* *geoms,
                                        unsigned int ngeoms);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyCollection_r(
+                                       GEOSContextHandle_t handle, int type);
 
 extern GEOSGeometry GEOS_DLL *GEOSGeom_clone(const GEOSGeometry* g);
 

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2010-02-11 08:18:44 UTC (rev 2909)
+++ trunk/capi/geos_ts_c.cpp	2010-02-11 08:33:30 UTC (rev 2910)
@@ -4,6 +4,7 @@
  *
  * C-Wrapper for GEOS library
  *
+ * Copyright (C) 2010 Sandro Santilli <strk at keybit.net>
  * Copyright (C) 2005-2006 Refractions Research Inc.
  *
  * This is free software; you can redistribute and/or modify it under
@@ -2207,6 +2208,67 @@
 }
 
 Geometry *
+GEOSGeom_createEmptyCollection_r(GEOSContextHandle_t extHandle, int type)
+{
+    if ( 0 == extHandle )
+    {
+        return NULL;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return NULL;
+    }
+
+#ifdef GEOS_DEBUG
+    char buf[256];
+    sprintf(buf, "createCollection: requested type %d, ngeoms: %d",
+            type, ngeoms);
+    handle->NOTICE_MESSAGE("%s", buf);// TODO: Can handle->NOTICE_MESSAGE format that directly? 
+#endif
+
+    try
+    {
+        const GeometryFactory* gf = handle->geomFactory;
+
+        Geometry *g = 0;
+        switch (type)
+        {
+            case GEOS_GEOMETRYCOLLECTION:
+                g = gf->createGeometryCollection();
+                break;
+            case GEOS_MULTIPOINT:
+                g = gf->createMultiPoint();
+                break;
+            case GEOS_MULTILINESTRING:
+                g = gf->createMultiLineString();
+                break;
+            case GEOS_MULTIPOLYGON:
+                g = gf->createMultiPolygon();
+                break;
+            default:
+                handle->ERROR_MESSAGE("Unsupported type request for GEOSGeom_createEmptyCollection_r");
+                g = 0;
+                
+        }
+        
+        return g;
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+    }
+
+    return 0;
+}
+
+Geometry *
 GEOSGeom_createCollection_r(GEOSContextHandle_t extHandle, int type, Geometry **geoms, unsigned int ngeoms)
 {
     if ( 0 == extHandle )
@@ -2958,6 +3020,38 @@
 }
 
 Geometry *
+GEOSGeom_createEmptyPoint_r(GEOSContextHandle_t extHandle)
+{
+    if ( 0 == extHandle )
+    {
+        return NULL;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return NULL;
+    }
+
+    try
+    {
+        const GeometryFactory *gf = handle->geomFactory;
+        return gf->createPoint();
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+    }
+    
+    return NULL;
+}
+
+Geometry *
 GEOSGeom_createPoint_r(GEOSContextHandle_t extHandle, CoordinateSequence *cs)
 {
     if ( 0 == extHandle )
@@ -3023,6 +3117,39 @@
 }
 
 Geometry *
+GEOSGeom_createEmptyLineString_r(GEOSContextHandle_t extHandle)
+{
+    if ( 0 == extHandle )
+    {
+        return NULL;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return NULL;
+    }
+
+    try
+    { 
+        const GeometryFactory *gf = handle->geomFactory;
+
+        return gf->createLineString();
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+    }
+    
+    return NULL;
+}
+
+Geometry *
 GEOSGeom_createLineString_r(GEOSContextHandle_t extHandle, CoordinateSequence *cs)
 {
     if ( 0 == extHandle )

Modified: trunk/tests/unit/capi/GEOSGeom_create.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSGeom_create.cpp	2010-02-11 08:18:44 UTC (rev 2909)
+++ trunk/tests/unit/capi/GEOSGeom_create.cpp	2010-02-11 08:33:30 UTC (rev 2910)
@@ -58,17 +58,84 @@
     // Test Cases
     //
 
-    // EMPTY polygon
+    // EMPTY point
     template<>
     template<>
     void object::test<1>()
     {
+        geom1_ = GEOSGeom_createEmptyPoint_r(handle_);
+        ensure(GEOSisEmpty_r(handle_, geom1_));
+	ensure_equals(GEOSGeomTypeId_r(handle_, geom1_), GEOS_POINT);
+	GEOSGeom_destroy(geom1_); geom1_=0;
+    }
+
+    // EMPTY linestring
+    template<>
+    template<>
+    void object::test<2>()
+    {
+        geom1_ = GEOSGeom_createEmptyLineString_r(handle_);
+        ensure(GEOSisEmpty_r(handle_, geom1_));
+	ensure_equals(GEOSGeomTypeId_r(handle_, geom1_), GEOS_LINESTRING);
+	GEOSGeom_destroy(geom1_); geom1_=0;
+    }
+    
+
+    // EMPTY polygon
+    template<>
+    template<>
+    void object::test<3>()
+    {
         geom1_ = GEOSGeom_createEmptyPolygon_r(handle_);
         ensure(GEOSisEmpty_r(handle_, geom1_));
 	ensure_equals(GEOSGeomTypeId_r(handle_, geom1_), GEOS_POLYGON);
 	GEOSGeom_destroy(geom1_); geom1_=0;
     }
-    
 
+    // EMPTY multipoint
+    template<>
+    template<>
+    void object::test<4>()
+    {
+        geom1_ = GEOSGeom_createEmptyCollection_r(handle_, GEOS_MULTIPOINT);
+        ensure(GEOSisEmpty_r(handle_, geom1_));
+	ensure_equals(GEOSGeomTypeId_r(handle_, geom1_), GEOS_MULTIPOINT);
+	GEOSGeom_destroy(geom1_); geom1_=0;
+    }
+
+    // EMPTY multilinestring
+    template<>
+    template<>
+    void object::test<5>()
+    {
+        geom1_ = GEOSGeom_createEmptyCollection_r(handle_, GEOS_MULTILINESTRING);
+        ensure(GEOSisEmpty_r(handle_, geom1_));
+	ensure_equals(GEOSGeomTypeId_r(handle_, geom1_), GEOS_MULTILINESTRING);
+	GEOSGeom_destroy(geom1_); geom1_=0;
+    }
+
+    // EMPTY multipolygon
+    template<>
+    template<>
+    void object::test<6>()
+    {
+        geom1_ = GEOSGeom_createEmptyCollection_r(handle_, GEOS_MULTIPOLYGON);
+        ensure(GEOSisEmpty_r(handle_, geom1_));
+	ensure_equals(GEOSGeomTypeId_r(handle_, geom1_), GEOS_MULTIPOLYGON);
+	GEOSGeom_destroy(geom1_); geom1_=0;
+    }
+
+    // EMPTY collection
+    template<>
+    template<>
+    void object::test<7>()
+    {
+        geom1_ = GEOSGeom_createEmptyCollection_r(handle_, GEOS_GEOMETRYCOLLECTION);
+        ensure(GEOSisEmpty_r(handle_, geom1_));
+	ensure_equals(GEOSGeomTypeId_r(handle_, geom1_), GEOS_GEOMETRYCOLLECTION);
+	GEOSGeom_destroy(geom1_); geom1_=0;
+    }
+
+
 } // namespace tut
 



More information about the geos-commits mailing list