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