#641 - distinguish between active and inactive group and add Regina Obe to list.
[geos.git] / php / geos.c
blobbd4d89ec65a7a2467584e7150d141c63b6716b6e
1 /***********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://trac.osgeo.org/geos
6 * Copyright (C) 2010 Sandro Santilli <strk@keybit.net>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301 USA
23 ***********************************************************************/
25 /* PHP stuff */
26 #include "php.h"
27 #include "ext/standard/info.h" /* for php_info_... */
28 #include "Zend/zend_exceptions.h" /* for zend_throw_exception_object */
30 /* GEOS stuff */
31 #include "geos_c.h"
33 /* Own stuff */
34 #include "php_geos.h"
36 PHP_MINIT_FUNCTION(geos);
37 PHP_MSHUTDOWN_FUNCTION(geos);
38 PHP_RINIT_FUNCTION(geos);
39 PHP_RSHUTDOWN_FUNCTION(geos);
40 PHP_MINFO_FUNCTION(geos);
41 PHP_FUNCTION(GEOSVersion);
42 PHP_FUNCTION(GEOSPolygonize);
43 PHP_FUNCTION(GEOSLineMerge);
44 PHP_FUNCTION(GEOSSharedPaths);
45 PHP_FUNCTION(GEOSRelateMatch);
47 #if PHP_VERSION_ID < 50399
48 #define zend_function_entry function_entry
49 #endif
51 static zend_function_entry geos_functions[] = {
52 PHP_FE(GEOSVersion, NULL)
53 PHP_FE(GEOSPolygonize, NULL)
54 PHP_FE(GEOSLineMerge, NULL)
55 PHP_FE(GEOSSharedPaths, NULL)
56 PHP_FE(GEOSRelateMatch, NULL)
57 {NULL, NULL, NULL}
60 zend_module_entry geos_module_entry = {
61 STANDARD_MODULE_HEADER,
62 PHP_GEOS_EXTNAME,
63 geos_functions,
64 PHP_MINIT(geos), /* module init function */
65 PHP_MSHUTDOWN(geos), /* module shutdown function */
66 PHP_RINIT(geos), /* request init function */
67 PHP_RSHUTDOWN(geos), /* request shutdown function */
68 PHP_MINFO(geos), /* module info function */
69 PHP_GEOS_VERSION,
70 STANDARD_MODULE_PROPERTIES
73 #ifdef COMPILE_DL_GEOS
74 ZEND_GET_MODULE(geos)
75 #endif
77 /* -- Utility functions ---------------------- */
79 static void noticeHandler(const char *fmt, ...)
81 char message[256];
82 va_list args;
83 va_start(args, fmt);
84 vsnprintf(message, sizeof(message) - 1, fmt, args);
85 va_end(args);
87 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s", message);
90 static void errorHandler(const char *fmt, ...)
92 char message[256];
93 va_list args;
94 va_start(args, fmt);
95 vsnprintf(message, sizeof(message) - 1, fmt, args);
96 va_end(args);
98 /* TODO: use a GEOSException ? */
99 zend_throw_exception_ex(zend_exception_get_default(TSRMLS_CC),
100 1 TSRMLS_CC, "%s", message);
104 typedef struct Proxy_t {
105 zend_object std;
106 void* relay;
107 } Proxy;
109 static void
110 setRelay(zval* val, void* obj) {
111 Proxy* proxy = (Proxy*)zend_object_store_get_object(val TSRMLS_CC);
112 proxy->relay = obj;
115 static inline void *
116 getRelay(zval* val, zend_class_entry* ce) {
117 Proxy *proxy = (Proxy*)zend_object_store_get_object(val TSRMLS_CC);
118 if ( proxy->std.ce != ce ) {
119 php_error_docref(NULL TSRMLS_CC, E_ERROR,
120 "Relay object is not an %s", ce->name);
122 if ( ! proxy->relay ) {
123 php_error_docref(NULL TSRMLS_CC, E_ERROR,
124 "Relay object for object of type %s is not set", ce->name);
126 return proxy->relay;
129 static long getZvalAsLong(zval* val)
131 long ret;
132 zval tmp;
134 tmp = *val;
135 zval_copy_ctor(&tmp);
136 convert_to_long(&tmp);
137 ret = Z_LVAL(tmp);
138 zval_dtor(&tmp);
139 return ret;
142 static long getZvalAsDouble(zval* val)
144 double ret;
145 zval tmp;
147 tmp = *val;
148 zval_copy_ctor(&tmp);
149 convert_to_double(&tmp);
150 ret = Z_DVAL(tmp);
151 zval_dtor(&tmp);
152 return ret;
155 static zend_object_value
156 Gen_create_obj (zend_class_entry *type TSRMLS_DC,
157 zend_objects_free_object_storage_t st, zend_object_handlers* handlers)
159 zval *tmp;
160 zend_object_value retval;
162 Proxy *obj = (Proxy *)emalloc(sizeof(Proxy));
163 memset(obj, 0, sizeof(Proxy));
164 obj->std.ce = type;
166 ALLOC_HASHTABLE(obj->std.properties);
167 zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
168 #if PHP_VERSION_ID < 50399
169 zend_hash_copy(obj->std.properties, &type->default_properties,
170 (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *));
171 #else
172 object_properties_init(&(obj->std), type);
173 #endif
175 retval.handle = zend_objects_store_put(obj, NULL, st, NULL TSRMLS_CC);
176 retval.handlers = handlers;
178 return retval;
182 /* -- class GEOSGeometry -------------------- */
184 PHP_METHOD(Geometry, __construct);
185 PHP_METHOD(Geometry, __toString);
186 PHP_METHOD(Geometry, project);
187 PHP_METHOD(Geometry, interpolate);
188 PHP_METHOD(Geometry, buffer);
189 PHP_METHOD(Geometry, offsetCurve);
190 PHP_METHOD(Geometry, envelope);
191 PHP_METHOD(Geometry, intersection);
192 PHP_METHOD(Geometry, convexHull);
193 PHP_METHOD(Geometry, difference);
194 PHP_METHOD(Geometry, symDifference);
195 PHP_METHOD(Geometry, boundary);
196 PHP_METHOD(Geometry, union); /* also does union cascaded */
197 PHP_METHOD(Geometry, pointOnSurface);
198 PHP_METHOD(Geometry, centroid);
199 PHP_METHOD(Geometry, relate);
200 PHP_METHOD(Geometry, relateBoundaryNodeRule);
201 PHP_METHOD(Geometry, simplify); /* also does topology-preserving */
202 PHP_METHOD(Geometry, extractUniquePoints);
203 PHP_METHOD(Geometry, disjoint);
204 PHP_METHOD(Geometry, touches);
205 PHP_METHOD(Geometry, intersects);
206 PHP_METHOD(Geometry, crosses);
207 PHP_METHOD(Geometry, within);
208 PHP_METHOD(Geometry, contains);
209 PHP_METHOD(Geometry, overlaps);
210 PHP_METHOD(Geometry, covers);
211 PHP_METHOD(Geometry, coveredBy);
212 PHP_METHOD(Geometry, equals);
213 PHP_METHOD(Geometry, equalsExact);
214 PHP_METHOD(Geometry, isEmpty);
215 PHP_METHOD(Geometry, checkValidity);
216 PHP_METHOD(Geometry, isSimple);
217 PHP_METHOD(Geometry, isRing);
218 PHP_METHOD(Geometry, hasZ);
219 PHP_METHOD(Geometry, isClosed);
220 PHP_METHOD(Geometry, typeName);
221 PHP_METHOD(Geometry, typeId);
222 PHP_METHOD(Geometry, getSRID);
223 PHP_METHOD(Geometry, setSRID);
224 PHP_METHOD(Geometry, numGeometries);
225 PHP_METHOD(Geometry, geometryN);
226 PHP_METHOD(Geometry, numInteriorRings);
227 PHP_METHOD(Geometry, numPoints);
228 PHP_METHOD(Geometry, getX);
229 PHP_METHOD(Geometry, getY);
230 PHP_METHOD(Geometry, interiorRingN);
231 PHP_METHOD(Geometry, exteriorRing);
232 PHP_METHOD(Geometry, numCoordinates);
233 PHP_METHOD(Geometry, dimension);
234 PHP_METHOD(Geometry, coordinateDimension);
235 PHP_METHOD(Geometry, pointN);
236 PHP_METHOD(Geometry, startPoint);
237 PHP_METHOD(Geometry, endPoint);
238 PHP_METHOD(Geometry, area);
239 PHP_METHOD(Geometry, length);
240 PHP_METHOD(Geometry, distance);
241 PHP_METHOD(Geometry, hausdorffDistance);
242 PHP_METHOD(Geometry, snapTo);
243 PHP_METHOD(Geometry, node);
244 PHP_METHOD(Geometry, delaunayTriangulation);
246 static zend_function_entry Geometry_methods[] = {
247 PHP_ME(Geometry, __construct, NULL, 0)
248 PHP_ME(Geometry, __toString, NULL, 0)
249 PHP_ME(Geometry, project, NULL, 0)
250 PHP_ME(Geometry, interpolate, NULL, 0)
251 PHP_ME(Geometry, buffer, NULL, 0)
252 PHP_ME(Geometry, offsetCurve, NULL, 0)
253 PHP_ME(Geometry, envelope, NULL, 0)
254 PHP_ME(Geometry, intersection, NULL, 0)
255 PHP_ME(Geometry, convexHull, NULL, 0)
256 PHP_ME(Geometry, difference, NULL, 0)
257 PHP_ME(Geometry, symDifference, NULL, 0)
258 PHP_ME(Geometry, boundary, NULL, 0)
259 PHP_ME(Geometry, union, NULL, 0)
260 PHP_ME(Geometry, pointOnSurface, NULL, 0)
261 PHP_ME(Geometry, centroid, NULL, 0)
262 PHP_ME(Geometry, relate, NULL, 0)
263 PHP_ME(Geometry, relateBoundaryNodeRule, NULL, 0)
264 PHP_ME(Geometry, simplify, NULL, 0)
265 PHP_ME(Geometry, extractUniquePoints, NULL, 0)
266 PHP_ME(Geometry, disjoint, NULL, 0)
267 PHP_ME(Geometry, touches, NULL, 0)
268 PHP_ME(Geometry, intersects, NULL, 0)
269 PHP_ME(Geometry, crosses, NULL, 0)
270 PHP_ME(Geometry, within, NULL, 0)
271 PHP_ME(Geometry, contains, NULL, 0)
272 PHP_ME(Geometry, overlaps, NULL, 0)
273 PHP_ME(Geometry, covers, NULL, 0)
274 PHP_ME(Geometry, coveredBy, NULL, 0)
275 PHP_ME(Geometry, equals, NULL, 0)
276 PHP_ME(Geometry, equalsExact, NULL, 0)
277 PHP_ME(Geometry, isEmpty, NULL, 0)
278 PHP_ME(Geometry, checkValidity, NULL, 0)
279 PHP_ME(Geometry, isSimple, NULL, 0)
280 PHP_ME(Geometry, isRing, NULL, 0)
281 PHP_ME(Geometry, hasZ, NULL, 0)
282 PHP_ME(Geometry, isClosed, NULL, 0)
283 PHP_ME(Geometry, typeName, NULL, 0)
284 PHP_ME(Geometry, typeId, NULL, 0)
285 PHP_ME(Geometry, getSRID, NULL, 0)
286 PHP_ME(Geometry, setSRID, NULL, 0)
287 PHP_ME(Geometry, numGeometries, NULL, 0)
288 PHP_ME(Geometry, geometryN, NULL, 0)
289 PHP_ME(Geometry, numInteriorRings, NULL, 0)
290 PHP_ME(Geometry, numPoints, NULL, 0)
291 PHP_ME(Geometry, getX, NULL, 0)
292 PHP_ME(Geometry, getY, NULL, 0)
293 PHP_ME(Geometry, interiorRingN, NULL, 0)
294 PHP_ME(Geometry, exteriorRing, NULL, 0)
295 PHP_ME(Geometry, numCoordinates, NULL, 0)
296 PHP_ME(Geometry, dimension, NULL, 0)
297 PHP_ME(Geometry, coordinateDimension, NULL, 0)
298 PHP_ME(Geometry, pointN, NULL, 0)
299 PHP_ME(Geometry, startPoint, NULL, 0)
300 PHP_ME(Geometry, endPoint, NULL, 0)
301 PHP_ME(Geometry, area, NULL, 0)
302 PHP_ME(Geometry, length, NULL, 0)
303 PHP_ME(Geometry, distance, NULL, 0)
304 PHP_ME(Geometry, hausdorffDistance, NULL, 0)
305 PHP_ME(Geometry, snapTo, NULL, 0)
306 PHP_ME(Geometry, node, NULL, 0)
307 PHP_ME(Geometry, delaunayTriangulation, NULL, 0)
308 {NULL, NULL, NULL}
311 static zend_class_entry *Geometry_ce_ptr;
313 static zend_object_handlers Geometry_object_handlers;
315 /* Geometry serializer */
317 static GEOSWKBWriter* Geometry_serializer = 0;
319 static GEOSWKBWriter* getGeometrySerializer()
321 if ( ! Geometry_serializer ) {
322 Geometry_serializer = GEOSWKBWriter_create();
323 GEOSWKBWriter_setIncludeSRID(Geometry_serializer, 1);
324 GEOSWKBWriter_setOutputDimension(Geometry_serializer, 3);
326 return Geometry_serializer;
329 static void delGeometrySerializer()
331 if ( Geometry_serializer ) {
332 GEOSWKBWriter_destroy(Geometry_serializer);
336 /* Geometry deserializer */
338 static GEOSWKBReader* Geometry_deserializer = 0;
340 static GEOSWKBReader* getGeometryDeserializer()
342 if ( ! Geometry_deserializer ) {
343 Geometry_deserializer = GEOSWKBReader_create();
345 return Geometry_deserializer;
348 static void delGeometryDeserializer()
350 if ( Geometry_deserializer ) {
351 GEOSWKBReader_destroy(Geometry_deserializer);
355 /* Serializer function for GEOSGeometry */
357 static int
358 Geometry_serialize(zval *object, unsigned char **buffer, zend_uint *buf_len,
359 zend_serialize_data *data TSRMLS_DC)
361 GEOSWKBWriter *serializer;
362 GEOSGeometry *geom;
363 char* ret;
364 size_t retsize;
367 serializer = getGeometrySerializer();
368 geom = (GEOSGeometry*)getRelay(object, Geometry_ce_ptr);
370 /* NOTE: we might be fine using binary here */
371 ret = (char*)GEOSWKBWriter_writeHEX(serializer, geom, &retsize);
372 /* we'll probably get an exception if ret is null */
373 if ( ! ret ) return FAILURE;
375 *buffer = (unsigned char*)estrndup(ret, retsize);
376 GEOSFree(ret);
378 *buf_len = retsize;
380 return SUCCESS;
383 static int
384 Geometry_deserialize(zval **object, zend_class_entry *ce, const unsigned char *buf,
385 zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC)
387 GEOSWKBReader* deserializer;
388 GEOSGeometry* geom;
390 deserializer = getGeometryDeserializer();
391 geom = GEOSWKBReader_readHEX(deserializer, buf, buf_len);
393 /* TODO: check zend_class_entry being what we expect! */
394 if ( ce != Geometry_ce_ptr ) {
395 php_error_docref(NULL TSRMLS_CC, E_ERROR,
396 "Geometry_deserialize called with unexpected zend_class_entry");
397 return FAILURE;
399 object_init_ex(*object, ce);
400 setRelay(*object, geom);
402 return SUCCESS;
406 * Push components of the given geometry
407 * to the given array zval.
408 * Components geometries are cloned.
409 * NOTE: collection components are not descended into
411 static void
412 dumpGeometry(GEOSGeometry* g, zval* array)
414 int ngeoms, i;
417 MAKE_STD_ZVAL(array);
418 array_init(array);
421 ngeoms = GEOSGetNumGeometries(g);
422 for (i=0; i<ngeoms; ++i)
424 zval *tmp;
425 GEOSGeometry* cc;
426 const GEOSGeometry* c = GEOSGetGeometryN(g, i);
427 if ( ! c ) continue; /* should get an exception */
428 /* we _need_ to clone as this one is owned by 'g' */
429 cc = GEOSGeom_clone(c);
430 if ( ! cc ) continue; /* should get an exception */
432 MAKE_STD_ZVAL(tmp);
433 object_init_ex(tmp, Geometry_ce_ptr);
434 setRelay(tmp, cc);
435 add_next_index_zval(array, tmp);
440 static void
441 Geometry_dtor (void *object TSRMLS_DC)
443 Proxy *obj = (Proxy *)object;
444 GEOSGeom_destroy((GEOSGeometry*)obj->relay);
446 zend_hash_destroy(obj->std.properties);
447 FREE_HASHTABLE(obj->std.properties);
449 efree(obj);
452 static zend_object_value
453 Geometry_create_obj (zend_class_entry *type TSRMLS_DC)
455 return Gen_create_obj(type, Geometry_dtor, &Geometry_object_handlers);
459 PHP_METHOD(Geometry, __construct)
461 php_error_docref(NULL TSRMLS_CC, E_ERROR,
462 "GEOSGeometry can't be constructed using new, check WKTReader");
466 PHP_METHOD(Geometry, __toString)
468 GEOSGeometry *geom;
469 GEOSWKTWriter *writer;
470 char *wkt;
471 char *ret;
473 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
474 writer = GEOSWKTWriter_create();
475 /* NOTE: if we get an exception before reaching
476 * GEOSWKTWriter_destory below we'll be leaking memory.
477 * One fix could be storing the object in a refcounted
478 * zval.
480 GEOSWKTWriter_setTrim(writer, 1);
482 wkt = GEOSWKTWriter_write(writer, geom);
483 /* we'll probably get an exception if wkt is null */
484 if ( ! wkt ) RETURN_NULL();
486 GEOSWKTWriter_destroy(writer);
489 ret = estrdup(wkt);
490 GEOSFree(wkt);
492 RETURN_STRING(ret, 0);
495 PHP_METHOD(Geometry, project)
497 GEOSGeometry *this;
498 GEOSGeometry *other;
499 zval *zobj;
500 zend_bool normalized = 0;
501 double ret;
503 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
505 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|b", &zobj,
506 &normalized) == FAILURE) {
507 RETURN_NULL();
509 other = getRelay(zobj, Geometry_ce_ptr);
511 if ( normalized ) {
512 ret = GEOSProjectNormalized(this, other);
513 } else {
514 ret = GEOSProject(this, other);
516 if ( ret < 0 ) RETURN_NULL(); /* should get an exception first */
518 RETURN_DOUBLE(ret);
521 PHP_METHOD(Geometry, interpolate)
523 GEOSGeometry *this;
524 double dist;
525 GEOSGeometry *ret;
526 zend_bool normalized = 0;
528 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
530 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|b",
531 &dist, &normalized) == FAILURE) {
532 RETURN_NULL();
535 if ( normalized ) {
536 ret = GEOSInterpolateNormalized(this, dist);
537 } else {
538 ret = GEOSInterpolate(this, dist);
540 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
542 /* return_value is a zval */
543 object_init_ex(return_value, Geometry_ce_ptr);
544 setRelay(return_value, ret);
548 * GEOSGeometry::buffer(dist, [<styleArray>])
550 * styleArray keys supported:
551 * 'quad_segs'
552 * Type: int
553 * Number of segments used to approximate
554 * a quarter circle (defaults to 8).
555 * 'endcap'
556 * Type: long
557 * Endcap style (defaults to GEOSBUF_CAP_ROUND)
558 * 'join'
559 * Type: long
560 * Join style (defaults to GEOSBUF_JOIN_ROUND)
561 * 'mitre_limit'
562 * Type: double
563 * mitre ratio limit (only affects joins with GEOSBUF_JOIN_MITRE style)
564 * 'miter_limit' is also accepted as a synonym for 'mitre_limit'.
565 * 'single_sided'
566 * Type: bool
567 * If true buffer lines only on one side, so that the input line
568 * will be a portion of the boundary of the returned polygon.
569 * Only applies to lineal input. Defaults to false.
571 PHP_METHOD(Geometry, buffer)
573 GEOSGeometry *this;
574 double dist;
575 GEOSGeometry *ret;
576 GEOSBufferParams *params;
577 static const double default_mitreLimit = 5.0;
578 static const int default_endCapStyle = GEOSBUF_CAP_ROUND;
579 static const int default_joinStyle = GEOSBUF_JOIN_ROUND;
580 static const int default_quadSegs = 8;
581 long int quadSegs = default_quadSegs;
582 long int endCapStyle = default_endCapStyle;
583 long int joinStyle = default_joinStyle;
584 double mitreLimit = default_mitreLimit;
585 long singleSided = 0;
586 zval *style_val = NULL;
587 zval **data;
588 HashTable *style;
589 char *key;
590 ulong index;
592 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
594 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|a",
595 &dist, &style_val) == FAILURE) {
596 RETURN_NULL();
599 params = GEOSBufferParams_create();
601 if ( style_val )
603 style = HASH_OF(style_val);
604 while(zend_hash_get_current_key(style, &key, &index, 0)
605 == HASH_KEY_IS_STRING)
607 if(!strcmp(key, "quad_segs"))
609 zend_hash_get_current_data(style, (void**)&data);
610 quadSegs = getZvalAsLong(*data);
611 GEOSBufferParams_setQuadrantSegments(params, quadSegs);
613 else if(!strcmp(key, "endcap"))
615 zend_hash_get_current_data(style, (void**)&data);
616 endCapStyle = getZvalAsLong(*data);
617 GEOSBufferParams_setEndCapStyle(params, endCapStyle);
619 else if(!strcmp(key, "join"))
621 zend_hash_get_current_data(style, (void**)&data);
622 joinStyle = getZvalAsLong(*data);
623 GEOSBufferParams_setJoinStyle(params, joinStyle);
625 else if(!strcmp(key, "mitre_limit"))
627 zend_hash_get_current_data(style, (void**)&data);
628 mitreLimit = getZvalAsDouble(*data);
629 GEOSBufferParams_setMitreLimit(params, mitreLimit);
631 else if(!strcmp(key, "single_sided"))
633 zend_hash_get_current_data(style, (void**)&data);
634 singleSided = getZvalAsLong(*data);
635 GEOSBufferParams_setSingleSided(params, singleSided);
638 zend_hash_move_forward(style);
642 ret = GEOSBufferWithParams(this, params, dist);
643 GEOSBufferParams_destroy(params);
644 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
646 /* return_value is a zval */
647 object_init_ex(return_value, Geometry_ce_ptr);
648 setRelay(return_value, ret);
652 * GEOSGeometry::offsetCurve(dist, [<styleArray>])
654 * styleArray keys supported:
655 * 'quad_segs'
656 * Type: int
657 * Number of segments used to approximate
658 * a quarter circle (defaults to 8).
659 * 'join'
660 * Type: long
661 * Join style (defaults to GEOSBUF_JOIN_ROUND)
662 * 'mitre_limit'
663 * Type: double
664 * mitre ratio limit (only affects joins with GEOSBUF_JOIN_MITRE style)
665 * 'miter_limit' is also accepted as a synonym for 'mitre_limit'.
667 PHP_METHOD(Geometry, offsetCurve)
669 GEOSGeometry *this;
670 double dist;
671 GEOSGeometry *ret;
672 static const double default_mitreLimit = 5.0;
673 static const int default_joinStyle = GEOSBUF_JOIN_ROUND;
674 static const int default_quadSegs = 8;
675 long int quadSegs = default_quadSegs;
676 long int joinStyle = default_joinStyle;
677 double mitreLimit = default_mitreLimit;
678 zval *style_val = NULL;
679 zval **data;
680 HashTable *style;
681 char *key;
682 ulong index;
684 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
686 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|a",
687 &dist, &style_val) == FAILURE) {
688 RETURN_NULL();
691 if ( style_val )
693 style = HASH_OF(style_val);
694 while(zend_hash_get_current_key(style, &key, &index, 0)
695 == HASH_KEY_IS_STRING)
697 if(!strcmp(key, "quad_segs"))
699 zend_hash_get_current_data(style, (void**)&data);
700 quadSegs = getZvalAsLong(*data);
702 else if(!strcmp(key, "join"))
704 zend_hash_get_current_data(style, (void**)&data);
705 joinStyle = getZvalAsLong(*data);
707 else if(!strcmp(key, "mitre_limit"))
709 zend_hash_get_current_data(style, (void**)&data);
710 mitreLimit = getZvalAsDouble(*data);
713 zend_hash_move_forward(style);
717 ret = GEOSOffsetCurve(this, dist, quadSegs, joinStyle, mitreLimit);
718 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
720 /* return_value is a zval */
721 object_init_ex(return_value, Geometry_ce_ptr);
722 setRelay(return_value, ret);
725 PHP_METHOD(Geometry, envelope)
727 GEOSGeometry *this;
728 GEOSGeometry *ret;
730 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
732 ret = GEOSEnvelope(this);
733 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
735 /* return_value is a zval */
736 object_init_ex(return_value, Geometry_ce_ptr);
737 setRelay(return_value, ret);
740 PHP_METHOD(Geometry, intersection)
742 GEOSGeometry *this;
743 GEOSGeometry *other;
744 GEOSGeometry *ret;
745 zval *zobj;
747 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
749 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
750 == FAILURE) {
751 RETURN_NULL();
753 other = getRelay(zobj, Geometry_ce_ptr);
755 ret = GEOSIntersection(this, other);
756 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
758 /* return_value is a zval */
759 object_init_ex(return_value, Geometry_ce_ptr);
760 setRelay(return_value, ret);
763 PHP_METHOD(Geometry, convexHull)
765 GEOSGeometry *this;
766 GEOSGeometry *ret;
768 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
770 ret = GEOSConvexHull(this);
771 if ( ret == NULL ) RETURN_NULL(); /* should get an exception first */
773 /* return_value is a zval */
774 object_init_ex(return_value, Geometry_ce_ptr);
775 setRelay(return_value, ret);
778 PHP_METHOD(Geometry, difference)
780 GEOSGeometry *this;
781 GEOSGeometry *other;
782 GEOSGeometry *ret;
783 zval *zobj;
785 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
787 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
788 == FAILURE) {
789 RETURN_NULL();
791 other = getRelay(zobj, Geometry_ce_ptr);
793 ret = GEOSDifference(this, other);
794 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
796 /* return_value is a zval */
797 object_init_ex(return_value, Geometry_ce_ptr);
798 setRelay(return_value, ret);
801 PHP_METHOD(Geometry, symDifference)
803 GEOSGeometry *this;
804 GEOSGeometry *other;
805 GEOSGeometry *ret;
806 zval *zobj;
808 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
810 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
811 == FAILURE) {
812 RETURN_NULL();
814 other = getRelay(zobj, Geometry_ce_ptr);
816 ret = GEOSSymDifference(this, other);
817 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
819 /* return_value is a zval */
820 object_init_ex(return_value, Geometry_ce_ptr);
821 setRelay(return_value, ret);
824 PHP_METHOD(Geometry, boundary)
826 GEOSGeometry *this;
827 GEOSGeometry *ret;
829 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
831 ret = GEOSBoundary(this);
832 if ( ret == NULL ) RETURN_NULL(); /* should get an exception first */
834 /* return_value is a zval */
835 object_init_ex(return_value, Geometry_ce_ptr);
836 setRelay(return_value, ret);
840 * GEOSGeometry::union(otherGeom)
841 * GEOSGeometry::union()
843 PHP_METHOD(Geometry, union)
845 GEOSGeometry *this;
846 GEOSGeometry *other;
847 GEOSGeometry *ret;
848 zval *zobj = NULL;
850 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
852 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|o", &zobj)
853 == FAILURE) {
854 RETURN_NULL();
857 if ( zobj ) {
858 other = getRelay(zobj, Geometry_ce_ptr);
859 ret = GEOSUnion(this, other);
860 } else {
861 ret = GEOSUnaryUnion(this);
864 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
866 /* return_value is a zval */
867 object_init_ex(return_value, Geometry_ce_ptr);
868 setRelay(return_value, ret);
872 * GEOSGeometry::pointOnSurface()
874 PHP_METHOD(Geometry, pointOnSurface)
876 GEOSGeometry *this;
877 GEOSGeometry *ret;
879 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
881 ret = GEOSPointOnSurface(this);
882 if ( ret == NULL ) RETURN_NULL(); /* should get an exception first */
884 /* return_value is a zval */
885 object_init_ex(return_value, Geometry_ce_ptr);
886 setRelay(return_value, ret);
890 * GEOSGeometry::centroid()
892 PHP_METHOD(Geometry, centroid)
894 GEOSGeometry *this;
895 GEOSGeometry *ret;
897 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
899 ret = GEOSGetCentroid(this);
900 if ( ret == NULL ) RETURN_NULL(); /* should get an exception first */
902 /* return_value is a zval */
903 object_init_ex(return_value, Geometry_ce_ptr);
904 setRelay(return_value, ret);
908 * GEOSGeometry::relate(otherGeom)
909 * GEOSGeometry::relate(otherGeom, pattern)
911 PHP_METHOD(Geometry, relate)
913 GEOSGeometry *this;
914 GEOSGeometry *other;
915 zval *zobj;
916 char* pat = NULL;
917 int patlen;
918 int retInt;
919 zend_bool retBool;
920 char* retStr;
922 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
924 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|s",
925 &zobj, &pat, &patlen) == FAILURE)
927 RETURN_NULL();
930 other = getRelay(zobj, Geometry_ce_ptr);
932 if ( ! pat ) {
933 /* we'll compute it */
934 pat = GEOSRelate(this, other);
935 if ( ! pat ) RETURN_NULL(); /* should get an exception first */
936 retStr = estrdup(pat);
937 GEOSFree(pat);
938 RETURN_STRING(retStr, 0);
939 } else {
940 retInt = GEOSRelatePattern(this, other, pat);
941 if ( retInt == 2 ) RETURN_NULL(); /* should get an exception first */
942 retBool = retInt;
943 RETURN_BOOL(retBool);
949 * GEOSGeometry::relateBoundaryNodeRule(otherGeom, rule)
951 PHP_METHOD(Geometry, relateBoundaryNodeRule)
953 GEOSGeometry *this;
954 GEOSGeometry *other;
955 zval *zobj;
956 char* pat;
957 long int bnr = GEOSRELATE_BNR_OGC;
958 char* retStr;
960 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
962 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ol",
963 &zobj, &bnr) == FAILURE)
965 RETURN_NULL();
968 other = getRelay(zobj, Geometry_ce_ptr);
970 /* we'll compute it */
971 pat = GEOSRelateBoundaryNodeRule(this, other, bnr);
972 if ( ! pat ) RETURN_NULL(); /* should get an exception first */
973 retStr = estrdup(pat);
974 GEOSFree(pat);
975 RETURN_STRING(retStr, 0);
979 * GEOSGeometry GEOSGeometry::simplify(tolerance)
980 * GEOSGeometry GEOSGeometry::simplify(tolerance, preserveTopology)
982 PHP_METHOD(Geometry, simplify)
984 GEOSGeometry *this;
985 double tolerance;
986 zend_bool preserveTopology = 0;
987 GEOSGeometry *ret;
989 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
991 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|b",
992 &tolerance, &preserveTopology) == FAILURE) {
993 RETURN_NULL();
996 if ( preserveTopology ) {
997 ret = GEOSTopologyPreserveSimplify(this, tolerance);
998 } else {
999 ret = GEOSSimplify(this, tolerance);
1002 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
1004 /* return_value is a zval */
1005 object_init_ex(return_value, Geometry_ce_ptr);
1006 setRelay(return_value, ret);
1010 * GEOSGeometry GEOSGeometry::extractUniquePoints()
1012 PHP_METHOD(Geometry, extractUniquePoints)
1014 GEOSGeometry *this;
1015 GEOSGeometry *ret;
1017 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1019 ret = GEOSGeom_extractUniquePoints(this);
1020 if ( ret == NULL ) RETURN_NULL(); /* should get an exception first */
1022 /* return_value is a zval */
1023 object_init_ex(return_value, Geometry_ce_ptr);
1024 setRelay(return_value, ret);
1028 * bool GEOSGeometry::disjoint(GEOSGeometry)
1030 PHP_METHOD(Geometry, disjoint)
1032 GEOSGeometry *this;
1033 GEOSGeometry *other;
1034 int ret;
1035 zend_bool retBool;
1036 zval *zobj;
1038 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1040 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
1041 == FAILURE) {
1042 RETURN_NULL();
1044 other = getRelay(zobj, Geometry_ce_ptr);
1046 ret = GEOSDisjoint(this, other);
1047 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1049 /* return_value is a zval */
1050 retBool = ret;
1051 RETURN_BOOL(retBool);
1055 * bool GEOSGeometry::touches(GEOSGeometry)
1057 PHP_METHOD(Geometry, touches)
1059 GEOSGeometry *this;
1060 GEOSGeometry *other;
1061 int ret;
1062 zend_bool retBool;
1063 zval *zobj;
1065 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1067 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
1068 == FAILURE) {
1069 RETURN_NULL();
1071 other = getRelay(zobj, Geometry_ce_ptr);
1073 ret = GEOSTouches(this, other);
1074 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1076 /* return_value is a zval */
1077 retBool = ret;
1078 RETURN_BOOL(retBool);
1082 * bool GEOSGeometry::intersects(GEOSGeometry)
1084 PHP_METHOD(Geometry, intersects)
1086 GEOSGeometry *this;
1087 GEOSGeometry *other;
1088 int ret;
1089 zend_bool retBool;
1090 zval *zobj;
1092 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1094 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
1095 == FAILURE) {
1096 RETURN_NULL();
1098 other = getRelay(zobj, Geometry_ce_ptr);
1100 ret = GEOSIntersects(this, other);
1101 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1103 /* return_value is a zval */
1104 retBool = ret;
1105 RETURN_BOOL(retBool);
1109 * bool GEOSGeometry::crosses(GEOSGeometry)
1111 PHP_METHOD(Geometry, crosses)
1113 GEOSGeometry *this;
1114 GEOSGeometry *other;
1115 int ret;
1116 zend_bool retBool;
1117 zval *zobj;
1119 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1121 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
1122 == FAILURE) {
1123 RETURN_NULL();
1125 other = getRelay(zobj, Geometry_ce_ptr);
1127 ret = GEOSCrosses(this, other);
1128 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1130 /* return_value is a zval */
1131 retBool = ret;
1132 RETURN_BOOL(retBool);
1136 * bool GEOSGeometry::within(GEOSGeometry)
1138 PHP_METHOD(Geometry, within)
1140 GEOSGeometry *this;
1141 GEOSGeometry *other;
1142 int ret;
1143 zend_bool retBool;
1144 zval *zobj;
1146 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1148 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
1149 == FAILURE) {
1150 RETURN_NULL();
1152 other = getRelay(zobj, Geometry_ce_ptr);
1154 ret = GEOSWithin(this, other);
1155 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1157 /* return_value is a zval */
1158 retBool = ret;
1159 RETURN_BOOL(retBool);
1163 * bool GEOSGeometry::contains(GEOSGeometry)
1165 PHP_METHOD(Geometry, contains)
1167 GEOSGeometry *this;
1168 GEOSGeometry *other;
1169 int ret;
1170 zend_bool retBool;
1171 zval *zobj;
1173 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1175 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
1176 == FAILURE) {
1177 RETURN_NULL();
1179 other = getRelay(zobj, Geometry_ce_ptr);
1181 ret = GEOSContains(this, other);
1182 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1184 /* return_value is a zval */
1185 retBool = ret;
1186 RETURN_BOOL(retBool);
1190 * bool GEOSGeometry::overlaps(GEOSGeometry)
1192 PHP_METHOD(Geometry, overlaps)
1194 GEOSGeometry *this;
1195 GEOSGeometry *other;
1196 int ret;
1197 zend_bool retBool;
1198 zval *zobj;
1200 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1202 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
1203 == FAILURE) {
1204 RETURN_NULL();
1206 other = getRelay(zobj, Geometry_ce_ptr);
1208 ret = GEOSOverlaps(this, other);
1209 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1211 /* return_value is a zval */
1212 retBool = ret;
1213 RETURN_BOOL(retBool);
1217 * bool GEOSGeometry::covers(GEOSGeometry)
1219 PHP_METHOD(Geometry, covers)
1221 GEOSGeometry *this;
1222 GEOSGeometry *other;
1223 int ret;
1224 zend_bool retBool;
1225 zval *zobj;
1227 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1229 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
1230 == FAILURE) {
1231 RETURN_NULL();
1233 other = getRelay(zobj, Geometry_ce_ptr);
1235 ret = GEOSCovers(this, other);
1236 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1238 /* return_value is a zval */
1239 retBool = ret;
1240 RETURN_BOOL(retBool);
1244 * bool GEOSGeometry::coveredBy(GEOSGeometry)
1246 PHP_METHOD(Geometry, coveredBy)
1248 GEOSGeometry *this;
1249 GEOSGeometry *other;
1250 int ret;
1251 zend_bool retBool;
1252 zval *zobj;
1254 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1256 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
1257 == FAILURE) {
1258 RETURN_NULL();
1260 other = getRelay(zobj, Geometry_ce_ptr);
1262 ret = GEOSCoveredBy(this, other);
1263 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1265 /* return_value is a zval */
1266 retBool = ret;
1267 RETURN_BOOL(retBool);
1271 * bool GEOSGeometry::equals(GEOSGeometry)
1273 PHP_METHOD(Geometry, equals)
1275 GEOSGeometry *this;
1276 GEOSGeometry *other;
1277 int ret;
1278 zend_bool retBool;
1279 zval *zobj;
1281 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1283 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o",
1284 &zobj) == FAILURE) {
1285 RETURN_NULL();
1287 other = getRelay(zobj, Geometry_ce_ptr);
1289 ret = GEOSEquals(this, other);
1290 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1292 /* return_value is a zval */
1293 retBool = ret;
1294 RETURN_BOOL(retBool);
1298 * bool GEOSGeometry::equalsExact(GEOSGeometry)
1299 * bool GEOSGeometry::equalsExact(GEOSGeometry, double tolerance)
1301 PHP_METHOD(Geometry, equalsExact)
1303 GEOSGeometry *this;
1304 GEOSGeometry *other;
1305 int ret;
1306 double tolerance = 0;
1307 zend_bool retBool;
1308 zval *zobj;
1310 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1312 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|d",
1313 &zobj, &tolerance) == FAILURE) {
1314 RETURN_NULL();
1316 other = getRelay(zobj, Geometry_ce_ptr);
1318 ret = GEOSEqualsExact(this, other, tolerance);
1319 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1321 /* return_value is a zval */
1322 retBool = ret;
1323 RETURN_BOOL(retBool);
1327 * bool GEOSGeometry::isEmpty()
1329 PHP_METHOD(Geometry, isEmpty)
1331 GEOSGeometry *this;
1332 int ret;
1333 zend_bool retBool;
1335 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1337 ret = GEOSisEmpty(this);
1338 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1340 /* return_value is a zval */
1341 retBool = ret;
1342 RETURN_BOOL(retBool);
1346 * array GEOSGeometry::checkValidity()
1348 PHP_METHOD(Geometry, checkValidity)
1350 GEOSGeometry *this;
1351 GEOSGeometry *location = NULL;
1352 int ret;
1353 char *reason = NULL;
1354 zend_bool retBool;
1355 char *reasonVal = NULL;
1356 zval *locationVal = NULL;
1357 long int flags = 0;
1359 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1361 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l",
1362 &flags) == FAILURE) {
1363 RETURN_NULL();
1366 ret = GEOSisValidDetail(this, flags, &reason, &location);
1367 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1369 if ( reason ) {
1370 reasonVal = estrdup(reason);
1371 GEOSFree(reason);
1374 if ( location ) {
1375 MAKE_STD_ZVAL(locationVal);
1376 object_init_ex(locationVal, Geometry_ce_ptr);
1377 setRelay(locationVal, location);
1380 retBool = ret;
1382 /* return value is an array */
1383 array_init(return_value);
1384 add_assoc_bool(return_value, "valid", retBool);
1385 if ( reasonVal ) add_assoc_string(return_value, "reason", reasonVal, 0);
1386 if ( locationVal ) add_assoc_zval(return_value, "location", locationVal);
1391 * bool GEOSGeometry::isSimple()
1393 PHP_METHOD(Geometry, isSimple)
1395 GEOSGeometry *this;
1396 int ret;
1397 zend_bool retBool;
1399 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1401 ret = GEOSisSimple(this);
1402 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1404 /* return_value is a zval */
1405 retBool = ret;
1406 RETURN_BOOL(retBool);
1410 * bool GEOSGeometry::isRing()
1412 PHP_METHOD(Geometry, isRing)
1414 GEOSGeometry *this;
1415 int ret;
1416 zend_bool retBool;
1418 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1420 ret = GEOSisRing(this);
1421 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1423 /* return_value is a zval */
1424 retBool = ret;
1425 RETURN_BOOL(retBool);
1429 * bool GEOSGeometry::hasZ()
1431 PHP_METHOD(Geometry, hasZ)
1433 GEOSGeometry *this;
1434 int ret;
1435 zend_bool retBool;
1437 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1439 ret = GEOSHasZ(this);
1440 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1442 /* return_value is a zval */
1443 retBool = ret;
1444 RETURN_BOOL(retBool);
1448 * bool GEOSGeometry::isClosed()
1450 PHP_METHOD(Geometry, isClosed)
1452 GEOSGeometry *this;
1453 int ret;
1454 zend_bool retBool;
1456 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1458 ret = GEOSisClosed(this);
1459 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
1461 /* return_value is a zval */
1462 retBool = ret;
1463 RETURN_BOOL(retBool);
1467 * string GEOSGeometry::typeName()
1469 PHP_METHOD(Geometry, typeName)
1471 GEOSGeometry *this;
1472 char *typ;
1473 char *typVal;
1475 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1477 /* TODO: define constant strings instead... */
1479 typ = GEOSGeomType(this);
1480 if ( ! typ ) RETURN_NULL(); /* should get an exception first */
1482 typVal = estrdup(typ);
1483 GEOSFree(typ);
1485 RETURN_STRING(typVal, 0);
1489 * long GEOSGeometry::typeId()
1491 PHP_METHOD(Geometry, typeId)
1493 GEOSGeometry *this;
1494 long typ;
1496 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1498 /* TODO: define constant strings instead... */
1500 typ = GEOSGeomTypeId(this);
1501 if ( typ == -1 ) RETURN_NULL(); /* should get an exception first */
1503 RETURN_LONG(typ);
1507 * long GEOSGeometry::getSRID()
1509 PHP_METHOD(Geometry, getSRID)
1511 GEOSGeometry *geom;
1512 long int ret;
1514 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1516 ret = GEOSGetSRID(geom);
1518 RETURN_LONG(ret);
1522 * void GEOSGeometry::setSRID(long)
1524 PHP_METHOD(Geometry, setSRID)
1526 GEOSGeometry *geom;
1527 long int srid;
1529 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1531 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1532 &srid) == FAILURE) {
1533 RETURN_NULL();
1536 GEOSSetSRID(geom, srid);
1540 * long GEOSGeometry::numGeometries()
1542 PHP_METHOD(Geometry, numGeometries)
1544 GEOSGeometry *geom;
1545 long int ret;
1547 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1549 ret = GEOSGetNumGeometries(geom);
1550 if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
1552 RETURN_LONG(ret);
1556 * GEOSGeometry GEOSGeometry::geometryN()
1558 PHP_METHOD(Geometry, geometryN)
1560 GEOSGeometry *geom;
1561 const GEOSGeometry *c;
1562 GEOSGeometry *cc;
1563 long int num;
1565 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1567 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1568 &num) == FAILURE) {
1569 RETURN_NULL();
1572 if ( num >= GEOSGetNumGeometries(geom) ) RETURN_NULL();
1573 c = GEOSGetGeometryN(geom, num);
1574 if ( ! c ) RETURN_NULL(); /* should get an exception first */
1575 cc = GEOSGeom_clone(c);
1576 if ( ! cc ) RETURN_NULL(); /* should get an exception first */
1578 object_init_ex(return_value, Geometry_ce_ptr);
1579 setRelay(return_value, cc);
1583 * long GEOSGeometry::numInteriorRings()
1585 PHP_METHOD(Geometry, numInteriorRings)
1587 GEOSGeometry *geom;
1588 long int ret;
1590 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1592 ret = GEOSGetNumInteriorRings(geom);
1593 if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
1595 RETURN_LONG(ret);
1599 * long GEOSGeometry::numPoints()
1601 PHP_METHOD(Geometry, numPoints)
1603 GEOSGeometry *geom;
1604 long int ret;
1606 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1608 ret = GEOSGeomGetNumPoints(geom);
1609 if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
1611 RETURN_LONG(ret);
1615 * double GEOSGeometry::getX()
1617 PHP_METHOD(Geometry, getX)
1619 GEOSGeometry *geom;
1620 int ret;
1621 double x;
1623 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1625 ret = GEOSGeomGetX(geom, &x);
1626 if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
1628 RETURN_DOUBLE(x);
1632 * double GEOSGeometry::getY()
1634 PHP_METHOD(Geometry, getY)
1636 GEOSGeometry *geom;
1637 int ret;
1638 double y;
1640 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1642 ret = GEOSGeomGetY(geom, &y);
1643 if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
1645 RETURN_DOUBLE(y);
1649 * GEOSGeometry GEOSGeometry::interiorRingN()
1651 PHP_METHOD(Geometry, interiorRingN)
1653 GEOSGeometry *geom;
1654 const GEOSGeometry *c;
1655 GEOSGeometry *cc;
1656 long int num;
1658 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1660 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1661 &num) == FAILURE) {
1662 RETURN_NULL();
1665 if ( num >= GEOSGetNumInteriorRings(geom) ) RETURN_NULL();
1666 c = GEOSGetInteriorRingN(geom, num);
1667 if ( ! c ) RETURN_NULL(); /* should get an exception first */
1668 cc = GEOSGeom_clone(c);
1669 if ( ! cc ) RETURN_NULL(); /* should get an exception first */
1671 object_init_ex(return_value, Geometry_ce_ptr);
1672 setRelay(return_value, cc);
1676 * GEOSGeometry GEOSGeometry::exteriorRing()
1678 PHP_METHOD(Geometry, exteriorRing)
1680 GEOSGeometry *geom;
1681 const GEOSGeometry *c;
1682 GEOSGeometry *cc;
1684 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1686 c = GEOSGetExteriorRing(geom);
1687 if ( ! c ) RETURN_NULL(); /* should get an exception first */
1688 cc = GEOSGeom_clone(c);
1689 if ( ! cc ) RETURN_NULL(); /* should get an exception first */
1691 object_init_ex(return_value, Geometry_ce_ptr);
1692 setRelay(return_value, cc);
1696 * long GEOSGeometry::numCoordinates()
1698 PHP_METHOD(Geometry, numCoordinates)
1700 GEOSGeometry *geom;
1701 long int ret;
1703 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1705 ret = GEOSGetNumCoordinates(geom);
1706 if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
1708 RETURN_LONG(ret);
1712 * long GEOSGeometry::dimension()
1713 * 0:puntual 1:lineal 2:areal
1715 PHP_METHOD(Geometry, dimension)
1717 GEOSGeometry *geom;
1718 long int ret;
1720 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1722 ret = GEOSGeom_getDimensions(geom);
1723 if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
1725 RETURN_LONG(ret);
1729 * long GEOSGeometry::coordinateDimension()
1731 PHP_METHOD(Geometry, coordinateDimension)
1733 GEOSGeometry *geom;
1734 long int ret;
1736 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1738 ret = GEOSGeom_getCoordinateDimension(geom);
1739 if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
1741 RETURN_LONG(ret);
1745 * GEOSGeometry GEOSGeometry::pointN()
1747 PHP_METHOD(Geometry, pointN)
1749 GEOSGeometry *geom;
1750 GEOSGeometry *c;
1751 long int num;
1753 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1755 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1756 &num) == FAILURE) {
1757 RETURN_NULL();
1760 if ( num >= GEOSGeomGetNumPoints(geom) ) RETURN_NULL();
1761 c = GEOSGeomGetPointN(geom, num);
1762 if ( ! c ) RETURN_NULL(); /* should get an exception first */
1764 object_init_ex(return_value, Geometry_ce_ptr);
1765 setRelay(return_value, c);
1769 * GEOSGeometry GEOSGeometry::startPoint()
1771 PHP_METHOD(Geometry, startPoint)
1773 GEOSGeometry *geom;
1774 GEOSGeometry *c;
1776 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1778 c = GEOSGeomGetStartPoint(geom);
1779 if ( ! c ) RETURN_NULL(); /* should get an exception first */
1781 object_init_ex(return_value, Geometry_ce_ptr);
1782 setRelay(return_value, c);
1786 * GEOSGeometry GEOSGeometry::endPoint()
1788 PHP_METHOD(Geometry, endPoint)
1790 GEOSGeometry *geom;
1791 GEOSGeometry *c;
1793 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1795 c = GEOSGeomGetEndPoint(geom);
1796 if ( ! c ) RETURN_NULL(); /* should get an exception first */
1798 object_init_ex(return_value, Geometry_ce_ptr);
1799 setRelay(return_value, c);
1803 * double GEOSGeometry::area()
1805 PHP_METHOD(Geometry, area)
1807 GEOSGeometry *geom;
1808 double area;
1809 int ret;
1811 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1813 ret = GEOSArea(geom, &area);
1814 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
1816 RETURN_DOUBLE(area);
1820 * double GEOSGeometry::length()
1822 PHP_METHOD(Geometry, length)
1824 GEOSGeometry *geom;
1825 double length;
1826 int ret;
1828 geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1830 ret = GEOSLength(geom, &length);
1831 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
1833 RETURN_DOUBLE(length);
1837 * double GEOSGeometry::distance(GEOSGeometry)
1839 PHP_METHOD(Geometry, distance)
1841 GEOSGeometry *this;
1842 GEOSGeometry *other;
1843 zval *zobj;
1844 double dist;
1845 int ret;
1847 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1849 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o",
1850 &zobj) == FAILURE)
1852 RETURN_NULL();
1855 other = getRelay(zobj, Geometry_ce_ptr);
1857 ret = GEOSDistance(this, other, &dist);
1858 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
1860 RETURN_DOUBLE(dist);
1864 * double GEOSGeometry::hausdorffDistance(GEOSGeometry)
1866 PHP_METHOD(Geometry, hausdorffDistance)
1868 GEOSGeometry *this;
1869 GEOSGeometry *other;
1870 zval *zobj;
1871 double dist;
1872 int ret;
1874 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1876 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o",
1877 &zobj) == FAILURE)
1879 RETURN_NULL();
1882 other = getRelay(zobj, Geometry_ce_ptr);
1884 ret = GEOSHausdorffDistance(this, other, &dist);
1885 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
1887 RETURN_DOUBLE(dist);
1890 PHP_METHOD(Geometry, snapTo)
1892 GEOSGeometry *this;
1893 GEOSGeometry *other;
1894 GEOSGeometry *ret;
1895 double tolerance;
1896 zval *zobj;
1898 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1900 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "od", &zobj,
1901 &tolerance) == FAILURE) {
1902 RETURN_NULL();
1904 other = getRelay(zobj, Geometry_ce_ptr);
1906 ret = GEOSSnap(this, other, tolerance);
1907 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
1909 /* return_value is a zval */
1910 object_init_ex(return_value, Geometry_ce_ptr);
1911 setRelay(return_value, ret);
1914 PHP_METHOD(Geometry, node)
1916 GEOSGeometry *this;
1917 GEOSGeometry *ret;
1919 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
1921 ret = GEOSNode(this);
1922 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
1924 /* return_value is a zval */
1925 object_init_ex(return_value, Geometry_ce_ptr);
1926 setRelay(return_value, ret);
1931 /* -- class GEOSWKTReader -------------------- */
1933 PHP_METHOD(WKTReader, __construct);
1934 PHP_METHOD(WKTReader, read);
1936 static zend_function_entry WKTReader_methods[] = {
1937 PHP_ME(WKTReader, __construct, NULL, 0)
1938 PHP_ME(WKTReader, read, NULL, 0)
1939 {NULL, NULL, NULL}
1942 static zend_class_entry *WKTReader_ce_ptr;
1944 static zend_object_handlers WKTReader_object_handlers;
1946 static void
1947 WKTReader_dtor (void *object TSRMLS_DC)
1949 Proxy *obj = (Proxy *)object;
1950 GEOSWKTReader_destroy((GEOSWKTReader*)obj->relay);
1952 zend_hash_destroy(obj->std.properties);
1953 FREE_HASHTABLE(obj->std.properties);
1955 efree(obj);
1958 static zend_object_value
1959 WKTReader_create_obj (zend_class_entry *type TSRMLS_DC)
1961 return Gen_create_obj(type, WKTReader_dtor, &WKTReader_object_handlers);
1965 PHP_METHOD(WKTReader, __construct)
1967 GEOSWKTReader* obj;
1968 zval *object = getThis();
1970 obj = GEOSWKTReader_create();
1971 if ( ! obj ) {
1972 php_error_docref(NULL TSRMLS_CC, E_ERROR,
1973 "GEOSWKTReader_create() failed (didn't initGEOS?)");
1976 setRelay(object, obj);
1979 PHP_METHOD(WKTReader, read)
1981 GEOSWKTReader *reader;
1982 GEOSGeometry *geom;
1983 char* wkt;
1984 int wktlen;
1986 reader = (GEOSWKTReader*)getRelay(getThis(), WKTReader_ce_ptr);
1988 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
1989 &wkt, &wktlen) == FAILURE)
1991 RETURN_NULL();
1994 geom = GEOSWKTReader_read(reader, wkt);
1995 /* we'll probably get an exception if geom is null */
1996 if ( ! geom ) RETURN_NULL();
1998 /* return_value is a zval */
1999 object_init_ex(return_value, Geometry_ce_ptr);
2000 setRelay(return_value, geom);
2004 /* -- class GEOSWKTWriter -------------------- */
2006 PHP_METHOD(WKTWriter, __construct);
2007 PHP_METHOD(WKTWriter, write);
2008 PHP_METHOD(WKTWriter, setTrim);
2009 PHP_METHOD(WKTWriter, setRoundingPrecision);
2010 PHP_METHOD(WKTWriter, setOutputDimension);
2011 PHP_METHOD(WKTWriter, getOutputDimension);
2012 PHP_METHOD(WKTWriter, setOld3D);
2014 static zend_function_entry WKTWriter_methods[] = {
2015 PHP_ME(WKTWriter, __construct, NULL, 0)
2016 PHP_ME(WKTWriter, write, NULL, 0)
2017 PHP_ME(WKTWriter, setTrim, NULL, 0)
2018 PHP_ME(WKTWriter, setRoundingPrecision, NULL, 0)
2019 PHP_ME(WKTWriter, setOutputDimension, NULL, 0)
2020 PHP_ME(WKTWriter, getOutputDimension, NULL, 0)
2021 PHP_ME(WKTWriter, setOld3D, NULL, 0)
2022 {NULL, NULL, NULL}
2025 static zend_class_entry *WKTWriter_ce_ptr;
2027 static zend_object_handlers WKTWriter_object_handlers;
2029 static void
2030 WKTWriter_dtor (void *object TSRMLS_DC)
2032 Proxy *obj = (Proxy *)object;
2033 GEOSWKTWriter_destroy((GEOSWKTWriter*)obj->relay);
2035 zend_hash_destroy(obj->std.properties);
2036 FREE_HASHTABLE(obj->std.properties);
2038 efree(obj);
2041 static zend_object_value
2042 WKTWriter_create_obj (zend_class_entry *type TSRMLS_DC)
2044 return Gen_create_obj(type, WKTWriter_dtor, &WKTWriter_object_handlers);
2047 PHP_METHOD(WKTWriter, __construct)
2049 GEOSWKTWriter* obj;
2050 zval *object = getThis();
2052 obj = GEOSWKTWriter_create();
2053 if ( ! obj ) {
2054 php_error_docref(NULL TSRMLS_CC, E_ERROR,
2055 "GEOSWKTWriter_create() failed (didn't initGEOS?)");
2058 setRelay(object, obj);
2061 PHP_METHOD(WKTWriter, write)
2063 GEOSWKTWriter *writer;
2064 zval *zobj;
2065 GEOSGeometry *geom;
2066 char* wkt;
2067 char* retstr;
2069 writer = (GEOSWKTWriter*)getRelay(getThis(), WKTWriter_ce_ptr);
2071 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
2072 == FAILURE)
2074 RETURN_NULL();
2077 geom = getRelay(zobj, Geometry_ce_ptr);
2079 wkt = GEOSWKTWriter_write(writer, geom);
2080 /* we'll probably get an exception if wkt is null */
2081 if ( ! wkt ) RETURN_NULL();
2083 retstr = estrdup(wkt);
2084 GEOSFree(wkt);
2086 RETURN_STRING(retstr, 0);
2089 PHP_METHOD(WKTWriter, setTrim)
2091 GEOSWKTWriter *writer;
2092 zend_bool trimval;
2093 char trim;
2095 writer = (GEOSWKTWriter*)getRelay(getThis(), WKTWriter_ce_ptr);
2097 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &trimval)
2098 == FAILURE)
2100 RETURN_NULL();
2103 trim = trimval;
2104 GEOSWKTWriter_setTrim(writer, trim);
2107 PHP_METHOD(WKTWriter, setRoundingPrecision)
2109 GEOSWKTWriter *writer;
2110 long int prec;
2112 writer = (GEOSWKTWriter*)getRelay(getThis(), WKTWriter_ce_ptr);
2114 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &prec)
2115 == FAILURE)
2117 RETURN_NULL();
2120 GEOSWKTWriter_setRoundingPrecision(writer, prec);
2124 * void GEOSWKTWriter::setOutputDimension()
2126 PHP_METHOD(WKTWriter, setOutputDimension)
2128 GEOSWKTWriter *writer;
2129 long int dim;
2131 writer = (GEOSWKTWriter*)getRelay(getThis(), WKTWriter_ce_ptr);
2133 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &dim)
2134 == FAILURE)
2136 RETURN_NULL();
2139 GEOSWKTWriter_setOutputDimension(writer, dim);
2143 * long GEOSWKTWriter::getOutputDimension()
2145 PHP_METHOD(WKTWriter, getOutputDimension)
2147 GEOSWKTWriter *writer;
2148 long int ret;
2150 writer = (GEOSWKTWriter*)getRelay(getThis(), WKTWriter_ce_ptr);
2152 ret = GEOSWKTWriter_getOutputDimension(writer);
2154 RETURN_LONG(ret);
2157 PHP_METHOD(WKTWriter, setOld3D)
2159 GEOSWKTWriter *writer;
2160 zend_bool bval;
2161 int val;
2163 writer = (GEOSWKTWriter*)getRelay(getThis(), WKTWriter_ce_ptr);
2165 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &bval)
2166 == FAILURE)
2168 RETURN_NULL();
2171 val = bval;
2172 GEOSWKTWriter_setOld3D(writer, val);
2175 /* -- class GEOSWKBWriter -------------------- */
2177 PHP_METHOD(WKBWriter, __construct);
2178 PHP_METHOD(WKBWriter, getOutputDimension);
2179 PHP_METHOD(WKBWriter, setOutputDimension);
2180 PHP_METHOD(WKBWriter, getByteOrder);
2181 PHP_METHOD(WKBWriter, setByteOrder);
2182 PHP_METHOD(WKBWriter, setIncludeSRID);
2183 PHP_METHOD(WKBWriter, getIncludeSRID);
2184 PHP_METHOD(WKBWriter, writeHEX);
2186 static zend_function_entry WKBWriter_methods[] = {
2187 PHP_ME(WKBWriter, __construct, NULL, 0)
2188 PHP_ME(WKBWriter, getOutputDimension, NULL, 0)
2189 PHP_ME(WKBWriter, setOutputDimension, NULL, 0)
2190 PHP_ME(WKBWriter, getByteOrder, NULL, 0)
2191 PHP_ME(WKBWriter, setByteOrder, NULL, 0)
2192 PHP_ME(WKBWriter, getIncludeSRID, NULL, 0)
2193 PHP_ME(WKBWriter, setIncludeSRID, NULL, 0)
2194 PHP_ME(WKBWriter, writeHEX, NULL, 0)
2195 {NULL, NULL, NULL}
2198 static zend_class_entry *WKBWriter_ce_ptr;
2200 static zend_object_handlers WKBWriter_object_handlers;
2202 static void
2203 WKBWriter_dtor (void *object TSRMLS_DC)
2205 Proxy *obj = (Proxy *)object;
2206 GEOSWKBWriter_destroy((GEOSWKBWriter*)obj->relay);
2208 zend_hash_destroy(obj->std.properties);
2209 FREE_HASHTABLE(obj->std.properties);
2211 efree(obj);
2214 static zend_object_value
2215 WKBWriter_create_obj (zend_class_entry *type TSRMLS_DC)
2217 return Gen_create_obj(type, WKBWriter_dtor, &WKBWriter_object_handlers);
2221 * GEOSWKBWriter w = new GEOSWKBWriter()
2223 PHP_METHOD(WKBWriter, __construct)
2225 GEOSWKBWriter* obj;
2226 zval *object = getThis();
2228 obj = GEOSWKBWriter_create();
2229 if ( ! obj ) {
2230 php_error_docref(NULL TSRMLS_CC, E_ERROR,
2231 "GEOSWKBWriter_create() failed (didn't initGEOS?)");
2234 setRelay(object, obj);
2238 * long GEOSWKBWriter::getOutputDimension();
2240 PHP_METHOD(WKBWriter, getOutputDimension)
2242 GEOSWKBWriter *writer;
2243 long int ret;
2245 writer = (GEOSWKBWriter*)getRelay(getThis(), WKBWriter_ce_ptr);
2247 ret = GEOSWKBWriter_getOutputDimension(writer);
2249 RETURN_LONG(ret);
2253 * void GEOSWKBWriter::setOutputDimension(dims);
2255 PHP_METHOD(WKBWriter, setOutputDimension)
2257 GEOSWKBWriter *writer;
2258 long int dim;
2260 writer = (GEOSWKBWriter*)getRelay(getThis(), WKBWriter_ce_ptr);
2262 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &dim)
2263 == FAILURE)
2265 RETURN_NULL();
2268 GEOSWKBWriter_setOutputDimension(writer, dim);
2273 * string GEOSWKBWriter::writeHEX(GEOSGeometry)
2275 PHP_METHOD(WKBWriter, writeHEX)
2277 GEOSWKBWriter *writer;
2278 zval *zobj;
2279 GEOSGeometry *geom;
2280 char *ret;
2281 size_t retsize; /* useless... */
2282 char* retstr;
2284 writer = (GEOSWKBWriter*)getRelay(getThis(), WKBWriter_ce_ptr);
2286 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
2287 == FAILURE)
2289 RETURN_NULL();
2292 geom = getRelay(zobj, Geometry_ce_ptr);
2294 ret = (char*)GEOSWKBWriter_writeHEX(writer, geom, &retsize);
2295 /* we'll probably get an exception if ret is null */
2296 if ( ! ret ) RETURN_NULL();
2298 retstr = estrndup(ret, retsize);
2299 GEOSFree(ret);
2301 RETURN_STRING(retstr, 0);
2305 * long GEOSWKBWriter::getByteOrder();
2307 PHP_METHOD(WKBWriter, getByteOrder)
2309 GEOSWKBWriter *writer;
2310 long int ret;
2312 writer = (GEOSWKBWriter*)getRelay(getThis(), WKBWriter_ce_ptr);
2314 ret = GEOSWKBWriter_getByteOrder(writer);
2316 RETURN_LONG(ret);
2320 * void GEOSWKBWriter::setByteOrder(dims);
2322 PHP_METHOD(WKBWriter, setByteOrder)
2324 GEOSWKBWriter *writer;
2325 long int dim;
2327 writer = (GEOSWKBWriter*)getRelay(getThis(), WKBWriter_ce_ptr);
2329 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &dim)
2330 == FAILURE)
2332 RETURN_NULL();
2335 GEOSWKBWriter_setByteOrder(writer, dim);
2340 * bool GEOSWKBWriter::getIncludeSRID();
2342 PHP_METHOD(WKBWriter, getIncludeSRID)
2344 GEOSWKBWriter *writer;
2345 int ret;
2346 zend_bool retBool;
2348 writer = (GEOSWKBWriter*)getRelay(getThis(), WKBWriter_ce_ptr);
2350 ret = GEOSWKBWriter_getIncludeSRID(writer);
2351 retBool = ret;
2353 RETURN_BOOL(retBool);
2357 * void GEOSWKBWriter::setIncludeSRID(bool);
2359 PHP_METHOD(WKBWriter, setIncludeSRID)
2361 GEOSWKBWriter *writer;
2362 int inc;
2363 zend_bool incVal;
2365 writer = (GEOSWKBWriter*)getRelay(getThis(), WKBWriter_ce_ptr);
2367 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &incVal)
2368 == FAILURE)
2370 RETURN_NULL();
2373 inc = incVal;
2374 GEOSWKBWriter_setIncludeSRID(writer, inc);
2377 /* -- class GEOSWKBReader -------------------- */
2379 PHP_METHOD(WKBReader, __construct);
2380 PHP_METHOD(WKBReader, readHEX);
2382 static zend_function_entry WKBReader_methods[] = {
2383 PHP_ME(WKBReader, __construct, NULL, 0)
2384 PHP_ME(WKBReader, readHEX, NULL, 0)
2385 {NULL, NULL, NULL}
2388 static zend_class_entry *WKBReader_ce_ptr;
2390 static zend_object_handlers WKBReader_object_handlers;
2392 static void
2393 WKBReader_dtor (void *object TSRMLS_DC)
2395 Proxy *obj = (Proxy *)object;
2396 GEOSWKBReader_destroy((GEOSWKBReader*)obj->relay);
2398 zend_hash_destroy(obj->std.properties);
2399 FREE_HASHTABLE(obj->std.properties);
2401 efree(obj);
2404 static zend_object_value
2405 WKBReader_create_obj (zend_class_entry *type TSRMLS_DC)
2407 return Gen_create_obj(type, WKBReader_dtor, &WKBReader_object_handlers);
2411 PHP_METHOD(WKBReader, __construct)
2413 GEOSWKBReader* obj;
2414 zval *object = getThis();
2416 obj = GEOSWKBReader_create();
2417 if ( ! obj ) {
2418 php_error_docref(NULL TSRMLS_CC, E_ERROR,
2419 "GEOSWKBReader_create() failed (didn't initGEOS?)");
2422 setRelay(object, obj);
2425 PHP_METHOD(WKBReader, readHEX)
2427 GEOSWKBReader *reader;
2428 GEOSGeometry *geom;
2429 unsigned char* wkb;
2430 int wkblen;
2432 reader = (GEOSWKBReader*)getRelay(getThis(), WKBReader_ce_ptr);
2434 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
2435 &wkb, &wkblen) == FAILURE)
2437 RETURN_NULL();
2440 geom = GEOSWKBReader_readHEX(reader, wkb, wkblen);
2441 /* we'll probably get an exception if geom is null */
2442 if ( ! geom ) RETURN_NULL();
2444 /* return_value is a zval */
2445 object_init_ex(return_value, Geometry_ce_ptr);
2446 setRelay(return_value, geom);
2451 /* -- Free functions ------------------------- */
2454 * string GEOSVersion()
2456 PHP_FUNCTION(GEOSVersion)
2458 char *str;
2460 str = estrdup(GEOSversion());
2461 RETURN_STRING(str, 0);
2465 * array GEOSPolygonize(GEOSGeometry $geom)
2467 * The returned array contains the following elements:
2469 * - 'rings'
2470 * Type: array of GEOSGeometry
2471 * Rings that can be formed by the costituent
2472 * linework of geometry.
2473 * - 'cut_edges' (optional)
2474 * Type: array of GEOSGeometry
2475 * Edges which are connected at both ends but
2476 * which do not form part of polygon.
2477 * - 'dangles'
2478 * Type: array of GEOSGeometry
2479 * Edges which have one or both ends which are
2480 * not incident on another edge endpoint
2481 * - 'invalid_rings'
2482 * Type: array of GEOSGeometry
2483 * Edges which form rings which are invalid
2484 * (e.g. the component lines contain a self-intersection)
2487 PHP_FUNCTION(GEOSPolygonize)
2489 GEOSGeometry *this;
2490 GEOSGeometry *rings;
2491 GEOSGeometry *cut_edges;
2492 GEOSGeometry *dangles;
2493 GEOSGeometry *invalid_rings;
2494 zval *array_elem;
2495 zval *zobj;
2497 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
2498 == FAILURE)
2500 RETURN_NULL();
2502 this = getRelay(zobj, Geometry_ce_ptr);
2504 rings = GEOSPolygonize_full(this, &cut_edges, &dangles, &invalid_rings);
2505 if ( ! rings ) RETURN_NULL(); /* should get an exception first */
2507 /* return value should be an array */
2508 array_init(return_value);
2510 MAKE_STD_ZVAL(array_elem);
2511 array_init(array_elem);
2512 dumpGeometry(rings, array_elem);
2513 GEOSGeom_destroy(rings);
2514 add_assoc_zval(return_value, "rings", array_elem);
2516 MAKE_STD_ZVAL(array_elem);
2517 array_init(array_elem);
2518 dumpGeometry(cut_edges, array_elem);
2519 GEOSGeom_destroy(cut_edges);
2520 add_assoc_zval(return_value, "cut_edges", array_elem);
2522 MAKE_STD_ZVAL(array_elem);
2523 array_init(array_elem);
2524 dumpGeometry(dangles, array_elem);
2525 GEOSGeom_destroy(dangles);
2526 add_assoc_zval(return_value, "dangles", array_elem);
2528 MAKE_STD_ZVAL(array_elem);
2529 array_init(array_elem);
2530 dumpGeometry(invalid_rings, array_elem);
2531 GEOSGeom_destroy(invalid_rings);
2532 add_assoc_zval(return_value, "invalid_rings", array_elem);
2537 * array GEOSLineMerge(GEOSGeometry $geom)
2539 PHP_FUNCTION(GEOSLineMerge)
2541 GEOSGeometry *geom_in;
2542 GEOSGeometry *geom_out;
2543 zval *zobj;
2545 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
2546 == FAILURE)
2548 RETURN_NULL();
2550 geom_in = getRelay(zobj, Geometry_ce_ptr);
2552 geom_out = GEOSLineMerge(geom_in);
2553 if ( ! geom_out ) RETURN_NULL(); /* should get an exception first */
2555 /* return value should be an array */
2556 array_init(return_value);
2557 dumpGeometry(geom_out, return_value);
2558 GEOSGeom_destroy(geom_out);
2562 * GEOSGeometry GEOSSharedPaths(GEOSGeometry $geom1, GEOSGeometry *geom2)
2564 PHP_FUNCTION(GEOSSharedPaths)
2566 GEOSGeometry *geom_in_1;
2567 GEOSGeometry *geom_in_2;
2568 GEOSGeometry *geom_out;
2569 zval *zobj1, *zobj2;
2571 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oo", &zobj1, &zobj2)
2572 == FAILURE)
2574 RETURN_NULL();
2576 geom_in_1 = getRelay(zobj1, Geometry_ce_ptr);
2577 geom_in_2 = getRelay(zobj2, Geometry_ce_ptr);
2579 geom_out = GEOSSharedPaths(geom_in_1, geom_in_2);
2580 if ( ! geom_out ) RETURN_NULL(); /* should get an exception first */
2582 /* return_value is a zval */
2583 object_init_ex(return_value, Geometry_ce_ptr);
2584 setRelay(return_value, geom_out);
2588 * GEOSGeometry::delaunayTriangulation([<tolerance>], [<onlyEdges>])
2590 * styleArray keys supported:
2591 * 'tolerance'
2592 * Type: double
2593 * snapping tolerance to use for improved robustness
2594 * 'edgesOnly'
2595 * Type: boolean
2596 * if true will return a MULTILINESTRING, otherwise (the default)
2597 * it will return a GEOMETRYCOLLECTION containing triangular POLYGONs.
2599 PHP_METHOD(Geometry, delaunayTriangulation)
2601 GEOSGeometry *this;
2602 GEOSGeometry *ret;
2603 double tolerance = 0.0;
2604 zend_bool edgeonly = 0;
2606 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
2608 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|db",
2609 &tolerance, &edgeonly) == FAILURE) {
2610 RETURN_NULL();
2613 ret = GEOSDelaunayTriangulation(this, tolerance, edgeonly ? 1 : 0);
2614 if ( ! ret ) RETURN_NULL(); /* should get an exception first */
2616 /* return_value is a zval */
2617 object_init_ex(return_value, Geometry_ce_ptr);
2618 setRelay(return_value, ret);
2622 * bool GEOSRelateMatch(string matrix, string pattern)
2624 PHP_FUNCTION(GEOSRelateMatch)
2626 char* mat = NULL;
2627 int matlen;
2628 char* pat = NULL;
2629 int patlen;
2630 int ret;
2631 zend_bool retBool;
2633 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
2634 &mat, &matlen, &pat, &patlen) == FAILURE)
2636 RETURN_NULL();
2639 ret = GEOSRelatePatternMatch(mat, pat);
2640 if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
2642 /* return_value is a zval */
2643 retBool = ret;
2644 RETURN_BOOL(retBool);
2647 /* ------ Initialization / Deinitialization / Meta ------------------ */
2649 /* per-module initialization */
2650 PHP_MINIT_FUNCTION(geos)
2652 zend_class_entry ce;
2654 /* WKTReader */
2655 INIT_CLASS_ENTRY(ce, "GEOSWKTReader", WKTReader_methods);
2656 WKTReader_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
2657 WKTReader_ce_ptr->create_object = WKTReader_create_obj;
2658 memcpy(&WKTReader_object_handlers,
2659 zend_get_std_object_handlers(), sizeof(zend_object_handlers));
2660 WKTReader_object_handlers.clone_obj = NULL;
2662 /* WKTWriter */
2663 INIT_CLASS_ENTRY(ce, "GEOSWKTWriter", WKTWriter_methods);
2664 WKTWriter_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
2665 WKTWriter_ce_ptr->create_object = WKTWriter_create_obj;
2666 memcpy(&WKTWriter_object_handlers,
2667 zend_get_std_object_handlers(), sizeof(zend_object_handlers));
2668 WKTWriter_object_handlers.clone_obj = NULL;
2670 /* Geometry */
2671 INIT_CLASS_ENTRY(ce, "GEOSGeometry", Geometry_methods);
2672 Geometry_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
2673 Geometry_ce_ptr->create_object = Geometry_create_obj;
2674 memcpy(&Geometry_object_handlers,
2675 zend_get_std_object_handlers(), sizeof(zend_object_handlers));
2676 Geometry_object_handlers.clone_obj = NULL;
2677 /* Geometry serialization */
2678 Geometry_ce_ptr->serialize = Geometry_serialize;
2679 Geometry_ce_ptr->unserialize = Geometry_deserialize;
2681 /* WKBWriter */
2682 INIT_CLASS_ENTRY(ce, "GEOSWKBWriter", WKBWriter_methods);
2683 WKBWriter_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
2684 WKBWriter_ce_ptr->create_object = WKBWriter_create_obj;
2685 memcpy(&WKBWriter_object_handlers,
2686 zend_get_std_object_handlers(), sizeof(zend_object_handlers));
2687 WKBWriter_object_handlers.clone_obj = NULL;
2689 /* WKBReader */
2690 INIT_CLASS_ENTRY(ce, "GEOSWKBReader", WKBReader_methods);
2691 WKBReader_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
2692 WKBReader_ce_ptr->create_object = WKBReader_create_obj;
2693 memcpy(&WKBReader_object_handlers,
2694 zend_get_std_object_handlers(), sizeof(zend_object_handlers));
2695 WKBReader_object_handlers.clone_obj = NULL;
2698 /* Constants */
2699 REGISTER_LONG_CONSTANT("GEOSBUF_CAP_ROUND", GEOSBUF_CAP_ROUND,
2700 CONST_CS|CONST_PERSISTENT);
2701 REGISTER_LONG_CONSTANT("GEOSBUF_CAP_FLAT", GEOSBUF_CAP_FLAT,
2702 CONST_CS|CONST_PERSISTENT);
2703 REGISTER_LONG_CONSTANT("GEOSBUF_CAP_SQUARE", GEOSBUF_CAP_SQUARE,
2704 CONST_CS|CONST_PERSISTENT);
2705 REGISTER_LONG_CONSTANT("GEOSBUF_JOIN_ROUND", GEOSBUF_JOIN_ROUND,
2706 CONST_CS|CONST_PERSISTENT);
2707 REGISTER_LONG_CONSTANT("GEOSBUF_JOIN_MITRE", GEOSBUF_JOIN_MITRE,
2708 CONST_CS|CONST_PERSISTENT);
2709 REGISTER_LONG_CONSTANT("GEOSBUF_JOIN_BEVEL", GEOSBUF_JOIN_BEVEL,
2710 CONST_CS|CONST_PERSISTENT);
2712 REGISTER_LONG_CONSTANT("GEOS_POINT", GEOS_POINT,
2713 CONST_CS|CONST_PERSISTENT);
2714 REGISTER_LONG_CONSTANT("GEOS_LINESTRING", GEOS_LINESTRING,
2715 CONST_CS|CONST_PERSISTENT);
2716 REGISTER_LONG_CONSTANT("GEOS_LINEARRING", GEOS_LINEARRING,
2717 CONST_CS|CONST_PERSISTENT);
2718 REGISTER_LONG_CONSTANT("GEOS_POLYGON", GEOS_POLYGON,
2719 CONST_CS|CONST_PERSISTENT);
2720 REGISTER_LONG_CONSTANT("GEOS_MULTIPOINT", GEOS_MULTIPOINT,
2721 CONST_CS|CONST_PERSISTENT);
2722 REGISTER_LONG_CONSTANT("GEOS_MULTILINESTRING", GEOS_MULTILINESTRING,
2723 CONST_CS|CONST_PERSISTENT);
2724 REGISTER_LONG_CONSTANT("GEOS_MULTIPOLYGON", GEOS_MULTIPOLYGON,
2725 CONST_CS|CONST_PERSISTENT);
2726 REGISTER_LONG_CONSTANT("GEOS_GEOMETRYCOLLECTION", GEOS_GEOMETRYCOLLECTION,
2727 CONST_CS|CONST_PERSISTENT);
2729 REGISTER_LONG_CONSTANT("GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE",
2730 GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE,
2731 CONST_CS|CONST_PERSISTENT);
2733 REGISTER_LONG_CONSTANT("GEOSRELATE_BNR_MOD2", GEOSRELATE_BNR_MOD2,
2734 CONST_CS|CONST_PERSISTENT);
2735 REGISTER_LONG_CONSTANT("GEOSRELATE_BNR_OGC", GEOSRELATE_BNR_OGC,
2736 CONST_CS|CONST_PERSISTENT);
2737 REGISTER_LONG_CONSTANT("GEOSRELATE_BNR_ENDPOINT", GEOSRELATE_BNR_ENDPOINT,
2738 CONST_CS|CONST_PERSISTENT);
2739 REGISTER_LONG_CONSTANT("GEOSRELATE_BNR_MULTIVALENT_ENDPOINT",
2740 GEOSRELATE_BNR_MULTIVALENT_ENDPOINT,
2741 CONST_CS|CONST_PERSISTENT);
2742 REGISTER_LONG_CONSTANT("GEOSRELATE_BNR_MONOVALENT_ENDPOINT",
2743 GEOSRELATE_BNR_MONOVALENT_ENDPOINT,
2744 CONST_CS|CONST_PERSISTENT);
2746 return SUCCESS;
2749 /* per-module shutdown */
2750 PHP_MSHUTDOWN_FUNCTION(geos)
2752 delGeometrySerializer();
2753 delGeometryDeserializer();
2754 return SUCCESS;
2757 /* per-request initialization */
2758 PHP_RINIT_FUNCTION(geos)
2760 initGEOS(noticeHandler, errorHandler);
2761 return SUCCESS;
2764 /* pre-request destruction */
2765 PHP_RSHUTDOWN_FUNCTION(geos)
2767 finishGEOS();
2768 return SUCCESS;
2771 /* module info */
2772 PHP_MINFO_FUNCTION(geos)
2774 php_info_print_table_start();
2775 php_info_print_table_row(2,
2776 "GEOS - Geometry Engine Open Source", "enabled");
2777 php_info_print_table_row(2,
2778 "Version", PHP_GEOS_VERSION);
2779 php_info_print_table_end();