GEOS 3.6.2
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>
41using std::size_t;
42#endif
43
44#ifdef __cplusplus
45extern "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 2
64#define GEOS_CAPI_VERSION "3.6.2-CAPI-1.10.2"
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 2
74#endif
75#ifndef GEOS_VERSION
76#define GEOS_VERSION "3.6.2"
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 2
85#define GEOS_CAPI_VERSION "3.6.2-CAPI-1.10.2"
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
97typedef struct GEOSContextHandle_HS *GEOSContextHandle_t;
98
99typedef 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 */
111typedef 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
120typedef struct GEOSGeom_t GEOSGeometry;
121typedef struct GEOSPrepGeom_t GEOSPreparedGeometry;
122typedef struct GEOSCoordSeq_t GEOSCoordSequence;
123typedef struct GEOSSTRtree_t GEOSSTRtree;
124typedef 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 */
130typedef GEOSGeometry* GEOSGeom;
131typedef 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
138enum GEOSGeomTypes {
139 GEOS_POINT,
140 GEOS_LINESTRING,
141 GEOS_LINEARRING,
142 GEOS_POLYGON,
143 GEOS_MULTIPOINT,
144 GEOS_MULTILINESTRING,
145 GEOS_MULTIPOLYGON,
146 GEOS_GEOMETRYCOLLECTION
147};
148
149/* Byte oders exposed via the c api */
150enum GEOSByteOrders {
151 GEOS_WKB_XDR = 0, /* Big Endian */
152 GEOS_WKB_NDR = 1 /* Little Endian */
153};
154
155typedef void (*GEOSQueryCallback)(void *item, void *userdata);
156typedef 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 */
172typedef void (GEOSInterruptCallback)();
173extern GEOSInterruptCallback GEOS_DLL *GEOS_interruptRegisterCallback(GEOSInterruptCallback* cb);
174/* Request safe interruption of operations */
175extern void GEOS_DLL GEOS_interruptRequest();
176/* Cancel a pending interruption request */
177extern 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 */
184extern 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 */
190extern void GEOS_DLL finishGEOS_r(GEOSContextHandle_t handle);
191
192extern GEOSContextHandle_t GEOS_DLL GEOS_init_r();
193extern void GEOS_DLL GEOS_finish_r(GEOSContextHandle_t handle);
194
195
196extern GEOSMessageHandler GEOS_DLL GEOSContext_setNoticeHandler_r(GEOSContextHandle_t extHandle,
197 GEOSMessageHandler nf);
198extern 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 */
210extern 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 */
223extern GEOSMessageHandler_r GEOS_DLL GEOSContext_setErrorMessageHandler_r(GEOSContextHandle_t extHandle,
224 GEOSMessageHandler_r ef,
225 void *userData);
226
227extern 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
237extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKT_r(GEOSContextHandle_t handle,
238 const char *wkt);
239extern 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
247extern int GEOS_DLL GEOS_getWKBOutputDims_r(GEOSContextHandle_t handle);
248extern 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
256extern int GEOS_DLL GEOS_getWKBByteOrder_r(GEOSContextHandle_t handle);
257extern int GEOS_DLL GEOS_setWKBByteOrder_r(GEOSContextHandle_t handle,
258 int byteOrder);
259
260extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKB_buf_r(GEOSContextHandle_t handle,
261 const unsigned char *wkb,
262 size_t size);
263extern unsigned char GEOS_DLL *GEOSGeomToWKB_buf_r(GEOSContextHandle_t handle,
264 const GEOSGeometry* g,
265 size_t *size);
266
267extern GEOSGeometry GEOS_DLL *GEOSGeomFromHEX_buf_r(GEOSContextHandle_t handle,
268 const unsigned char *hex,
269 size_t size);
270extern 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 */
285extern 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 */
294extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_clone_r(
295 GEOSContextHandle_t handle,
296 const GEOSCoordSequence* s);
297
298/*
299 * Destroy a Coordinate Sequence.
300 */
301extern 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 */
308extern int GEOS_DLL GEOSCoordSeq_setX_r(GEOSContextHandle_t handle,
309 GEOSCoordSequence* s, unsigned int idx,
310 double val);
311extern int GEOS_DLL GEOSCoordSeq_setY_r(GEOSContextHandle_t handle,
312 GEOSCoordSequence* s, unsigned int idx,
313 double val);
314extern int GEOS_DLL GEOSCoordSeq_setZ_r(GEOSContextHandle_t handle,
315 GEOSCoordSequence* s, unsigned int idx,
316 double val);
317extern 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 */
326extern int GEOS_DLL GEOSCoordSeq_getX_r(GEOSContextHandle_t handle,
327 const GEOSCoordSequence* s,
328 unsigned int idx, double *val);
329extern int GEOS_DLL GEOSCoordSeq_getY_r(GEOSContextHandle_t handle,
330 const GEOSCoordSequence* s,
331 unsigned int idx, double *val);
332extern int GEOS_DLL GEOSCoordSeq_getZ_r(GEOSContextHandle_t handle,
333 const GEOSCoordSequence* s,
334 unsigned int idx, double *val);
335extern 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 */
343extern int GEOS_DLL GEOSCoordSeq_getSize_r(GEOSContextHandle_t handle,
344 const GEOSCoordSequence* s,
345 unsigned int *size);
346extern 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 */
364extern 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 */
370extern GEOSGeometry GEOS_DLL *GEOSInterpolate_r(GEOSContextHandle_t handle,
371 const GEOSGeometry *g,
372 double d);
373
374extern double GEOS_DLL GEOSProjectNormalized_r(GEOSContextHandle_t handle,
375 const GEOSGeometry *g,
376 const GEOSGeometry *p);
377
378extern 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 */
391extern GEOSGeometry GEOS_DLL *GEOSBuffer_r(GEOSContextHandle_t handle,
392 const GEOSGeometry* g,
393 double width, int quadsegs);
394
395enum GEOSBufCapStyles {
396 GEOSBUF_CAP_ROUND=1,
397 GEOSBUF_CAP_FLAT=2,
398 GEOSBUF_CAP_SQUARE=3
399};
400
401enum GEOSBufJoinStyles {
402 GEOSBUF_JOIN_ROUND=1,
403 GEOSBUF_JOIN_MITRE=2,
404 GEOSBUF_JOIN_BEVEL=3
405};
406
407/* @return 0 on exception */
408extern GEOSBufferParams GEOS_DLL *GEOSBufferParams_create_r(
409 GEOSContextHandle_t handle);
410extern void GEOS_DLL GEOSBufferParams_destroy_r(
411 GEOSContextHandle_t handle,
412 GEOSBufferParams* parms);
413
414/* @return 0 on exception */
415extern int GEOS_DLL GEOSBufferParams_setEndCapStyle_r(
416 GEOSContextHandle_t handle,
417 GEOSBufferParams* p,
418 int style);
419
420/* @return 0 on exception */
421extern int GEOS_DLL GEOSBufferParams_setJoinStyle_r(
422 GEOSContextHandle_t handle,
423 GEOSBufferParams* p,
424 int joinStyle);
425
426/* @return 0 on exception */
427extern int GEOS_DLL GEOSBufferParams_setMitreLimit_r(
428 GEOSContextHandle_t handle,
429 GEOSBufferParams* p,
430 double mitreLimit);
431
432/* @return 0 on exception */
433extern 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 */
440extern int GEOS_DLL GEOSBufferParams_setSingleSided_r(
441 GEOSContextHandle_t handle,
442 GEOSBufferParams* p,
443 int singleSided);
444
445/* @return NULL on exception */
446extern 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. */
453extern 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 */
459extern 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 */
471extern 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
484extern GEOSGeometry GEOS_DLL *GEOSGeom_createPoint_r(
485 GEOSContextHandle_t handle,
486 GEOSCoordSequence* s);
487extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPoint_r(
488 GEOSContextHandle_t handle);
489extern GEOSGeometry GEOS_DLL *GEOSGeom_createLinearRing_r(
490 GEOSContextHandle_t handle,
491 GEOSCoordSequence* s);
492extern GEOSGeometry GEOS_DLL *GEOSGeom_createLineString_r(
493 GEOSContextHandle_t handle,
494 GEOSCoordSequence* s);
495extern 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 */
503extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPolygon_r(
504 GEOSContextHandle_t handle);
505extern GEOSGeometry GEOS_DLL *GEOSGeom_createPolygon_r(
506 GEOSContextHandle_t handle,
507 GEOSGeometry* shell,
508 GEOSGeometry** holes,
509 unsigned int nholes);
510extern GEOSGeometry GEOS_DLL *GEOSGeom_createCollection_r(
511 GEOSContextHandle_t handle, int type,
512 GEOSGeometry* *geoms,
513 unsigned int ngeoms);
514extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyCollection_r(
515 GEOSContextHandle_t handle, int type);
516
517extern GEOSGeometry GEOS_DLL *GEOSGeom_clone_r(GEOSContextHandle_t handle,
518 const GEOSGeometry* g);
519
520/************************************************************************
521 *
522 * Memory management
523 *
524 ***********************************************************************/
525
526extern 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
535extern GEOSGeometry GEOS_DLL *GEOSEnvelope_r(GEOSContextHandle_t handle,
536 const GEOSGeometry* g);
537extern GEOSGeometry GEOS_DLL *GEOSIntersection_r(GEOSContextHandle_t handle,
538 const GEOSGeometry* g1,
539 const GEOSGeometry* g2);
540extern 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 */
548extern 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 */
557extern GEOSGeometry GEOS_DLL *GEOSMinimumWidth_r(GEOSContextHandle_t handle,
558 const GEOSGeometry* g);
559
560extern GEOSGeometry GEOS_DLL *GEOSMinimumClearanceLine_r(GEOSContextHandle_t handle,
561 const GEOSGeometry* g);
562
563extern int GEOS_DLL GEOSMinimumClearance_r(GEOSContextHandle_t handle,
564 const GEOSGeometry* g,
565 double* distance);
566
567extern GEOSGeometry GEOS_DLL *GEOSDifference_r(GEOSContextHandle_t handle,
568 const GEOSGeometry* g1,
569 const GEOSGeometry* g2);
570extern GEOSGeometry GEOS_DLL *GEOSSymDifference_r(GEOSContextHandle_t handle,
571 const GEOSGeometry* g1,
572 const GEOSGeometry* g2);
573extern GEOSGeometry GEOS_DLL *GEOSBoundary_r(GEOSContextHandle_t handle,
574 const GEOSGeometry* g);
575extern GEOSGeometry GEOS_DLL *GEOSUnion_r(GEOSContextHandle_t handle,
576 const GEOSGeometry* g1,
577 const GEOSGeometry* g2);
578extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion_r(GEOSContextHandle_t handle,
579 const GEOSGeometry* g);
580/* @deprecated in 3.3.0: use GEOSUnaryUnion_r instead */
581extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded_r(GEOSContextHandle_t handle,
582 const GEOSGeometry* g);
583extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface_r(GEOSContextHandle_t handle,
584 const GEOSGeometry* g);
585extern GEOSGeometry GEOS_DLL *GEOSGetCentroid_r(GEOSContextHandle_t handle,
586 const GEOSGeometry* g);
587extern 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. */
591extern 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
628extern GEOSGeometry GEOS_DLL *GEOSPolygonize_r(GEOSContextHandle_t handle,
629 const GEOSGeometry *const geoms[],
630 unsigned int ngeoms);
631extern GEOSGeometry GEOS_DLL *GEOSPolygonizer_getCutEdges_r(
632 GEOSContextHandle_t handle,
633 const GEOSGeometry * const geoms[],
634 unsigned int ngeoms);
635extern GEOSGeometry GEOS_DLL *GEOSPolygonize_full_r(GEOSContextHandle_t handle,
636 const GEOSGeometry* input, GEOSGeometry** cuts,
637 GEOSGeometry** dangles, GEOSGeometry** invalidRings);
638
639extern GEOSGeometry GEOS_DLL *GEOSLineMerge_r(GEOSContextHandle_t handle,
640 const GEOSGeometry* g);
641extern GEOSGeometry GEOS_DLL *GEOSSimplify_r(GEOSContextHandle_t handle,
642 const GEOSGeometry* g,
643 double tolerance);
644extern 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 */
653extern 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 */
668extern 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 */
675extern 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 */
688extern 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 */
707extern 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
721extern char GEOS_DLL GEOSDisjoint_r(GEOSContextHandle_t handle,
722 const GEOSGeometry* g1,
723 const GEOSGeometry* g2);
724extern char GEOS_DLL GEOSTouches_r(GEOSContextHandle_t handle,
725 const GEOSGeometry* g1,
726 const GEOSGeometry* g2);
727extern char GEOS_DLL GEOSIntersects_r(GEOSContextHandle_t handle,
728 const GEOSGeometry* g1,
729 const GEOSGeometry* g2);
730extern char GEOS_DLL GEOSCrosses_r(GEOSContextHandle_t handle,
731 const GEOSGeometry* g1,
732 const GEOSGeometry* g2);
733extern char GEOS_DLL GEOSWithin_r(GEOSContextHandle_t handle,
734 const GEOSGeometry* g1,
735 const GEOSGeometry* g2);
736extern char GEOS_DLL GEOSContains_r(GEOSContextHandle_t handle,
737 const GEOSGeometry* g1,
738 const GEOSGeometry* g2);
739extern char GEOS_DLL GEOSOverlaps_r(GEOSContextHandle_t handle,
740 const GEOSGeometry* g1,
741 const GEOSGeometry* g2);
742extern char GEOS_DLL GEOSEquals_r(GEOSContextHandle_t handle,
743 const GEOSGeometry* g1,
744 const GEOSGeometry* g2);
745extern char GEOS_DLL GEOSEqualsExact_r(GEOSContextHandle_t handle,
746 const GEOSGeometry* g1,
747 const GEOSGeometry* g2,
748 double tolerance);
749extern char GEOS_DLL GEOSCovers_r(GEOSContextHandle_t handle,
750 const GEOSGeometry* g1,
751 const GEOSGeometry* g2);
752extern 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 */
765extern const GEOSPreparedGeometry GEOS_DLL *GEOSPrepare_r(
766 GEOSContextHandle_t handle,
767 const GEOSGeometry* g);
768
769extern void GEOS_DLL GEOSPreparedGeom_destroy_r(GEOSContextHandle_t handle,
770 const GEOSPreparedGeometry* g);
771
772extern char GEOS_DLL GEOSPreparedContains_r(GEOSContextHandle_t handle,
773 const GEOSPreparedGeometry* pg1,
774 const GEOSGeometry* g2);
775extern char GEOS_DLL GEOSPreparedContainsProperly_r(GEOSContextHandle_t handle,
776 const GEOSPreparedGeometry* pg1,
777 const GEOSGeometry* g2);
778extern char GEOS_DLL GEOSPreparedCoveredBy_r(GEOSContextHandle_t handle,
779 const GEOSPreparedGeometry* pg1,
780 const GEOSGeometry* g2);
781extern char GEOS_DLL GEOSPreparedCovers_r(GEOSContextHandle_t handle,
782 const GEOSPreparedGeometry* pg1,
783 const GEOSGeometry* g2);
784extern char GEOS_DLL GEOSPreparedCrosses_r(GEOSContextHandle_t handle,
785 const GEOSPreparedGeometry* pg1,
786 const GEOSGeometry* g2);
787extern char GEOS_DLL GEOSPreparedDisjoint_r(GEOSContextHandle_t handle,
788 const GEOSPreparedGeometry* pg1,
789 const GEOSGeometry* g2);
790extern char GEOS_DLL GEOSPreparedIntersects_r(GEOSContextHandle_t handle,
791 const GEOSPreparedGeometry* pg1,
792 const GEOSGeometry* g2);
793extern char GEOS_DLL GEOSPreparedOverlaps_r(GEOSContextHandle_t handle,
794 const GEOSPreparedGeometry* pg1,
795 const GEOSGeometry* g2);
796extern char GEOS_DLL GEOSPreparedTouches_r(GEOSContextHandle_t handle,
797 const GEOSPreparedGeometry* pg1,
798 const GEOSGeometry* g2);
799extern 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
813extern GEOSSTRtree GEOS_DLL *GEOSSTRtree_create_r(
814 GEOSContextHandle_t handle,
815 size_t nodeCapacity);
816extern void GEOS_DLL GEOSSTRtree_insert_r(GEOSContextHandle_t handle,
817 GEOSSTRtree *tree,
818 const GEOSGeometry *g,
819 void *item);
820extern void GEOS_DLL GEOSSTRtree_query_r(GEOSContextHandle_t handle,
821 GEOSSTRtree *tree,
822 const GEOSGeometry *g,
823 GEOSQueryCallback callback,
824 void *userdata);
825
826extern const GEOSGeometry GEOS_DLL *GEOSSTRtree_nearest_r(GEOSContextHandle_t handle,
827 GEOSSTRtree *tree,
828 const GEOSGeometry* geom);
829
830
831extern 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
838extern void GEOS_DLL GEOSSTRtree_iterate_r(GEOSContextHandle_t handle,
839 GEOSSTRtree *tree,
840 GEOSQueryCallback callback,
841 void *userdata);
842extern char GEOS_DLL GEOSSTRtree_remove_r(GEOSContextHandle_t handle,
843 GEOSSTRtree *tree,
844 const GEOSGeometry *g,
845 void *item);
846extern 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
856extern char GEOS_DLL GEOSisEmpty_r(GEOSContextHandle_t handle,
857 const GEOSGeometry* g);
858extern char GEOS_DLL GEOSisSimple_r(GEOSContextHandle_t handle,
859 const GEOSGeometry* g);
860extern char GEOS_DLL GEOSisRing_r(GEOSContextHandle_t handle,
861 const GEOSGeometry* g);
862extern char GEOS_DLL GEOSHasZ_r(GEOSContextHandle_t handle,
863 const GEOSGeometry* g);
864extern 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) */
874enum 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 */
886extern 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 */
892extern 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 */
897extern 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 */
902extern 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) */
914enum GEOSValidFlags {
915 GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE=1
916};
917
918/* return 2 on exception, 1 on true, 0 on false */
919extern char GEOS_DLL GEOSisValid_r(GEOSContextHandle_t handle,
920 const GEOSGeometry* g);
921
922/* return NULL on exception, a string to GEOSFree otherwise */
923extern 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 */
931extern 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. */
944extern char GEOS_DLL *GEOSGeomType_r(GEOSContextHandle_t handle,
945 const GEOSGeometry* g);
946
947/* Return -1 on exception */
948extern int GEOS_DLL GEOSGeomTypeId_r(GEOSContextHandle_t handle,
949 const GEOSGeometry* g);
950
951/* Return 0 on exception */
952extern int GEOS_DLL GEOSGetSRID_r(GEOSContextHandle_t handle,
953 const GEOSGeometry* g);
954
955extern void GEOS_DLL GEOSSetSRID_r(GEOSContextHandle_t handle,
956 GEOSGeometry* g, int SRID);
957
958extern void GEOS_DLL *GEOSGeom_getUserData_r(GEOSContextHandle_t handle,
959const GEOSGeometry* g);
960
961extern 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 */
970extern 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 */
981extern const GEOSGeometry GEOS_DLL *GEOSGetGeometryN_r(
982 GEOSContextHandle_t handle,
983 const GEOSGeometry* g, int n);
984
985/* Return -1 on exception */
986extern 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
1012extern GEOSGeometry GEOS_DLL *GEOSGeom_setPrecision_r(
1013 GEOSContextHandle_t handle,
1014 const GEOSGeometry *g,
1015 double gridSize, int flags);
1016
1023extern double GEOS_DLL GEOSGeom_getPrecision_r(
1024 GEOSContextHandle_t handle,
1025 const GEOSGeometry *g);
1026
1027/* Return -1 on exception */
1028extern int GEOS_DLL GEOSGetNumInteriorRings_r(GEOSContextHandle_t handle,
1029 const GEOSGeometry* g);
1030
1031/* Return -1 on exception, Geometry must be a LineString. */
1032extern int GEOS_DLL GEOSGeomGetNumPoints_r(GEOSContextHandle_t handle,
1033 const GEOSGeometry* g);
1034
1035/* Return -1 on exception, Geometry must be a Point. */
1036extern int GEOS_DLL GEOSGeomGetX_r(GEOSContextHandle_t handle, const GEOSGeometry *g, double *x);
1037extern 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 */
1044extern 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 */
1053extern const GEOSGeometry GEOS_DLL *GEOSGetExteriorRing_r(
1054 GEOSContextHandle_t handle,
1055 const GEOSGeometry* g);
1056
1057/* Return -1 on exception */
1058extern 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 */
1065extern 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 */
1072extern int GEOS_DLL GEOSGeom_getDimensions_r(GEOSContextHandle_t handle,
1073 const GEOSGeometry* g);
1074
1075/*
1076 * Return 2 or 3.
1077 */
1078extern 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 */
1085extern GEOSGeometry GEOS_DLL *GEOSGeomGetPointN_r(GEOSContextHandle_t handle, const GEOSGeometry *g, int n);
1086extern GEOSGeometry GEOS_DLL *GEOSGeomGetStartPoint_r(GEOSContextHandle_t handle, const GEOSGeometry *g);
1087extern 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 */
1096extern int GEOS_DLL GEOSArea_r(GEOSContextHandle_t handle,
1097 const GEOSGeometry* g, double *area);
1098extern int GEOS_DLL GEOSLength_r(GEOSContextHandle_t handle,
1099 const GEOSGeometry* g, double *length);
1100extern int GEOS_DLL GEOSDistance_r(GEOSContextHandle_t handle,
1101 const GEOSGeometry* g1,
1102 const GEOSGeometry* g2, double *dist);
1103extern int GEOS_DLL GEOSHausdorffDistance_r(GEOSContextHandle_t handle,
1104 const GEOSGeometry *g1,
1105 const GEOSGeometry *g2,
1106 double *dist);
1107extern int GEOS_DLL GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t handle,
1108 const GEOSGeometry *g1,
1109 const GEOSGeometry *g2,
1110 double densifyFrac, double *dist);
1111extern 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 */
1117extern 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 */
1135extern 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
1145typedef struct GEOSWKTReader_t GEOSWKTReader;
1146typedef struct GEOSWKTWriter_t GEOSWKTWriter;
1147typedef struct GEOSWKBReader_t GEOSWKBReader;
1148typedef struct GEOSWKBWriter_t GEOSWKBWriter;
1149
1150
1151/* WKT Reader */
1152extern GEOSWKTReader GEOS_DLL *GEOSWKTReader_create_r(
1153 GEOSContextHandle_t handle);
1154extern void GEOS_DLL GEOSWKTReader_destroy_r(GEOSContextHandle_t handle,
1155 GEOSWKTReader* reader);
1156extern GEOSGeometry GEOS_DLL *GEOSWKTReader_read_r(GEOSContextHandle_t handle,
1157 GEOSWKTReader* reader,
1158 const char *wkt);
1159
1160/* WKT Writer */
1161extern GEOSWKTWriter GEOS_DLL *GEOSWKTWriter_create_r(
1162 GEOSContextHandle_t handle);
1163extern void GEOS_DLL GEOSWKTWriter_destroy_r(GEOSContextHandle_t handle,
1164 GEOSWKTWriter* writer);
1165extern char GEOS_DLL *GEOSWKTWriter_write_r(GEOSContextHandle_t handle,
1166 GEOSWKTWriter* writer,
1167 const GEOSGeometry* g);
1168extern void GEOS_DLL GEOSWKTWriter_setTrim_r(GEOSContextHandle_t handle,
1169 GEOSWKTWriter *writer,
1170 char trim);
1171extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t handle,
1172 GEOSWKTWriter *writer,
1173 int precision);
1174extern void GEOS_DLL GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t handle,
1175 GEOSWKTWriter *writer,
1176 int dim);
1177extern int GEOS_DLL GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t handle,
1178 GEOSWKTWriter *writer);
1179extern void GEOS_DLL GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t handle,
1180 GEOSWKTWriter *writer,
1181 int useOld3D);
1182
1183/* WKB Reader */
1184extern GEOSWKBReader GEOS_DLL *GEOSWKBReader_create_r(
1185 GEOSContextHandle_t handle);
1186extern void GEOS_DLL GEOSWKBReader_destroy_r(GEOSContextHandle_t handle,
1187 GEOSWKBReader* reader);
1188extern GEOSGeometry GEOS_DLL *GEOSWKBReader_read_r(GEOSContextHandle_t handle,
1189 GEOSWKBReader* reader,
1190 const unsigned char *wkb,
1191 size_t size);
1192extern 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 */
1199extern GEOSWKBWriter GEOS_DLL *GEOSWKBWriter_create_r(
1200 GEOSContextHandle_t handle);
1201extern void GEOS_DLL GEOSWKBWriter_destroy_r(GEOSContextHandle_t handle,
1202 GEOSWKBWriter* writer);
1203
1204/* The caller owns the results for these two methods! */
1205extern unsigned char GEOS_DLL *GEOSWKBWriter_write_r(
1206 GEOSContextHandle_t handle,
1207 GEOSWKBWriter* writer,
1208 const GEOSGeometry* g,
1209 size_t *size);
1210extern 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 */
1220extern int GEOS_DLL GEOSWKBWriter_getOutputDimension_r(
1221 GEOSContextHandle_t handle,
1222 const GEOSWKBWriter* writer);
1223extern 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 */
1231extern int GEOS_DLL GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t handle,
1232 const GEOSWKBWriter* writer);
1233extern 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 */
1240extern char GEOS_DLL GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t handle,
1241 const GEOSWKBWriter* writer);
1242extern 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 */
1250extern 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
1263extern void GEOS_DLL initGEOS(GEOSMessageHandler notice_function,
1264 GEOSMessageHandler error_function);
1265extern 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
1274extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKT(const char *wkt);
1275extern 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 */
1281extern int GEOS_DLL GEOS_getWKBOutputDims();
1282extern 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 */
1288extern int GEOS_DLL GEOS_getWKBByteOrder();
1289extern int GEOS_DLL GEOS_setWKBByteOrder(int byteOrder);
1290
1291extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKB_buf(const unsigned char *wkb, size_t size);
1292extern unsigned char GEOS_DLL *GEOSGeomToWKB_buf(const GEOSGeometry* g, size_t *size);
1293
1294extern GEOSGeometry GEOS_DLL *GEOSGeomFromHEX_buf(const unsigned char *hex, size_t size);
1295extern 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 */
1308extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_create(unsigned int size, unsigned int dims);
1309
1310/*
1311 * Clone a Coordinate Sequence.
1312 * Return NULL on exception.
1313 */
1314extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_clone(const GEOSCoordSequence* s);
1315
1316/*
1317 * Destroy a Coordinate Sequence.
1318 */
1319extern void GEOS_DLL GEOSCoordSeq_destroy(GEOSCoordSequence* s);
1320
1321/*
1322 * Set ordinate values in a Coordinate Sequence.
1323 * Return 0 on exception.
1324 */
1325extern int GEOS_DLL GEOSCoordSeq_setX(GEOSCoordSequence* s,
1326 unsigned int idx, double val);
1327extern int GEOS_DLL GEOSCoordSeq_setY(GEOSCoordSequence* s,
1328 unsigned int idx, double val);
1329extern int GEOS_DLL GEOSCoordSeq_setZ(GEOSCoordSequence* s,
1330 unsigned int idx, double val);
1331extern 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 */
1338extern int GEOS_DLL GEOSCoordSeq_getX(const GEOSCoordSequence* s,
1339 unsigned int idx, double *val);
1340extern int GEOS_DLL GEOSCoordSeq_getY(const GEOSCoordSequence* s,
1341 unsigned int idx, double *val);
1342extern int GEOS_DLL GEOSCoordSeq_getZ(const GEOSCoordSequence* s,
1343 unsigned int idx, double *val);
1344extern 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 */
1350extern int GEOS_DLL GEOSCoordSeq_getSize(const GEOSCoordSequence* s,
1351 unsigned int *size);
1352extern 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 */
1369extern 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 */
1374extern GEOSGeometry GEOS_DLL *GEOSInterpolate(const GEOSGeometry *g,
1375 double d);
1376
1377extern double GEOS_DLL GEOSProjectNormalized(const GEOSGeometry *g,
1378 const GEOSGeometry* p);
1379
1380extern 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 */
1391extern GEOSGeometry GEOS_DLL *GEOSBuffer(const GEOSGeometry* g,
1392 double width, int quadsegs);
1393
1394/* @return 0 on exception */
1395extern GEOSBufferParams GEOS_DLL *GEOSBufferParams_create();
1396extern void GEOS_DLL GEOSBufferParams_destroy(GEOSBufferParams* parms);
1397
1398/* @return 0 on exception */
1399extern int GEOS_DLL GEOSBufferParams_setEndCapStyle(
1400 GEOSBufferParams* p,
1401 int style);
1402
1403/* @return 0 on exception */
1404extern int GEOS_DLL GEOSBufferParams_setJoinStyle(
1405 GEOSBufferParams* p,
1406 int joinStyle);
1407
1408/* @return 0 on exception */
1409extern int GEOS_DLL GEOSBufferParams_setMitreLimit(
1410 GEOSBufferParams* p,
1411 double mitreLimit);
1412
1413/* @return 0 on exception */
1414extern 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 */
1420extern int GEOS_DLL GEOSBufferParams_setSingleSided(
1421 GEOSBufferParams* p,
1422 int singleSided);
1423
1424/* @return NULL on exception */
1425extern GEOSGeometry GEOS_DLL *GEOSBufferWithParams(
1426 const GEOSGeometry* g,
1427 const GEOSBufferParams* p,
1428 double width);
1429
1430/* These functions return NULL on exception. */
1431extern 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 */
1437extern 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 */
1448extern 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
1459extern GEOSGeometry GEOS_DLL *GEOSGeom_createPoint(GEOSCoordSequence* s);
1460extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPoint();
1461extern GEOSGeometry GEOS_DLL *GEOSGeom_createLinearRing(GEOSCoordSequence* s);
1462extern GEOSGeometry GEOS_DLL *GEOSGeom_createLineString(GEOSCoordSequence* s);
1463extern 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 */
1470extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPolygon();
1471extern GEOSGeometry GEOS_DLL *GEOSGeom_createPolygon(GEOSGeometry* shell,
1472 GEOSGeometry** holes, unsigned int nholes);
1473extern GEOSGeometry GEOS_DLL *GEOSGeom_createCollection(int type,
1474 GEOSGeometry* *geoms, unsigned int ngeoms);
1475extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyCollection(int type);
1476
1477extern GEOSGeometry GEOS_DLL *GEOSGeom_clone(const GEOSGeometry* g);
1478
1479/************************************************************************
1480 *
1481 * Memory management
1482 *
1483 ***********************************************************************/
1484
1485extern void GEOS_DLL GEOSGeom_destroy(GEOSGeometry* g);
1486
1487/************************************************************************
1488 *
1489 * Topology operations - return NULL on exception.
1490 *
1491 ***********************************************************************/
1492
1493extern GEOSGeometry GEOS_DLL *GEOSEnvelope(const GEOSGeometry* g);
1494extern GEOSGeometry GEOS_DLL *GEOSIntersection(const GEOSGeometry* g1, const GEOSGeometry* g2);
1495extern 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 */
1502extern 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 */
1510extern 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 */
1528extern 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 */
1536extern GEOSGeometry GEOS_DLL *GEOSMinimumClearanceLine(const GEOSGeometry* g);
1537
1538extern GEOSGeometry GEOS_DLL *GEOSDifference(const GEOSGeometry* g1, const GEOSGeometry* g2);
1539extern GEOSGeometry GEOS_DLL *GEOSSymDifference(const GEOSGeometry* g1, const GEOSGeometry* g2);
1540extern GEOSGeometry GEOS_DLL *GEOSBoundary(const GEOSGeometry* g);
1541extern GEOSGeometry GEOS_DLL *GEOSUnion(const GEOSGeometry* g1, const GEOSGeometry* g2);
1542extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion(const GEOSGeometry* g);
1543
1544/* @deprecated in 3.3.0: use GEOSUnaryUnion instead */
1545extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded(const GEOSGeometry* g);
1546extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface(const GEOSGeometry* g);
1547extern GEOSGeometry GEOS_DLL *GEOSGetCentroid(const GEOSGeometry* g);
1548extern GEOSGeometry GEOS_DLL *GEOSNode(const GEOSGeometry* g);
1549extern 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 */
1555extern GEOSGeometry GEOS_DLL *GEOSPolygonize(const GEOSGeometry * const geoms[], unsigned int ngeoms);
1556extern 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 */
1584extern GEOSGeometry GEOS_DLL *GEOSPolygonize_full(const GEOSGeometry* input,
1585 GEOSGeometry** cuts, GEOSGeometry** dangles, GEOSGeometry** invalid);
1586
1587extern GEOSGeometry GEOS_DLL *GEOSLineMerge(const GEOSGeometry* g);
1588extern GEOSGeometry GEOS_DLL *GEOSSimplify(const GEOSGeometry* g, double tolerance);
1589extern 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 */
1597extern 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 */
1611extern 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 */
1618extern 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 */
1631extern 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 */
1649extern 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
1661extern char GEOS_DLL GEOSDisjoint(const GEOSGeometry* g1, const GEOSGeometry* g2);
1662extern char GEOS_DLL GEOSTouches(const GEOSGeometry* g1, const GEOSGeometry* g2);
1663extern char GEOS_DLL GEOSIntersects(const GEOSGeometry* g1, const GEOSGeometry* g2);
1664extern char GEOS_DLL GEOSCrosses(const GEOSGeometry* g1, const GEOSGeometry* g2);
1665extern char GEOS_DLL GEOSWithin(const GEOSGeometry* g1, const GEOSGeometry* g2);
1666extern char GEOS_DLL GEOSContains(const GEOSGeometry* g1, const GEOSGeometry* g2);
1667extern char GEOS_DLL GEOSOverlaps(const GEOSGeometry* g1, const GEOSGeometry* g2);
1668extern char GEOS_DLL GEOSEquals(const GEOSGeometry* g1, const GEOSGeometry* g2);
1669extern char GEOS_DLL GEOSEqualsExact(const GEOSGeometry* g1, const GEOSGeometry* g2, double tolerance);
1670extern char GEOS_DLL GEOSCovers(const GEOSGeometry* g1, const GEOSGeometry* g2);
1671extern 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 */
1682extern const GEOSPreparedGeometry GEOS_DLL *GEOSPrepare(const GEOSGeometry* g);
1683
1684extern void GEOS_DLL GEOSPreparedGeom_destroy(const GEOSPreparedGeometry* g);
1685
1686extern char GEOS_DLL GEOSPreparedContains(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1687extern char GEOS_DLL GEOSPreparedContainsProperly(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1688extern char GEOS_DLL GEOSPreparedCoveredBy(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1689extern char GEOS_DLL GEOSPreparedCovers(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1690extern char GEOS_DLL GEOSPreparedCrosses(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1691extern char GEOS_DLL GEOSPreparedDisjoint(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1692extern char GEOS_DLL GEOSPreparedIntersects(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1693extern char GEOS_DLL GEOSPreparedOverlaps(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1694extern char GEOS_DLL GEOSPreparedTouches(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
1695extern 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 */
1715extern 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 */
1724extern 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 */
1738extern 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 */
1752extern 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 */
1770extern 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 */
1781extern 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 */
1795extern char GEOS_DLL GEOSSTRtree_remove(GEOSSTRtree *tree,
1796 const GEOSGeometry *g,
1797 void *item);
1798extern 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
1807extern char GEOS_DLL GEOSisEmpty(const GEOSGeometry* g);
1808extern char GEOS_DLL GEOSisSimple(const GEOSGeometry* g);
1809extern char GEOS_DLL GEOSisRing(const GEOSGeometry* g);
1810extern char GEOS_DLL GEOSHasZ(const GEOSGeometry* g);
1811extern 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 */
1820extern char GEOS_DLL GEOSRelatePattern(const GEOSGeometry* g1, const GEOSGeometry* g2, const char *pat);
1821
1822/* return NULL on exception, a string to GEOSFree otherwise */
1823extern char GEOS_DLL *GEOSRelate(const GEOSGeometry* g1, const GEOSGeometry* g2);
1824
1825/* return 2 on exception, 1 on true, 0 on false */
1826extern char GEOS_DLL GEOSRelatePatternMatch(const char *mat, const char *pat);
1827
1828/* return NULL on exception, a string to GEOSFree otherwise */
1829extern 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 */
1840extern char GEOS_DLL GEOSisValid(const GEOSGeometry* g);
1841
1842/* return NULL on exception, a string to GEOSFree otherwise */
1843extern 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 */
1850extern 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. */
1861extern char GEOS_DLL *GEOSGeomType(const GEOSGeometry* g);
1862
1863/* Return -1 on exception */
1864extern int GEOS_DLL GEOSGeomTypeId(const GEOSGeometry* g);
1865
1866/* Return 0 on exception */
1867extern int GEOS_DLL GEOSGetSRID(const GEOSGeometry* g);
1868
1869extern void GEOS_DLL GEOSSetSRID(GEOSGeometry* g, int SRID);
1870
1871extern void GEOS_DLL *GEOSGeom_getUserData(const GEOSGeometry* g);
1872
1873extern 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 */
1882extern 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 */
1892extern const GEOSGeometry GEOS_DLL *GEOSGetGeometryN(const GEOSGeometry* g, int n);
1893
1894/* Return -1 on exception */
1895extern int GEOS_DLL GEOSNormalize(GEOSGeometry* g);
1896
1897/* Return NULL on exception */
1898extern GEOSGeometry GEOS_DLL *GEOSGeom_setPrecision(
1899 const GEOSGeometry *g, double gridSize, int flags);
1900
1901/* Return -1 on exception */
1902extern double GEOS_DLL GEOSGeom_getPrecision(const GEOSGeometry *g);
1903
1904/* Return -1 on exception */
1905extern int GEOS_DLL GEOSGetNumInteriorRings(const GEOSGeometry* g);
1906
1907/* Return -1 on exception, Geometry must be a LineString. */
1908extern int GEOS_DLL GEOSGeomGetNumPoints(const GEOSGeometry* g);
1909
1910/* Return -1 on exception, Geometry must be a Point. */
1911extern int GEOS_DLL GEOSGeomGetX(const GEOSGeometry *g, double *x);
1912extern 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 */
1919extern 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 */
1926extern const GEOSGeometry GEOS_DLL *GEOSGetExteriorRing(const GEOSGeometry* g);
1927
1928/* Return -1 on exception */
1929extern int GEOS_DLL GEOSGetNumCoordinates(const GEOSGeometry* g);
1930
1931/*
1932 * Return NULL on exception.
1933 * Geometry must be a LineString, LinearRing or Point.
1934 */
1935extern const GEOSCoordSequence GEOS_DLL *GEOSGeom_getCoordSeq(const GEOSGeometry* g);
1936
1937/*
1938 * Return 0 on exception (or empty geometry)
1939 */
1940extern int GEOS_DLL GEOSGeom_getDimensions(const GEOSGeometry* g);
1941
1942/*
1943 * Return 2 or 3.
1944 */
1945extern 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 */
1951extern GEOSGeometry GEOS_DLL *GEOSGeomGetPointN(const GEOSGeometry *g, int n);
1952extern GEOSGeometry GEOS_DLL *GEOSGeomGetStartPoint(const GEOSGeometry *g);
1953extern GEOSGeometry GEOS_DLL *GEOSGeomGetEndPoint(const GEOSGeometry *g);
1954
1955/************************************************************************
1956 *
1957 * Misc functions
1958 *
1959 ***********************************************************************/
1960
1961/* Return 0 on exception, 1 otherwise */
1962extern int GEOS_DLL GEOSArea(const GEOSGeometry* g, double *area);
1963extern int GEOS_DLL GEOSLength(const GEOSGeometry* g, double *length);
1964extern int GEOS_DLL GEOSDistance(const GEOSGeometry* g1, const GEOSGeometry* g2,
1965 double *dist);
1966extern int GEOS_DLL GEOSHausdorffDistance(const GEOSGeometry *g1,
1967 const GEOSGeometry *g2, double *dist);
1968extern int GEOS_DLL GEOSHausdorffDistanceDensify(const GEOSGeometry *g1,
1969 const GEOSGeometry *g2, double densifyFrac, double *dist);
1970extern 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 */
1975extern 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 */
1993extern 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 */
2003extern GEOSWKTReader GEOS_DLL *GEOSWKTReader_create();
2004extern void GEOS_DLL GEOSWKTReader_destroy(GEOSWKTReader* reader);
2005extern GEOSGeometry GEOS_DLL *GEOSWKTReader_read(GEOSWKTReader* reader, const char *wkt);
2006
2007/* WKT Writer */
2008extern GEOSWKTWriter GEOS_DLL *GEOSWKTWriter_create();
2009extern void GEOS_DLL GEOSWKTWriter_destroy(GEOSWKTWriter* writer);
2010extern char GEOS_DLL *GEOSWKTWriter_write(GEOSWKTWriter* writer, const GEOSGeometry* g);
2011extern void GEOS_DLL GEOSWKTWriter_setTrim(GEOSWKTWriter *writer, char trim);
2012extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision(GEOSWKTWriter *writer, int precision);
2013extern void GEOS_DLL GEOSWKTWriter_setOutputDimension(GEOSWKTWriter *writer, int dim);
2014extern int GEOS_DLL GEOSWKTWriter_getOutputDimension(GEOSWKTWriter *writer);
2015extern void GEOS_DLL GEOSWKTWriter_setOld3D(GEOSWKTWriter *writer, int useOld3D);
2016
2017/* WKB Reader */
2018extern GEOSWKBReader GEOS_DLL *GEOSWKBReader_create();
2019extern void GEOS_DLL GEOSWKBReader_destroy(GEOSWKBReader* reader);
2020extern GEOSGeometry GEOS_DLL *GEOSWKBReader_read(GEOSWKBReader* reader, const unsigned char *wkb, size_t size);
2021extern GEOSGeometry GEOS_DLL *GEOSWKBReader_readHEX(GEOSWKBReader* reader, const unsigned char *hex, size_t size);
2022
2023/* WKB Writer */
2024extern GEOSWKBWriter GEOS_DLL *GEOSWKBWriter_create();
2025extern void GEOS_DLL GEOSWKBWriter_destroy(GEOSWKBWriter* writer);
2026
2027/* The caller owns the results for these two methods! */
2028extern unsigned char GEOS_DLL *GEOSWKBWriter_write(GEOSWKBWriter* writer, const GEOSGeometry* g, size_t *size);
2029extern 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 */
2035extern int GEOS_DLL GEOSWKBWriter_getOutputDimension(const GEOSWKBWriter* writer);
2036extern 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 */
2042extern int GEOS_DLL GEOSWKBWriter_getByteOrder(const GEOSWKBWriter* writer);
2043extern void GEOS_DLL GEOSWKBWriter_setByteOrder(GEOSWKBWriter* writer, int byteOrder);
2044
2045/*
2046 * Specify whether SRID values should be output.
2047 */
2048extern char GEOS_DLL GEOSWKBWriter_getIncludeSRID(const GEOSWKBWriter* writer);
2049extern 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 */
2055extern 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 */