[geos-commits] r3201 - in trunk: . capi tests/unit tests/unit/capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Fri Feb 11 04:58:29 EST 2011
Author: strk
Date: 2011-02-11 01:58:29 -0800 (Fri, 11 Feb 2011)
New Revision: 3201
Added:
trunk/tests/unit/capi/GEOSUnaryUnionTest.cpp
Modified:
trunk/NEWS
trunk/capi/geos_c.cpp
trunk/capi/geos_c.h.in
trunk/capi/geos_ts_c.cpp
trunk/tests/unit/Makefile.am
Log:
GEOSUnaryUnion C-API interface (and test)
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2011-02-10 21:05:32 UTC (rev 3200)
+++ trunk/NEWS 2011-02-11 09:58:29 UTC (rev 3201)
@@ -2,6 +2,7 @@
????-??-??
- New things:
+ - CAPI: GEOSUnaryUnion
- CAPI: GEOSisValidDetail: tell state, reason & location apart
- CAPI: GEOSContext_setNoticeHandler_r, GEOSContext_setErrorHandler_r
- CAPI: GEOSGeom_createEmptyPoint, GEOSGeom_createEmptyLineString
Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp 2011-02-10 21:05:32 UTC (rev 3200)
+++ trunk/capi/geos_c.cpp 2011-02-11 09:58:29 UTC (rev 3201)
@@ -4,6 +4,7 @@
*
* C-Wrapper for GEOS library
*
+ * Copyright (C) 2010 2011 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
@@ -405,6 +406,12 @@
}
Geometry *
+GEOSUnaryUnion(const Geometry *g1)
+{
+ return GEOSUnaryUnion_r( handle, g1);
+}
+
+Geometry *
GEOSUnionCascaded(const Geometry *g1)
{
return GEOSUnionCascaded_r( handle, g1 );
Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in 2011-02-10 21:05:32 UTC (rev 3200)
+++ trunk/capi/geos_c.h.in 2011-02-11 09:58:29 UTC (rev 3201)
@@ -4,7 +4,7 @@
*
* C-Wrapper for GEOS library
*
- * Copyright (C) 2010 Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2010 2011 Sandro Santilli <strk at keybit.net>
* Copyright (C) 2005 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
@@ -492,6 +492,7 @@
const GEOSGeometry* g2);
extern GEOSGeometry GEOS_DLL *GEOSBoundary(const GEOSGeometry* g1);
extern GEOSGeometry GEOS_DLL *GEOSUnion(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion(const GEOSGeometry* g1);
extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded(const GEOSGeometry* g1);
extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface(const GEOSGeometry* g1);
@@ -516,6 +517,8 @@
extern GEOSGeometry GEOS_DLL *GEOSUnion_r(GEOSContextHandle_t handle,
const GEOSGeometry* g1,
const GEOSGeometry* g2);
+extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion_r(GEOSContextHandle_t handle,
+ const GEOSGeometry* g);
extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded_r(GEOSContextHandle_t handle, const GEOSGeometry* g1);
extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface_r(GEOSContextHandle_t handle,
const GEOSGeometry* g1);
Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp 2011-02-10 21:05:32 UTC (rev 3200)
+++ trunk/capi/geos_ts_c.cpp 2011-02-11 09:58:29 UTC (rev 3201)
@@ -4,7 +4,7 @@
*
* C-Wrapper for GEOS library
*
- * Copyright (C) 2010 Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2010 2011 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
@@ -1799,6 +1799,45 @@
}
Geometry *
+GEOSUnaryUnion_r(GEOSContextHandle_t extHandle, const Geometry *g)
+{
+ if ( 0 == extHandle )
+ {
+ return NULL;
+ }
+
+ GEOSContextHandleInternal_t *handle = 0;
+ handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+ if ( 0 == handle->initialized )
+ {
+ return NULL;
+ }
+
+ try
+ {
+ GeomAutoPtr g3 ( g->Union() );
+ return g3.release();
+ }
+ catch (const std::exception &e)
+ {
+#if VERBOSE_EXCEPTIONS
+ std::ostringstream s;
+ s << "Exception on GEOSUnaryUnion with following inputs:" << std::endl;
+ s << "A: "<<g1->toString() << std::endl;
+ s << "B: "<<g2->toString() << std::endl;
+ handle->NOTICE_MESSAGE("%s", s.str().c_str());
+#endif // VERBOSE_EXCEPTIONS
+ handle->ERROR_MESSAGE("%s", e.what());
+ }
+ catch (...)
+ {
+ handle->ERROR_MESSAGE("Unknown exception thrown");
+ }
+
+ return NULL;
+}
+
+Geometry *
GEOSUnionCascaded_r(GEOSContextHandle_t extHandle, const Geometry *g1)
{
if ( 0 == extHandle )
Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am 2011-02-10 21:05:32 UTC (rev 3200)
+++ trunk/tests/unit/Makefile.am 2011-02-11 09:58:29 UTC (rev 3201)
@@ -104,7 +104,8 @@
capi/GEOSLineString_PointTest.cpp \
capi/GEOSSnapTest.cpp \
capi/GEOSSharedPathsTest.cpp \
- capi/GEOSRelatePatternMatchTest.cpp
+ capi/GEOSRelatePatternMatchTest.cpp \
+ capi/GEOSUnaryUnionTest.cpp
noinst_HEADERS = \
utility.h
Added: trunk/tests/unit/capi/GEOSUnaryUnionTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSUnaryUnionTest.cpp (rev 0)
+++ trunk/tests/unit/capi/GEOSUnaryUnionTest.cpp 2011-02-11 09:58:29 UTC (rev 3201)
@@ -0,0 +1,197 @@
+// $Id$
+//
+// Test Suite for C-API GEOSUnaryUnion
+
+#include <tut.hpp>
+// geos
+#include <geos_c.h>
+// std
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+namespace tut
+{
+ //
+ // Test Group
+ //
+
+ // Common data used in test cases.
+ struct test_capiunaryunion_data
+ {
+ GEOSWKTWriter* wktw_;
+ GEOSGeometry* geom1_;
+ GEOSGeometry* geom2_;
+
+ static void notice(const char *fmt, ...)
+ {
+ std::fprintf( stdout, "NOTICE: ");
+
+ va_list ap;
+ va_start(ap, fmt);
+ std::vfprintf(stdout, fmt, ap);
+ va_end(ap);
+
+ std::fprintf(stdout, "\n");
+ }
+
+ test_capiunaryunion_data()
+ : geom1_(0), geom2_(0)
+ {
+ initGEOS(notice, notice);
+ wktw_ = GEOSWKTWriter_create();
+ GEOSWKTWriter_setTrim(wktw_, 1);
+ GEOSWKTWriter_setOutputDimension(wktw_, 3);
+ }
+
+ std::string toWKT(GEOSGeometry* g)
+ {
+ char* wkt = GEOSWKTWriter_write(wktw_, g);
+ std::string ret (wkt);
+ GEOSFree(wkt);
+ return ret;
+ }
+
+ ~test_capiunaryunion_data()
+ {
+ GEOSGeom_destroy(geom1_);
+ GEOSGeom_destroy(geom2_);
+ GEOSWKTWriter_destroy(wktw_);
+ geom1_ = 0;
+ geom2_ = 0;
+ finishGEOS();
+ }
+
+ };
+
+ typedef test_group<test_capiunaryunion_data> group;
+ typedef group::object object;
+
+ group test_capiunaryunion_group("capi::GEOSUnaryUnion");
+
+ //
+ // Test Cases
+ //
+
+
+ // Self-union an empty point
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ geom1_ = GEOSGeomFromWKT("POINT EMPTY");
+ ensure( 0 != geom1_ );
+
+ geom2_ = GEOSUnaryUnion(geom1_);
+ ensure( 0 != geom2_ );
+
+ ensure_equals(toWKT(geom2_), std::string("GEOMETRYCOLLECTION EMPTY"));
+ }
+
+ // Self-union a 2d point
+ template<>
+ template<>
+ void object::test<2>()
+ {
+ geom1_ = GEOSGeomFromWKT("POINT (6 3)");
+ ensure( 0 != geom1_ );
+
+ geom2_ = GEOSUnaryUnion(geom1_);
+ ensure( 0 != geom2_ );
+
+ ensure_equals(toWKT(geom2_), std::string("POINT (6 3)"));
+ }
+
+ // Self-union a 3d point
+ template<>
+ template<>
+ void object::test<3>()
+ {
+ geom1_ = GEOSGeomFromWKT("POINT (4 5 6)");
+ ensure( 0 != geom1_ );
+
+ geom2_ = GEOSUnaryUnion(geom1_);
+ ensure( 0 != geom2_ );
+
+ ensure_equals(toWKT(geom2_), std::string("POINT Z (4 5 6)"));
+ }
+
+ // Self-union a multipoint with duplicated points
+ template<>
+ template<>
+ void object::test<4>()
+ {
+ geom1_ = GEOSGeomFromWKT("MULTIPOINT (4 5, 6 7, 4 5, 6 5, 6 7)");
+ ensure( 0 != geom1_ );
+
+ geom2_ = GEOSUnaryUnion(geom1_);
+ ensure( 0 != geom2_ );
+
+ ensure_equals(toWKT(geom2_), std::string("MULTIPOINT (4 5, 6 5, 6 7)"));
+ }
+
+ // Self-union a collection of puntal and lineal geometries
+ template<>
+ template<>
+ void object::test<5>()
+ {
+ geom1_ = GEOSGeomFromWKT("GEOMETRYCOLLECTION (POINT(4 5), MULTIPOINT(6 7, 6 5, 6 7), LINESTRING(0 5, 10 5), LINESTRING(4 -10, 4 10))");
+ ensure( 0 != geom1_ );
+
+ geom2_ = GEOSUnaryUnion(geom1_);
+ ensure( 0 != geom2_ );
+
+ ensure_equals(toWKT(geom2_), std::string("GEOMETRYCOLLECTION (POINT (6 7), LINESTRING (0 5, 4 5), LINESTRING (4 5, 10 5), LINESTRING (4 -10, 4 5), LINESTRING (4 5, 4 10))"));
+ }
+
+ // Self-union a collection of puntal and polygonal geometries
+ template<>
+ template<>
+ void object::test<6>()
+ {
+ geom1_ = GEOSGeomFromWKT("GEOMETRYCOLLECTION (POINT(4 5), MULTIPOINT(6 7, 6 5, 6 7), POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(5 6, 7 6, 7 8, 5 8, 5 6)))");
+ ensure( 0 != geom1_ );
+
+ geom2_ = GEOSUnaryUnion(geom1_);
+ ensure( 0 != geom2_ );
+
+ ensure_equals(toWKT(geom2_), std::string(
+"GEOMETRYCOLLECTION (POINT (6 7), POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (5 6, 7 6, 7 8, 5 8, 5 6)))"
+));
+ }
+
+ // Self-union a collection of lineal and polygonal geometries
+ template<>
+ template<>
+ void object::test<7>()
+ {
+ geom1_ = GEOSGeomFromWKT("GEOMETRYCOLLECTION (MULTILINESTRING((5 7, 12 7), (4 5, 6 5), (5.5 7.5, 6.5 7.5)), POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(5 6, 7 6, 7 8, 5 8, 5 6)))");
+ ensure( 0 != geom1_ );
+
+ geom2_ = GEOSUnaryUnion(geom1_);
+ ensure( 0 != geom2_ );
+
+ ensure_equals(toWKT(geom2_), std::string(
+"GEOMETRYCOLLECTION (LINESTRING (5 7, 7 7), LINESTRING (10 7, 12 7), LINESTRING (5.5 7.5, 6.5 7.5), POLYGON ((10 7, 10 0, 0 0, 0 10, 10 10, 10 7), (5 6, 7 6, 7 7, 7 8, 5 8, 5 7, 5 6)))"
+));
+ }
+
+ // Self-union a collection of puntal, lineal and polygonal geometries
+ template<>
+ template<>
+ void object::test<8>()
+ {
+ geom1_ = GEOSGeomFromWKT("GEOMETRYCOLLECTION (MULTILINESTRING((5 7, 12 7), (4 5, 6 5), (5.5 7.5, 6.5 7.5)), POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(5 6, 7 6, 7 8, 5 8, 5 6)), MULTIPOINT(6 6.5, 6 1, 12 2, 6 1))");
+ ensure( 0 != geom1_ );
+
+ geom2_ = GEOSUnaryUnion(geom1_);
+ ensure( 0 != geom2_ );
+
+ ensure_equals(toWKT(geom2_), std::string(
+"GEOMETRYCOLLECTION (POINT (6 6.5), POINT (12 2), LINESTRING (5 7, 7 7), LINESTRING (10 7, 12 7), LINESTRING (5.5 7.5, 6.5 7.5), POLYGON ((10 7, 10 0, 0 0, 0 10, 10 10, 10 7), (5 6, 7 6, 7 7, 7 8, 5 8, 5 7, 5 6)))"
+));
+ }
+
+} // namespace tut
+
More information about the geos-commits
mailing list