1 /***********************************************************************
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 ***********************************************************************/
27 #include "ext/standard/info.h" /* for php_info_... */
28 #include "Zend/zend_exceptions.h" /* for zend_throw_exception_object */
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
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
)
60 zend_module_entry geos_module_entry
= {
61 STANDARD_MODULE_HEADER
,
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 */
70 STANDARD_MODULE_PROPERTIES
73 #ifdef COMPILE_DL_GEOS
77 /* -- Utility functions ---------------------- */
79 static void noticeHandler(const char *fmt
, ...)
84 vsnprintf(message
, sizeof(message
) - 1, fmt
, args
);
87 php_error_docref(NULL TSRMLS_CC
, E_NOTICE
, "%s", message
);
90 static void errorHandler(const char *fmt
, ...)
95 vsnprintf(message
, sizeof(message
) - 1, fmt
, 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
{
110 setRelay(zval
* val
, void* obj
) {
111 Proxy
* proxy
= (Proxy
*)zend_object_store_get_object(val TSRMLS_CC
);
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
);
129 static long getZvalAsLong(zval
* val
)
135 zval_copy_ctor(&tmp
);
136 convert_to_long(&tmp
);
142 static long getZvalAsDouble(zval
* val
)
148 zval_copy_ctor(&tmp
);
149 convert_to_double(&tmp
);
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
)
160 zend_object_value retval
;
162 Proxy
*obj
= (Proxy
*)emalloc(sizeof(Proxy
));
163 memset(obj
, 0, sizeof(Proxy
));
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
*));
172 object_properties_init(&(obj
->std
), type
);
175 retval
.handle
= zend_objects_store_put(obj
, NULL
, st
, NULL TSRMLS_CC
);
176 retval
.handlers
= handlers
;
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)
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 */
358 Geometry_serialize(zval
*object
, unsigned char **buffer
, zend_uint
*buf_len
,
359 zend_serialize_data
*data TSRMLS_DC
)
361 GEOSWKBWriter
*serializer
;
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
);
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
;
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");
399 object_init_ex(*object
, ce
);
400 setRelay(*object
, geom
);
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
412 dumpGeometry(GEOSGeometry
* g
, zval
* array
)
417 MAKE_STD_ZVAL(array);
421 ngeoms
= GEOSGetNumGeometries(g
);
422 for (i
=0; i
<ngeoms
; ++i
)
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 */
433 object_init_ex(tmp
, Geometry_ce_ptr
);
435 add_next_index_zval(array
, tmp
);
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
);
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
)
469 GEOSWKTWriter
*writer
;
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
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
);
492 RETURN_STRING(ret
, 0);
495 PHP_METHOD(Geometry
, project
)
500 zend_bool normalized
= 0;
503 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
505 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o|b", &zobj
,
506 &normalized
) == FAILURE
) {
509 other
= getRelay(zobj
, Geometry_ce_ptr
);
512 ret
= GEOSProjectNormalized(this, other
);
514 ret
= GEOSProject(this, other
);
516 if ( ret
< 0 ) RETURN_NULL(); /* should get an exception first */
521 PHP_METHOD(Geometry
, interpolate
)
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
) {
536 ret
= GEOSInterpolateNormalized(this, dist
);
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:
553 * Number of segments used to approximate
554 * a quarter circle (defaults to 8).
557 * Endcap style (defaults to GEOSBUF_CAP_ROUND)
560 * Join style (defaults to GEOSBUF_JOIN_ROUND)
563 * mitre ratio limit (only affects joins with GEOSBUF_JOIN_MITRE style)
564 * 'miter_limit' is also accepted as a synonym for 'mitre_limit'.
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
)
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
;
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
) {
599 params
= GEOSBufferParams_create();
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:
657 * Number of segments used to approximate
658 * a quarter circle (defaults to 8).
661 * Join style (defaults to GEOSBUF_JOIN_ROUND)
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
)
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
;
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
) {
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
)
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
)
747 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
749 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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
)
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
)
785 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
787 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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
)
808 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
810 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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
)
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)
850 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
852 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|o", &zobj
)
858 other
= getRelay(zobj
, Geometry_ce_ptr
);
859 ret
= GEOSUnion(this, other
);
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
)
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
)
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
)
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
)
930 other
= getRelay(zobj
, Geometry_ce_ptr
);
933 /* we'll compute it */
934 pat
= GEOSRelate(this, other
);
935 if ( ! pat
) RETURN_NULL(); /* should get an exception first */
936 retStr
= estrdup(pat
);
938 RETURN_STRING(retStr
, 0);
940 retInt
= GEOSRelatePattern(this, other
, pat
);
941 if ( retInt
== 2 ) RETURN_NULL(); /* should get an exception first */
943 RETURN_BOOL(retBool
);
949 * GEOSGeometry::relateBoundaryNodeRule(otherGeom, rule)
951 PHP_METHOD(Geometry
, relateBoundaryNodeRule
)
957 long int bnr
= GEOSRELATE_BNR_OGC
;
960 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
962 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ol",
963 &zobj
, &bnr
) == FAILURE
)
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
);
975 RETURN_STRING(retStr
, 0);
979 * GEOSGeometry GEOSGeometry::simplify(tolerance)
980 * GEOSGeometry GEOSGeometry::simplify(tolerance, preserveTopology)
982 PHP_METHOD(Geometry
, simplify
)
986 zend_bool preserveTopology
= 0;
989 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
991 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "d|b",
992 &tolerance
, &preserveTopology
) == FAILURE
) {
996 if ( preserveTopology
) {
997 ret
= GEOSTopologyPreserveSimplify(this, tolerance
);
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
)
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
)
1033 GEOSGeometry
*other
;
1038 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1040 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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 */
1051 RETURN_BOOL(retBool
);
1055 * bool GEOSGeometry::touches(GEOSGeometry)
1057 PHP_METHOD(Geometry
, touches
)
1060 GEOSGeometry
*other
;
1065 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1067 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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 */
1078 RETURN_BOOL(retBool
);
1082 * bool GEOSGeometry::intersects(GEOSGeometry)
1084 PHP_METHOD(Geometry
, intersects
)
1087 GEOSGeometry
*other
;
1092 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1094 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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 */
1105 RETURN_BOOL(retBool
);
1109 * bool GEOSGeometry::crosses(GEOSGeometry)
1111 PHP_METHOD(Geometry
, crosses
)
1114 GEOSGeometry
*other
;
1119 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1121 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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 */
1132 RETURN_BOOL(retBool
);
1136 * bool GEOSGeometry::within(GEOSGeometry)
1138 PHP_METHOD(Geometry
, within
)
1141 GEOSGeometry
*other
;
1146 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1148 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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 */
1159 RETURN_BOOL(retBool
);
1163 * bool GEOSGeometry::contains(GEOSGeometry)
1165 PHP_METHOD(Geometry
, contains
)
1168 GEOSGeometry
*other
;
1173 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1175 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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 */
1186 RETURN_BOOL(retBool
);
1190 * bool GEOSGeometry::overlaps(GEOSGeometry)
1192 PHP_METHOD(Geometry
, overlaps
)
1195 GEOSGeometry
*other
;
1200 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1202 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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 */
1213 RETURN_BOOL(retBool
);
1217 * bool GEOSGeometry::covers(GEOSGeometry)
1219 PHP_METHOD(Geometry
, covers
)
1222 GEOSGeometry
*other
;
1227 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1229 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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 */
1240 RETURN_BOOL(retBool
);
1244 * bool GEOSGeometry::coveredBy(GEOSGeometry)
1246 PHP_METHOD(Geometry
, coveredBy
)
1249 GEOSGeometry
*other
;
1254 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1256 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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 */
1267 RETURN_BOOL(retBool
);
1271 * bool GEOSGeometry::equals(GEOSGeometry)
1273 PHP_METHOD(Geometry
, equals
)
1276 GEOSGeometry
*other
;
1281 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1283 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o",
1284 &zobj
) == FAILURE
) {
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 */
1294 RETURN_BOOL(retBool
);
1298 * bool GEOSGeometry::equalsExact(GEOSGeometry)
1299 * bool GEOSGeometry::equalsExact(GEOSGeometry, double tolerance)
1301 PHP_METHOD(Geometry
, equalsExact
)
1304 GEOSGeometry
*other
;
1306 double tolerance
= 0;
1310 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1312 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o|d",
1313 &zobj
, &tolerance
) == FAILURE
) {
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 */
1323 RETURN_BOOL(retBool
);
1327 * bool GEOSGeometry::isEmpty()
1329 PHP_METHOD(Geometry
, isEmpty
)
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 */
1342 RETURN_BOOL(retBool
);
1346 * array GEOSGeometry::checkValidity()
1348 PHP_METHOD(Geometry
, checkValidity
)
1351 GEOSGeometry
*location
= NULL
;
1353 char *reason
= NULL
;
1355 char *reasonVal
= NULL
;
1356 zval
*locationVal
= NULL
;
1359 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1361 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l",
1362 &flags
) == FAILURE
) {
1366 ret
= GEOSisValidDetail(this, flags
, &reason
, &location
);
1367 if ( ret
== 2 ) RETURN_NULL(); /* should get an exception first */
1370 reasonVal
= estrdup(reason
);
1375 MAKE_STD_ZVAL(locationVal
);
1376 object_init_ex(locationVal
, Geometry_ce_ptr
);
1377 setRelay(locationVal
, location
);
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
)
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 */
1406 RETURN_BOOL(retBool
);
1410 * bool GEOSGeometry::isRing()
1412 PHP_METHOD(Geometry
, isRing
)
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 */
1425 RETURN_BOOL(retBool
);
1429 * bool GEOSGeometry::hasZ()
1431 PHP_METHOD(Geometry
, hasZ
)
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 */
1444 RETURN_BOOL(retBool
);
1448 * bool GEOSGeometry::isClosed()
1450 PHP_METHOD(Geometry
, isClosed
)
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 */
1463 RETURN_BOOL(retBool
);
1467 * string GEOSGeometry::typeName()
1469 PHP_METHOD(Geometry
, typeName
)
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
);
1485 RETURN_STRING(typVal
, 0);
1489 * long GEOSGeometry::typeId()
1491 PHP_METHOD(Geometry
, typeId
)
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 */
1507 * long GEOSGeometry::getSRID()
1509 PHP_METHOD(Geometry
, getSRID
)
1514 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1516 ret
= GEOSGetSRID(geom
);
1522 * void GEOSGeometry::setSRID(long)
1524 PHP_METHOD(Geometry
, setSRID
)
1529 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1531 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l",
1532 &srid
) == FAILURE
) {
1536 GEOSSetSRID(geom
, srid
);
1540 * long GEOSGeometry::numGeometries()
1542 PHP_METHOD(Geometry
, numGeometries
)
1547 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1549 ret
= GEOSGetNumGeometries(geom
);
1550 if ( ret
== -1 ) RETURN_NULL(); /* should get an exception first */
1556 * GEOSGeometry GEOSGeometry::geometryN()
1558 PHP_METHOD(Geometry
, geometryN
)
1561 const GEOSGeometry
*c
;
1565 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1567 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l",
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
)
1590 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1592 ret
= GEOSGetNumInteriorRings(geom
);
1593 if ( ret
== -1 ) RETURN_NULL(); /* should get an exception first */
1599 * long GEOSGeometry::numPoints()
1601 PHP_METHOD(Geometry
, numPoints
)
1606 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1608 ret
= GEOSGeomGetNumPoints(geom
);
1609 if ( ret
== -1 ) RETURN_NULL(); /* should get an exception first */
1615 * double GEOSGeometry::getX()
1617 PHP_METHOD(Geometry
, getX
)
1623 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1625 ret
= GEOSGeomGetX(geom
, &x
);
1626 if ( ret
== -1 ) RETURN_NULL(); /* should get an exception first */
1632 * double GEOSGeometry::getY()
1634 PHP_METHOD(Geometry
, getY
)
1640 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1642 ret
= GEOSGeomGetY(geom
, &y
);
1643 if ( ret
== -1 ) RETURN_NULL(); /* should get an exception first */
1649 * GEOSGeometry GEOSGeometry::interiorRingN()
1651 PHP_METHOD(Geometry
, interiorRingN
)
1654 const GEOSGeometry
*c
;
1658 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1660 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l",
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
)
1681 const GEOSGeometry
*c
;
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
)
1703 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1705 ret
= GEOSGetNumCoordinates(geom
);
1706 if ( ret
== -1 ) RETURN_NULL(); /* should get an exception first */
1712 * long GEOSGeometry::dimension()
1713 * 0:puntual 1:lineal 2:areal
1715 PHP_METHOD(Geometry
, dimension
)
1720 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1722 ret
= GEOSGeom_getDimensions(geom
);
1723 if ( ret
== -1 ) RETURN_NULL(); /* should get an exception first */
1729 * long GEOSGeometry::coordinateDimension()
1731 PHP_METHOD(Geometry
, coordinateDimension
)
1736 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1738 ret
= GEOSGeom_getCoordinateDimension(geom
);
1739 if ( ret
== -1 ) RETURN_NULL(); /* should get an exception first */
1745 * GEOSGeometry GEOSGeometry::pointN()
1747 PHP_METHOD(Geometry
, pointN
)
1753 geom
= (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1755 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l",
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
)
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
)
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
)
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
)
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
)
1842 GEOSGeometry
*other
;
1847 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1849 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o",
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
)
1869 GEOSGeometry
*other
;
1874 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1876 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o",
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
)
1893 GEOSGeometry
*other
;
1898 this = (GEOSGeometry
*)getRelay(getThis(), Geometry_ce_ptr
);
1900 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "od", &zobj
,
1901 &tolerance
) == FAILURE
) {
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
)
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)
1942 static zend_class_entry
*WKTReader_ce_ptr
;
1944 static zend_object_handlers WKTReader_object_handlers
;
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
);
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
)
1968 zval
*object
= getThis();
1970 obj
= GEOSWKTReader_create();
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
;
1986 reader
= (GEOSWKTReader
*)getRelay(getThis(), WKTReader_ce_ptr
);
1988 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s",
1989 &wkt
, &wktlen
) == FAILURE
)
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)
2025 static zend_class_entry
*WKTWriter_ce_ptr
;
2027 static zend_object_handlers WKTWriter_object_handlers
;
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
);
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
)
2050 zval
*object
= getThis();
2052 obj
= GEOSWKTWriter_create();
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
;
2069 writer
= (GEOSWKTWriter
*)getRelay(getThis(), WKTWriter_ce_ptr
);
2071 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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
);
2086 RETURN_STRING(retstr
, 0);
2089 PHP_METHOD(WKTWriter
, setTrim
)
2091 GEOSWKTWriter
*writer
;
2095 writer
= (GEOSWKTWriter
*)getRelay(getThis(), WKTWriter_ce_ptr
);
2097 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "b", &trimval
)
2104 GEOSWKTWriter_setTrim(writer
, trim
);
2107 PHP_METHOD(WKTWriter
, setRoundingPrecision
)
2109 GEOSWKTWriter
*writer
;
2112 writer
= (GEOSWKTWriter
*)getRelay(getThis(), WKTWriter_ce_ptr
);
2114 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &prec
)
2120 GEOSWKTWriter_setRoundingPrecision(writer
, prec
);
2124 * void GEOSWKTWriter::setOutputDimension()
2126 PHP_METHOD(WKTWriter
, setOutputDimension
)
2128 GEOSWKTWriter
*writer
;
2131 writer
= (GEOSWKTWriter
*)getRelay(getThis(), WKTWriter_ce_ptr
);
2133 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &dim
)
2139 GEOSWKTWriter_setOutputDimension(writer
, dim
);
2143 * long GEOSWKTWriter::getOutputDimension()
2145 PHP_METHOD(WKTWriter
, getOutputDimension
)
2147 GEOSWKTWriter
*writer
;
2150 writer
= (GEOSWKTWriter
*)getRelay(getThis(), WKTWriter_ce_ptr
);
2152 ret
= GEOSWKTWriter_getOutputDimension(writer
);
2157 PHP_METHOD(WKTWriter
, setOld3D
)
2159 GEOSWKTWriter
*writer
;
2163 writer
= (GEOSWKTWriter
*)getRelay(getThis(), WKTWriter_ce_ptr
);
2165 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "b", &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)
2198 static zend_class_entry
*WKBWriter_ce_ptr
;
2200 static zend_object_handlers WKBWriter_object_handlers
;
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
);
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
)
2226 zval
*object
= getThis();
2228 obj
= GEOSWKBWriter_create();
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
;
2245 writer
= (GEOSWKBWriter
*)getRelay(getThis(), WKBWriter_ce_ptr
);
2247 ret
= GEOSWKBWriter_getOutputDimension(writer
);
2253 * void GEOSWKBWriter::setOutputDimension(dims);
2255 PHP_METHOD(WKBWriter
, setOutputDimension
)
2257 GEOSWKBWriter
*writer
;
2260 writer
= (GEOSWKBWriter
*)getRelay(getThis(), WKBWriter_ce_ptr
);
2262 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &dim
)
2268 GEOSWKBWriter_setOutputDimension(writer
, dim
);
2273 * string GEOSWKBWriter::writeHEX(GEOSGeometry)
2275 PHP_METHOD(WKBWriter
, writeHEX
)
2277 GEOSWKBWriter
*writer
;
2281 size_t retsize
; /* useless... */
2284 writer
= (GEOSWKBWriter
*)getRelay(getThis(), WKBWriter_ce_ptr
);
2286 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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
);
2301 RETURN_STRING(retstr
, 0);
2305 * long GEOSWKBWriter::getByteOrder();
2307 PHP_METHOD(WKBWriter
, getByteOrder
)
2309 GEOSWKBWriter
*writer
;
2312 writer
= (GEOSWKBWriter
*)getRelay(getThis(), WKBWriter_ce_ptr
);
2314 ret
= GEOSWKBWriter_getByteOrder(writer
);
2320 * void GEOSWKBWriter::setByteOrder(dims);
2322 PHP_METHOD(WKBWriter
, setByteOrder
)
2324 GEOSWKBWriter
*writer
;
2327 writer
= (GEOSWKBWriter
*)getRelay(getThis(), WKBWriter_ce_ptr
);
2329 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &dim
)
2335 GEOSWKBWriter_setByteOrder(writer
, dim
);
2340 * bool GEOSWKBWriter::getIncludeSRID();
2342 PHP_METHOD(WKBWriter
, getIncludeSRID
)
2344 GEOSWKBWriter
*writer
;
2348 writer
= (GEOSWKBWriter
*)getRelay(getThis(), WKBWriter_ce_ptr
);
2350 ret
= GEOSWKBWriter_getIncludeSRID(writer
);
2353 RETURN_BOOL(retBool
);
2357 * void GEOSWKBWriter::setIncludeSRID(bool);
2359 PHP_METHOD(WKBWriter
, setIncludeSRID
)
2361 GEOSWKBWriter
*writer
;
2365 writer
= (GEOSWKBWriter
*)getRelay(getThis(), WKBWriter_ce_ptr
);
2367 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "b", &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)
2388 static zend_class_entry
*WKBReader_ce_ptr
;
2390 static zend_object_handlers WKBReader_object_handlers
;
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
);
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
)
2414 zval
*object
= getThis();
2416 obj
= GEOSWKBReader_create();
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
;
2432 reader
= (GEOSWKBReader
*)getRelay(getThis(), WKBReader_ce_ptr
);
2434 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s",
2435 &wkb
, &wkblen
) == FAILURE
)
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
)
2460 str
= estrdup(GEOSversion());
2461 RETURN_STRING(str
, 0);
2465 * array GEOSPolygonize(GEOSGeometry $geom)
2467 * The returned array contains the following elements:
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.
2478 * Type: array of GEOSGeometry
2479 * Edges which have one or both ends which are
2480 * not incident on another edge endpoint
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
)
2490 GEOSGeometry
*rings
;
2491 GEOSGeometry
*cut_edges
;
2492 GEOSGeometry
*dangles
;
2493 GEOSGeometry
*invalid_rings
;
2497 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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
;
2545 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "o", &zobj
)
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
)
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:
2593 * snapping tolerance to use for improved robustness
2596 * if true will return a MULTILINESTRING, otherwise (the default)
2597 * it will return a GEOMETRYCOLLECTION containing triangular POLYGONs.
2599 PHP_METHOD(Geometry
, delaunayTriangulation
)
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
) {
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
)
2633 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss",
2634 &mat
, &matlen
, &pat
, &patlen
) == FAILURE
)
2639 ret
= GEOSRelatePatternMatch(mat
, pat
);
2640 if ( ret
== 2 ) RETURN_NULL(); /* should get an exception first */
2642 /* return_value is a zval */
2644 RETURN_BOOL(retBool
);
2647 /* ------ Initialization / Deinitialization / Meta ------------------ */
2649 /* per-module initialization */
2650 PHP_MINIT_FUNCTION(geos
)
2652 zend_class_entry ce
;
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
;
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
;
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
;
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
;
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
;
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
);
2749 /* per-module shutdown */
2750 PHP_MSHUTDOWN_FUNCTION(geos
)
2752 delGeometrySerializer();
2753 delGeometryDeserializer();
2757 /* per-request initialization */
2758 PHP_RINIT_FUNCTION(geos
)
2760 initGEOS(noticeHandler
, errorHandler
);
2764 /* pre-request destruction */
2765 PHP_RSHUTDOWN_FUNCTION(geos
)
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();