GEOS  3.6.1
geos_c.h
1 /************************************************************************
2  *
3  *
4  * C-Wrapper for GEOS library
5  *
6  * Copyright (C) 2010 2011 Sandro Santilli <strk@keybit.net>
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@keybit.net>
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 10
63 #define GEOS_CAPI_VERSION_PATCH 1
64 #define GEOS_CAPI_VERSION "3.6.1-CAPI-1.10.1"
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 6
71 #endif
72 #ifndef GEOS_VERSION_PATCH
73 #define GEOS_VERSION_PATCH 1
74 #endif
75 #ifndef GEOS_VERSION
76 #define GEOS_VERSION "3.6.1"
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 10
84 #define GEOS_CAPI_VERSION_PATCH 1
85 #define GEOS_CAPI_VERSION "3.6.1-CAPI-1.10.1"
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 GEOSHausdorffDistance_r(GEOSContextHandle_t handle,
1104  const GEOSGeometry *g1,
1105  const GEOSGeometry *g2,
1106  double *dist);
1107 extern int GEOS_DLL GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t handle,
1108  const GEOSGeometry *g1,
1109  const GEOSGeometry *g2,
1110  double densifyFrac, double *dist);
1111 extern int GEOS_DLL GEOSGeomGetLength_r(GEOSContextHandle_t handle,
1112  const GEOSGeometry *g, double *length);
1113 
1114 /* Return 0 on exception, the closest points of the two geometries otherwise.
1115  * The first point comes from g1 geometry and the second point comes from g2.
1116  */
1117 extern GEOSCoordSequence GEOS_DLL *GEOSNearestPoints_r(
1118  GEOSContextHandle_t handle, const GEOSGeometry* g1, const GEOSGeometry* g2);
1119 
1120 
1121 /************************************************************************
1122  *
1123  * Algorithms
1124  *
1125  ***********************************************************************/
1126 
1127 /* Walking from A to B:
1128  * return -1 if reaching P takes a counter-clockwise (left) turn
1129  * return 1 if reaching P takes a clockwise (right) turn
1130  * return 0 if P is collinear with A-B
1131  *
1132  * On exceptions, return 2.
1133  *
1134  */
1135 extern int GEOS_DLL GEOSOrientationIndex_r(GEOSContextHandle_t handle,
1136  double Ax, double Ay, double Bx, double By, double Px, double Py);
1137 
1138 
1139 /************************************************************************
1140  *
1141  * Reader and Writer APIs
1142  *
1143  ***********************************************************************/
1144 
1145 typedef struct GEOSWKTReader_t GEOSWKTReader;
1146 typedef struct GEOSWKTWriter_t GEOSWKTWriter;
1147 typedef struct GEOSWKBReader_t GEOSWKBReader;
1148 typedef struct GEOSWKBWriter_t GEOSWKBWriter;
1149 
1150 
1151 /* WKT Reader */
1152 extern GEOSWKTReader GEOS_DLL *GEOSWKTReader_create_r(
1153  GEOSContextHandle_t handle);
1154 extern void GEOS_DLL GEOSWKTReader_destroy_r(GEOSContextHandle_t handle,
1155  GEOSWKTReader* reader);
1156 extern GEOSGeometry GEOS_DLL *GEOSWKTReader_read_r(GEOSContextHandle_t handle,
1157  GEOSWKTReader* reader,
1158  const char *wkt);
1159 
1160 /* WKT Writer */
1161 extern GEOSWKTWriter GEOS_DLL *GEOSWKTWriter_create_r(
1162  GEOSContextHandle_t handle);
1163 extern void GEOS_DLL GEOSWKTWriter_destroy_r(GEOSContextHandle_t handle,
1164  GEOSWKTWriter* writer);
1165 extern char GEOS_DLL *GEOSWKTWriter_write_r(GEOSContextHandle_t handle,
1166  GEOSWKTWriter* writer,
1167  const GEOSGeometry* g);
1168 extern void GEOS_DLL GEOSWKTWriter_setTrim_r(GEOSContextHandle_t handle,
1169  GEOSWKTWriter *writer,
1170  char trim);
1171 extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t handle,
1172  GEOSWKTWriter *writer,
1173  int precision);
1174 extern void GEOS_DLL GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t handle,
1175  GEOSWKTWriter *writer,
1176  int dim);
1177 extern int GEOS_DLL GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t handle,
1178  GEOSWKTWriter *writer);
1179 extern void GEOS_DLL GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t handle,
1180  GEOSWKTWriter *writer,
1181  int useOld3D);
1182 
1183 /* WKB Reader */
1184 extern GEOSWKBReader GEOS_DLL *GEOSWKBReader_create_r(
1185  GEOSContextHandle_t handle);
1186 extern void GEOS_DLL GEOSWKBReader_destroy_r(GEOSContextHandle_t handle,
1187  GEOSWKBReader* reader);
1188 extern GEOSGeometry GEOS_DLL *GEOSWKBReader_read_r(GEOSContextHandle_t handle,
1189  GEOSWKBReader* reader,
1190  const unsigned char *wkb,
1191  size_t size);
1192 extern GEOSGeometry GEOS_DLL *GEOSWKBReader_readHEX_r(
1193  GEOSContextHandle_t handle,
1194  GEOSWKBReader* reader,
1195  const unsigned char *hex,
1196  size_t size);
1197 
1198 /* WKB Writer */
1199 extern GEOSWKBWriter GEOS_DLL *GEOSWKBWriter_create_r(
1200  GEOSContextHandle_t handle);
1201 extern void GEOS_DLL GEOSWKBWriter_destroy_r(GEOSContextHandle_t handle,
1202  GEOSWKBWriter* writer);
1203 
1204 /* The caller owns the results for these two methods! */
1205 extern unsigned char GEOS_DLL *GEOSWKBWriter_write_r(
1206  GEOSContextHandle_t handle,
1207  GEOSWKBWriter* writer,
1208  const GEOSGeometry* g,
1209  size_t *size);
1210 extern unsigned char GEOS_DLL *GEOSWKBWriter_writeHEX_r(
1211  GEOSContextHandle_t handle,
1212  GEOSWKBWriter* writer,
1213  const GEOSGeometry* g,
1214  size_t *size);
1215 
1216 /*
1217  * Specify whether output WKB should be 2d or 3d.
1218  * Return previously set number of dimensions.
1219  */
1220 extern int GEOS_DLL GEOSWKBWriter_getOutputDimension_r(
1221  GEOSContextHandle_t handle,
1222  const GEOSWKBWriter* writer);
1223 extern void GEOS_DLL GEOSWKBWriter_setOutputDimension_r(
1224  GEOSContextHandle_t handle,
1225  GEOSWKBWriter* writer, int newDimension);
1226 
1227 /*
1228  * Specify whether the WKB byte order is big or little endian.
1229  * The return value is the previous byte order.
1230  */
1231 extern int GEOS_DLL GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t handle,
1232  const GEOSWKBWriter* writer);
1233 extern void GEOS_DLL GEOSWKBWriter_setByteOrder_r(GEOSContextHandle_t handle,
1234  GEOSWKBWriter* writer,
1235  int byteOrder);
1236 
1237 /*
1238  * Specify whether SRID values should be output.
1239  */
1240 extern char GEOS_DLL GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t handle,
1241  const GEOSWKBWriter* writer);
1242 extern void GEOS_DLL GEOSWKBWriter_setIncludeSRID_r(GEOSContextHandle_t handle,
1243  GEOSWKBWriter* writer, const char writeSRID);
1244 
1245 
1246 /*
1247  * Free buffers returned by stuff like GEOSWKBWriter_write(),
1248  * GEOSWKBWriter_writeHEX() and GEOSWKTWriter_write().
1249  */
1250 extern void GEOS_DLL GEOSFree_r(GEOSContextHandle_t handle, void *buffer);
1251 
1252 
1253 /* External code to GEOS can define GEOS_USE_ONLY_R_API to avoid the */
1254 /* non _r API to be available */
1255 #ifndef GEOS_USE_ONLY_R_API
1256 
1257 /************************************************************************
1258  *
1259  * Initialization, cleanup, version
1260  *
1261  ***********************************************************************/
1262 
1263 extern void GEOS_DLL initGEOS(GEOSMessageHandler notice_function,
1264  GEOSMessageHandler error_function);
1265 extern void GEOS_DLL finishGEOS(void);
1266 
1267 /************************************************************************
1268  *
1269  * NOTE - These functions are DEPRECATED. Please use the new Reader and
1270  * writer APIS!
1271  *
1272  ***********************************************************************/
1273 
1274 extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKT(const char *wkt);
1275 extern char GEOS_DLL *GEOSGeomToWKT(const GEOSGeometry* g);
1276 
1277 /*
1278  * Specify whether output WKB should be 2d or 3d.
1279  * Return previously set number of dimensions.
1280  */
1281 extern int GEOS_DLL GEOS_getWKBOutputDims();
1282 extern int GEOS_DLL GEOS_setWKBOutputDims(int newDims);
1283 
1284 /*
1285  * Specify whether the WKB byte order is big or little endian.
1286  * The return value is the previous byte order.
1287  */
1288 extern int GEOS_DLL GEOS_getWKBByteOrder();
1289 extern int GEOS_DLL GEOS_setWKBByteOrder(int byteOrder);
1290 
1291 extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKB_buf(const unsigned char *wkb, size_t size);
1292 extern unsigned char GEOS_DLL *GEOSGeomToWKB_buf(const GEOSGeometry* g, size_t *size);
1293 
1294 extern GEOSGeometry GEOS_DLL *GEOSGeomFromHEX_buf(const unsigned char *hex, size_t size);
1295 extern unsigned char GEOS_DLL *GEOSGeomToHEX_buf(const GEOSGeometry* g, size_t *size);
1296 
1297 /************************************************************************
1298  *
1299  * Coordinate Sequence functions
1300  *
1301  ***********************************************************************/
1302 
1303 /*
1304  * Create a Coordinate sequence with ``size'' coordinates
1305  * of ``dims'' dimensions.
1306  * Return NULL on exception.
1307  */
1308 extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_create(unsigned int size, unsigned int dims);
1309 
1310 /*
1311  * Clone a Coordinate Sequence.
1312  * Return NULL on exception.
1313  */
1314 extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_clone(const GEOSCoordSequence* s);
1315 
1316 /*
1317  * Destroy a Coordinate Sequence.
1318  */
1319 extern void GEOS_DLL GEOSCoordSeq_destroy(GEOSCoordSequence* s);
1320 
1321 /*
1322  * Set ordinate values in a Coordinate Sequence.
1323  * Return 0 on exception.
1324  */
1325 extern int GEOS_DLL GEOSCoordSeq_setX(GEOSCoordSequence* s,
1326  unsigned int idx, double val);
1327 extern int GEOS_DLL GEOSCoordSeq_setY(GEOSCoordSequence* s,
1328  unsigned int idx, double val);
1329 extern int GEOS_DLL GEOSCoordSeq_setZ(GEOSCoordSequence* s,
1330  unsigned int idx, double val);
1331 extern int GEOS_DLL GEOSCoordSeq_setOrdinate(GEOSCoordSequence* s,
1332  unsigned int idx, unsigned int dim, double val);
1333 
1334 /*
1335  * Get ordinate values from a Coordinate Sequence.
1336  * Return 0 on exception.
1337  */
1338 extern int GEOS_DLL GEOSCoordSeq_getX(const GEOSCoordSequence* s,
1339  unsigned int idx, double *val);
1340 extern int GEOS_DLL GEOSCoordSeq_getY(const GEOSCoordSequence* s,
1341  unsigned int idx, double *val);
1342 extern int GEOS_DLL GEOSCoordSeq_getZ(const GEOSCoordSequence* s,
1343  unsigned int idx, double *val);
1344 extern int GEOS_DLL GEOSCoordSeq_getOrdinate(const GEOSCoordSequence* s,
1345  unsigned int idx, unsigned int dim, double *val);
1346 /*
1347  * Get size and dimensions info from a Coordinate Sequence.
1348  * Return 0 on exception.
1349  */
1350 extern int GEOS_DLL GEOSCoordSeq_getSize(const GEOSCoordSequence* s,
1351  unsigned int *size);
1352 extern int GEOS_DLL GEOSCoordSeq_getDimensions(const GEOSCoordSequence* s,
1353  unsigned int *dims);
1354 
1355 /************************************************************************
1356  *
1357  * Linear referencing functions -- there are more, but these are
1358  * probably sufficient for most purposes
1359  *
1360  ***********************************************************************/
1361 
1362 /*
1363  * GEOSGeometry ownership is retained by caller
1364  */
1365 
1366 
1367 /* Return distance of point 'p' projected on 'g' from origin
1368  * of 'g'. Geometry 'g' must be a lineal geometry */
1369 extern double GEOS_DLL GEOSProject(const GEOSGeometry *g,
1370  const GEOSGeometry* p);
1371 
1372 /* Return closest point to given distance within geometry
1373  * Geometry must be a LineString */
1374 extern GEOSGeometry GEOS_DLL *GEOSInterpolate(const GEOSGeometry *g,
1375  double d);
1376 
1377 extern double GEOS_DLL GEOSProjectNormalized(const GEOSGeometry *g,
1378  const GEOSGeometry* p);
1379 
1380 extern GEOSGeometry GEOS_DLL *GEOSInterpolateNormalized(const GEOSGeometry *g,
1381  double d);
1382 
1383 /************************************************************************
1384  *
1385  * Buffer related functions
1386  *
1387  ***********************************************************************/
1388 
1389 
1390 /* @return NULL on exception */
1391 extern GEOSGeometry GEOS_DLL *GEOSBuffer(const GEOSGeometry* g,
1392  double width, int quadsegs);
1393 
1394 /* @return 0 on exception */
1395 extern GEOSBufferParams GEOS_DLL *GEOSBufferParams_create();
1396 extern void GEOS_DLL GEOSBufferParams_destroy(GEOSBufferParams* parms);
1397 
1398 /* @return 0 on exception */
1399 extern int GEOS_DLL GEOSBufferParams_setEndCapStyle(
1400  GEOSBufferParams* p,
1401  int style);
1402 
1403 /* @return 0 on exception */
1404 extern int GEOS_DLL GEOSBufferParams_setJoinStyle(
1405  GEOSBufferParams* p,
1406  int joinStyle);
1407 
1408 /* @return 0 on exception */
1409 extern int GEOS_DLL GEOSBufferParams_setMitreLimit(
1410  GEOSBufferParams* p,
1411  double mitreLimit);
1412 
1413 /* @return 0 on exception */
1414 extern int GEOS_DLL GEOSBufferParams_setQuadrantSegments(
1415  GEOSBufferParams* p,
1416  int quadSegs);
1417 
1418 /* @param singleSided: 1 for single sided, 0 otherwise */
1419 /* @return 0 on exception */
1420 extern int GEOS_DLL GEOSBufferParams_setSingleSided(
1421  GEOSBufferParams* p,
1422  int singleSided);
1423 
1424 /* @return NULL on exception */
1425 extern GEOSGeometry GEOS_DLL *GEOSBufferWithParams(
1426  const GEOSGeometry* g,
1427  const GEOSBufferParams* p,
1428  double width);
1429 
1430 /* These functions return NULL on exception. */
1431 extern GEOSGeometry GEOS_DLL *GEOSBufferWithStyle(const GEOSGeometry* g,
1432  double width, int quadsegs, int endCapStyle, int joinStyle,
1433  double mitreLimit);
1434 
1435 /* These functions return NULL on exception. Only LINESTRINGs are accepted. */
1436 /* @deprecated in 3.3.0: use GEOSOffsetCurve instead */
1437 extern GEOSGeometry GEOS_DLL *GEOSSingleSidedBuffer(const GEOSGeometry* g,
1438  double width, int quadsegs, int joinStyle, double mitreLimit,
1439  int leftSide);
1440 
1441 /*
1442  * Only LINESTRINGs are accepted.
1443  * @param width : offset distance.
1444  * negative for right side offset.
1445  * positive for left side offset.
1446  * @return NULL on exception
1447  */
1448 extern GEOSGeometry GEOS_DLL *GEOSOffsetCurve(const GEOSGeometry* g,
1449  double width, int quadsegs, int joinStyle, double mitreLimit);
1450 
1451 /************************************************************************
1452  *
1453  * Geometry Constructors.
1454  * GEOSCoordSequence* arguments will become ownership of the returned object.
1455  * All functions return NULL on exception.
1456  *
1457  ***********************************************************************/
1458 
1459 extern GEOSGeometry GEOS_DLL *GEOSGeom_createPoint(GEOSCoordSequence* s);
1460 extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPoint();
1461 extern GEOSGeometry GEOS_DLL *GEOSGeom_createLinearRing(GEOSCoordSequence* s);
1462 extern GEOSGeometry GEOS_DLL *GEOSGeom_createLineString(GEOSCoordSequence* s);
1463 extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyLineString();
1464 
1465 /*
1466  * Second argument is an array of GEOSGeometry* objects.
1467  * The caller remains owner of the array, but pointed-to
1468  * objects become ownership of the returned GEOSGeometry.
1469  */
1470 extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPolygon();
1471 extern GEOSGeometry GEOS_DLL *GEOSGeom_createPolygon(GEOSGeometry* shell,
1472  GEOSGeometry** holes, unsigned int nholes);
1473 extern GEOSGeometry GEOS_DLL *GEOSGeom_createCollection(int type,
1474  GEOSGeometry* *geoms, unsigned int ngeoms);
1475 extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyCollection(int type);
1476 
1477 extern GEOSGeometry GEOS_DLL *GEOSGeom_clone(const GEOSGeometry* g);
1478 
1479 /************************************************************************
1480  *
1481  * Memory management
1482  *
1483  ***********************************************************************/
1484 
1485 extern void GEOS_DLL GEOSGeom_destroy(GEOSGeometry* g);
1486 
1487 /************************************************************************
1488  *
1489  * Topology operations - return NULL on exception.
1490  *
1491  ***********************************************************************/
1492 
1493 extern GEOSGeometry GEOS_DLL *GEOSEnvelope(const GEOSGeometry* g);
1494 extern GEOSGeometry GEOS_DLL *GEOSIntersection(const GEOSGeometry* g1, const GEOSGeometry* g2);
1495 extern GEOSGeometry GEOS_DLL *GEOSConvexHull(const GEOSGeometry* g);
1496 
1497 /* Returns the minimum rotated rectangular POLYGON which encloses the input geometry. The rectangle
1498  * has width equal to the minimum diameter, and a longer length. If the convex hill of the input is
1499  * degenerate (a line or point) a LINESTRING or POINT is returned. The minimum rotated rectangle can
1500  * be used as an extremely generalized representation for the given geometry.
1501  */
1502 extern GEOSGeometry GEOS_DLL *GEOSMinimumRotatedRectangle(const GEOSGeometry* g);
1503 
1504 /* Returns a LINESTRING geometry which represents the minimum diameter of the geometry.
1505  * The minimum diameter is defined to be the width of the smallest band that
1506  * contains the geometry, where a band is a strip of the plane defined
1507  * by two parallel lines. This can be thought of as the smallest hole that the geometry
1508  * can be moved through, with a single rotation.
1509  */
1510 extern GEOSGeometry GEOS_DLL *GEOSMinimumWidth(const GEOSGeometry* g);
1511 
1512 /* Computes the minimum clearance of a geometry. The minimum clearance is the smallest amount by which
1513  * a vertex could be move to produce an invalid polygon, a non-simple linestring, or a multipoint with
1514  * repeated points. If a geometry has a minimum clearance of 'eps', it can be said that:
1515  *
1516  * - No two distinct vertices in the geometry are separated by less than 'eps'
1517  * - No vertex is closer than 'eps' to a line segment of which it is not an endpoint.
1518  *
1519  * If the minimum clearance cannot be defined for a geometry (such as with a single point, or a multipoint
1520  * whose points are identical, a value of Infinity will be calculated.
1521  *
1522  * @param g the input geometry
1523  * @param d a double to which the result can be stored
1524  *
1525  * @return 0 if no exception occurred
1526  * 2 if an exception occurred
1527  */
1528 extern int GEOS_DLL GEOSMinimumClearance(const GEOSGeometry* g, double* d);
1529 
1530 /* Returns a LineString whose endpoints define the minimum clearance of a geometry.
1531  * If the geometry has no minimum clearance, an empty LineString will be returned.
1532  *
1533  * @param g the input geometry
1534  * @return a LineString, or NULL if an exception occurred.
1535  */
1536 extern GEOSGeometry GEOS_DLL *GEOSMinimumClearanceLine(const GEOSGeometry* g);
1537 
1538 extern GEOSGeometry GEOS_DLL *GEOSDifference(const GEOSGeometry* g1, const GEOSGeometry* g2);
1539 extern GEOSGeometry GEOS_DLL *GEOSSymDifference(const GEOSGeometry* g1, const GEOSGeometry* g2);
1540 extern GEOSGeometry GEOS_DLL *GEOSBoundary(const GEOSGeometry* g);
1541 extern GEOSGeometry GEOS_DLL *GEOSUnion(const GEOSGeometry* g1, const GEOSGeometry* g2);
1542 extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion(const GEOSGeometry* g);
1543 
1544 /* @deprecated in 3.3.0: use GEOSUnaryUnion instead */
1545 extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded(const GEOSGeometry* g);
1546 extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface(const GEOSGeometry* g);
1547 extern GEOSGeometry GEOS_DLL *GEOSGetCentroid(const GEOSGeometry* g);
1548 extern GEOSGeometry GEOS_DLL *GEOSNode(const GEOSGeometry* g);
1549 extern GEOSGeometry GEOS_DLL *GEOSClipByRect(const GEOSGeometry* g, double xmin, double ymin, double xmax, double ymax);
1550 
1551 /*
1552  * all arguments remain ownership of the caller
1553  * (both Geometries and pointers)
1554  */
1555 extern GEOSGeometry GEOS_DLL *GEOSPolygonize(const GEOSGeometry * const geoms[], unsigned int ngeoms);
1556 extern GEOSGeometry GEOS_DLL *GEOSPolygonizer_getCutEdges(const GEOSGeometry * const geoms[], unsigned int ngeoms);
1557 /*
1558  * Polygonizes a set of Geometries which contain linework that
1559  * represents the edges of a planar graph.
1560  *
1561  * Any dimension of Geometry is handled - the constituent linework
1562  * is extracted to form the edges.
1563  *
1564  * The edges must be correctly noded; that is, they must only meet
1565  * at their endpoints.
1566  * The Polygonizer will still run on incorrectly noded input
1567  * but will not form polygons from incorrectly noded edges.
1568  *
1569  * The Polygonizer reports the follow kinds of errors:
1570  *
1571  * - Dangles - edges which have one or both ends which are
1572  * not incident on another edge endpoint
1573  * - Cut Edges - edges which are connected at both ends but
1574  * which do not form part of polygon
1575  * - Invalid Ring Lines - edges which form rings which are invalid
1576  * (e.g. the component lines contain a self-intersection)
1577  *
1578  * Errors are reported to output parameters "cuts", "dangles" and
1579  * "invalid" (if not-null). Formed polygons are returned as a
1580  * collection. NULL is returned on exception. All returned
1581  * geometries must be destroyed by caller.
1582  *
1583  */
1584 extern GEOSGeometry GEOS_DLL *GEOSPolygonize_full(const GEOSGeometry* input,
1585  GEOSGeometry** cuts, GEOSGeometry** dangles, GEOSGeometry** invalid);
1586 
1587 extern GEOSGeometry GEOS_DLL *GEOSLineMerge(const GEOSGeometry* g);
1588 extern GEOSGeometry GEOS_DLL *GEOSSimplify(const GEOSGeometry* g, double tolerance);
1589 extern GEOSGeometry GEOS_DLL *GEOSTopologyPreserveSimplify(const GEOSGeometry* g,
1590  double tolerance);
1591 
1592 /*
1593  * Return all distinct vertices of input geometry as a MULTIPOINT.
1594  * Note that only 2 dimensions of the vertices are considered when
1595  * testing for equality.
1596  */
1597 extern GEOSGeometry GEOS_DLL *GEOSGeom_extractUniquePoints(
1598  const GEOSGeometry* g);
1599 
1600 /*
1601  * Find paths shared between the two given lineal geometries.
1602  *
1603  * Returns a GEOMETRYCOLLECTION having two elements:
1604  * - first element is a MULTILINESTRING containing shared paths
1605  * having the _same_ direction on both inputs
1606  * - second element is a MULTILINESTRING containing shared paths
1607  * having the _opposite_ direction on the two inputs
1608  *
1609  * Returns NULL on exception
1610  */
1611 extern GEOSGeometry GEOS_DLL *GEOSSharedPaths(const GEOSGeometry* g1,
1612  const GEOSGeometry* g2);
1613 
1614 /*
1615  * Snap first geometry on to second with given tolerance
1616  * Returns a newly allocated geometry, or NULL on exception
1617  */
1618 extern GEOSGeometry GEOS_DLL *GEOSSnap(const GEOSGeometry* g1,
1619  const GEOSGeometry* g2, double tolerance);
1620 
1621 /*
1622  * Return a Delaunay triangulation of the vertex of the given geometry
1623  *
1624  * @param g the input geometry whose vertex will be used as "sites"
1625  * @param tolerance optional snapping tolerance to use for improved robustness
1626  * @param onlyEdges if non-zero will return a MULTILINESTRING, otherwise it will
1627  * return a GEOMETRYCOLLECTION containing triangular POLYGONs.
1628  *
1629  * @return a newly allocated geometry, or NULL on exception
1630  */
1631 extern GEOSGeometry GEOS_DLL * GEOSDelaunayTriangulation(
1632  const GEOSGeometry *g,
1633  double tolerance,
1634  int onlyEdges);
1635 
1636 /*
1637  * Returns the Voronoi polygons of a set of Vertices given as input
1638  *
1639  * @param g the input geometry whose vertex will be used as sites.
1640  * @param tolerance snapping tolerance to use for improved robustness
1641  * @param onlyEdges whether to return only edges of the voronoi cells
1642  * @param env clipping envelope for the returned diagram, automatically
1643  * determined if NULL.
1644  * The diagram will be clipped to the larger
1645  * of this envelope or an envelope surrounding the sites.
1646  *
1647  * @return a newly allocated geometry, or NULL on exception.
1648  */
1649 extern GEOSGeometry GEOS_DLL * GEOSVoronoiDiagram(
1650  const GEOSGeometry *g,
1651  const GEOSGeometry *env,
1652  double tolerance,
1653  int onlyEdges);
1654 
1655 /************************************************************************
1656  *
1657  * Binary predicates - return 2 on exception, 1 on true, 0 on false
1658  *
1659  ***********************************************************************/
1660 
1661 extern char GEOS_DLL GEOSDisjoint(const GEOSGeometry* g1, const GEOSGeometry* g2);
1662 extern char GEOS_DLL GEOSTouches(const GEOSGeometry* g1, const GEOSGeometry* g2);
1663 extern char GEOS_DLL GEOSIntersects(const GEOSGeometry* g1, const GEOSGeometry* g2);
1664 extern char GEOS_DLL GEOSCrosses(const GEOSGeometry* g1, const GEOSGeometry* g2);
1665 extern char GEOS_DLL GEOSWithin(const GEOSGeometry* g1, const GEOSGeometry* g2);
1666 extern char GEOS_DLL GEOSContains(const GEOSGeometry* g1, const GEOSGeometry* g2);
1667 extern char GEOS_DLL GEOSOverlaps(const GEOSGeometry* g1, const GEOSGeometry* g2);
1668 extern char GEOS_DLL GEOSEquals(const GEOSGeometry* g1, const GEOSGeometry* g2);
1669 extern char GEOS_DLL GEOSEqualsExact(const GEOSGeometry* g1, const GEOSGeometry* g2, double tolerance);
1670 extern char GEOS_DLL GEOSCovers(const GEOSGeometry* g1, const GEOSGeometry* g2);
1671 extern char GEOS_DLL GEOSCoveredBy(const GEOSGeometry* g1, const GEOSGeometry* g2);
1672 
1673 /************************************************************************
1674  *
1675  * Prepared Geometry Binary predicates - return 2 on exception, 1 on true, 0 on false
1676  *
1677  ***********************************************************************/
1678 
1679 /*
1680  * GEOSGeometry ownership is retained by caller
1681  */
1682 extern const GEOSPreparedGeometry GEOS_DLL *GEOSPrepare(const GEOSGeometry* g);
1683 
1684 extern void GEOS_DLL GEOSPreparedGeom_destroy(const GEOSPreparedGeometry* g);
1685 
1686 extern char GEOS_DLL GEOSPreparedContains(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1687 extern char GEOS_DLL GEOSPreparedContainsProperly(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1688 extern char GEOS_DLL GEOSPreparedCoveredBy(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1689 extern char GEOS_DLL GEOSPreparedCovers(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1690 extern char GEOS_DLL GEOSPreparedCrosses(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1691 extern char GEOS_DLL GEOSPreparedDisjoint(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1692 extern char GEOS_DLL GEOSPreparedIntersects(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1693 extern char GEOS_DLL GEOSPreparedOverlaps(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1694 extern char GEOS_DLL GEOSPreparedTouches(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1695 extern char GEOS_DLL GEOSPreparedWithin(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1696 
1697 /************************************************************************
1698  *
1699  * STRtree functions
1700  *
1701  ***********************************************************************/
1702 
1703 /*
1704  * GEOSGeometry ownership is retained by caller
1705  */
1706 
1707 /*
1708  * Create a new R-tree using the Sort-Tile-Recursive algorithm (STRtree) for two-dimensional
1709  * spatial data.
1710  *
1711  * @param nodeCapacity the maximum number of child nodes that a node may have. The minimum
1712  * recommended capacity value is 4. If unsure, use a default node capacity of 10.
1713  * @return a pointer to the created tree
1714  */
1715 extern GEOSSTRtree GEOS_DLL *GEOSSTRtree_create(size_t nodeCapacity);
1716 
1717 /*
1718  * Insert an item into an STRtree
1719  *
1720  * @param tree the STRtree in which the item should be inserted
1721  * @param g a GEOSGeometry whose envelope corresponds to the extent of 'item'
1722  * @param item the item to insert into the tree
1723  */
1724 extern void GEOS_DLL GEOSSTRtree_insert(GEOSSTRtree *tree,
1725  const GEOSGeometry *g,
1726  void *item);
1727 
1728 /*
1729  * Query an STRtree for items intersecting a specified envelope
1730  *
1731  * @param tree the STRtree to search
1732  * @param g a GEOSGeomety from which a query envelope will be extracted
1733  * @param callback a function to be executed for each item in the tree whose envelope intersects
1734  * the envelope of 'g'. The callback function should take two parameters: a void
1735  * pointer representing the located item in the tree, and a void userdata pointer.
1736  * @param userdata an optional pointer to pe passed to 'callback' as an argument
1737  */
1738 extern void GEOS_DLL GEOSSTRtree_query(GEOSSTRtree *tree,
1739  const GEOSGeometry *g,
1740  GEOSQueryCallback callback,
1741  void *userdata);
1742 /*
1743  * Returns the nearest item in the STRtree to the supplied GEOSGeometry.
1744  * All items in the tree MUST be of type GEOSGeometry. If this is not the case, use
1745  * GEOSSTRtree_nearest_generic instead.
1746 *
1747  * @param tree the STRtree to search
1748  * @param geom the geometry with which the tree should be queried
1749  * @return a const pointer to the nearest GEOSGeometry in the tree to 'geom', or NULL in
1750  * case of exception
1751  */
1752 extern const GEOSGeometry GEOS_DLL *GEOSSTRtree_nearest(GEOSSTRtree *tree, const GEOSGeometry* geom);
1753 
1754 /*
1755  * Returns the nearest item in the STRtree to the supplied item
1756  *
1757  * @param tree the STRtree to search
1758  * @param item the item with which the tree should be queried
1759  * @param itemEnvelope a GEOSGeometry having the bounding box of 'item'
1760  * @param distancefn a function that can compute the distance between two items
1761  * in the STRtree. The function should return zero in case of error,
1762  * and should store the computed distance to the location pointed to by
1763  * the 'distance' argument. The computed distance between two items
1764  * must not exceed the Cartesian distance between their envelopes.
1765  * @param userdata optional pointer to arbitrary data; will be passed to distancefn
1766  * each time it is called.
1767  * @return a const pointer to the nearest item in the tree to 'item', or NULL in
1768  * case of exception
1769  */
1770 extern const void GEOS_DLL *GEOSSTRtree_nearest_generic(GEOSSTRtree *tree,
1771  const void* item,
1772  const GEOSGeometry* itemEnvelope,
1773  GEOSDistanceCallback distancefn,
1774  void* userdata);
1775 /*
1776  * Iterates over all items in the STRtree
1777  *
1778  * @param tree the STRtree over which to iterate
1779  * @param callback a function to be executed for each item in the tree.
1780  */
1781 extern void GEOS_DLL GEOSSTRtree_iterate(GEOSSTRtree *tree,
1782  GEOSQueryCallback callback,
1783  void *userdata);
1784 
1785 /*
1786  * Removes an item from the STRtree
1787  *
1788  * @param tree the STRtree from which to remove an item
1789  * @param g the envelope of the item to remove
1790  * @param the item to remove
1791  * @return 0 if the item was not removed;
1792  * 1 if the item was removed;
1793  * 2 if an exception occurred
1794  */
1795 extern char GEOS_DLL GEOSSTRtree_remove(GEOSSTRtree *tree,
1796  const GEOSGeometry *g,
1797  void *item);
1798 extern void GEOS_DLL GEOSSTRtree_destroy(GEOSSTRtree *tree);
1799 
1800 
1801 /************************************************************************
1802  *
1803  * Unary predicate - return 2 on exception, 1 on true, 0 on false
1804  *
1805  ***********************************************************************/
1806 
1807 extern char GEOS_DLL GEOSisEmpty(const GEOSGeometry* g);
1808 extern char GEOS_DLL GEOSisSimple(const GEOSGeometry* g);
1809 extern char GEOS_DLL GEOSisRing(const GEOSGeometry* g);
1810 extern char GEOS_DLL GEOSHasZ(const GEOSGeometry* g);
1811 extern char GEOS_DLL GEOSisClosed(const GEOSGeometry *g);
1812 
1813 /************************************************************************
1814  *
1815  * Dimensionally Extended 9 Intersection Model related
1816  *
1817  ***********************************************************************/
1818 
1819 /* return 2 on exception, 1 on true, 0 on false */
1820 extern char GEOS_DLL GEOSRelatePattern(const GEOSGeometry* g1, const GEOSGeometry* g2, const char *pat);
1821 
1822 /* return NULL on exception, a string to GEOSFree otherwise */
1823 extern char GEOS_DLL *GEOSRelate(const GEOSGeometry* g1, const GEOSGeometry* g2);
1824 
1825 /* return 2 on exception, 1 on true, 0 on false */
1826 extern char GEOS_DLL GEOSRelatePatternMatch(const char *mat, const char *pat);
1827 
1828 /* return NULL on exception, a string to GEOSFree otherwise */
1829 extern char GEOS_DLL *GEOSRelateBoundaryNodeRule(const GEOSGeometry* g1,
1830  const GEOSGeometry* g2,
1831  int bnr);
1832 
1833 /************************************************************************
1834  *
1835  * Validity checking
1836  *
1837  ***********************************************************************/
1838 
1839 /* return 2 on exception, 1 on true, 0 on false */
1840 extern char GEOS_DLL GEOSisValid(const GEOSGeometry* g);
1841 
1842 /* return NULL on exception, a string to GEOSFree otherwise */
1843 extern char GEOS_DLL *GEOSisValidReason(const GEOSGeometry *g);
1844 /*
1845  * Caller has the responsibility to destroy 'reason' (GEOSFree)
1846  * and 'location' (GEOSGeom_destroy) params
1847  * return 2 on exception, 1 when valid, 0 when invalid
1848  * Use enum GEOSValidFlags values for the flags param.
1849  */
1850 extern char GEOS_DLL GEOSisValidDetail(const GEOSGeometry* g,
1851  int flags,
1852  char** reason, GEOSGeometry** location);
1853 
1854 /************************************************************************
1855  *
1856  * Geometry info
1857  *
1858  ***********************************************************************/
1859 
1860 /* Return NULL on exception, result must be freed by caller. */
1861 extern char GEOS_DLL *GEOSGeomType(const GEOSGeometry* g);
1862 
1863 /* Return -1 on exception */
1864 extern int GEOS_DLL GEOSGeomTypeId(const GEOSGeometry* g);
1865 
1866 /* Return 0 on exception */
1867 extern int GEOS_DLL GEOSGetSRID(const GEOSGeometry* g);
1868 
1869 extern void GEOS_DLL GEOSSetSRID(GEOSGeometry* g, int SRID);
1870 
1871 extern void GEOS_DLL *GEOSGeom_getUserData(const GEOSGeometry* g);
1872 
1873 extern void GEOS_DLL GEOSGeom_setUserData(GEOSGeometry* g, void* userData);
1874 
1875 
1876 /* May be called on all geometries in GEOS 3.x, returns -1 on error and 1
1877  * for non-multi geometries. Older GEOS versions only accept
1878  * GeometryCollections or Multi* geometries here, and are likely to crash
1879  * when fed simple geometries, so beware if you need compatibility with
1880  * old GEOS versions.
1881  */
1882 extern int GEOS_DLL GEOSGetNumGeometries(const GEOSGeometry* g);
1883 
1884 /*
1885  * Return NULL on exception.
1886  * Returned object is a pointer to internal storage:
1887  * it must NOT be destroyed directly.
1888  * Up to GEOS 3.2.0 the input geometry must be a Collection, in
1889  * later version it doesn't matter (getGeometryN(0) for a single will
1890  * return the input).
1891  */
1892 extern const GEOSGeometry GEOS_DLL *GEOSGetGeometryN(const GEOSGeometry* g, int n);
1893 
1894 /* Return -1 on exception */
1895 extern int GEOS_DLL GEOSNormalize(GEOSGeometry* g);
1896 
1897 /* Return NULL on exception */
1898 extern GEOSGeometry GEOS_DLL *GEOSGeom_setPrecision(
1899  const GEOSGeometry *g, double gridSize, int flags);
1900 
1901 /* Return -1 on exception */
1902 extern double GEOS_DLL GEOSGeom_getPrecision(const GEOSGeometry *g);
1903 
1904 /* Return -1 on exception */
1905 extern int GEOS_DLL GEOSGetNumInteriorRings(const GEOSGeometry* g);
1906 
1907 /* Return -1 on exception, Geometry must be a LineString. */
1908 extern int GEOS_DLL GEOSGeomGetNumPoints(const GEOSGeometry* g);
1909 
1910 /* Return -1 on exception, Geometry must be a Point. */
1911 extern int GEOS_DLL GEOSGeomGetX(const GEOSGeometry *g, double *x);
1912 extern int GEOS_DLL GEOSGeomGetY(const GEOSGeometry *g, double *y);
1913 
1914 /*
1915  * Return NULL on exception, Geometry must be a Polygon.
1916  * Returned object is a pointer to internal storage:
1917  * it must NOT be destroyed directly.
1918  */
1919 extern const GEOSGeometry GEOS_DLL *GEOSGetInteriorRingN(const GEOSGeometry* g, int n);
1920 
1921 /*
1922  * Return NULL on exception, Geometry must be a Polygon.
1923  * Returned object is a pointer to internal storage:
1924  * it must NOT be destroyed directly.
1925  */
1926 extern const GEOSGeometry GEOS_DLL *GEOSGetExteriorRing(const GEOSGeometry* g);
1927 
1928 /* Return -1 on exception */
1929 extern int GEOS_DLL GEOSGetNumCoordinates(const GEOSGeometry* g);
1930 
1931 /*
1932  * Return NULL on exception.
1933  * Geometry must be a LineString, LinearRing or Point.
1934  */
1935 extern const GEOSCoordSequence GEOS_DLL *GEOSGeom_getCoordSeq(const GEOSGeometry* g);
1936 
1937 /*
1938  * Return 0 on exception (or empty geometry)
1939  */
1940 extern int GEOS_DLL GEOSGeom_getDimensions(const GEOSGeometry* g);
1941 
1942 /*
1943  * Return 2 or 3.
1944  */
1945 extern int GEOS_DLL GEOSGeom_getCoordinateDimension(const GEOSGeometry* g);
1946 
1947 /*
1948  * Return NULL on exception.
1949  * Must be LineString and must be freed by called.
1950  */
1951 extern GEOSGeometry GEOS_DLL *GEOSGeomGetPointN(const GEOSGeometry *g, int n);
1952 extern GEOSGeometry GEOS_DLL *GEOSGeomGetStartPoint(const GEOSGeometry *g);
1953 extern GEOSGeometry GEOS_DLL *GEOSGeomGetEndPoint(const GEOSGeometry *g);
1954 
1955 /************************************************************************
1956  *
1957  * Misc functions
1958  *
1959  ***********************************************************************/
1960 
1961 /* Return 0 on exception, 1 otherwise */
1962 extern int GEOS_DLL GEOSArea(const GEOSGeometry* g, double *area);
1963 extern int GEOS_DLL GEOSLength(const GEOSGeometry* g, double *length);
1964 extern int GEOS_DLL GEOSDistance(const GEOSGeometry* g1, const GEOSGeometry* g2,
1965  double *dist);
1966 extern int GEOS_DLL GEOSHausdorffDistance(const GEOSGeometry *g1,
1967  const GEOSGeometry *g2, double *dist);
1968 extern int GEOS_DLL GEOSHausdorffDistanceDensify(const GEOSGeometry *g1,
1969  const GEOSGeometry *g2, double densifyFrac, double *dist);
1970 extern int GEOS_DLL GEOSGeomGetLength(const GEOSGeometry *g, double *length);
1971 
1972 /* Return 0 on exception, the closest points of the two geometries otherwise.
1973  * The first point comes from g1 geometry and the second point comes from g2.
1974  */
1975 extern GEOSCoordSequence GEOS_DLL *GEOSNearestPoints(
1976  const GEOSGeometry* g1, const GEOSGeometry* g2);
1977 
1978 
1979 /************************************************************************
1980  *
1981  * Algorithms
1982  *
1983  ***********************************************************************/
1984 
1985 /* Walking from A to B:
1986  * return -1 if reaching P takes a counter-clockwise (left) turn
1987  * return 1 if reaching P takes a clockwise (right) turn
1988  * return 0 if P is collinear with A-B
1989  *
1990  * On exceptions, return 2.
1991  *
1992  */
1993 extern int GEOS_DLL GEOSOrientationIndex(double Ax, double Ay, double Bx, double By,
1994  double Px, double Py);
1995 
1996 /************************************************************************
1997  *
1998  * Reader and Writer APIs
1999  *
2000  ***********************************************************************/
2001 
2002 /* WKT Reader */
2003 extern GEOSWKTReader GEOS_DLL *GEOSWKTReader_create();
2004 extern void GEOS_DLL GEOSWKTReader_destroy(GEOSWKTReader* reader);
2005 extern GEOSGeometry GEOS_DLL *GEOSWKTReader_read(GEOSWKTReader* reader, const char *wkt);
2006 
2007 /* WKT Writer */
2008 extern GEOSWKTWriter GEOS_DLL *GEOSWKTWriter_create();
2009 extern void GEOS_DLL GEOSWKTWriter_destroy(GEOSWKTWriter* writer);
2010 extern char GEOS_DLL *GEOSWKTWriter_write(GEOSWKTWriter* writer, const GEOSGeometry* g);
2011 extern void GEOS_DLL GEOSWKTWriter_setTrim(GEOSWKTWriter *writer, char trim);
2012 extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision(GEOSWKTWriter *writer, int precision);
2013 extern void GEOS_DLL GEOSWKTWriter_setOutputDimension(GEOSWKTWriter *writer, int dim);
2014 extern int GEOS_DLL GEOSWKTWriter_getOutputDimension(GEOSWKTWriter *writer);
2015 extern void GEOS_DLL GEOSWKTWriter_setOld3D(GEOSWKTWriter *writer, int useOld3D);
2016 
2017 /* WKB Reader */
2018 extern GEOSWKBReader GEOS_DLL *GEOSWKBReader_create();
2019 extern void GEOS_DLL GEOSWKBReader_destroy(GEOSWKBReader* reader);
2020 extern GEOSGeometry GEOS_DLL *GEOSWKBReader_read(GEOSWKBReader* reader, const unsigned char *wkb, size_t size);
2021 extern GEOSGeometry GEOS_DLL *GEOSWKBReader_readHEX(GEOSWKBReader* reader, const unsigned char *hex, size_t size);
2022 
2023 /* WKB Writer */
2024 extern GEOSWKBWriter GEOS_DLL *GEOSWKBWriter_create();
2025 extern void GEOS_DLL GEOSWKBWriter_destroy(GEOSWKBWriter* writer);
2026 
2027 /* The caller owns the results for these two methods! */
2028 extern unsigned char GEOS_DLL *GEOSWKBWriter_write(GEOSWKBWriter* writer, const GEOSGeometry* g, size_t *size);
2029 extern unsigned char GEOS_DLL *GEOSWKBWriter_writeHEX(GEOSWKBWriter* writer, const GEOSGeometry* g, size_t *size);
2030 
2031 /*
2032  * Specify whether output WKB should be 2d or 3d.
2033  * Return previously set number of dimensions.
2034  */
2035 extern int GEOS_DLL GEOSWKBWriter_getOutputDimension(const GEOSWKBWriter* writer);
2036 extern void GEOS_DLL GEOSWKBWriter_setOutputDimension(GEOSWKBWriter* writer, int newDimension);
2037 
2038 /*
2039  * Specify whether the WKB byte order is big or little endian.
2040  * The return value is the previous byte order.
2041  */
2042 extern int GEOS_DLL GEOSWKBWriter_getByteOrder(const GEOSWKBWriter* writer);
2043 extern void GEOS_DLL GEOSWKBWriter_setByteOrder(GEOSWKBWriter* writer, int byteOrder);
2044 
2045 /*
2046  * Specify whether SRID values should be output.
2047  */
2048 extern char GEOS_DLL GEOSWKBWriter_getIncludeSRID(const GEOSWKBWriter* writer);
2049 extern void GEOS_DLL GEOSWKBWriter_setIncludeSRID(GEOSWKBWriter* writer, const char writeSRID);
2050 
2051 /*
2052  * Free buffers returned by stuff like GEOSWKBWriter_write(),
2053  * GEOSWKBWriter_writeHEX() and GEOSWKTWriter_write().
2054  */
2055 extern void GEOS_DLL GEOSFree(void *buffer);
2056 
2057 #endif /* #ifndef GEOS_USE_ONLY_R_API */
2058 
2059 
2060 #ifdef __cplusplus
2061 } // extern "C"
2062 #endif
2063 
2064 #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