[geos-commits] r3071 - in trunk/php: . test
svn_geos at osgeo.org
svn_geos at osgeo.org
Thu Jun 24 05:41:10 EDT 2010
Author: strk
Date: 2010-06-24 09:41:10 +0000 (Thu, 24 Jun 2010)
New Revision: 3071
Modified:
trunk/php/geos.c
trunk/php/test/test.php
Log:
WKBReader: construct and readHEX; improve WKTReader test to include 'Z' label
Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c 2010-06-24 09:20:36 UTC (rev 3070)
+++ trunk/php/geos.c 2010-06-24 09:41:10 UTC (rev 3071)
@@ -2014,7 +2014,80 @@
GEOSWKBWriter_setIncludeSRID(writer, inc);
}
+/* -- class GEOSWKBReader -------------------- */
+PHP_METHOD(WKBReader, __construct);
+PHP_METHOD(WKBReader, readHEX);
+
+static function_entry WKBReader_methods[] = {
+ PHP_ME(WKBReader, __construct, NULL, 0)
+ PHP_ME(WKBReader, readHEX, NULL, 0)
+ {NULL, NULL, NULL}
+};
+
+static zend_class_entry *WKBReader_ce_ptr;
+
+static zend_object_handlers WKBReader_object_handlers;
+
+static void
+WKBReader_dtor (void *object TSRMLS_DC)
+{
+ Proxy *obj = (Proxy *)object;
+ GEOSWKBReader_destroy((GEOSWKBReader*)obj->relay);
+
+ zend_hash_destroy(obj->std.properties);
+ FREE_HASHTABLE(obj->std.properties);
+
+ efree(obj);
+}
+
+static zend_object_value
+WKBReader_create_obj (zend_class_entry *type TSRMLS_DC)
+{
+ return Gen_create_obj(type, WKBReader_dtor, &WKBReader_object_handlers);
+}
+
+
+PHP_METHOD(WKBReader, __construct)
+{
+ GEOSWKBReader* obj;
+ zval *object = getThis();
+
+ obj = GEOSWKBReader_create();
+ if ( ! obj ) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR,
+ "GEOSWKBReader_create() failed (didn't initGEOS?)");
+ }
+
+ setRelay(object, obj);
+}
+
+PHP_METHOD(WKBReader, readHEX)
+{
+ GEOSWKBReader *reader;
+ GEOSGeometry *geom;
+ unsigned char* wkb;
+ int wkblen;
+
+ reader = (GEOSWKBReader*)getRelay(getThis(), WKBReader_ce_ptr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
+ &wkb, &wkblen) == FAILURE)
+ {
+ RETURN_NULL();
+ }
+
+ geom = GEOSWKBReader_readHEX(reader, wkb, wkblen);
+ /* we'll probably get an exception if geom is null */
+ if ( ! geom ) RETURN_NULL();
+
+ /* return_value is a zval */
+ object_init_ex(return_value, Geometry_ce_ptr);
+ setRelay(return_value, geom);
+
+}
+
+
/* -- Free functions ------------------------- */
/**
@@ -2164,7 +2237,15 @@
zend_get_std_object_handlers(), sizeof(zend_object_handlers));
WKBWriter_object_handlers.clone_obj = NULL;
+ /* WKBReader */
+ INIT_CLASS_ENTRY(ce, "GEOSWKBReader", WKBReader_methods);
+ WKBReader_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
+ WKBReader_ce_ptr->create_object = WKBReader_create_obj;
+ memcpy(&WKBReader_object_handlers,
+ zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ WKBReader_object_handlers.clone_obj = NULL;
+
/* Constants */
REGISTER_LONG_CONSTANT("GEOSBUF_CAP_ROUND", GEOSBUF_CAP_ROUND,
CONST_CS|CONST_PERSISTENT);
Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php 2010-06-24 09:20:36 UTC (rev 3070)
+++ trunk/php/test/test.php 2010-06-24 09:41:10 UTC (rev 3071)
@@ -48,10 +48,16 @@
/* Good WKT */
$geom = $reader->read('POINT(0 0)');
$this->assertNotNull($geom);
+ $geom = $reader->read('POINT(0 0 0)');
+ $this->assertNotNull($geom);
+ $geom = $reader->read('POINT Z (0 0 0)');
+ $this->assertNotNull($geom);
$geom = $reader->read('POINT EMPTY');
$this->assertNotNull($geom);
$geom = $reader->read('MULTIPOINT(0 0 1, 2 3 4)');
$this->assertNotNull($geom);
+ $geom = $reader->read('MULTIPOINT Z (0 0 1, 2 3 4)');
+ $this->assertNotNull($geom);
$geom = $reader->read('MULTIPOINT((0 0), (2 3))');
$this->assertNotNull($geom);
$geom = $reader->read('MULTIPOINT EMPTY');
@@ -63,6 +69,9 @@
$geom = $reader->read('MULTILINESTRING((0 0 1, 2 3 4),
(10 10 2, 3 4 5))');
$this->assertNotNull($geom);
+ $geom = $reader->read('MULTILINESTRING Z ((0 0 1, 2 3 4),
+ (10 10 2, 3 4 5))');
+ $this->assertNotNull($geom);
$geom = $reader->read('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))');
$this->assertNotNull($geom);
$geom = $reader->read('POLYGON EMPTY');
@@ -1896,4 +1905,70 @@
$writer->writeHEX($g));
$writer->setIncludeSRID(FALSE);
}
+
+ public function testWKBReader__construct()
+ {
+ $reader = new GEOSWKBReader();
+ $this->assertNotNull($reader);
+ }
+
+ public function testWKBReader_readHEX()
+ {
+ $reader = new GEOSWKBReader();
+
+ $writer = new GEOSWKTWriter();
+ $writer->setTrim(TRUE);
+ $writer->setOutputDimension(3);
+
+
+ // 2D LITTLE endian
+ $g = $reader->readHEX(
+ '010100000000000000000018400000000000001C40'
+ );
+ $this->assertEquals('POINT (6 7)', $writer->write($g));
+ $this->assertEquals(0, $g->getSRID());
+
+ // 2D BIG endian
+ $g = $reader->readHEX(
+ '00000000014018000000000000401C000000000000'
+ );
+ $this->assertEquals('POINT (6 7)', $writer->write($g));
+ $this->assertEquals(0, $g->getSRID());
+
+ // 2D LITTLE endian + SRID
+ $g = $reader->readHEX(
+ '01010000202B00000000000000000018400000000000001C40'
+ );
+ $this->assertEquals('POINT (6 7)', $writer->write($g));
+ $this->assertEquals(43, $g->getSRID());
+
+ // 2D BIG endian + SRID
+ $g = $reader->readHEX(
+ '00200000010000002B4018000000000000401C000000000000'
+ );
+ $this->assertEquals('POINT (6 7)', $writer->write($g));
+ $this->assertEquals(43, $g->getSRID());
+
+ // 3D LITTLE endian
+ $g = $reader->readHEX(
+ '010100008000000000000018400000000000001C400000000000002040'
+ );
+ $this->assertEquals('POINT Z (6 7 8)', $writer->write($g));
+ $this->assertEquals(0, $g->getSRID());
+
+ // 3D BIG endian
+ $g = $reader->readHEX(
+ '00800000014018000000000000401C0000000000004020000000000000'
+ );
+ $this->assertEquals('POINT Z (6 7 8)', $writer->write($g));
+ $this->assertEquals(0, $g->getSRID());
+
+ // 3D BIG endian + SRID
+ $g = $reader->readHEX(
+ '00A0000001000000354018000000000000401C0000000000004020000000000000'
+ );
+ $this->assertEquals('POINT Z (6 7 8)', $writer->write($g));
+ $this->assertEquals(53, $g->getSRID());
+
+ }
}
More information about the geos-commits
mailing list