[geos-commits] r3036 - in trunk/php: . test
svn_geos at osgeo.org
svn_geos at osgeo.org
Sun Jun 20 15:05:57 EDT 2010
Author: strk
Date: 2010-06-20 19:05:57 +0000 (Sun, 20 Jun 2010)
New Revision: 3036
Modified:
trunk/php/geos.c
trunk/php/test/test.php
Log:
Simplify (also topology-preserving), ExtractUniquePoints
Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c 2010-06-20 17:00:29 UTC (rev 3035)
+++ trunk/php/geos.c 2010-06-20 19:05:57 UTC (rev 3036)
@@ -183,6 +183,8 @@
PHP_METHOD(Geometry, pointOnSurface);
PHP_METHOD(Geometry, centroid);
PHP_METHOD(Geometry, relate);
+PHP_METHOD(Geometry, simplify); /* also does topology-preserving */
+PHP_METHOD(Geometry, extractUniquePoints);
PHP_METHOD(Geometry, numGeometries);
@@ -202,6 +204,8 @@
PHP_ME(Geometry, pointOnSurface, NULL, 0)
PHP_ME(Geometry, centroid, NULL, 0)
PHP_ME(Geometry, relate, NULL, 0)
+ PHP_ME(Geometry, simplify, NULL, 0)
+ PHP_ME(Geometry, extractUniquePoints, NULL, 0)
PHP_ME(Geometry, numGeometries, NULL, 0)
{NULL, NULL, NULL}
@@ -1015,8 +1019,57 @@
GEOSGeom_destroy(geom_out);
}
+/**
+ * GEOSGeometry GEOSGeometry::simplify(tolerance)
+ * GEOSGeometry GEOSGeometry::simplify(tolerance, preserveTopology)
+ */
+PHP_METHOD(Geometry, simplify)
+{
+ GEOSGeometry *this;
+ double tolerance;
+ zend_bool preserveTopology = 0;
+ GEOSGeometry *ret;
+ this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|b",
+ &tolerance, &preserveTopology) == FAILURE) {
+ RETURN_NULL();
+ }
+
+ if ( preserveTopology ) {
+ ret = GEOSTopologyPreserveSimplify(this, tolerance);
+ } else {
+ ret = GEOSSimplify(this, tolerance);
+ }
+
+ if ( ! ret ) RETURN_NULL(); /* should get an exception first */
+
+ /* return_value is a zval */
+ object_init_ex(return_value, Geometry_ce_ptr);
+ setRelay(return_value, ret);
+}
+
+/**
+ * GEOSGeometry GEOSGeometry::extractUniquePoints()
+ */
+PHP_METHOD(Geometry, extractUniquePoints)
+{
+ GEOSGeometry *this;
+ GEOSGeometry *ret;
+
+ this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+ ret = GEOSGeom_extractUniquePoints(this);
+ if ( ret == NULL ) RETURN_NULL(); /* should get an exception first */
+
+ /* return_value is a zval */
+ object_init_ex(return_value, Geometry_ce_ptr);
+ setRelay(return_value, ret);
+}
+
+
+
/* ------ Initialization / Deinitialization / Meta ------------------ */
/* per-module initialization */
Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php 2010-06-20 17:00:29 UTC (rev 3035)
+++ trunk/php/test/test.php 2010-06-20 19:05:57 UTC (rev 3036)
@@ -970,7 +970,6 @@
)');
$ret = GEOSLineMerge($g);
-/*
$this->assertEquals('array', gettype($ret));
$this->assertEquals('1', count($ret));
@@ -978,7 +977,51 @@
$this->assertEquals(
'LINESTRING (0 0, 10 10, 10 0, 5 0, 5 -5)'
, $writer->write($ret[0]));
-*/
}
+
+ public function testGeometry_simplify()
+ {
+ $reader = new GEOSWKTReader();
+ $writer = new GEOSWKTWriter();
+ $writer->setRoundingPrecision(0);
+
+ $g = $reader->read('LINESTRING(0 0, 3 4, 5 10, 10 0, 10 9, 5 11, 0 9)');
+ $gs = $g->simplify(2);
+ $this->assertEquals( 'LINESTRING (0 0, 5 10, 10 0, 10 9, 0 9)'
+ , $writer->write($gs));
+ $gs = $g->simplify(2, TRUE);
+ $this->assertEquals( 'LINESTRING (0 0, 5 10, 10 0, 10 9, 5 11, 0 9)'
+ , $writer->write($gs));
+ }
+
+ public function testGeometry_extractUniquePoints()
+ {
+ $reader = new GEOSWKTReader();
+ $writer = new GEOSWKTWriter();
+ $writer->setRoundingPrecision(0);
+
+ $g = $reader->read(
+ 'GEOMETRYCOLLECTION (
+ MULTIPOLYGON (
+ ((0 0, 1 0, 1 1, 0 1, 0 0)),
+ ((10 10, 10 14, 14 14, 14 10, 10 10),
+ (11 11, 11 12, 12 12, 12 11, 11 11))
+ ),
+ POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
+ MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
+ LINESTRING (0 0, 2 3),
+ MULTIPOINT (0 0, 2 3),
+ POINT (9 0),
+ POINT(1 0)),
+ LINESTRING EMPTY
+');
+
+ $gs = $g->extractUniquePoints();
+ if ( ! $gs ) RETURN_NULL(); /* should get an exception before */
+
+ $this->assertEquals(
+'MULTIPOINT (0 0, 1 0, 1 1, 0 1, 10 10, 10 14, 14 14, 14 10, 11 11, 11 12, 12 12, 12 11, 2 3, 3 4, 9 0)'
+ , $writer->write($gs));
+ }
}
More information about the geos-commits
mailing list