[geos-commits] r3042 - in trunk/php: . test
svn_geos at osgeo.org
svn_geos at osgeo.org
Sun Jun 20 19:53:46 EDT 2010
Author: strk
Date: 2010-06-20 23:53:46 +0000 (Sun, 20 Jun 2010)
New Revision: 3042
Modified:
trunk/php/geos.c
trunk/php/test/test.php
Log:
typeName, typeId
Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c 2010-06-20 23:40:21 UTC (rev 3041)
+++ trunk/php/geos.c 2010-06-20 23:53:46 UTC (rev 3042)
@@ -200,6 +200,8 @@
PHP_METHOD(Geometry, isRing);
PHP_METHOD(Geometry, hasZ);
PHP_METHOD(Geometry, isClosed);
+PHP_METHOD(Geometry, typeName);
+PHP_METHOD(Geometry, typeId);
PHP_METHOD(Geometry, numGeometries);
@@ -236,6 +238,8 @@
PHP_ME(Geometry, isRing, NULL, 0)
PHP_ME(Geometry, hasZ, NULL, 0)
PHP_ME(Geometry, isClosed, NULL, 0)
+ PHP_ME(Geometry, typeName, NULL, 0)
+ PHP_ME(Geometry, typeId, NULL, 0)
PHP_ME(Geometry, numGeometries, NULL, 0)
{NULL, NULL, NULL}
@@ -1475,7 +1479,47 @@
RETURN_BOOL(retBool);
}
+/**
+ * string GEOSGeometry::typeName()
+ */
+PHP_METHOD(Geometry, typeName)
+{
+ GEOSGeometry *this;
+ char *typ;
+ char *typVal;
+ this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+ /* TODO: define constant strings instead... */
+
+ typ = GEOSGeomType(this);
+ if ( ! typ ) RETURN_NULL(); /* should get an exception first */
+
+ typVal = estrdup(typ);
+ GEOSFree(typ);
+
+ RETURN_STRING(typVal, 0);
+}
+
+/**
+ * long GEOSGeometry::typeId()
+ */
+PHP_METHOD(Geometry, typeId)
+{
+ GEOSGeometry *this;
+ long typ;
+
+ this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+ /* TODO: define constant strings instead... */
+
+ typ = GEOSGeomTypeId(this);
+ if ( typ == -1 ) RETURN_NULL(); /* should get an exception first */
+
+ RETURN_LONG(typ);
+}
+
+
/* ------ Initialization / Deinitialization / Meta ------------------ */
/* per-module initialization */
Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php 2010-06-20 23:40:21 UTC (rev 3041)
+++ trunk/php/test/test.php 2010-06-20 23:53:46 UTC (rev 3042)
@@ -1258,4 +1258,38 @@
$g = $reader->read('LINESTRING(0 0, 10 0, 5 5, 0 0)');
$this->assertTrue( $g->isClosed() );
}
+
+ public function testGeometry_type()
+ {
+ $reader = new GEOSWKTReader();
+
+ $g = $reader->read('POINT(0 0)');
+ $this->assertEquals('Point', $g->typeName());
+ $this->assertEquals(GEOS_POINT, $g->typeId());
+
+ $g = $reader->read('MULTIPOINT (0 1, 2 3)');
+ $this->assertEquals('MultiPoint', $g->typeName());
+ $this->assertEquals(GEOS_MULTIPOINT, $g->typeId());
+
+ $g = $reader->read('LINESTRING (0 0, 2 3)');
+ $this->assertEquals('LineString', $g->typeName());
+ $this->assertEquals(GEOS_LINESTRING, $g->typeId());
+
+ $g = $reader->read('MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))');
+ $this->assertEquals('MultiLineString', $g->typeName());
+ $this->assertEquals(GEOS_MULTILINESTRING, $g->typeId());
+
+ $g = $reader->read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))');
+ $this->assertEquals('Polygon', $g->typeName());
+ $this->assertEquals(GEOS_POLYGON, $g->typeId());
+
+ $g = $reader->read('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)))');
+ $this->assertEquals('MultiPolygon', $g->typeName());
+ $this->assertEquals(GEOS_MULTIPOLYGON, $g->typeId());
+
+ $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))');
+ $this->assertEquals('GeometryCollection', $g->typeName());
+ $this->assertEquals(GEOS_GEOMETRYCOLLECTION, $g->typeId());
+ }
+
}
More information about the geos-commits
mailing list