[geos-commits] r3039 - in trunk/php: . test
svn_geos at osgeo.org
svn_geos at osgeo.org
Sun Jun 20 18:59:31 EDT 2010
Author: strk
Date: 2010-06-20 22:59:31 +0000 (Sun, 20 Jun 2010)
New Revision: 3039
Modified:
trunk/php/geos.c
trunk/php/test/test.php
Log:
checkValidity (isValid in disguise)
Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c 2010-06-20 21:10:10 UTC (rev 3038)
+++ trunk/php/geos.c 2010-06-20 22:59:31 UTC (rev 3039)
@@ -195,6 +195,7 @@
PHP_METHOD(Geometry, equals);
PHP_METHOD(Geometry, equalsExact);
PHP_METHOD(Geometry, isEmpty);
+PHP_METHOD(Geometry, checkValidity);
PHP_METHOD(Geometry, numGeometries);
@@ -226,6 +227,7 @@
PHP_ME(Geometry, equals, NULL, 0)
PHP_ME(Geometry, equalsExact, NULL, 0)
PHP_ME(Geometry, isEmpty, NULL, 0)
+ PHP_ME(Geometry, checkValidity, NULL, 0)
PHP_ME(Geometry, numGeometries, NULL, 0)
{NULL, NULL, NULL}
@@ -267,8 +269,6 @@
setRelay(tmp, cc);
add_next_index_zval(array, tmp);
}
-
- //return array;
}
@@ -1352,7 +1352,46 @@
RETURN_BOOL(retBool);
}
+/**
+ * array GEOSGeometry::checkValidity()
+ */
+PHP_METHOD(Geometry, checkValidity)
+{
+ GEOSGeometry *this;
+ GEOSGeometry *location = NULL;
+ int ret;
+ char *reason = NULL;
+ zend_bool retBool;
+ char *reasonVal = NULL;
+ zval *locationVal = NULL;
+ this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+ ret = GEOSisValidDetail(this, &reason, (const GEOSGeometry**)&location);
+ if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
+
+ if ( reason ) {
+ reasonVal = estrdup(reason);
+ GEOSFree(reason);
+ }
+
+ if ( location ) {
+ MAKE_STD_ZVAL(locationVal);
+ object_init_ex(locationVal, Geometry_ce_ptr);
+ setRelay(locationVal, location);
+ }
+
+ retBool = ret;
+
+ /* return value is an array */
+ array_init(return_value);
+ add_assoc_bool(return_value, "valid", retBool);
+ if ( reasonVal ) add_assoc_string(return_value, "reason", reasonVal, 0);
+ if ( locationVal ) add_assoc_zval(return_value, "location", locationVal);
+
+}
+
+
/* ------ Initialization / Deinitialization / Meta ------------------ */
/* per-module initialization */
Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php 2010-06-20 21:10:10 UTC (rev 3038)
+++ trunk/php/test/test.php 2010-06-20 22:59:31 UTC (rev 3039)
@@ -1167,4 +1167,26 @@
$g1 = $reader->read('GEOMETRYCOLLECTION EMPTY');
$this->assertTrue( $g1->isEmpty() );
}
+
+ public function testGeometry_checkValidity()
+ {
+ $reader = new GEOSWKTReader();
+ $writer = new GEOSWKTWriter();
+ $writer->setRoundingPrecision(0);
+
+ $g = $reader->read('POINT(0 0)');
+ $val = $g->checkValidity();
+ $this->assertType( 'array', $val );
+ $this->assertTrue( $val['valid'] );
+ $this->assertNull( $val['reason'] );
+ $this->assertNull( $val['location'] );
+
+ $g = $reader->read('POINT(0 NaN)');
+ $val = $g->checkValidity();
+ $this->assertType( 'array', $val );
+ $this->assertFalse( $val['valid'] );
+ $this->assertEquals( 'Invalid Coordinate', $val['reason'] );
+ $this->assertEquals( 'POINT (0 nan)',
+ $writer->write($val['location']) );
+ }
}
More information about the geos-commits
mailing list