1/************************************************************************
2 *
3 *
4 * C-Wrapper for GEOS library
5 *
6 * Copyright (C) 2010 2011 Sandro Santilli <strk@kbt.io>
7 * Copyright (C) 2005 Refractions Research Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 * Author: Sandro Santilli <strk@kbt.io>
15 *
16 ***********************************************************************
17 *
18 * GENERAL NOTES:
19 *
20 *	- Remember to call initGEOS() before any use of this library's
21 *	  functions, and call finishGEOS() when done.
22 *
23 *	- Currently you have to explicitly GEOSGeom_destroy() all
24 *	  GEOSGeom objects to avoid memory leaks, and GEOSFree()
25 *	  all returned char * (unless const).
26 *
27 *	- Functions ending with _r are thread safe; see details in RFC 3
28 *	  http://trac.osgeo.org/geos/wiki/RFC3.
29 *	  To avoid using by accident non _r functions,
30 *	  define GEOS_USE_ONLY_R_API before including geos_c.h
31 *
32 ***********************************************************************/
33
34#ifndef GEOS_C_H_INCLUDED
35#define GEOS_C_H_INCLUDED
36
37#ifndef __cplusplus
38# include <stddef.h> /* for size_t definition */
39#else
40# include <cstddef>
41using std::size_t;
42#endif
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/************************************************************************
49 *
50 * Version
51 *
52 ***********************************************************************/
53
54#ifndef GEOS_VERSION_MAJOR
55#define GEOS_VERSION_MAJOR @VERSION_MAJOR@
56#endif
57#ifndef GEOS_VERSION_MINOR
58#define GEOS_VERSION_MINOR @VERSION_MINOR@
59#endif
60#ifndef GEOS_VERSION_PATCH
61#define GEOS_VERSION_PATCH @VERSION_PATCH@
62#endif
63#ifndef GEOS_VERSION
64#define GEOS_VERSION "@VERSION@"
65#endif
66#ifndef GEOS_JTS_PORT
67#define GEOS_JTS_PORT "@JTS_PORT@"
68#endif
69
70#define GEOS_CAPI_VERSION_MAJOR @CAPI_VERSION_MAJOR@
71#define GEOS_CAPI_VERSION_MINOR @CAPI_VERSION_MINOR@
72#define GEOS_CAPI_VERSION_PATCH @CAPI_VERSION_PATCH@
73#define GEOS_CAPI_VERSION "@VERSION@-CAPI-@CAPI_VERSION@"
74
75#define GEOS_CAPI_FIRST_INTERFACE GEOS_CAPI_VERSION_MAJOR
76#define GEOS_CAPI_LAST_INTERFACE (GEOS_CAPI_VERSION_MAJOR+GEOS_CAPI_VERSION_MINOR)
77
78
79/************************************************************************
80 *
81 * (Abstract) type definitions
82 *
83 ************************************************************************/
84
85typedef struct GEOSContextHandle_HS *GEOSContextHandle_t;
86
87typedef void (*GEOSMessageHandler)(const char *fmt, ...);
88
89/*
90 * A GEOS message handler function.
91 *
92 * @param message the message contents
93 * @param userdata the user data pointer that was passed to GEOS when registering this message handler.
94 *
95 *
96 * @see GEOSContext_setErrorMessageHandler
97 * @see GEOSContext_setNoticeMessageHandler
98 */
99typedef void (*GEOSMessageHandler_r)(const char *message, void *userdata);
100
101/* When we're included by geos_c.cpp, those are #defined to the original
102 * JTS definitions via preprocessor. We don't touch them to allow the
103 * compiler to cross-check the declarations. However, for all "normal"
104 * C-API users, we need to define them as "opaque" struct pointers, as
105 * those clients don't have access to the original C++ headers, by design.
106 */
107#ifndef GEOSGeometry
108typedef struct GEOSGeom_t GEOSGeometry;
109typedef struct GEOSPrepGeom_t GEOSPreparedGeometry;
110typedef struct GEOSCoordSeq_t GEOSCoordSequence;
111typedef struct GEOSSTRtree_t GEOSSTRtree;
112typedef struct GEOSBufParams_t GEOSBufferParams;
113#endif
114
115/* Those are compatibility definitions for source compatibility
116 * with GEOS 2.X clients relying on that type.
117 */
118typedef GEOSGeometry* GEOSGeom;
119typedef GEOSCoordSequence* GEOSCoordSeq;
120
121/* Supported geometry types
122 * This was renamed from GEOSGeomTypeId in GEOS 2.2.X, which might
123 * break compatibility, this issue is still under investigation.
124 */
125
126enum GEOSGeomTypes {
127    GEOS_POINT,
128    GEOS_LINESTRING,
129    GEOS_LINEARRING,
130    GEOS_POLYGON,
131    GEOS_MULTIPOINT,
132    GEOS_MULTILINESTRING,
133    GEOS_MULTIPOLYGON,
134    GEOS_GEOMETRYCOLLECTION
135};
136
137/* Byte orders exposed via the C API */
138enum GEOSByteOrders {
139    GEOS_WKB_XDR = 0, /* Big Endian */
140    GEOS_WKB_NDR = 1 /* Little Endian */
141};
142
143typedef void (*GEOSQueryCallback)(void *item, void *userdata);
144typedef int (*GEOSDistanceCallback)(const void *item1, const void* item2, double* distance, void* userdata);
145
146/************************************************************************
147 *
148 * Initialization, cleanup, version
149 *
150 ***********************************************************************/
151
152#include <geos/export.h>
153
154/*
155 * Register an interruption checking callback
156 *
157 * The callback will be invoked _before_ checking for
158 * interruption, so can be used to request it.
159 */
160typedef void (GEOSInterruptCallback)();
161extern GEOSInterruptCallback GEOS_DLL *GEOS_interruptRegisterCallback(GEOSInterruptCallback* cb);
162/* Request safe interruption of operations */
163extern void GEOS_DLL GEOS_interruptRequest();
164/* Cancel a pending interruption request */
165extern void GEOS_DLL GEOS_interruptCancel();
166
167/*
168 * @deprecated in 3.5.0
169 *     initialize using GEOS_init_r() and set the message handlers using
170 *     GEOSContext_setNoticeHandler_r and/or GEOSContext_setErrorHandler_r
171 */
172extern GEOSContextHandle_t GEOS_DLL initGEOS_r(
173                                    GEOSMessageHandler notice_function,
174                                    GEOSMessageHandler error_function);
175/*
176 * @deprecated in 3.5.0 replaced by GEOS_finish_r.
177 */
178extern void GEOS_DLL finishGEOS_r(GEOSContextHandle_t handle);
179
180extern GEOSContextHandle_t GEOS_DLL GEOS_init_r();
181extern void GEOS_DLL GEOS_finish_r(GEOSContextHandle_t handle);
182
183
184extern GEOSMessageHandler GEOS_DLL GEOSContext_setNoticeHandler_r(GEOSContextHandle_t extHandle,
185                                                                  GEOSMessageHandler nf);
186extern GEOSMessageHandler GEOS_DLL GEOSContext_setErrorHandler_r(GEOSContextHandle_t extHandle,
187                                                                 GEOSMessageHandler ef);
188
189/*
190 * Sets a notice message handler on the given GEOS context.
191 *
192 * @param extHandle the GEOS context
193 * @param nf the message handler
194 * @param userData optional user data pointer that will be passed to the message handler
195 *
196 * @return the previously configured message handler or NULL if no message handler was configured
197 */
198extern GEOSMessageHandler_r GEOS_DLL GEOSContext_setNoticeMessageHandler_r(GEOSContextHandle_t extHandle,
199                                                                           GEOSMessageHandler_r nf,
200                                                                           void *userData);
201
202/*
203 * Sets an error message handler on the given GEOS context.
204 *
205 * @param extHandle the GEOS context
206 * @param ef the message handler
207 * @param userData optional user data pointer that will be passed to the message handler
208 *
209 * @return the previously configured message handler or NULL if no message handler was configured
210 */
211extern GEOSMessageHandler_r GEOS_DLL GEOSContext_setErrorMessageHandler_r(GEOSContextHandle_t extHandle,
212                                                                          GEOSMessageHandler_r ef,
213                                                                          void *userData);
214
215extern const char GEOS_DLL *GEOSversion();
216
217
218/************************************************************************
219 *
220 * NOTE - These functions are DEPRECATED.  Please use the new Reader and
221 * writer APIS!
222 *
223 ***********************************************************************/
224
225extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKT_r(GEOSContextHandle_t handle,
226                                                const char *wkt);
227extern char GEOS_DLL *GEOSGeomToWKT_r(GEOSContextHandle_t handle,
228                                      const GEOSGeometry* g);
229
230/*
231 * Specify whether output WKB should be 2d or 3d.
232 * Return previously set number of dimensions.
233 */
234
235extern int GEOS_DLL GEOS_getWKBOutputDims_r(GEOSContextHandle_t handle);
236extern int GEOS_DLL GEOS_setWKBOutputDims_r(GEOSContextHandle_t handle,
237                                            int newDims);
238
239/*
240 * Specify whether the WKB byte order is big or little endian.
241 * The return value is the previous byte order.
242 */
243
244extern int GEOS_DLL GEOS_getWKBByteOrder_r(GEOSContextHandle_t handle);
245extern int GEOS_DLL GEOS_setWKBByteOrder_r(GEOSContextHandle_t handle,
246                                           int byteOrder);
247
248extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKB_buf_r(GEOSContextHandle_t handle,
249                                                    const unsigned char *wkb,
250                                                    size_t size);
251extern unsigned char GEOS_DLL *GEOSGeomToWKB_buf_r(GEOSContextHandle_t handle,
252                                                   const GEOSGeometry* g,
253                                                   size_t *size);
254
255extern GEOSGeometry GEOS_DLL *GEOSGeomFromHEX_buf_r(GEOSContextHandle_t handle,
256                                                    const unsigned char *hex,
257                                                    size_t size);
258extern unsigned char GEOS_DLL *GEOSGeomToHEX_buf_r(GEOSContextHandle_t handle,
259                                                   const GEOSGeometry* g,
260                                                   size_t *size);
261
262/************************************************************************
263 *
264 * Coordinate Sequence functions
265 *
266 ***********************************************************************/
267
268/*
269 * Create a Coordinate sequence with ``size'' coordinates
270 * of ``dims'' dimensions.
271 * Return NULL on exception.
272 */
273extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_create_r(
274                                                GEOSContextHandle_t handle,
275                                                unsigned int size,
276                                                unsigned int dims);
277
278/*
279 * Clone a Coordinate Sequence.
280 * Return NULL on exception.
281 */
282extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_clone_r(
283                                                GEOSContextHandle_t handle,
284                                                const GEOSCoordSequence* s);
285
286/*
287 * Destroy a Coordinate Sequence.
288 */
289extern void GEOS_DLL GEOSCoordSeq_destroy_r(GEOSContextHandle_t handle,
290                                            GEOSCoordSequence* s);
291
292/*
293 * Set ordinate values in a Coordinate Sequence.
294 * Return 0 on exception.
295 */
296extern int GEOS_DLL GEOSCoordSeq_setX_r(GEOSContextHandle_t handle,
297                                        GEOSCoordSequence* s, unsigned int idx,
298                                        double val);
299extern int GEOS_DLL GEOSCoordSeq_setY_r(GEOSContextHandle_t handle,
300                                        GEOSCoordSequence* s, unsigned int idx,
301                                        double val);
302extern int GEOS_DLL GEOSCoordSeq_setZ_r(GEOSContextHandle_t handle,
303                                        GEOSCoordSequence* s, unsigned int idx,
304                                        double val);
305extern int GEOS_DLL GEOSCoordSeq_setXY_r(GEOSContextHandle_t handle,
306                                        GEOSCoordSequence* s, unsigned int idx,
307                                        double x, double y);
308extern int GEOS_DLL GEOSCoordSeq_setXYZ_r(GEOSContextHandle_t handle,
309                                        GEOSCoordSequence* s, unsigned int idx,
310                                        double x, double y, double z);
311
312extern int GEOS_DLL GEOSCoordSeq_setOrdinate_r(GEOSContextHandle_t handle,
313                                               GEOSCoordSequence* s,
314                                               unsigned int idx,
315                                               unsigned int dim, double val);
316
317/*
318 * Get ordinate values from a Coordinate Sequence.
319 * Return 0 on exception.
320 */
321extern int GEOS_DLL GEOSCoordSeq_getX_r(GEOSContextHandle_t handle,
322                                        const GEOSCoordSequence* s,
323                                        unsigned int idx, double *val);
324extern int GEOS_DLL GEOSCoordSeq_getY_r(GEOSContextHandle_t handle,
325                                        const GEOSCoordSequence* s,
326                                        unsigned int idx, double *val);
327extern int GEOS_DLL GEOSCoordSeq_getZ_r(GEOSContextHandle_t handle,
328                                        const GEOSCoordSequence* s,
329                                        unsigned int idx, double *val);
330extern int GEOS_DLL GEOSCoordSeq_getXY_r(GEOSContextHandle_t handle,
331                                         const GEOSCoordSequence* s,
332                                         unsigned int idx, double *x, double *y);
333extern int GEOS_DLL GEOSCoordSeq_getXYZ_r(GEOSContextHandle_t handle,
334                                          const GEOSCoordSequence* s,
335                                          unsigned int idx, double *x, double *y, double *z);
336extern int GEOS_DLL GEOSCoordSeq_getOrdinate_r(GEOSContextHandle_t handle,
337                                               const GEOSCoordSequence* s,
338                                               unsigned int idx,
339                                               unsigned int dim, double *val);
340/*
341 * Get size and dimensions info from a Coordinate Sequence.
342 * Return 0 on exception.
343 */
344extern int GEOS_DLL GEOSCoordSeq_getSize_r(GEOSContextHandle_t handle,
345                                           const GEOSCoordSequence* s,
346                                           unsigned int *size);
347extern int GEOS_DLL GEOSCoordSeq_getDimensions_r(GEOSContextHandle_t handle,
348                                                 const GEOSCoordSequence* s,
349                                                 unsigned int *dims);
350/*
351 * Check orientation of a CoordinateSequence and set 'is_ccw' to 1
352 * if it has counter-clockwise orientation, 0 otherwise.
353 * Return 0 on exception, 1 on success.
354 */
355extern int GEOS_DLL GEOSCoordSeq_isCCW_r(GEOSContextHandle_t handle,
356                                         const GEOSCoordSequence* s,
357                                         char* is_ccw);
358
359/************************************************************************
360 *
361 *  Linear referencing functions -- there are more, but these are
362 *  probably sufficient for most purposes
363 *
364 ***********************************************************************/
365
366/*
367 * GEOSGeometry ownership is retained by caller
368 */
369
370
371/* Return distance of point 'p' projected on 'g' from origin
372 * of 'g'. Geometry 'g' must be a lineal geometry.
373 * Return -1 on exception*/
374extern double GEOS_DLL GEOSProject_r(GEOSContextHandle_t handle,
375                                     const GEOSGeometry *g,
376                                     const GEOSGeometry *p);
377
378/* Return closest point to given distance within geometry
379 * Geometry must be a LineString */
380extern GEOSGeometry GEOS_DLL *GEOSInterpolate_r(GEOSContextHandle_t handle,
381                                                const GEOSGeometry *g,
382                                                double d);
383
384extern double GEOS_DLL GEOSProjectNormalized_r(GEOSContextHandle_t handle,
385                                               const GEOSGeometry *g,
386                                               const GEOSGeometry *p);
387
388extern GEOSGeometry GEOS_DLL *GEOSInterpolateNormalized_r(
389                                                GEOSContextHandle_t handle,
390                                                const GEOSGeometry *g,
391                                                double d);
392
393/************************************************************************
394 *
395 * Buffer related functions
396 *
397 ***********************************************************************/
398
399
400/* @return NULL on exception */
401extern GEOSGeometry GEOS_DLL *GEOSBuffer_r(GEOSContextHandle_t handle,
402                                           const GEOSGeometry* g,
403                                           double width, int quadsegs);
404
405enum GEOSBufCapStyles {
406	GEOSBUF_CAP_ROUND=1,
407	GEOSBUF_CAP_FLAT=2,
408	GEOSBUF_CAP_SQUARE=3
409};
410
411enum GEOSBufJoinStyles {
412	GEOSBUF_JOIN_ROUND=1,
413	GEOSBUF_JOIN_MITRE=2,
414	GEOSBUF_JOIN_BEVEL=3
415};
416
417/* @return 0 on exception */
418extern GEOSBufferParams GEOS_DLL *GEOSBufferParams_create_r(
419                                              GEOSContextHandle_t handle);
420extern void GEOS_DLL GEOSBufferParams_destroy_r(
421                                              GEOSContextHandle_t handle,
422                                              GEOSBufferParams* parms);
423
424/* @return 0 on exception */
425extern int GEOS_DLL GEOSBufferParams_setEndCapStyle_r(
426                                              GEOSContextHandle_t handle,
427                                              GEOSBufferParams* p,
428                                              int style);
429
430/* @return 0 on exception */
431extern int GEOS_DLL GEOSBufferParams_setJoinStyle_r(
432                                              GEOSContextHandle_t handle,
433                                              GEOSBufferParams* p,
434                                              int joinStyle);
435
436/* @return 0 on exception */
437extern int GEOS_DLL GEOSBufferParams_setMitreLimit_r(
438                                              GEOSContextHandle_t handle,
439                                              GEOSBufferParams* p,
440                                              double mitreLimit);
441
442/* @return 0 on exception */
443extern int GEOS_DLL GEOSBufferParams_setQuadrantSegments_r(
444                                              GEOSContextHandle_t handle,
445                                              GEOSBufferParams* p,
446                                              int quadSegs);
447
448/* @param singleSided: 1 for single sided, 0 otherwise */
449/* @return 0 on exception */
450extern int GEOS_DLL GEOSBufferParams_setSingleSided_r(
451                                              GEOSContextHandle_t handle,
452                                              GEOSBufferParams* p,
453                                              int singleSided);
454
455/* @return NULL on exception */
456extern GEOSGeometry GEOS_DLL *GEOSBufferWithParams_r(
457                                              GEOSContextHandle_t handle,
458                                              const GEOSGeometry* g,
459                                              const GEOSBufferParams* p,
460                                              double width);
461
462/* These functions return NULL on exception. */
463extern GEOSGeometry GEOS_DLL *GEOSBufferWithStyle_r(GEOSContextHandle_t handle,
464	const GEOSGeometry* g, double width, int quadsegs, int endCapStyle,
465	int joinStyle, double mitreLimit);
466
467/* These functions return NULL on exception. Only LINESTRINGs are accepted. */
468/* @deprecated in 3.3.0: use GEOSOffsetCurve instead */
469extern GEOSGeometry GEOS_DLL *GEOSSingleSidedBuffer_r(
470	GEOSContextHandle_t handle,
471	const GEOSGeometry* g, double width, int quadsegs,
472	int joinStyle, double mitreLimit, int leftSide);
473
474/*
475 * Only LINESTRINGs are accepted.
476 * @param width : offset distance.
477 *                negative for right side offset.
478 *                positive for left side offset.
479 * @return NULL on exception
480 */
481extern GEOSGeometry GEOS_DLL *GEOSOffsetCurve_r(GEOSContextHandle_t handle,
482	const GEOSGeometry* g, double width, int quadsegs,
483	int joinStyle, double mitreLimit);
484
485
486/************************************************************************
487 *
488 * Geometry Constructors.
489 * GEOSCoordSequence* arguments will become ownership of the returned object.
490 * All functions return NULL on exception.
491 *
492 ***********************************************************************/
493
494extern GEOSGeometry GEOS_DLL *GEOSGeom_createPoint_r(
495                                       GEOSContextHandle_t handle,
496                                       GEOSCoordSequence* s);
497extern GEOSGeometry GEOS_DLL *GEOSGeom_createPointFromXY_r(
498                                       GEOSContextHandle_t handle,
499                                       double x,
500                                       double y);
501extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPoint_r(
502                                       GEOSContextHandle_t handle);
503extern GEOSGeometry GEOS_DLL *GEOSGeom_createLinearRing_r(
504                                       GEOSContextHandle_t handle,
505                                       GEOSCoordSequence* s);
506extern GEOSGeometry GEOS_DLL *GEOSGeom_createLineString_r(
507                                       GEOSContextHandle_t handle,
508                                       GEOSCoordSequence* s);
509extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyLineString_r(
510                                       GEOSContextHandle_t handle);
511
512/*
513 * Second argument is an array of GEOSGeometry* objects.
514 * The caller remains owner of the array, but pointed-to
515 * objects become ownership of the returned GEOSGeometry.
516 */
517extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPolygon_r(
518                                       GEOSContextHandle_t handle);
519extern GEOSGeometry GEOS_DLL *GEOSGeom_createPolygon_r(
520                                       GEOSContextHandle_t handle,
521                                       GEOSGeometry* shell,
522                                       GEOSGeometry** holes,
523                                       unsigned int nholes);
524extern GEOSGeometry GEOS_DLL *GEOSGeom_createCollection_r(
525                                       GEOSContextHandle_t handle, int type,
526                                       GEOSGeometry* *geoms,
527                                       unsigned int ngeoms);
528extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyCollection_r(
529                                       GEOSContextHandle_t handle, int type);
530
531extern GEOSGeometry GEOS_DLL *GEOSGeom_clone_r(GEOSContextHandle_t handle,
532                                               const GEOSGeometry* g);
533
534/************************************************************************
535 *
536 * Memory management
537 *
538 ***********************************************************************/
539
540extern void GEOS_DLL GEOSGeom_destroy_r(GEOSContextHandle_t handle,
541                                        GEOSGeometry* g);
542
543/************************************************************************
544 *
545 * Topology operations - return NULL on exception.
546 *
547 ***********************************************************************/
548
549extern GEOSGeometry GEOS_DLL *GEOSEnvelope_r(GEOSContextHandle_t handle,
550                                             const GEOSGeometry* g);
551extern GEOSGeometry GEOS_DLL *GEOSIntersection_r(GEOSContextHandle_t handle,
552                                                 const GEOSGeometry* g1,
553                                                 const GEOSGeometry* g2);
554extern GEOSGeometry GEOS_DLL *GEOSIntersectionPrec_r(GEOSContextHandle_t handle,
555                                                 const GEOSGeometry* g1,
556                                                 const GEOSGeometry* g2,
557                                                 double gridSize);
558extern GEOSGeometry GEOS_DLL *GEOSConvexHull_r(GEOSContextHandle_t handle,
559                                               const GEOSGeometry* g);
560
561/* Returns the minimum rotated rectangular POLYGON which encloses the input geometry. The rectangle
562 * has width equal to the minimum diameter, and a longer length. If the convex hill of the input is
563 * degenerate (a line or point) a LINESTRING or POINT is returned. The minimum rotated rectangle can
564 * be used as an extremely generalized representation for the given geometry.
565 */
566extern GEOSGeometry GEOS_DLL *GEOSMinimumRotatedRectangle_r(GEOSContextHandle_t handle,
567                                               const GEOSGeometry* g);
568
569extern GEOSGeometry GEOS_DLL *GEOSMaximumInscribedCircle_r(GEOSContextHandle_t handle, const GEOSGeometry* g, double tolerance);
570extern GEOSGeometry GEOS_DLL *GEOSLargestEmptyCircle_r(GEOSContextHandle_t handle, const GEOSGeometry* g, const GEOSGeometry* boundary, double tolerance);
571
572/* Returns a LINESTRING geometry which represents the minimum diameter of the geometry.
573 * The minimum diameter is defined to be the width of the smallest band that
574 * contains the geometry, where a band is a strip of the plane defined
575 * by two parallel lines. This can be thought of as the smallest hole that the geometry
576 * can be moved through, with a single rotation.
577 */
578extern GEOSGeometry GEOS_DLL *GEOSMinimumWidth_r(GEOSContextHandle_t handle,
579                                               const GEOSGeometry* g);
580
581extern GEOSGeometry GEOS_DLL *GEOSMinimumClearanceLine_r(GEOSContextHandle_t handle,
582                                                     const GEOSGeometry* g);
583
584extern int GEOS_DLL GEOSMinimumClearance_r(GEOSContextHandle_t handle,
585                                           const GEOSGeometry* g,
586                                           double* distance);
587
588extern GEOSGeometry GEOS_DLL *GEOSDifference_r(GEOSContextHandle_t handle,
589                                               const GEOSGeometry* g1,
590                                               const GEOSGeometry* g2);
591extern GEOSGeometry GEOS_DLL *GEOSDifferencePrec_r(GEOSContextHandle_t handle,
592                                                   const GEOSGeometry* g1,
593                                                   const GEOSGeometry* g2,
594                                                   double gridSize);
595extern GEOSGeometry GEOS_DLL *GEOSSymDifference_r(GEOSContextHandle_t handle,
596                                                  const GEOSGeometry* g1,
597                                                  const GEOSGeometry* g2);
598extern GEOSGeometry GEOS_DLL *GEOSSymDifferencePrec_r(GEOSContextHandle_t handle,
599                                                      const GEOSGeometry* g1,
600                                                      const GEOSGeometry* g2,
601                                                      double gridSize);
602extern GEOSGeometry GEOS_DLL *GEOSBoundary_r(GEOSContextHandle_t handle,
603                                             const GEOSGeometry* g);
604extern GEOSGeometry GEOS_DLL *GEOSUnion_r(GEOSContextHandle_t handle,
605                                          const GEOSGeometry* g1,
606                                          const GEOSGeometry* g2);
607extern GEOSGeometry GEOS_DLL *GEOSUnionPrec_r(GEOSContextHandle_t handle,
608                                              const GEOSGeometry* g1,
609                                              const GEOSGeometry* g2,
610                                              double gridSize);
611extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion_r(GEOSContextHandle_t handle,
612                                          const GEOSGeometry* g);
613extern GEOSGeometry GEOS_DLL *GEOSUnaryUnionPrec_r(GEOSContextHandle_t handle,
614                                          const GEOSGeometry* g,
615                                          double gridSize);
616/* GEOSCoverageUnion is an optimized union algorithm for polygonal inputs that are correctly
617 * noded and do not overlap. It will not generate an error (return NULL) for inputs that
618 * do not satisfy this constraint. */
619extern GEOSGeometry GEOS_DLL *GEOSCoverageUnion_r(GEOSContextHandle_t handle,
620                                                  const GEOSGeometry* g);
621/* @deprecated in 3.3.0: use GEOSUnaryUnion_r instead */
622extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded_r(GEOSContextHandle_t handle,
623                                                  const GEOSGeometry* g);
624extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface_r(GEOSContextHandle_t handle,
625                                                   const GEOSGeometry* g);
626extern GEOSGeometry GEOS_DLL *GEOSGetCentroid_r(GEOSContextHandle_t handle,
627                                                const GEOSGeometry* g);
628extern GEOSGeometry GEOS_DLL *GEOSMinimumBoundingCircle_r(GEOSContextHandle_t handle,
629                                                const GEOSGeometry* g, double* radius,
630                                                GEOSGeometry** center);
631extern GEOSGeometry GEOS_DLL *GEOSNode_r(GEOSContextHandle_t handle,
632                                         const GEOSGeometry* g);
633/* Fast, non-robust intersection between an arbitrary geometry and
634 * a rectangle. The returned geometry may be invalid. */
635extern GEOSGeometry GEOS_DLL *GEOSClipByRect_r(GEOSContextHandle_t handle,
636                                                 const GEOSGeometry* g,
637                                                 double xmin, double ymin,
638                                                 double xmax, double ymax);
639
640/*
641 * all arguments remain ownership of the caller
642 * (both Geometries and pointers)
643 */
644/*
645 * Polygonizes a set of Geometries which contain linework that
646 * represents the edges of a planar graph.
647 *
648 * All types of Geometry are accepted as input; the constituent
649 * linework is extracted as the edges to be polygonized.
650 *
651 * The edges must be correctly noded; that is, they must only meet
652 * at their endpoints. Polygonization will accept incorrectly noded
653 * input but will not form polygons from non-noded edges, and reports
654 * them as errors.
655 *
656 * The Polygonizer reports the follow kinds of errors:
657 *
658 * - Dangles - edges which have one or both ends which are
659 *   not incident on another edge endpoint
660 * - Cut Edges - edges which are connected at both ends but
661 *   which do not form part of a polygon
662 * - Invalid Ring Lines - edges which form rings which are invalid
663 *   (e.g. the component lines contain a self-intersection)
664 *
665 * Errors are reported to output parameters "cuts", "dangles" and
666 * "invalid" (if not-null). Formed polygons are returned as a
667 * collection. NULL is returned on exception. All returned
668 * geometries must be destroyed by caller.
669 *
670 * The GEOSPolygonize_valid_r variant allows extracting only polygons
671 * which form a valid polygonal result. The set of extracted polygons
672 * is guaranteed to be edge-disjoint. This is useful when it is known
673 * that the input lines form a valid polygonal geometry (which may
674 * include holes or nested polygons).
675 */
676
677extern GEOSGeometry GEOS_DLL *GEOSPolygonize_r(GEOSContextHandle_t handle,
678                              const GEOSGeometry *const geoms[],
679                              unsigned int ngeoms);
680extern GEOSGeometry GEOS_DLL *GEOSPolygonize_valid_r(GEOSContextHandle_t handle,
681                                                     const GEOSGeometry *const geoms[],
682                                                     unsigned int ngems);
683extern GEOSGeometry GEOS_DLL *GEOSPolygonizer_getCutEdges_r(
684                              GEOSContextHandle_t handle,
685                              const GEOSGeometry * const geoms[],
686                              unsigned int ngeoms);
687extern GEOSGeometry GEOS_DLL *GEOSPolygonize_full_r(GEOSContextHandle_t handle,
688                              const GEOSGeometry* input, GEOSGeometry** cuts,
689                              GEOSGeometry** dangles, GEOSGeometry** invalidRings);
690
691extern GEOSGeometry GEOS_DLL *GEOSBuildArea_r(
692                                              GEOSContextHandle_t handle,
693                                              const GEOSGeometry* g);
694
695extern GEOSGeometry GEOS_DLL *GEOSLineMerge_r(GEOSContextHandle_t handle,
696                                              const GEOSGeometry* g);
697extern GEOSGeometry GEOS_DLL *GEOSReverse_r(GEOSContextHandle_t handle,
698                                            const GEOSGeometry* g);
699extern GEOSGeometry GEOS_DLL *GEOSSimplify_r(GEOSContextHandle_t handle,
700                                             const GEOSGeometry* g,
701                                             double tolerance);
702extern GEOSGeometry GEOS_DLL *GEOSTopologyPreserveSimplify_r(
703                              GEOSContextHandle_t handle,
704                              const GEOSGeometry* g, double tolerance);
705
706/*
707 * Return all distinct vertices of input geometry as a MULTIPOINT.
708 * Note that only 2 dimensions of the vertices are considered when
709 * testing for equality.
710 */
711extern GEOSGeometry GEOS_DLL *GEOSGeom_extractUniquePoints_r(
712                              GEOSContextHandle_t handle,
713                              const GEOSGeometry* g);
714
715/*
716 * Find paths shared between the two given lineal geometries.
717 *
718 * Returns a GEOMETRYCOLLECTION having two elements:
719 * - first element is a MULTILINESTRING containing shared paths
720 *   having the _same_ direction on both inputs
721 * - second element is a MULTILINESTRING containing shared paths
722 *   having the _opposite_ direction on the two inputs
723 *
724 * Returns NULL on exception
725 */
726extern GEOSGeometry GEOS_DLL *GEOSSharedPaths_r(GEOSContextHandle_t handle,
727  const GEOSGeometry* g1, const GEOSGeometry* g2);
728
729/*
730 * Snap first geometry on to second with given tolerance
731 * Returns a newly allocated geometry, or NULL on exception
732 */
733extern GEOSGeometry GEOS_DLL *GEOSSnap_r(GEOSContextHandle_t handle,
734  const GEOSGeometry* g1, const GEOSGeometry* g2, double tolerance);
735
736/*
737 * Return a Delaunay triangulation of the vertex of the given geometry
738 *
739 * @param g the input geometry whose vertex will be used as "sites"
740 * @param tolerance optional snapping tolerance to use for improved robustness
741 * @param onlyEdges if non-zero will return a MULTILINESTRING, otherwise it will
742 *                  return a GEOMETRYCOLLECTION containing triangular POLYGONs.
743 *
744 * @return  a newly allocated geometry, or NULL on exception
745 */
746extern GEOSGeometry GEOS_DLL * GEOSDelaunayTriangulation_r(
747                                  GEOSContextHandle_t handle,
748                                  const GEOSGeometry *g,
749                                  double tolerance,
750                                  int onlyEdges);
751
752/*
753 * Returns the Voronoi polygons of a set of Vertices given as input
754 *
755 * @param g the input geometry whose vertex will be used as sites.
756 * @param tolerance snapping tolerance to use for improved robustness
757 * @param onlyEdges whether to return only edges of the Voronoi cells
758 * @param env clipping envelope for the returned diagram, automatically
759 *            determined if NULL.
760 *            The diagram will be clipped to the larger
761 *            of this envelope or an envelope surrounding the sites.
762 *
763 * @return a newly allocated geometry, or NULL on exception.
764 */
765extern GEOSGeometry GEOS_DLL * GEOSVoronoiDiagram_r(
766				GEOSContextHandle_t extHandle,
767				const GEOSGeometry *g,
768				const GEOSGeometry *env,
769				double tolerance,
770				int onlyEdges);
771
772/*
773 * Computes the coordinate where two line segments intersect, if any
774 *
775 * @param ax0 x-coordinate of first point in first segment
776 * @param ay0 y-coordinate of first point in first segment
777 * @param ax1 x-coordinate of second point in first segment
778 * @param ay1 y-coordinate of second point in first segment
779 * @param bx0 x-coordinate of first point in second segment
780 * @param by0 y-coordinate of first point in second segment
781 * @param bx1 x-coordinate of second point in second segment
782 * @param by1 y-coordinate of second point in second segment
783 * @param cx x-coordinate of intersection point
784 * @param cy y-coordinate of intersection point
785 *
786 * @return 0 on error, 1 on success, -1 if segments do not intersect
787 */
788
789extern int GEOS_DLL GEOSSegmentIntersection_r(
790       GEOSContextHandle_t extHandle,
791       double ax0, double ay0,
792       double ax1, double ay1,
793       double bx0, double by0,
794       double bx1, double by1,
795       double* cx, double* cy);
796
797/************************************************************************
798 *
799 *  Binary predicates - return 2 on exception, 1 on true, 0 on false
800 *
801 ***********************************************************************/
802
803extern char GEOS_DLL GEOSDisjoint_r(GEOSContextHandle_t handle,
804                                    const GEOSGeometry* g1,
805                                    const GEOSGeometry* g2);
806extern char GEOS_DLL GEOSTouches_r(GEOSContextHandle_t handle,
807                                   const GEOSGeometry* g1,
808                                   const GEOSGeometry* g2);
809extern char GEOS_DLL GEOSIntersects_r(GEOSContextHandle_t handle,
810                                      const GEOSGeometry* g1,
811                                      const GEOSGeometry* g2);
812extern char GEOS_DLL GEOSCrosses_r(GEOSContextHandle_t handle,
813                                   const GEOSGeometry* g1,
814                                   const GEOSGeometry* g2);
815extern char GEOS_DLL GEOSWithin_r(GEOSContextHandle_t handle,
816                                  const GEOSGeometry* g1,
817                                  const GEOSGeometry* g2);
818extern char GEOS_DLL GEOSContains_r(GEOSContextHandle_t handle,
819                                    const GEOSGeometry* g1,
820                                    const GEOSGeometry* g2);
821extern char GEOS_DLL GEOSOverlaps_r(GEOSContextHandle_t handle,
822                                    const GEOSGeometry* g1,
823                                    const GEOSGeometry* g2);
824extern char GEOS_DLL GEOSEquals_r(GEOSContextHandle_t handle,
825                                  const GEOSGeometry* g1,
826                                  const GEOSGeometry* g2);
827extern char GEOS_DLL GEOSEqualsExact_r(GEOSContextHandle_t handle,
828                                       const GEOSGeometry* g1,
829                                       const GEOSGeometry* g2,
830                                       double tolerance);
831extern char GEOS_DLL GEOSCovers_r(GEOSContextHandle_t handle,
832                                  const GEOSGeometry* g1,
833                                  const GEOSGeometry* g2);
834extern char GEOS_DLL GEOSCoveredBy_r(GEOSContextHandle_t handle,
835                                  const GEOSGeometry* g1,
836                                  const GEOSGeometry* g2);
837
838/************************************************************************
839 *
840 *  Prepared Geometry Binary predicates - return 2 on exception, 1 on true, 0 on false
841 *
842 ***********************************************************************/
843
844/*
845 * GEOSGeometry ownership is retained by caller
846 */
847extern const GEOSPreparedGeometry GEOS_DLL *GEOSPrepare_r(
848                                            GEOSContextHandle_t handle,
849                                            const GEOSGeometry* g);
850
851extern void GEOS_DLL GEOSPreparedGeom_destroy_r(GEOSContextHandle_t handle,
852                                                const GEOSPreparedGeometry* g);
853
854extern char GEOS_DLL GEOSPreparedContains_r(GEOSContextHandle_t handle,
855                                            const GEOSPreparedGeometry* pg1,
856                                            const GEOSGeometry* g2);
857extern char GEOS_DLL GEOSPreparedContainsProperly_r(GEOSContextHandle_t handle,
858                                         const GEOSPreparedGeometry* pg1,
859                                         const GEOSGeometry* g2);
860extern char GEOS_DLL GEOSPreparedCoveredBy_r(GEOSContextHandle_t handle,
861                                          const GEOSPreparedGeometry* pg1,
862                                          const GEOSGeometry* g2);
863extern char GEOS_DLL GEOSPreparedCovers_r(GEOSContextHandle_t handle,
864                                          const GEOSPreparedGeometry* pg1,
865                                          const GEOSGeometry* g2);
866extern char GEOS_DLL GEOSPreparedCrosses_r(GEOSContextHandle_t handle,
867                                          const GEOSPreparedGeometry* pg1,
868                                          const GEOSGeometry* g2);
869extern char GEOS_DLL GEOSPreparedDisjoint_r(GEOSContextHandle_t handle,
870                                          const GEOSPreparedGeometry* pg1,
871                                          const GEOSGeometry* g2);
872extern char GEOS_DLL GEOSPreparedIntersects_r(GEOSContextHandle_t handle,
873                                              const GEOSPreparedGeometry* pg1,
874                                              const GEOSGeometry* g2);
875extern char GEOS_DLL GEOSPreparedOverlaps_r(GEOSContextHandle_t handle,
876                                          const GEOSPreparedGeometry* pg1,
877                                          const GEOSGeometry* g2);
878extern char GEOS_DLL GEOSPreparedTouches_r(GEOSContextHandle_t handle,
879                                          const GEOSPreparedGeometry* pg1,
880                                          const GEOSGeometry* g2);
881extern char GEOS_DLL GEOSPreparedWithin_r(GEOSContextHandle_t handle,
882                                          const GEOSPreparedGeometry* pg1,
883                                          const GEOSGeometry* g2);
884
885/* Return 0 on exception, the closest points of the two geometries otherwise.
886 * The first point comes from pg1 geometry and the second point comes from g2.
887 */
888extern GEOSCoordSequence GEOS_DLL *GEOSPreparedNearestPoints_r(
889                                          GEOSContextHandle_t handle,
890                                          const GEOSPreparedGeometry* pg1,
891                                          const GEOSGeometry* g2);
892
893extern int GEOS_DLL GEOSPreparedDistance_r(
894                                GEOSContextHandle_t handle,
895                                const GEOSPreparedGeometry* pg1,
896                                const GEOSGeometry* g2, double *dist);
897
898/************************************************************************
899 *
900 *  STRtree functions
901 *
902 ***********************************************************************/
903
904/*
905 * GEOSGeometry ownership is retained by caller
906 */
907
908extern GEOSSTRtree GEOS_DLL *GEOSSTRtree_create_r(
909                                    GEOSContextHandle_t handle,
910                                    size_t nodeCapacity);
911extern void GEOS_DLL GEOSSTRtree_insert_r(GEOSContextHandle_t handle,
912                                          GEOSSTRtree *tree,
913                                          const GEOSGeometry *g,
914                                          void *item);
915extern void GEOS_DLL GEOSSTRtree_query_r(GEOSContextHandle_t handle,
916                                         GEOSSTRtree *tree,
917                                         const GEOSGeometry *g,
918                                         GEOSQueryCallback callback,
919                                         void *userdata);
920
921extern const GEOSGeometry GEOS_DLL *GEOSSTRtree_nearest_r(GEOSContextHandle_t handle,
922                                                  GEOSSTRtree *tree,
923                                                  const GEOSGeometry* geom);
924
925
926extern const void GEOS_DLL *GEOSSTRtree_nearest_generic_r(GEOSContextHandle_t handle,
927                                                          GEOSSTRtree *tree,
928                                                          const void* item,
929                                                          const GEOSGeometry* itemEnvelope,
930                                                          GEOSDistanceCallback distancefn,
931                                                          void* userdata);
932
933extern void GEOS_DLL GEOSSTRtree_iterate_r(GEOSContextHandle_t handle,
934                                       GEOSSTRtree *tree,
935                                       GEOSQueryCallback callback,
936                                       void *userdata);
937extern char GEOS_DLL GEOSSTRtree_remove_r(GEOSContextHandle_t handle,
938                                          GEOSSTRtree *tree,
939                                          const GEOSGeometry *g,
940                                          void *item);
941extern void GEOS_DLL GEOSSTRtree_destroy_r(GEOSContextHandle_t handle,
942                                           GEOSSTRtree *tree);
943
944
945/************************************************************************
946 *
947 *  Unary predicate - return 2 on exception, 1 on true, 0 on false
948 *
949 ***********************************************************************/
950
951extern char GEOS_DLL GEOSisEmpty_r(GEOSContextHandle_t handle,
952                                   const GEOSGeometry* g);
953extern char GEOS_DLL GEOSisSimple_r(GEOSContextHandle_t handle,
954                                    const GEOSGeometry* g);
955extern char GEOS_DLL GEOSisRing_r(GEOSContextHandle_t handle,
956                                  const GEOSGeometry* g);
957extern char GEOS_DLL GEOSHasZ_r(GEOSContextHandle_t handle,
958                                const GEOSGeometry* g);
959extern char GEOS_DLL GEOSisClosed_r(GEOSContextHandle_t handle,
960                                const GEOSGeometry *g);
961
962/************************************************************************
963 *
964 *  Dimensionally Extended 9 Intersection Model related
965 *
966 ***********************************************************************/
967
968/* These are for use with GEOSRelateBoundaryNodeRule (flags param) */
969enum GEOSRelateBoundaryNodeRules {
970	/* MOD2 and OGC are the same rule, and is the default
971	 * used by GEOSRelatePattern
972	 */
973	GEOSRELATE_BNR_MOD2=1,
974	GEOSRELATE_BNR_OGC=1,
975	GEOSRELATE_BNR_ENDPOINT=2,
976	GEOSRELATE_BNR_MULTIVALENT_ENDPOINT=3,
977	GEOSRELATE_BNR_MONOVALENT_ENDPOINT=4
978};
979
980/* return 2 on exception, 1 on true, 0 on false */
981extern char GEOS_DLL GEOSRelatePattern_r(GEOSContextHandle_t handle,
982                                         const GEOSGeometry* g1,
983                                         const GEOSGeometry* g2,
984                                         const char *pat);
985
986/* return NULL on exception, a string to GEOSFree otherwise */
987extern char GEOS_DLL *GEOSRelate_r(GEOSContextHandle_t handle,
988                                   const GEOSGeometry* g1,
989                                   const GEOSGeometry* g2);
990
991/* return 2 on exception, 1 on true, 0 on false */
992extern char GEOS_DLL GEOSRelatePatternMatch_r(GEOSContextHandle_t handle,
993                                         const char *mat,
994                                         const char *pat);
995
996/* return NULL on exception, a string to GEOSFree otherwise */
997extern char GEOS_DLL *GEOSRelateBoundaryNodeRule_r(GEOSContextHandle_t handle,
998                                                   const GEOSGeometry* g1,
999                                                   const GEOSGeometry* g2,
1000                                                   int bnr);
1001
1002/************************************************************************
1003 *
1004 *  Validity checking
1005 *
1006 ***********************************************************************/
1007
1008/* These are for use with GEOSisValidDetail (flags param) */
1009enum GEOSValidFlags {
1010	GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE=1
1011};
1012
1013/* return 2 on exception, 1 on true, 0 on false */
1014extern char GEOS_DLL GEOSisValid_r(GEOSContextHandle_t handle,
1015                                   const GEOSGeometry* g);
1016
1017/* return NULL on exception, a string to GEOSFree otherwise */
1018extern char GEOS_DLL *GEOSisValidReason_r(GEOSContextHandle_t handle,
1019                                         const GEOSGeometry* g);
1020
1021/*
1022 * Caller has the responsibility to destroy 'reason' (GEOSFree)
1023 * and 'location' (GEOSGeom_destroy) params
1024 * return 2 on exception, 1 when valid, 0 when invalid
1025 */
1026extern char GEOS_DLL GEOSisValidDetail_r(GEOSContextHandle_t handle,
1027                                         const GEOSGeometry* g,
1028                                         int flags,
1029                                         char** reason,
1030                                         GEOSGeometry** location);
1031
1032extern GEOSGeometry GEOS_DLL *GEOSMakeValid_r(GEOSContextHandle_t handle,
1033                                              const GEOSGeometry* g);
1034
1035/************************************************************************
1036 *
1037 *  Geometry info
1038 *
1039 ***********************************************************************/
1040
1041/* Return NULL on exception, result must be freed by caller. */
1042extern char GEOS_DLL *GEOSGeomType_r(GEOSContextHandle_t handle,
1043                                     const GEOSGeometry* g);
1044
1045/* Return -1 on exception */
1046extern int GEOS_DLL GEOSGeomTypeId_r(GEOSContextHandle_t handle,
1047                                     const GEOSGeometry* g);
1048
1049/* Return 0 on exception */
1050extern int GEOS_DLL GEOSGetSRID_r(GEOSContextHandle_t handle,
1051                                  const GEOSGeometry* g);
1052
1053extern void GEOS_DLL GEOSSetSRID_r(GEOSContextHandle_t handle,
1054                                   GEOSGeometry* g, int SRID);
1055
1056extern void GEOS_DLL *GEOSGeom_getUserData_r(GEOSContextHandle_t handle,
1057const GEOSGeometry* g);
1058
1059extern void GEOS_DLL GEOSGeom_setUserData_r(GEOSContextHandle_t handle,
1060                                   GEOSGeometry* g, void* userData);
1061
1062/* May be called on all geometries in GEOS 3.x, returns -1 on error and 1
1063 * for non-multi geometries. Older GEOS versions only accept
1064 * GeometryCollections or Multi* geometries here, and are likely to crash
1065 * when fed simple geometries, so beware if you need compatibility with
1066 * old GEOS versions.
1067 */
1068extern int GEOS_DLL GEOSGetNumGeometries_r(GEOSContextHandle_t handle,
1069                                           const GEOSGeometry* g);
1070
1071/*
1072 * Return NULL on exception.
1073 * Returned object is a pointer to internal storage:
1074 * it must NOT be destroyed directly.
1075 * Up to GEOS 3.2.0 the input geometry must be a Collection, in
1076 * later version it doesn't matter (getGeometryN(0) for a single will
1077 * return the input).
1078 */
1079extern const GEOSGeometry GEOS_DLL *GEOSGetGeometryN_r(
1080                                    GEOSContextHandle_t handle,
1081                                    const GEOSGeometry* g, int n);
1082
1083/* Return -1 on exception */
1084extern int GEOS_DLL GEOSNormalize_r(GEOSContextHandle_t handle,
1085                                    GEOSGeometry* g);
1086
1087/** This option causes #GEOSGeom_setPrecision_r()
1088  * to not attempt at preserving the topology */
1089#define GEOS_PREC_NO_TOPO         (1<<0)
1090
1091/** This option causes #GEOSGeom_setPrecision_r()
1092  * to retain collapsed elements */
1093#define GEOS_PREC_KEEP_COLLAPSED  (1<<1)
1094
1095/**
1096 * Set the geometry's precision, optionally rounding all its
1097 * coordinates to the precision grid (if it changes).
1098 *
1099 * Note that operations will always be performed in the precision
1100 * of the geometry with higher precision (smaller "gridSize").
1101 * That same precision will be attached to the operation outputs.
1102 *
1103 * @param gridSize size of the precision grid, or 0 for FLOATING
1104 *                 precision.
1105 * @param flags The bitwise OR of one of more of the
1106 *              @ref GEOS_PREC_NO_TOPO "precision options"
1107 * @retuns NULL on exception or a new GEOSGeometry object
1108 *
1109 */
1110extern GEOSGeometry GEOS_DLL *GEOSGeom_setPrecision_r(
1111                                       GEOSContextHandle_t handle,
1112                                       const GEOSGeometry *g,
1113                                       double gridSize, int flags);
1114
1115/**
1116 * Get a geometry's precision
1117 *
1118 * @return the size of the geometry's precision grid, 0 for FLOATING
1119 *         precision or -1 on exception
1120 */
1121extern double GEOS_DLL GEOSGeom_getPrecision_r(
1122                                       GEOSContextHandle_t handle,
1123                                       const GEOSGeometry *g);
1124
1125/* Return -1 on exception */
1126extern int GEOS_DLL GEOSGetNumInteriorRings_r(GEOSContextHandle_t handle,
1127                                              const GEOSGeometry* g);
1128
1129/* Return -1 on exception, Geometry must be a LineString. */
1130extern int GEOS_DLL GEOSGeomGetNumPoints_r(GEOSContextHandle_t handle,
1131                                       const GEOSGeometry* g);
1132
1133/* Return 0 on exception, otherwise 1, Geometry must be a Point. */
1134extern int GEOS_DLL GEOSGeomGetX_r(GEOSContextHandle_t handle, const GEOSGeometry *g, double *x);
1135extern int GEOS_DLL GEOSGeomGetY_r(GEOSContextHandle_t handle, const GEOSGeometry *g, double *y);
1136extern int GEOS_DLL GEOSGeomGetZ_r(GEOSContextHandle_t handle, const GEOSGeometry *g, double *z);
1137
1138/*
1139 * Return NULL on exception, Geometry must be a Polygon.
1140 * Returned object is a pointer to internal storage:
1141 * it must NOT be destroyed directly.
1142 */
1143extern const GEOSGeometry GEOS_DLL *GEOSGetInteriorRingN_r(
1144                                    GEOSContextHandle_t handle,
1145                                    const GEOSGeometry* g, int n);
1146
1147/*
1148 * Return NULL on exception, Geometry must be a Polygon.
1149 * Returned object is a pointer to internal storage:
1150 * it must NOT be destroyed directly.
1151 */
1152extern const GEOSGeometry GEOS_DLL *GEOSGetExteriorRing_r(
1153                                    GEOSContextHandle_t handle,
1154                                    const GEOSGeometry* g);
1155
1156/* Return -1 on exception */
1157extern int GEOS_DLL GEOSGetNumCoordinates_r(GEOSContextHandle_t handle,
1158                                            const GEOSGeometry* g);
1159
1160/*
1161 * Return NULL on exception.
1162 * Geometry must be a LineString, LinearRing or Point.
1163 */
1164extern const GEOSCoordSequence GEOS_DLL *GEOSGeom_getCoordSeq_r(
1165                                         GEOSContextHandle_t handle,
1166                                         const GEOSGeometry* g);
1167
1168/*
1169 * Return 0 on exception (or empty geometry)
1170 */
1171extern int GEOS_DLL GEOSGeom_getDimensions_r(GEOSContextHandle_t handle,
1172                                             const GEOSGeometry* g);
1173
1174/*
1175 * Return 2 or 3.
1176 */
1177extern int GEOS_DLL GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t handle,
1178                                                      const GEOSGeometry* g);
1179/*
1180 * Return 0 on exception
1181 */
1182extern int GEOS_DLL GEOSGeom_getXMin_r(GEOSContextHandle_t handle, const GEOSGeometry* g, double* value);
1183extern int GEOS_DLL GEOSGeom_getYMin_r(GEOSContextHandle_t handle, const GEOSGeometry* g, double* value);
1184extern int GEOS_DLL GEOSGeom_getXMax_r(GEOSContextHandle_t handle, const GEOSGeometry* g, double* value);
1185extern int GEOS_DLL GEOSGeom_getYMax_r(GEOSContextHandle_t handle, const GEOSGeometry* g, double* value);
1186
1187/*
1188 * Return NULL on exception.
1189 * Must be LineString and must be freed by called.
1190 */
1191extern GEOSGeometry GEOS_DLL *GEOSGeomGetPointN_r(GEOSContextHandle_t handle, const GEOSGeometry *g, int n);
1192extern GEOSGeometry GEOS_DLL *GEOSGeomGetStartPoint_r(GEOSContextHandle_t handle, const GEOSGeometry *g);
1193extern GEOSGeometry GEOS_DLL *GEOSGeomGetEndPoint_r(GEOSContextHandle_t handle, const GEOSGeometry *g);
1194
1195/************************************************************************
1196 *
1197 *  Misc functions
1198 *
1199 ***********************************************************************/
1200
1201/* Return 0 on exception, 1 otherwise */
1202extern int GEOS_DLL GEOSArea_r(GEOSContextHandle_t handle,
1203                               const GEOSGeometry* g, double *area);
1204extern int GEOS_DLL GEOSLength_r(GEOSContextHandle_t handle,
1205                                 const GEOSGeometry* g, double *length);
1206extern int GEOS_DLL GEOSDistance_r(GEOSContextHandle_t handle,
1207                                   const GEOSGeometry* g1,
1208                                   const GEOSGeometry* g2, double *dist);
1209extern int GEOS_DLL GEOSDistanceIndexed_r(GEOSContextHandle_t handle,
1210                                   const GEOSGeometry* g1,
1211                                   const GEOSGeometry* g2, double *dist);
1212extern int GEOS_DLL GEOSHausdorffDistance_r(GEOSContextHandle_t handle,
1213                                   const GEOSGeometry *g1,
1214                                   const GEOSGeometry *g2,
1215                                   double *dist);
1216extern int GEOS_DLL GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t handle,
1217                                   const GEOSGeometry *g1,
1218                                   const GEOSGeometry *g2,
1219                                   double densifyFrac, double *dist);
1220extern int GEOS_DLL GEOSFrechetDistance_r(GEOSContextHandle_t handle,
1221                                   const GEOSGeometry *g1,
1222                                   const GEOSGeometry *g2,
1223                                   double *dist);
1224extern int GEOS_DLL GEOSFrechetDistanceDensify_r(GEOSContextHandle_t handle,
1225                                   const GEOSGeometry *g1,
1226                                   const GEOSGeometry *g2,
1227                                   double densifyFrac, double *dist);
1228extern int GEOS_DLL GEOSGeomGetLength_r(GEOSContextHandle_t handle,
1229                                   const GEOSGeometry *g, double *length);
1230
1231/* Return 0 on exception, the closest points of the two geometries otherwise.
1232 * The first point comes from g1 geometry and the second point comes from g2.
1233 */
1234extern GEOSCoordSequence GEOS_DLL *GEOSNearestPoints_r(
1235  GEOSContextHandle_t handle, const GEOSGeometry* g1, const GEOSGeometry* g2);
1236
1237
1238/************************************************************************
1239 *
1240 * Algorithms
1241 *
1242 ***********************************************************************/
1243
1244/* Walking from A to B:
1245 *  return -1 if reaching P takes a counter-clockwise (left) turn
1246 *  return  1 if reaching P takes a clockwise (right) turn
1247 *  return  0 if P is collinear with A-B
1248 *
1249 * On exceptions, return 2.
1250 *
1251 */
1252extern int GEOS_DLL GEOSOrientationIndex_r(GEOSContextHandle_t handle,
1253	double Ax, double Ay, double Bx, double By, double Px, double Py);
1254
1255
1256/************************************************************************
1257 *
1258 * Reader and Writer APIs
1259 *
1260 ***********************************************************************/
1261
1262#ifndef GEOSWKTReader
1263typedef struct GEOSWKTReader_t GEOSWKTReader;
1264typedef struct GEOSWKTWriter_t GEOSWKTWriter;
1265typedef struct GEOSWKBReader_t GEOSWKBReader;
1266typedef struct GEOSWKBWriter_t GEOSWKBWriter;
1267#endif
1268
1269/* WKT Reader */
1270extern GEOSWKTReader GEOS_DLL *GEOSWKTReader_create_r(
1271                                             GEOSContextHandle_t handle);
1272extern void GEOS_DLL GEOSWKTReader_destroy_r(GEOSContextHandle_t handle,
1273                                             GEOSWKTReader* reader);
1274extern GEOSGeometry GEOS_DLL *GEOSWKTReader_read_r(GEOSContextHandle_t handle,
1275                                                   GEOSWKTReader* reader,
1276                                                   const char *wkt);
1277
1278/* WKT Writer */
1279extern GEOSWKTWriter GEOS_DLL *GEOSWKTWriter_create_r(
1280                                             GEOSContextHandle_t handle);
1281extern void GEOS_DLL GEOSWKTWriter_destroy_r(GEOSContextHandle_t handle,
1282                                             GEOSWKTWriter* writer);
1283extern char GEOS_DLL *GEOSWKTWriter_write_r(GEOSContextHandle_t handle,
1284                                            GEOSWKTWriter* writer,
1285                                            const GEOSGeometry* g);
1286extern void GEOS_DLL GEOSWKTWriter_setTrim_r(GEOSContextHandle_t handle,
1287                                            GEOSWKTWriter *writer,
1288                                            char trim);
1289extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t handle,
1290                                            GEOSWKTWriter *writer,
1291                                            int precision);
1292extern void GEOS_DLL GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t handle,
1293                                                        GEOSWKTWriter *writer,
1294                                                        int dim);
1295extern int  GEOS_DLL GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t handle,
1296                                                        GEOSWKTWriter *writer);
1297extern void GEOS_DLL GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t handle,
1298                                              GEOSWKTWriter *writer,
1299                                              int useOld3D);
1300
1301/* WKB Reader */
1302extern GEOSWKBReader GEOS_DLL *GEOSWKBReader_create_r(
1303                                             GEOSContextHandle_t handle);
1304extern void GEOS_DLL GEOSWKBReader_destroy_r(GEOSContextHandle_t handle,
1305                                             GEOSWKBReader* reader);
1306extern GEOSGeometry GEOS_DLL *GEOSWKBReader_read_r(GEOSContextHandle_t handle,
1307                                                   GEOSWKBReader* reader,
1308                                                   const unsigned char *wkb,
1309                                                   size_t size);
1310extern GEOSGeometry GEOS_DLL *GEOSWKBReader_readHEX_r(
1311                                            GEOSContextHandle_t handle,
1312                                            GEOSWKBReader* reader,
1313                                            const unsigned char *hex,
1314                                            size_t size);
1315
1316/* WKB Writer */
1317extern GEOSWKBWriter GEOS_DLL *GEOSWKBWriter_create_r(
1318                                             GEOSContextHandle_t handle);
1319extern void GEOS_DLL GEOSWKBWriter_destroy_r(GEOSContextHandle_t handle,
1320                                             GEOSWKBWriter* writer);
1321
1322/* The caller owns the results for these two methods! */
1323extern unsigned char GEOS_DLL *GEOSWKBWriter_write_r(
1324                                             GEOSContextHandle_t handle,
1325                                             GEOSWKBWriter* writer,
1326                                             const GEOSGeometry* g,
1327                                             size_t *size);
1328extern unsigned char GEOS_DLL *GEOSWKBWriter_writeHEX_r(
1329                                             GEOSContextHandle_t handle,
1330                                             GEOSWKBWriter* writer,
1331                                             const GEOSGeometry* g,
1332                                             size_t *size);
1333
1334/*
1335 * Specify whether output WKB should be 2d or 3d.
1336 * Return previously set number of dimensions.
1337 */
1338extern int GEOS_DLL GEOSWKBWriter_getOutputDimension_r(
1339                                  GEOSContextHandle_t handle,
1340                                  const GEOSWKBWriter* writer);
1341extern void GEOS_DLL GEOSWKBWriter_setOutputDimension_r(
1342                                   GEOSContextHandle_t handle,
1343                                   GEOSWKBWriter* writer, int newDimension);
1344
1345/*
1346 * Specify whether the WKB byte order is big or little endian.
1347 * The return value is the previous byte order.
1348 */
1349extern int GEOS_DLL GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t handle,
1350                                                 const GEOSWKBWriter* writer);
1351extern void GEOS_DLL GEOSWKBWriter_setByteOrder_r(GEOSContextHandle_t handle,
1352                                                  GEOSWKBWriter* writer,
1353                                                  int byteOrder);
1354
1355/*
1356 * Specify whether SRID values should be output.
1357 */
1358extern char GEOS_DLL GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t handle,
1359                                   const GEOSWKBWriter* writer);
1360extern void GEOS_DLL GEOSWKBWriter_setIncludeSRID_r(GEOSContextHandle_t handle,
1361                                   GEOSWKBWriter* writer, const char writeSRID);
1362
1363
1364/*
1365 * Free buffers returned by stuff like GEOSWKBWriter_write(),
1366 * GEOSWKBWriter_writeHEX() and GEOSWKTWriter_write().
1367 */
1368extern void GEOS_DLL GEOSFree_r(GEOSContextHandle_t handle, void *buffer);
1369
1370
1371/* External code to GEOS can define GEOS_USE_ONLY_R_API to avoid the */
1372/* non _r API to be available */
1373#ifndef GEOS_USE_ONLY_R_API
1374
1375/************************************************************************
1376 *
1377 * Initialization, cleanup, version
1378 *
1379 ***********************************************************************/
1380
1381extern void GEOS_DLL initGEOS(GEOSMessageHandler notice_function,
1382    GEOSMessageHandler error_function);
1383extern void GEOS_DLL finishGEOS(void);
1384
1385/************************************************************************
1386 *
1387 * NOTE - These functions are DEPRECATED.  Please use the new Reader and
1388 * writer APIS!
1389 *
1390 ***********************************************************************/
1391
1392extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKT(const char *wkt);
1393extern char GEOS_DLL *GEOSGeomToWKT(const GEOSGeometry* g);
1394
1395/*
1396 * Specify whether output WKB should be 2d or 3d.
1397 * Return previously set number of dimensions.
1398 */
1399extern int GEOS_DLL GEOS_getWKBOutputDims();
1400extern int GEOS_DLL GEOS_setWKBOutputDims(int newDims);
1401
1402/*
1403 * Specify whether the WKB byte order is big or little endian.
1404 * The return value is the previous byte order.
1405 */
1406extern int GEOS_DLL GEOS_getWKBByteOrder();
1407extern int GEOS_DLL GEOS_setWKBByteOrder(int byteOrder);
1408
1409extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKB_buf(const unsigned char *wkb, size_t size);
1410extern unsigned char GEOS_DLL *GEOSGeomToWKB_buf(const GEOSGeometry* g, size_t *size);
1411
1412extern GEOSGeometry GEOS_DLL *GEOSGeomFromHEX_buf(const unsigned char *hex, size_t size);
1413extern unsigned char GEOS_DLL *GEOSGeomToHEX_buf(const GEOSGeometry* g, size_t *size);
1414
1415/************************************************************************
1416 *
1417 * Coordinate Sequence functions
1418 *
1419 ***********************************************************************/
1420
1421/*
1422 * Create a Coordinate sequence with ``size'' coordinates
1423 * of ``dims'' dimensions.
1424 * Return NULL on exception.
1425 */
1426extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_create(unsigned int size, unsigned int dims);
1427
1428/*
1429 * Clone a Coordinate Sequence.
1430 * Return NULL on exception.
1431 */
1432extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_clone(const GEOSCoordSequence* s);
1433
1434/*
1435 * Destroy a Coordinate Sequence.
1436 */
1437extern void GEOS_DLL GEOSCoordSeq_destroy(GEOSCoordSequence* s);
1438
1439/*
1440 * Set ordinate values in a Coordinate Sequence.
1441 * Return 0 on exception.
1442 */
1443extern int GEOS_DLL GEOSCoordSeq_setX(GEOSCoordSequence* s,
1444    unsigned int idx, double val);
1445extern int GEOS_DLL GEOSCoordSeq_setY(GEOSCoordSequence* s,
1446    unsigned int idx, double val);
1447extern int GEOS_DLL GEOSCoordSeq_setZ(GEOSCoordSequence* s,
1448    unsigned int idx, double val);
1449extern int GEOS_DLL GEOSCoordSeq_setXY(GEOSCoordSequence* s,
1450    unsigned int idx, double x, double y);
1451extern int GEOS_DLL GEOSCoordSeq_setXYZ(GEOSCoordSequence* s,
1452    unsigned int idx, double x, double y, double z);
1453extern int GEOS_DLL GEOSCoordSeq_setOrdinate(GEOSCoordSequence* s,
1454    unsigned int idx, unsigned int dim, double val);
1455
1456/*
1457 * Get ordinate values from a Coordinate Sequence.
1458 * Return 0 on exception.
1459 */
1460extern int GEOS_DLL GEOSCoordSeq_getX(const GEOSCoordSequence* s,
1461    unsigned int idx, double *val);
1462extern int GEOS_DLL GEOSCoordSeq_getY(const GEOSCoordSequence* s,
1463    unsigned int idx, double *val);
1464extern int GEOS_DLL GEOSCoordSeq_getZ(const GEOSCoordSequence* s,
1465    unsigned int idx, double *val);
1466extern int GEOS_DLL GEOSCoordSeq_getXY(const GEOSCoordSequence* s,
1467    unsigned int idx, double *x, double *y);
1468extern int GEOS_DLL GEOSCoordSeq_getXYZ(const GEOSCoordSequence* s,
1469    unsigned int idx, double *x, double *y, double *z);
1470extern int GEOS_DLL GEOSCoordSeq_getOrdinate(const GEOSCoordSequence* s,
1471    unsigned int idx, unsigned int dim, double *val);
1472/*
1473 * Get size and dimensions info from a Coordinate Sequence.
1474 * Return 0 on exception.
1475 */
1476extern int GEOS_DLL GEOSCoordSeq_getSize(const GEOSCoordSequence* s,
1477    unsigned int *size);
1478extern int GEOS_DLL GEOSCoordSeq_getDimensions(const GEOSCoordSequence* s,
1479    unsigned int *dims);
1480
1481/*
1482 * Check orientation of a CoordinateSequence and set 'is_ccw' to 1
1483 * if it has counter-clockwise orientation, 0 otherwise.
1484 * Return 0 on exception, 1 on success.
1485 */
1486extern int GEOS_DLL GEOSCoordSeq_isCCW(const GEOSCoordSequence* s, char* is_ccw);
1487
1488/************************************************************************
1489 *
1490 *  Linear referencing functions -- there are more, but these are
1491 *  probably sufficient for most purposes
1492 *
1493 ***********************************************************************/
1494
1495/*
1496 * GEOSGeometry ownership is retained by caller
1497 */
1498
1499
1500/* Return distance of point 'p' projected on 'g' from origin
1501 * of 'g'. Geometry 'g' must be a lineal geometry.
1502 * Return -1 on exception */
1503extern double GEOS_DLL GEOSProject(const GEOSGeometry *g,
1504                                   const GEOSGeometry* p);
1505
1506/* Return closest point to given distance within geometry
1507 * Geometry must be a LineString */
1508extern GEOSGeometry GEOS_DLL *GEOSInterpolate(const GEOSGeometry *g,
1509                                              double d);
1510
1511extern double GEOS_DLL GEOSProjectNormalized(const GEOSGeometry *g,
1512                                             const GEOSGeometry* p);
1513
1514extern GEOSGeometry GEOS_DLL *GEOSInterpolateNormalized(const GEOSGeometry *g,
1515                                                        double d);
1516
1517/************************************************************************
1518 *
1519 * Buffer related functions
1520 *
1521 ***********************************************************************/
1522
1523
1524/* @return NULL on exception */
1525extern GEOSGeometry GEOS_DLL *GEOSBuffer(const GEOSGeometry* g,
1526    double width, int quadsegs);
1527
1528/* @return 0 on exception */
1529extern GEOSBufferParams GEOS_DLL *GEOSBufferParams_create();
1530extern void GEOS_DLL GEOSBufferParams_destroy(GEOSBufferParams* parms);
1531
1532/* @return 0 on exception */
1533extern int GEOS_DLL GEOSBufferParams_setEndCapStyle(
1534                                              GEOSBufferParams* p,
1535                                              int style);
1536
1537/* @return 0 on exception */
1538extern int GEOS_DLL GEOSBufferParams_setJoinStyle(
1539                                              GEOSBufferParams* p,
1540                                              int joinStyle);
1541
1542/* @return 0 on exception */
1543extern int GEOS_DLL GEOSBufferParams_setMitreLimit(
1544                                              GEOSBufferParams* p,
1545                                              double mitreLimit);
1546
1547/* @return 0 on exception */
1548extern int GEOS_DLL GEOSBufferParams_setQuadrantSegments(
1549                                              GEOSBufferParams* p,
1550                                              int quadSegs);
1551
1552/* @param singleSided: 1 for single sided, 0 otherwise */
1553/* @return 0 on exception */
1554extern int GEOS_DLL GEOSBufferParams_setSingleSided(
1555                                              GEOSBufferParams* p,
1556                                              int singleSided);
1557
1558/* @return NULL on exception */
1559extern GEOSGeometry GEOS_DLL *GEOSBufferWithParams(
1560                                              const GEOSGeometry* g,
1561                                              const GEOSBufferParams* p,
1562                                              double width);
1563
1564/* These functions return NULL on exception. */
1565extern GEOSGeometry GEOS_DLL *GEOSBufferWithStyle(const GEOSGeometry* g,
1566    double width, int quadsegs, int endCapStyle, int joinStyle,
1567    double mitreLimit);
1568
1569/* These functions return NULL on exception. Only LINESTRINGs are accepted. */
1570/* @deprecated in 3.3.0: use GEOSOffsetCurve instead */
1571extern GEOSGeometry GEOS_DLL *GEOSSingleSidedBuffer(const GEOSGeometry* g,
1572    double width, int quadsegs, int joinStyle, double mitreLimit,
1573    int leftSide);
1574
1575/*
1576 * Only LINESTRINGs are accepted.
1577 * @param width : offset distance.
1578 *                negative for right side offset.
1579 *                positive for left side offset.
1580 * @return NULL on exception
1581 */
1582extern GEOSGeometry GEOS_DLL *GEOSOffsetCurve(const GEOSGeometry* g,
1583    double width, int quadsegs, int joinStyle, double mitreLimit);
1584
1585/************************************************************************
1586 *
1587 * Geometry Constructors.
1588 * GEOSCoordSequence* arguments will become ownership of the returned object.
1589 * All functions return NULL on exception.
1590 *
1591 ***********************************************************************/
1592
1593extern GEOSGeometry GEOS_DLL *GEOSGeom_createPoint(GEOSCoordSequence* s);
1594extern GEOSGeometry GEOS_DLL *GEOSGeom_createPointFromXY(double x, double y);
1595extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPoint();
1596extern GEOSGeometry GEOS_DLL *GEOSGeom_createLinearRing(GEOSCoordSequence* s);
1597extern GEOSGeometry GEOS_DLL *GEOSGeom_createLineString(GEOSCoordSequence* s);
1598extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyLineString();
1599
1600/*
1601 * Second argument is an array of GEOSGeometry* objects.
1602 * The caller remains owner of the array, but pointed-to
1603 * objects become ownership of the returned GEOSGeometry.
1604 */
1605extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPolygon();
1606extern GEOSGeometry GEOS_DLL *GEOSGeom_createPolygon(GEOSGeometry* shell,
1607    GEOSGeometry** holes, unsigned int nholes);
1608extern GEOSGeometry GEOS_DLL *GEOSGeom_createCollection(int type,
1609    GEOSGeometry* *geoms, unsigned int ngeoms);
1610extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyCollection(int type);
1611
1612extern GEOSGeometry GEOS_DLL *GEOSGeom_clone(const GEOSGeometry* g);
1613
1614/************************************************************************
1615 *
1616 * Memory management
1617 *
1618 ***********************************************************************/
1619
1620extern void GEOS_DLL GEOSGeom_destroy(GEOSGeometry* g);
1621
1622/************************************************************************
1623 *
1624 * Topology operations - return NULL on exception.
1625 *
1626 ***********************************************************************/
1627
1628extern GEOSGeometry GEOS_DLL *GEOSEnvelope(const GEOSGeometry* g);
1629extern GEOSGeometry GEOS_DLL *GEOSIntersection(const GEOSGeometry* g1, const GEOSGeometry* g2);
1630extern GEOSGeometry GEOS_DLL *GEOSIntersectionPrec(const GEOSGeometry* g1, const GEOSGeometry* g2, double gridSize);
1631extern GEOSGeometry GEOS_DLL *GEOSConvexHull(const GEOSGeometry* g);
1632
1633/* Returns the minimum rotated rectangular POLYGON which encloses the input geometry. The rectangle
1634 * has width equal to the minimum diameter, and a longer length. If the convex hill of the input is
1635 * degenerate (a line or point) a LINESTRING or POINT is returned. The minimum rotated rectangle can
1636 * be used as an extremely generalized representation for the given geometry.
1637 */
1638extern GEOSGeometry GEOS_DLL *GEOSMinimumRotatedRectangle(const GEOSGeometry* g);
1639
1640/* Constructs the Maximum Inscribed Circle for a  polygonal geometry, up to a specified tolerance.
1641 * The Maximum Inscribed Circle is determined by a point in the interior of the area
1642 * which has the farthest distance from the area boundary, along with a boundary point at that distance.
1643 * In the context of geography the center of the Maximum Inscribed Circle is known as the
1644 * Pole of Inaccessibility. A cartographic use case is to determine a suitable point
1645 * to place a map label within a polygon.
1646 * The radius length of the Maximum Inscribed Circle is a  measure of how "narrow" a polygon is. It is the
1647 * distance at which the negative buffer becomes empty.
1648 * The class supports polygons with holes and multipolygons.
1649 * The implementation uses a successive-approximation technique over a grid of square cells covering the area geometry.
1650 * The grid is refined using a branch-and-bound algorithm. Point containment and distance are computed in a performant
1651 * way by using spatial indexes.
1652 * Returns a two-point linestring, with one point at the center of the inscribed circle and the other
1653 * on the boundary of the inscribed circle.
1654*/
1655extern GEOSGeometry GEOS_DLL *GEOSMaximumInscribedCircle(const GEOSGeometry* g, double tolerance);
1656
1657/* Constructs the Largest Empty Circle for a set of obstacle geometries, up to a
1658 * specified tolerance. The obstacles are point and line geometries.
1659 * The Largest Empty Circle is the largest circle which  has its center in the convex hull of the
1660 * obstacles (the boundary), and whose interior does not intersect with any obstacle.
1661 * The circle center is the point in the interior of the boundary which has the farthest distance from
1662 * the obstacles (up to tolerance). The circle is determined by the center point and a point lying on an
1663 * obstacle indicating the circle radius.
1664 * The implementation uses a successive-approximation technique over a grid of square cells covering the obstacles and boundary.
1665 * The grid is refined using a branch-and-bound algorithm.  Point containment and distance are computed in a performant
1666 * way by using spatial indexes.
1667 * Returns a two-point linestring, with one point at the center of the inscribed circle and the other
1668 * on the boundary of the inscribed circle.
1669 */
1670extern GEOSGeometry GEOS_DLL *GEOSLargestEmptyCircle(const GEOSGeometry* g, const GEOSGeometry* boundary, double tolerance);
1671
1672/* Returns a LINESTRING geometry which represents the minimum diameter of the geometry.
1673 * The minimum diameter is defined to be the width of the smallest band that
1674 * contains the geometry, where a band is a strip of the plane defined
1675 * by two parallel lines. This can be thought of as the smallest hole that the geometry
1676 * can be moved through, with a single rotation.
1677 */
1678extern GEOSGeometry GEOS_DLL *GEOSMinimumWidth(const GEOSGeometry* g);
1679
1680/* Computes the minimum clearance of a geometry.  The minimum clearance is the smallest amount by which
1681 * a vertex could be move to produce an invalid polygon, a non-simple linestring, or a multipoint with
1682 * repeated points.  If a geometry has a minimum clearance of 'eps', it can be said that:
1683 *
1684 * -  No two distinct vertices in the geometry are separated by less than 'eps'
1685 * -  No vertex is closer than 'eps' to a line segment of which it is not an endpoint.
1686 *
1687 * If the minimum clearance cannot be defined for a geometry (such as with a single point, or a multipoint
1688 * whose points are identical, a value of Infinity will be calculated.
1689 *
1690 * @param g the input geometry
1691 * @param d a double to which the result can be stored
1692 *
1693 * @return 0 if no exception occurred
1694 *         2 if an exception occurred
1695 */
1696extern int GEOS_DLL GEOSMinimumClearance(const GEOSGeometry* g, double* d);
1697
1698/* Returns a LineString whose endpoints define the minimum clearance of a geometry.
1699 * If the geometry has no minimum clearance, an empty LineString will be returned.
1700 *
1701 * @param g the input geometry
1702 * @return a LineString, or NULL if an exception occurred.
1703 */
1704extern GEOSGeometry GEOS_DLL *GEOSMinimumClearanceLine(const GEOSGeometry* g);
1705
1706extern GEOSGeometry GEOS_DLL *GEOSDifference(const GEOSGeometry* g1, const GEOSGeometry* g2);
1707extern GEOSGeometry GEOS_DLL *GEOSDifferencePrec(const GEOSGeometry* g1, const GEOSGeometry* g2, double gridSize);
1708extern GEOSGeometry GEOS_DLL *GEOSSymDifference(const GEOSGeometry* g1, const GEOSGeometry* g2);
1709extern GEOSGeometry GEOS_DLL *GEOSSymDifferencePrec(const GEOSGeometry* g1, const GEOSGeometry* g2, double gridSize);
1710extern GEOSGeometry GEOS_DLL *GEOSBoundary(const GEOSGeometry* g);
1711extern GEOSGeometry GEOS_DLL *GEOSUnion(const GEOSGeometry* g1, const GEOSGeometry* g2);
1712extern GEOSGeometry GEOS_DLL *GEOSUnionPrec(const GEOSGeometry* g1, const GEOSGeometry* g2, double gridSize);
1713extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion(const GEOSGeometry* g);
1714extern GEOSGeometry GEOS_DLL *GEOSUnaryUnionPrec(const GEOSGeometry* g, double gridSize);
1715
1716/* GEOSCoverageUnion is an optimized union algorithm for polygonal inputs that are correctly
1717 * noded and do not overlap. It will not generate an error (return NULL) for inputs that
1718 * do not satisfy this constraint. */
1719extern GEOSGeometry GEOS_DLL *GEOSCoverageUnion(const GEOSGeometry *g);
1720
1721/* @deprecated in 3.3.0: use GEOSUnaryUnion instead */
1722extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded(const GEOSGeometry* g);
1723
1724extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface(const GEOSGeometry* g);
1725extern GEOSGeometry GEOS_DLL *GEOSGetCentroid(const GEOSGeometry* g);
1726extern GEOSGeometry GEOS_DLL *GEOSMinimumBoundingCircle(const GEOSGeometry* g, double* radius, GEOSGeometry** center);
1727extern GEOSGeometry GEOS_DLL *GEOSNode(const GEOSGeometry* g);
1728extern GEOSGeometry GEOS_DLL *GEOSClipByRect(const GEOSGeometry* g, double xmin, double ymin, double xmax, double ymax);
1729
1730/*
1731 * all arguments remain ownership of the caller
1732 * (both Geometries and pointers)
1733 */
1734extern GEOSGeometry GEOS_DLL *GEOSPolygonize(const GEOSGeometry * const geoms[], unsigned int ngeoms);
1735extern GEOSGeometry GEOS_DLL *GEOSPolygonize_valid(const GEOSGeometry * const geoms[], unsigned int ngeoms);
1736extern GEOSGeometry GEOS_DLL *GEOSPolygonizer_getCutEdges(const GEOSGeometry * const geoms[], unsigned int ngeoms);
1737extern GEOSGeometry GEOS_DLL *GEOSPolygonize_full(const GEOSGeometry* input,
1738    GEOSGeometry** cuts, GEOSGeometry** dangles, GEOSGeometry** invalid);
1739
1740extern GEOSGeometry GEOS_DLL *GEOSBuildArea(const GEOSGeometry* g);
1741
1742extern GEOSGeometry GEOS_DLL *GEOSLineMerge(const GEOSGeometry* g);
1743extern GEOSGeometry GEOS_DLL *GEOSReverse(const GEOSGeometry* g);
1744extern GEOSGeometry GEOS_DLL *GEOSSimplify(const GEOSGeometry* g, double tolerance);
1745extern GEOSGeometry GEOS_DLL *GEOSTopologyPreserveSimplify(const GEOSGeometry* g,
1746    double tolerance);
1747
1748/*
1749 * Return all distinct vertices of input geometry as a MULTIPOINT.
1750 * Note that only 2 dimensions of the vertices are considered when
1751 * testing for equality.
1752 */
1753extern GEOSGeometry GEOS_DLL *GEOSGeom_extractUniquePoints(
1754                              const GEOSGeometry* g);
1755
1756/*
1757 * Find paths shared between the two given lineal geometries.
1758 *
1759 * Returns a GEOMETRYCOLLECTION having two elements:
1760 * - first element is a MULTILINESTRING containing shared paths
1761 *   having the _same_ direction on both inputs
1762 * - second element is a MULTILINESTRING containing shared paths
1763 *   having the _opposite_ direction on the two inputs
1764 *
1765 * Returns NULL on exception
1766 */
1767extern GEOSGeometry GEOS_DLL *GEOSSharedPaths(const GEOSGeometry* g1,
1768  const GEOSGeometry* g2);
1769
1770/*
1771 * Snap first geometry on to second with given tolerance
1772 * Returns a newly allocated geometry, or NULL on exception
1773 */
1774extern GEOSGeometry GEOS_DLL *GEOSSnap(const GEOSGeometry* g1,
1775  const GEOSGeometry* g2, double tolerance);
1776
1777/*
1778 * Return a Delaunay triangulation of the vertex of the given geometry
1779 *
1780 * @param g the input geometry whose vertex will be used as "sites"
1781 * @param tolerance optional snapping tolerance to use for improved robustness
1782 * @param onlyEdges if non-zero will return a MULTILINESTRING, otherwise it will
1783 *                  return a GEOMETRYCOLLECTION containing triangular POLYGONs.
1784 *
1785 * @return  a newly allocated geometry, or NULL on exception
1786 */
1787extern GEOSGeometry GEOS_DLL * GEOSDelaunayTriangulation(
1788                                  const GEOSGeometry *g,
1789                                  double tolerance,
1790                                  int onlyEdges);
1791
1792/*
1793 * Returns the Voronoi polygons of a set of Vertices given as input
1794 *
1795 * @param g the input geometry whose vertex will be used as sites.
1796 * @param tolerance snapping tolerance to use for improved robustness
1797 * @param onlyEdges whether to return only edges of the voronoi cells
1798 * @param env clipping envelope for the returned diagram, automatically
1799 *            determined if NULL.
1800 *            The diagram will be clipped to the larger
1801 *            of this envelope or an envelope surrounding the sites.
1802 *
1803 * @return a newly allocated geometry, or NULL on exception.
1804 */
1805extern GEOSGeometry GEOS_DLL * GEOSVoronoiDiagram(
1806                const GEOSGeometry *g,
1807                const GEOSGeometry *env,
1808                double tolerance,
1809                int onlyEdges);
1810/*
1811 * Computes the coordinate where two line segments intersect, if any
1812 *
1813 * @param ax0 x-coordinate of first point in first segment
1814 * @param ay0 y-coordinate of first point in first segment
1815 * @param ax1 x-coordinate of second point in first segment
1816 * @param ay1 y-coordinate of second point in first segment
1817 * @param bx0 x-coordinate of first point in second segment
1818 * @param by0 y-coordinate of first point in second segment
1819 * @param bx1 x-coordinate of second point in second segment
1820 * @param by1 y-coordinate of second point in second segment
1821 * @param cx x-coordinate of intersection point
1822 * @param cy y-coordinate of intersection point
1823 *
1824 * @return 0 on error, 1 on success, -1 if segments do not intersect
1825 */
1826
1827extern int GEOS_DLL GEOSSegmentIntersection(
1828       double ax0, double ay0,
1829       double ax1, double ay1,
1830       double bx0, double by0,
1831       double bx1, double by1,
1832       double* cx, double* cy);
1833
1834/************************************************************************
1835 *
1836 *  Binary predicates - return 2 on exception, 1 on true, 0 on false
1837 *
1838 ***********************************************************************/
1839
1840extern char GEOS_DLL GEOSDisjoint(const GEOSGeometry* g1, const GEOSGeometry* g2);
1841extern char GEOS_DLL GEOSTouches(const GEOSGeometry* g1, const GEOSGeometry* g2);
1842extern char GEOS_DLL GEOSIntersects(const GEOSGeometry* g1, const GEOSGeometry* g2);
1843extern char GEOS_DLL GEOSCrosses(const GEOSGeometry* g1, const GEOSGeometry* g2);
1844extern char GEOS_DLL GEOSWithin(const GEOSGeometry* g1, const GEOSGeometry* g2);
1845extern char GEOS_DLL GEOSContains(const GEOSGeometry* g1, const GEOSGeometry* g2);
1846extern char GEOS_DLL GEOSOverlaps(const GEOSGeometry* g1, const GEOSGeometry* g2);
1847extern char GEOS_DLL GEOSEquals(const GEOSGeometry* g1, const GEOSGeometry* g2);
1848extern char GEOS_DLL GEOSCovers(const GEOSGeometry* g1, const GEOSGeometry* g2);
1849extern char GEOS_DLL GEOSCoveredBy(const GEOSGeometry* g1, const GEOSGeometry* g2);
1850
1851/**
1852 * Determine pointwise equivalence of two geometries, by checking if each vertex of g2 is
1853 * within tolerance of the corresponding vertex in g1.
1854 * Unlike GEOSEquals, geometries that are topologically equivalent but have different
1855 * representations (e.g., LINESTRING (0 0, 1 1) and MULTILINESTRING ((0 0, 1 1)) ) are not
1856 * considered equivalent by GEOSEqualsExact.
1857 * returns 2 on exception, 1 on true, 0 on false
1858 */
1859extern char GEOS_DLL GEOSEqualsExact(const GEOSGeometry* g1, const GEOSGeometry* g2, double tolerance);
1860
1861/************************************************************************
1862 *
1863 *  Prepared Geometry Binary predicates - return 2 on exception, 1 on true, 0 on false
1864 *
1865 ***********************************************************************/
1866
1867/*
1868 * GEOSGeometry ownership is retained by caller
1869 */
1870extern const GEOSPreparedGeometry GEOS_DLL *GEOSPrepare(const GEOSGeometry* g);
1871
1872extern void GEOS_DLL GEOSPreparedGeom_destroy(const GEOSPreparedGeometry* g);
1873
1874extern char GEOS_DLL GEOSPreparedContains(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1875extern char GEOS_DLL GEOSPreparedContainsProperly(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1876extern char GEOS_DLL GEOSPreparedCoveredBy(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1877extern char GEOS_DLL GEOSPreparedCovers(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1878extern char GEOS_DLL GEOSPreparedCrosses(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1879extern char GEOS_DLL GEOSPreparedDisjoint(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1880extern char GEOS_DLL GEOSPreparedIntersects(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1881extern char GEOS_DLL GEOSPreparedOverlaps(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1882extern char GEOS_DLL GEOSPreparedTouches(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1883extern char GEOS_DLL GEOSPreparedWithin(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1884extern GEOSCoordSequence GEOS_DLL *GEOSPreparedNearestPoints(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1885extern int GEOS_DLL GEOSPreparedDistance(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2, double *dist);
1886
1887/************************************************************************
1888 *
1889 *  STRtree functions
1890 *
1891 ***********************************************************************/
1892
1893/*
1894 * GEOSGeometry ownership is retained by caller
1895 */
1896
1897/*
1898 * Create a new R-tree using the Sort-Tile-Recursive algorithm (STRtree) for two-dimensional
1899 * spatial data.
1900 *
1901 * @param nodeCapacity the maximum number of child nodes that a node may have.  The minimum
1902 *            recommended capacity value is 4.  If unsure, use a default node capacity of 10.
1903 * @return a pointer to the created tree
1904 */
1905extern GEOSSTRtree GEOS_DLL *GEOSSTRtree_create(size_t nodeCapacity);
1906
1907/*
1908 * Insert an item into an STRtree
1909 *
1910 * @param tree the STRtree in which the item should be inserted
1911 * @param g a GEOSGeometry whose envelope corresponds to the extent of 'item'
1912 * @param item the item to insert into the tree
1913 */
1914extern void GEOS_DLL GEOSSTRtree_insert(GEOSSTRtree *tree,
1915                                        const GEOSGeometry *g,
1916                                        void *item);
1917
1918/*
1919 * Query an STRtree for items intersecting a specified envelope
1920 *
1921 * @param tree the STRtree to search
1922 * @param g a GEOSGeomety from which a query envelope will be extracted
1923 * @param callback a function to be executed for each item in the tree whose envelope intersects
1924 *            the envelope of 'g'.  The callback function should take two parameters: a void
1925 *            pointer representing the located item in the tree, and a void userdata pointer.
1926 * @param userdata an optional pointer to pe passed to 'callback' as an argument
1927 */
1928extern void GEOS_DLL GEOSSTRtree_query(GEOSSTRtree *tree,
1929                                       const GEOSGeometry *g,
1930                                       GEOSQueryCallback callback,
1931                                       void *userdata);
1932/*
1933 * Returns the nearest item in the STRtree to the supplied GEOSGeometry.
1934 * All items in the tree MUST be of type GEOSGeometry.  If this is not the case, use
1935 * GEOSSTRtree_nearest_generic instead.
1936*
1937 * @param tree the STRtree to search
1938 * @param geom the geometry with which the tree should be queried
1939 * @return a const pointer to the nearest GEOSGeometry in the tree to 'geom', or NULL in
1940 *            case of exception
1941 */
1942extern const GEOSGeometry GEOS_DLL *GEOSSTRtree_nearest(GEOSSTRtree *tree, const GEOSGeometry* geom);
1943
1944/*
1945 * Returns the nearest item in the STRtree to the supplied item
1946 *
1947 * @param tree the STRtree to search
1948 * @param item the item with which the tree should be queried
1949 * @param itemEnvelope a GEOSGeometry having the bounding box of 'item'
1950 * @param distancefn a function that can compute the distance between two items
1951 *            in the STRtree.  The function should return zero in case of error,
1952 *            and should store the computed distance to the location pointed to by
1953 *            the 'distance' argument.  The computed distance between two items
1954 *            must not exceed the Cartesian distance between their envelopes.
1955 * @param userdata optional pointer to arbitrary data; will be passed to distancefn
1956 *            each time it is called.
1957 * @return a const pointer to the nearest item in the tree to 'item', or NULL in
1958 *            case of exception
1959 */
1960extern const void GEOS_DLL *GEOSSTRtree_nearest_generic(GEOSSTRtree *tree,
1961                                                        const void* item,
1962                                                        const GEOSGeometry* itemEnvelope,
1963                                                        GEOSDistanceCallback distancefn,
1964                                                        void* userdata);
1965/*
1966 * Iterates over all items in the STRtree
1967 *
1968 * @param tree the STRtree over which to iterate
1969 * @param callback a function to be executed for each item in the tree.
1970 */
1971extern void GEOS_DLL GEOSSTRtree_iterate(GEOSSTRtree *tree,
1972                                       GEOSQueryCallback callback,
1973                                       void *userdata);
1974
1975/*
1976 * Removes an item from the STRtree
1977 *
1978 * @param tree the STRtree from which to remove an item
1979 * @param g the envelope of the item to remove
1980 * @param the item to remove
1981 * @return 0 if the item was not removed;
1982 *         1 if the item was removed;
1983 *         2 if an exception occurred
1984 */
1985extern char GEOS_DLL GEOSSTRtree_remove(GEOSSTRtree *tree,
1986                                        const GEOSGeometry *g,
1987                                        void *item);
1988extern void GEOS_DLL GEOSSTRtree_destroy(GEOSSTRtree *tree);
1989
1990
1991/************************************************************************
1992 *
1993 *  Unary predicate - return 2 on exception, 1 on true, 0 on false
1994 *
1995 ***********************************************************************/
1996
1997extern char GEOS_DLL GEOSisEmpty(const GEOSGeometry* g);
1998extern char GEOS_DLL GEOSisSimple(const GEOSGeometry* g);
1999extern char GEOS_DLL GEOSisRing(const GEOSGeometry* g);
2000extern char GEOS_DLL GEOSHasZ(const GEOSGeometry* g);
2001extern char GEOS_DLL GEOSisClosed(const GEOSGeometry *g);
2002
2003/************************************************************************
2004 *
2005 *  Dimensionally Extended 9 Intersection Model related
2006 *
2007 ***********************************************************************/
2008
2009/* return 2 on exception, 1 on true, 0 on false */
2010extern char GEOS_DLL GEOSRelatePattern(const GEOSGeometry* g1, const GEOSGeometry* g2, const char *pat);
2011
2012/* return NULL on exception, a string to GEOSFree otherwise */
2013extern char GEOS_DLL *GEOSRelate(const GEOSGeometry* g1, const GEOSGeometry* g2);
2014
2015/* return 2 on exception, 1 on true, 0 on false */
2016extern char GEOS_DLL GEOSRelatePatternMatch(const char *mat, const char *pat);
2017
2018/* return NULL on exception, a string to GEOSFree otherwise */
2019extern char GEOS_DLL *GEOSRelateBoundaryNodeRule(const GEOSGeometry* g1,
2020                                                 const GEOSGeometry* g2,
2021                                                 int bnr);
2022
2023/************************************************************************
2024 *
2025 *  Validity checking
2026 *
2027 ***********************************************************************/
2028
2029/* return 2 on exception, 1 on true, 0 on false */
2030extern char GEOS_DLL GEOSisValid(const GEOSGeometry* g);
2031
2032/* return NULL on exception, a string to GEOSFree otherwise */
2033extern char GEOS_DLL *GEOSisValidReason(const GEOSGeometry *g);
2034/*
2035 * Caller has the responsibility to destroy 'reason' (GEOSFree)
2036 * and 'location' (GEOSGeom_destroy) params
2037 * return 2 on exception, 1 when valid, 0 when invalid
2038 * Use enum GEOSValidFlags values for the flags param.
2039 */
2040extern char GEOS_DLL GEOSisValidDetail(const GEOSGeometry* g,
2041                                       int flags,
2042                                       char** reason, GEOSGeometry** location);
2043
2044extern GEOSGeometry GEOS_DLL *GEOSMakeValid(const GEOSGeometry* g);
2045
2046/************************************************************************
2047 *
2048 *  Geometry info
2049 *
2050 ***********************************************************************/
2051
2052/* Return NULL on exception, result must be freed by caller. */
2053extern char GEOS_DLL *GEOSGeomType(const GEOSGeometry* g);
2054
2055/* Return -1 on exception */
2056extern int GEOS_DLL GEOSGeomTypeId(const GEOSGeometry* g);
2057
2058/* Return 0 on exception */
2059extern int GEOS_DLL GEOSGetSRID(const GEOSGeometry* g);
2060
2061extern void GEOS_DLL GEOSSetSRID(GEOSGeometry* g, int SRID);
2062
2063extern void GEOS_DLL *GEOSGeom_getUserData(const GEOSGeometry* g);
2064
2065extern void GEOS_DLL GEOSGeom_setUserData(GEOSGeometry* g, void* userData);
2066
2067
2068/* May be called on all geometries in GEOS 3.x, returns -1 on error and 1
2069 * for non-multi geometries. Older GEOS versions only accept
2070 * GeometryCollections or Multi* geometries here, and are likely to crash
2071 * when fed simple geometries, so beware if you need compatibility with
2072 * old GEOS versions.
2073 */
2074extern int GEOS_DLL GEOSGetNumGeometries(const GEOSGeometry* g);
2075
2076/*
2077 * Return NULL on exception.
2078 * Returned object is a pointer to internal storage:
2079 * it must NOT be destroyed directly.
2080 * Up to GEOS 3.2.0 the input geometry must be a Collection, in
2081 * later version it doesn't matter (getGeometryN(0) for a single will
2082 * return the input).
2083 */
2084extern const GEOSGeometry GEOS_DLL *GEOSGetGeometryN(const GEOSGeometry* g, int n);
2085
2086/* Return -1 on exception */
2087extern int GEOS_DLL GEOSNormalize(GEOSGeometry* g);
2088
2089/* Return NULL on exception */
2090extern GEOSGeometry GEOS_DLL *GEOSGeom_setPrecision(
2091	const GEOSGeometry *g, double gridSize, int flags);
2092
2093/* Return -1 on exception */
2094extern double GEOS_DLL GEOSGeom_getPrecision(const GEOSGeometry *g);
2095
2096/* Return -1 on exception */
2097extern int GEOS_DLL GEOSGetNumInteriorRings(const GEOSGeometry* g);
2098
2099/* Return -1 on exception, Geometry must be a LineString. */
2100extern int GEOS_DLL GEOSGeomGetNumPoints(const GEOSGeometry* g);
2101
2102/* Return 0 on exception, otherwise 1, Geometry must be a Point. */
2103extern int GEOS_DLL GEOSGeomGetX(const GEOSGeometry *g, double *x);
2104extern int GEOS_DLL GEOSGeomGetY(const GEOSGeometry *g, double *y);
2105extern int GEOS_DLL GEOSGeomGetZ(const GEOSGeometry *g, double *z);
2106
2107/*
2108 * Return NULL on exception, Geometry must be a Polygon.
2109 * Returned object is a pointer to internal storage:
2110 * it must NOT be destroyed directly.
2111 */
2112extern const GEOSGeometry GEOS_DLL *GEOSGetInteriorRingN(const GEOSGeometry* g, int n);
2113
2114/*
2115 * Return NULL on exception, Geometry must be a Polygon.
2116 * Returned object is a pointer to internal storage:
2117 * it must NOT be destroyed directly.
2118 */
2119extern const GEOSGeometry GEOS_DLL *GEOSGetExteriorRing(const GEOSGeometry* g);
2120
2121/* Return -1 on exception */
2122extern int GEOS_DLL GEOSGetNumCoordinates(const GEOSGeometry* g);
2123
2124/*
2125 * Return NULL on exception.
2126 * Geometry must be a LineString, LinearRing or Point.
2127 */
2128extern const GEOSCoordSequence GEOS_DLL *GEOSGeom_getCoordSeq(const GEOSGeometry* g);
2129
2130/*
2131 * Return 0 on exception (or empty geometry)
2132 */
2133extern int GEOS_DLL GEOSGeom_getDimensions(const GEOSGeometry* g);
2134
2135/*
2136 * Return 2 or 3.
2137 */
2138extern int GEOS_DLL GEOSGeom_getCoordinateDimension(const GEOSGeometry* g);
2139
2140/*
2141 * Return 0 on exception
2142 */
2143extern int GEOS_DLL GEOSGeom_getXMin(const GEOSGeometry* g, double* value);
2144extern int GEOS_DLL GEOSGeom_getYMin(const GEOSGeometry* g, double* value);
2145extern int GEOS_DLL GEOSGeom_getXMax(const GEOSGeometry* g, double* value);
2146extern int GEOS_DLL GEOSGeom_getYMax(const GEOSGeometry* g, double* value);
2147
2148/*
2149 * Return NULL on exception.
2150 * Must be LineString and must be freed by called.
2151 */
2152extern GEOSGeometry GEOS_DLL *GEOSGeomGetPointN(const GEOSGeometry *g, int n);
2153extern GEOSGeometry GEOS_DLL *GEOSGeomGetStartPoint(const GEOSGeometry *g);
2154extern GEOSGeometry GEOS_DLL *GEOSGeomGetEndPoint(const GEOSGeometry *g);
2155
2156/************************************************************************
2157 *
2158 *  Misc functions
2159 *
2160 ***********************************************************************/
2161
2162/* Return 0 on exception, 1 otherwise */
2163extern int GEOS_DLL GEOSArea(const GEOSGeometry* g, double *area);
2164extern int GEOS_DLL GEOSLength(const GEOSGeometry* g, double *length);
2165extern int GEOS_DLL GEOSDistance(const GEOSGeometry* g1, const GEOSGeometry* g2,
2166    double *dist);
2167extern int GEOS_DLL GEOSDistanceIndexed(const GEOSGeometry* g1, const GEOSGeometry* g2,
2168    double *dist);
2169extern int GEOS_DLL GEOSHausdorffDistance(const GEOSGeometry *g1,
2170        const GEOSGeometry *g2, double *dist);
2171extern int GEOS_DLL GEOSHausdorffDistanceDensify(const GEOSGeometry *g1,
2172        const GEOSGeometry *g2, double densifyFrac, double *dist);
2173extern int GEOS_DLL GEOSFrechetDistance(const GEOSGeometry *g1,
2174        const GEOSGeometry *g2, double *dist);
2175extern int GEOS_DLL GEOSFrechetDistanceDensify(const GEOSGeometry *g1,
2176        const GEOSGeometry *g2, double densifyFrac, double *dist);
2177extern int GEOS_DLL GEOSGeomGetLength(const GEOSGeometry *g, double *length);
2178
2179/* Return 0 on exception, the closest points of the two geometries otherwise.
2180 * The first point comes from g1 geometry and the second point comes from g2.
2181 */
2182extern GEOSCoordSequence GEOS_DLL *GEOSNearestPoints(
2183  const GEOSGeometry* g1, const GEOSGeometry* g2);
2184
2185
2186/************************************************************************
2187 *
2188 * Algorithms
2189 *
2190 ***********************************************************************/
2191
2192/* Walking from A to B:
2193 *  return -1 if reaching P takes a counter-clockwise (left) turn
2194 *  return  1 if reaching P takes a clockwise (right) turn
2195 *  return  0 if P is collinear with A-B
2196 *
2197 * On exceptions, return 2.
2198 *
2199 */
2200extern int GEOS_DLL GEOSOrientationIndex(double Ax, double Ay, double Bx, double By,
2201    double Px, double Py);
2202
2203/************************************************************************
2204 *
2205 * Reader and Writer APIs
2206 *
2207 ***********************************************************************/
2208
2209/* WKT Reader */
2210extern GEOSWKTReader GEOS_DLL *GEOSWKTReader_create();
2211extern void GEOS_DLL GEOSWKTReader_destroy(GEOSWKTReader* reader);
2212extern GEOSGeometry GEOS_DLL *GEOSWKTReader_read(GEOSWKTReader* reader, const char *wkt);
2213
2214/* WKT Writer */
2215extern GEOSWKTWriter GEOS_DLL *GEOSWKTWriter_create();
2216extern void GEOS_DLL GEOSWKTWriter_destroy(GEOSWKTWriter* writer);
2217extern char GEOS_DLL *GEOSWKTWriter_write(GEOSWKTWriter* writer, const GEOSGeometry* g);
2218extern void GEOS_DLL GEOSWKTWriter_setTrim(GEOSWKTWriter *writer, char trim);
2219extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision(GEOSWKTWriter *writer, int precision);
2220extern void GEOS_DLL GEOSWKTWriter_setOutputDimension(GEOSWKTWriter *writer, int dim);
2221extern int  GEOS_DLL GEOSWKTWriter_getOutputDimension(GEOSWKTWriter *writer);
2222extern void GEOS_DLL GEOSWKTWriter_setOld3D(GEOSWKTWriter *writer, int useOld3D);
2223
2224/* WKB Reader */
2225extern GEOSWKBReader GEOS_DLL *GEOSWKBReader_create();
2226extern void GEOS_DLL GEOSWKBReader_destroy(GEOSWKBReader* reader);
2227extern GEOSGeometry GEOS_DLL *GEOSWKBReader_read(GEOSWKBReader* reader, const unsigned char *wkb, size_t size);
2228extern GEOSGeometry GEOS_DLL *GEOSWKBReader_readHEX(GEOSWKBReader* reader, const unsigned char *hex, size_t size);
2229
2230/* WKB Writer */
2231extern GEOSWKBWriter GEOS_DLL *GEOSWKBWriter_create();
2232extern void GEOS_DLL GEOSWKBWriter_destroy(GEOSWKBWriter* writer);
2233
2234/* The caller owns the results for these two methods! */
2235extern unsigned char GEOS_DLL *GEOSWKBWriter_write(GEOSWKBWriter* writer, const GEOSGeometry* g, size_t *size);
2236extern unsigned char GEOS_DLL *GEOSWKBWriter_writeHEX(GEOSWKBWriter* writer, const GEOSGeometry* g, size_t *size);
2237
2238/*
2239 * Specify whether output WKB should be 2d or 3d.
2240 * Return previously set number of dimensions.
2241 */
2242extern int GEOS_DLL GEOSWKBWriter_getOutputDimension(const GEOSWKBWriter* writer);
2243extern void GEOS_DLL GEOSWKBWriter_setOutputDimension(GEOSWKBWriter* writer, int newDimension);
2244
2245/*
2246 * Specify whether the WKB byte order is big or little endian.
2247 * The return value is the previous byte order.
2248 */
2249extern int GEOS_DLL GEOSWKBWriter_getByteOrder(const GEOSWKBWriter* writer);
2250extern void GEOS_DLL GEOSWKBWriter_setByteOrder(GEOSWKBWriter* writer, int byteOrder);
2251
2252/*
2253 * Specify whether SRID values should be output.
2254 */
2255extern char GEOS_DLL GEOSWKBWriter_getIncludeSRID(const GEOSWKBWriter* writer);
2256extern void GEOS_DLL GEOSWKBWriter_setIncludeSRID(GEOSWKBWriter* writer, const char writeSRID);
2257
2258/*
2259 * Free buffers returned by stuff like GEOSWKBWriter_write(),
2260 * GEOSWKBWriter_writeHEX() and GEOSWKTWriter_write().
2261 */
2262extern void GEOS_DLL GEOSFree(void *buffer);
2263
2264#endif /* #ifndef GEOS_USE_ONLY_R_API */
2265
2266
2267#ifdef __cplusplus
2268} // extern "C"
2269#endif
2270
2271#endif /* #ifndef GEOS_C_H_INCLUDED */
2272