PostGIS  3.7.0dev-r@@SVN_REVISION@@
liblwgeom_internal.h
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * PostGIS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * PostGIS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  **********************************************************************
20  *
21  * Copyright (C) 2011-2021 Sandro Santilli <strk@kbt.io>
22  * Copyright (C) 2011 Paul Ramsey <pramsey@cleverelephant.ca>
23  * Copyright (C) 2007-2008 Mark Cave-Ayland
24  * Copyright (C) 2001-2006 Refractions Research Inc.
25  *
26  **********************************************************************/
27 
28 
29 #ifndef _LIBLWGEOM_INTERNAL_H
30 #define _LIBLWGEOM_INTERNAL_H 1
31 
32 #include "../postgis_config.h"
33 
34 #include "lwgeom_log.h"
35 
36 #include <assert.h>
37 #include <stdarg.h>
38 #include <stdint.h>
39 #include <stdio.h>
40 #include <string.h>
41 #include <stdlib.h>
42 #include <float.h>
43 #include <math.h>
44 
45 #if HAVE_IEEEFP_H
46 #include <ieeefp.h>
47 #endif
48 
49 #include "liblwgeom.h"
50 
54 #define FP_TOLERANCE 1e-12
55 #define FP_IS_ZERO(A) (fabs(A) <= FP_TOLERANCE)
56 #define FP_MAX(A, B) (((A) > (B)) ? (A) : (B))
57 #define FP_MIN(A, B) (((A) < (B)) ? (A) : (B))
58 #define FP_ABS(a) ((a) < (0) ? -(a) : (a))
59 #define FP_EQUALS(A, B) (fabs((A)-(B)) <= FP_TOLERANCE)
60 #define FP_NEQUALS(A, B) (fabs((A)-(B)) > FP_TOLERANCE)
61 #define FP_LT(A, B) (((A) + FP_TOLERANCE) < (B))
62 #define FP_LTEQ(A, B) (((A) - FP_TOLERANCE) <= (B))
63 #define FP_GT(A, B) (((A) - FP_TOLERANCE) > (B))
64 #define FP_GTEQ(A, B) (((A) + FP_TOLERANCE) >= (B))
65 #define FP_CONTAINS_TOP(A, X, B) (FP_LT(A, X) && FP_LTEQ(X, B))
66 #define FP_CONTAINS_BOTTOM(A, X, B) (FP_LTEQ(A, X) && FP_LT(X, B))
67 #define FP_CONTAINS_INCL(A, X, B) (FP_LTEQ(A, X) && FP_LTEQ(X, B))
68 #define FP_CONTAINS_EXCL(A, X, B) (FP_LT(A, X) && FP_LT(X, B))
69 #define FP_CONTAINS(A, X, B) FP_CONTAINS_EXCL(A, X, B)
70 
71 #define STR_EQUALS(A, B) strcmp((A), (B)) == 0
72 #define STR_IEQUALS(A, B) (strcasecmp((A), (B)) == 0)
73 #define STR_ISTARTS(A, B) (strncasecmp((A), (B), strlen((B))) == 0)
74 
75 
76 /*
77 * this will change to NaN when I figure out how to
78 * get NaN in a platform-independent way
79 */
80 #define NO_VALUE 0.0
81 #define NO_Z_VALUE NO_VALUE
82 #define NO_M_VALUE NO_VALUE
83 
84 
88 #define WKT_NO_TYPE 0x08 /* Internal use only */
89 #define WKT_NO_PARENS 0x10 /* Internal use only */
90 #define WKT_IS_CHILD 0x20 /* Internal use only */
91 
96 #define WKB_DOUBLE_SIZE 8 /* Internal use only */
97 #define WKB_INT_SIZE 4 /* Internal use only */
98 #define WKB_BYTE_SIZE 1 /* Internal use only */
99 
103 #define WKB_POINT_TYPE 1
104 #define WKB_LINESTRING_TYPE 2
105 #define WKB_POLYGON_TYPE 3
106 #define WKB_MULTIPOINT_TYPE 4
107 #define WKB_MULTILINESTRING_TYPE 5
108 #define WKB_MULTIPOLYGON_TYPE 6
109 #define WKB_GEOMETRYCOLLECTION_TYPE 7
110 #define WKB_CIRCULARSTRING_TYPE 8
111 #define WKB_COMPOUNDCURVE_TYPE 9
112 #define WKB_CURVEPOLYGON_TYPE 10
113 #define WKB_MULTICURVE_TYPE 11
114 #define WKB_MULTISURFACE_TYPE 12
115 #define WKB_CURVE_TYPE 13 /* from ISO draft, not sure is real */
116 #define WKB_SURFACE_TYPE 14 /* from ISO draft, not sure is real */
117 #define WKB_POLYHEDRALSURFACE_TYPE 15
118 #define WKB_TIN_TYPE 16
119 #define WKB_TRIANGLE_TYPE 17
120 
121 
128 #define SIGNUM(n) (((n) > 0) - ((n) < 0))
129 
133 #define EPSILON_SQLMM 1e-8
134 
135 /*
136  * Export functions
137  */
138 
139 /* Any (absolute) values outside this range will be printed in scientific notation */
140 #define OUT_MIN_DOUBLE 1E-8
141 #define OUT_MAX_DOUBLE 1E15
142 #define OUT_DEFAULT_DECIMAL_DIGITS 15
143 
144 /* 17 digits are sufficient for round-tripping
145  * Then we might add up to 8 (from OUT_MIN_DOUBLE) max leading zeroes (or 2 digits for "e+") */
146 #define OUT_MAX_DIGITS 17 + 8
147 
148 /* Limit for the max amount of characters that a double can use, including dot and sign */
149 /* */
150 #define OUT_MAX_BYTES_DOUBLE (1 /* Sign */ + 2 /* 0.x */ + OUT_MAX_DIGITS)
151 #define OUT_DOUBLE_BUFFER_SIZE OUT_MAX_BYTES_DOUBLE + 1 /* +1 including NULL */
152 
156 #define LW_INSIDE 1
157 #define LW_BOUNDARY 0
158 #define LW_OUTSIDE -1
159 
160 /*
161 * Internal prototypes
162 */
163 
164 /* Machine endianness */
165 #define XDR 0 /* big endian */
166 #define NDR 1 /* little endian */
167 
168 
169 /*
170 * Force dims
171 */
172 LWGEOM* lwgeom_force_dims(const LWGEOM *lwgeom, int hasz, int hasm, double zval, double mval);
173 LWPOINT* lwpoint_force_dims(const LWPOINT *lwpoint, int hasz, int hasm, double zval, double mval);
174 LWLINE* lwline_force_dims(const LWLINE *lwline, int hasz, int hasm, double zval, double mval);
175 LWPOLY* lwpoly_force_dims(const LWPOLY *lwpoly, int hasz, int hasm, double zval, double mval);
176 LWCOLLECTION* lwcollection_force_dims(const LWCOLLECTION *lwcol, int hasz, int hasm, double zval, double mval);
177 POINTARRAY* ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm, double zval, double mval);
178 
184 void ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2);
185 
186 /*
187 * Is Empty?
188 */
189 int lwpoly_is_empty(const LWPOLY *poly);
192 int lwtriangle_is_empty(const LWTRIANGLE *triangle);
193 int lwline_is_empty(const LWLINE *line);
194 int lwpoint_is_empty(const LWPOINT *point);
195 
196 /*
197 * Number of vertices?
198 */
199 uint32_t lwline_count_vertices(const LWLINE *line);
200 uint32_t lwpoly_count_vertices(const LWPOLY *poly);
201 uint32_t lwcollection_count_vertices(const LWCOLLECTION *col);
202 
203 /*
204 * DP simplification
205 */
206 
210 void ptarray_simplify_in_place(POINTARRAY *pa, double tolerance, uint32_t minpts);
211 
212 /*
213 * The possible ways a pair of segments can interact. Returned by lw_segment_intersects
214 */
216  SEG_ERROR = -1,
222  SEG_TOUCH_RIGHT = 5
223 };
224 
225 /*
226 * Do the segments intersect? How?
227 */
228 int lw_segment_intersects(const POINT2D *p1, const POINT2D *p2, const POINT2D *q1, const POINT2D *q2);
229 
230 /*
231 * Get/Set an enumeratoed ordinate. (x,y,z,m)
232 */
233 double lwpoint_get_ordinate(const POINT4D *p, char ordinate);
234 void lwpoint_set_ordinate(POINT4D *p, char ordinate, double value);
235 
236 /*
237 * Generate an interpolated coordinate p given an interpolation value and ordinate to apply it to
238 */
239 int point_interpolate(const POINT4D *p1, const POINT4D *p2, POINT4D *p, int hasz, int hasm, char ordinate, double interpolation_value);
240 
241 
242 /*
243 * Geohash
244 */
245 int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds);
246 lwvarlena_t *geohash_point(double longitude, double latitude, int precision);
247 void decode_geohash_bbox(char *geohash, double *lat, double *lon, int precision);
248 
249 /*
250 * Point comparisons (FP tolerance based)
251 */
252 int p4d_same(const POINT4D *p1, const POINT4D *p2);
253 int p3d_same(const POINT3D *p1, const POINT3D *p2);
254 int p3dz_same(const POINT3DZ *p1, const POINT3DZ *p2);
255 int p2d_same(const POINT2D *p1, const POINT2D *p2);
256 
257 /*
258  * Non-tolerance based equality for points
259  * whereas the p#d_same function are tolerance based
260  */
261 #define P2D_SAME_STRICT(a,b) ((a)->x == (b)->x && (a)->y == (b)->y)
262 #define P3DZ_SAME_STRICT(a,b) ((a)->x == (b)->x && (a)->y == (b)->y && (a)->z == (b)->z )
263 #define P3DM_SAME_STRICT(a,b) ((a)->x == (b)->x && (a)->y == (b)->y && (a)->m == (b)->m )
264 #define P4D_SAME_STRICT(a,b) ((a)->x == (b)->x && (a)->y == (b)->y && (a)->z == (b)->z && (a)->m == (b)->m )
265 
266 /*
267 * Projections
268 */
269 int project_pt(const POINT2D *P, double distance, double azimuth, POINT2D *R);
270 int project_pt_pt(const POINT4D *A, const POINT4D *B, double distance, POINT4D *R);
271 
272 /*
273 * Area calculations
274 */
275 double lwpoly_area(const LWPOLY *poly);
276 double lwcurvepoly_area(const LWCURVEPOLY *curvepoly);
277 double lwtriangle_area(const LWTRIANGLE *triangle);
278 
284 
285 /*
286  * Populate a bounding box *without* allocating an LWGEOM. Useful for some performance
287  * purposes. Use only if gserialized_read_gbox_p failed
288  */
290 
296 size_t gserialized_from_lwgeom_size(const LWGEOM *geom);
297 
298 /*
299 * Length calculations
300 */
301 double lwcompound_length(const LWCOMPOUND *comp);
302 double lwcompound_length_2d(const LWCOMPOUND *comp);
303 double lwline_length(const LWLINE *line);
304 double lwline_length_2d(const LWLINE *line);
305 double lwcircstring_length(const LWCIRCSTRING *circ);
306 double lwcircstring_length_2d(const LWCIRCSTRING *circ);
307 double lwpoly_perimeter(const LWPOLY *poly);
308 double lwpoly_perimeter_2d(const LWPOLY *poly);
309 double lwcurvepoly_perimeter(const LWCURVEPOLY *poly);
310 double lwcurvepoly_perimeter_2d(const LWCURVEPOLY *poly);
311 double lwtriangle_perimeter(const LWTRIANGLE *triangle);
312 double lwtriangle_perimeter_2d(const LWTRIANGLE *triangle);
313 
314 /*
315 * Segmentization
316 */
317 LWPOLY *lwcurvepoly_stroke(const LWCURVEPOLY *curvepoly, uint32_t perQuad);
318 
319 /*
320 * Affine
321 */
322 void ptarray_affine(POINTARRAY *pa, const AFFINE *affine);
323 void affine_invert(AFFINE *affine);
324 
325 /*
326 * Scale
327 */
328 void ptarray_scale(POINTARRAY *pa, const POINT4D *factor);
329 
330 /*
331 * Scroll
332 */
333 int ptarray_scroll_in_place(POINTARRAY *pa, const POINT4D *newbase);
334 
335 /*
336 * PointArray
337 */
338 int ptarray_has_z(const POINTARRAY *pa);
339 int ptarray_has_m(const POINTARRAY *pa);
340 double ptarray_signed_area(const POINTARRAY *pa);
341 
342 /*
343 * Length
344 */
345 double ptarray_length(const POINTARRAY *pts);
346 double ptarray_arc_length_2d(const POINTARRAY *pts);
347 
348 /*
349 * Clone support
350 */
351 LWPOINT *lwpoint_clone(const LWPOINT *lwgeom);
352 LWLINE *lwline_clone(const LWLINE *lwgeom);
353 LWPOLY *lwpoly_clone(const LWPOLY *lwgeom);
354 LWTRIANGLE *lwtriangle_clone(const LWTRIANGLE *lwgeom);
357 POINTARRAY *ptarray_clone(const POINTARRAY *ptarray);
358 LWLINE *lwline_clone_deep(const LWLINE *lwgeom);
359 LWPOLY *lwpoly_clone_deep(const LWPOLY *lwgeom);
361 GBOX *gbox_clone(const GBOX *gbox);
362 
363 /*
364 * Clockwise
365 */
366 void lwpoly_force_clockwise(LWPOLY *poly);
367 void lwtriangle_force_clockwise(LWTRIANGLE *triangle);
368 int lwpoly_is_clockwise(LWPOLY *poly);
369 int lwtriangle_is_clockwise(LWTRIANGLE *triangle);
370 int ptarray_isccw(const POINTARRAY *pa);
371 
372 /*
373 * Same
374 */
375 char ptarray_same2d(const POINTARRAY *pa1, const POINTARRAY *pa2);
376 char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2);
377 char lwpoint_same2d(const LWPOINT *p1, const LWPOINT *p2);
378 char lwpoint_same(const LWPOINT *p1, const LWPOINT *p2);
379 char lwline_same(const LWLINE *p1, const LWLINE *p2);
380 char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2);
381 char lwtriangle_same(const LWTRIANGLE *p1, const LWTRIANGLE *p2);
382 char lwcollection_same(const LWCOLLECTION *p1, const LWCOLLECTION *p2);
383 char lwcircstring_same(const LWCIRCSTRING *p1, const LWCIRCSTRING *p2);
384 
385 /*
386 * Shift
387 */
389 
390 /*
391 * Support for in place modification of point arrays, fast
392 * function to move coordinate values around
393 */
394 void ptarray_copy_point(POINTARRAY *pa, uint32_t from, uint32_t to);
395 
396 /*
397 * Reverse
398 */
400 
401 /*
402 * Startpoint
403 */
404 int lwpoly_startpoint(const LWPOLY* lwpoly, POINT4D* pt);
405 int ptarray_startpoint(const POINTARRAY* pa, POINT4D* pt);
406 int lwcollection_startpoint(const LWCOLLECTION* col, POINT4D* pt);
407 
408 /*
409  * Write into *ret the coordinates of the closest point on
410  * segment A-B to the reference input point R
411  */
412 void closest_point_on_segment(const POINT4D *R, const POINT4D *A, const POINT4D *B, POINT4D *ret);
413 
414 /*
415 * Repeated points
416 */
417 POINTARRAY *ptarray_remove_repeated_points(const POINTARRAY *in, double tolerance);
418 LWGEOM* lwline_remove_repeated_points(const LWLINE *in, double tolerance);
419 void ptarray_remove_repeated_points_in_place(POINTARRAY *pa, double tolerance, uint32_t min_points);
420 
421 /*
422 * Closure test
423 */
424 int lwline_is_closed(const LWLINE *line);
425 int lwpoly_is_closed(const LWPOLY *poly);
426 int lwcircstring_is_closed(const LWCIRCSTRING *curve);
427 int lwcompound_is_closed(const LWCOMPOUND *curve);
428 int lwcompound_is_valid(const LWCOMPOUND *curve);
429 int lwpsurface_is_closed(const LWPSURFACE *psurface);
430 int lwtin_is_closed(const LWTIN *tin);
431 
435 void ptarray_grid_in_place(POINTARRAY *pa, gridspec *grid);
436 
437 /*
438 * What side of the line formed by p1 and p2 does q fall?
439 * Returns -1 for left and 1 for right and 0 for co-linearity
440 */
441 int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q);
442 int lw_arc_side(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *Q);
443 int lw_arc_calculate_gbox_cartesian_2d(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, GBOX *gbox);
444 double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result);
445 int lw_pt_in_seg(const POINT2D *P, const POINT2D *A1, const POINT2D *A2);
446 int lw_pt_in_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3);
447 int lw_arc_is_pt(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3);
448 double lw_seg_length(const POINT2D *A1, const POINT2D *A2);
449 double lw_arc_length(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3);
450 int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
451 int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt);
452 int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt);
453 int ptarray_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number);
454 int ptarrayarc_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number);
455 int lwcompound_contains_point(const LWCOMPOUND *comp, const POINT2D *pt);
456 int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt);
457 
468 int lwline_split_by_point_to(const LWLINE* ln, const LWPOINT* pt, LWMLINE* to);
469 
471 void lwcollection_reserve(LWCOLLECTION *col, uint32_t ngeoms);
472 
474 int lwcollection_allows_subtype(int collectiontype, int subtype);
475 
477 double gbox_angular_height(const GBOX* gbox);
478 double gbox_angular_width(const GBOX* gbox);
479 int gbox_centroid(const GBOX* gbox, POINT2D* out);
480 
481 /* Utilities */
482 int lwprint_double(double d, int maxdd, char *buf);
483 extern uint8_t MULTITYPE[NUMTYPES];
484 
486 extern int _lwgeom_interrupt_requested;
487 #define LW_ON_INTERRUPT(x) { \
488  if ( _lwgeom_interrupt_callback ) { \
489  (*_lwgeom_interrupt_callback)(); \
490  } \
491  if ( _lwgeom_interrupt_requested ) { \
492  _lwgeom_interrupt_requested = 0; \
493  lwnotice("liblwgeom code interrupted"); \
494  x; \
495  } \
496 }
497 
498 int ptarray_npoints_in_rect(const POINTARRAY *pa, const GBOX *gbox);
499 int gbox_contains_point2d(const GBOX *g, const POINT2D *p);
500 int lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt);
501 POINT4D* lwmpoint_extract_points_4d(const LWMPOINT* g, uint32_t* npoints, int* input_empty);
502 char* lwstrdup(const char* a);
503 void* lwalloc0(size_t sz);
504 
505 #endif /* _LIBLWGEOM_INTERNAL_H */
static uint8_t precision
Definition: cu_in_twkb.c:25
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
void() lwinterrupt_callback(void)
Install a callback to be called periodically during algorithm execution.
Definition: liblwgeom.h:291
#define NUMTYPES
Definition: liblwgeom.h:118
enum LWORD_T LWORD
Ordinate names.
This library is the generic geometry handling section of PostGIS.
int ptarray_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
Definition: ptarray.c:763
POINTARRAY * ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm, double zval, double mval)
Definition: ptarray.c:1060
char * lwstrdup(const char *a)
Definition: lwutil.c:254
size_t gserialized_from_lwgeom_size(const LWGEOM *geom)
Calculate required memory segment to contain a serialized form of the LWGEOM.
Definition: gserialized.c:259
double lwline_length_2d(const LWLINE *line)
Definition: lwline.c:520
void ptarray_longitude_shift(POINTARRAY *pa)
Longitude shift for a pointarray.
Definition: ptarray.c:1502
void lwpoint_set_ordinate(POINT4D *p, char ordinate, double value)
Given a point, ordinate number and value, set that ordinate on the point.
LWLINE * lwline_clone_deep(const LWLINE *lwgeom)
Definition: lwline.c:109
int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds)
Definition: lwalgorithm.c:771
double lwcircstring_length_2d(const LWCIRCSTRING *circ)
Definition: lwcircstring.c:274
LWPOINT * lwpoint_clone(const LWPOINT *lwgeom)
Definition: lwpoint.c:239
lwinterrupt_callback * _lwgeom_interrupt_callback
Definition: lwgeom_api.c:666
LWGEOM * lwline_remove_repeated_points(const LWLINE *in, double tolerance)
Definition: lwline.c:439
int lwcircstring_is_closed(const LWCIRCSTRING *curve)
Definition: lwcircstring.c:261
void ptarray_reverse_in_place(POINTARRAY *pa)
Definition: ptarray.c:339
LWLINE * lwline_clone(const LWLINE *lwgeom)
Definition: lwline.c:93
char lwcollection_same(const LWCOLLECTION *p1, const LWCOLLECTION *p2)
check for same geometry composition
Definition: lwcollection.c:279
int p4d_same(const POINT4D *p1, const POINT4D *p2)
Definition: lwalgorithm.c:32
int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt)
For POINTARRAYs representing CIRCULARSTRINGS.
Definition: ptarray.c:856
double lwtriangle_area(const LWTRIANGLE *triangle)
Find the area of the outer ring.
Definition: lwtriangle.c:178
int p3d_same(const POINT3D *p1, const POINT3D *p2)
Definition: lwalgorithm.c:41
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.
double lw_arc_length(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns the length of a circular arc segment.
Definition: lwalgorithm.c:124
double lwcompound_length_2d(const LWCOMPOUND *comp)
Definition: lwcompound.c:117
int lwline_is_empty(const LWLINE *line)
int lwcompound_contains_point(const LWCOMPOUND *comp, const POINT2D *pt)
Definition: lwcompound.c:188
double ptarray_length(const POINTARRAY *pts)
Find the 3d/2d length of the given POINTARRAY (depending on its dimensionality)
Definition: ptarray.c:1868
lwvarlena_t * geohash_point(double longitude, double latitude, int precision)
Definition: lwalgorithm.c:603
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
Definition: ptarray.c:1020
int lwline_is_closed(const LWLINE *line)
Definition: lwline.c:445
uint32_t lwline_count_vertices(const LWLINE *line)
Definition: lwline.c:505
int lwcompound_is_valid(const LWCOMPOUND *curve)
Definition: lwcompound.c:81
char lwtriangle_same(const LWTRIANGLE *p1, const LWTRIANGLE *p2)
Definition: lwtriangle.c:126
int lwpoly_startpoint(const LWPOLY *lwpoly, POINT4D *pt)
Definition: lwpoly.c:524
LWPOINT * lwpoint_force_dims(const LWPOINT *lwpoint, int hasz, int hasm, double zval, double mval)
Definition: lwpoint.c:304
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
Definition: ptarray.c:674
int lwcollection_startpoint(const LWCOLLECTION *col, POINT4D *pt)
Definition: lwcollection.c:550
int _lwgeom_interrupt_requested
Definition: lwgeom_api.c:656
int ptarray_startpoint(const POINTARRAY *pa, POINT4D *pt)
Definition: ptarray.c:2084
int lwcompound_is_closed(const LWCOMPOUND *curve)
Definition: lwcompound.c:48
int gbox_contains_point2d(const GBOX *g, const POINT2D *p)
Definition: gbox.c:362
double lwtriangle_perimeter_2d(const LWTRIANGLE *triangle)
Definition: lwtriangle.c:210
int ptarray_scroll_in_place(POINTARRAY *pa, const POINT4D *newbase)
Definition: ptarray.c:2202
int lwpoly_is_clockwise(LWPOLY *poly)
Definition: lwpoly.c:288
double gbox_angular_height(const GBOX *gbox)
GBOX utility functions to figure out coverage/location on the globe.
Definition: lwgeodetic.c:188
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
Definition: lwpoly.c:434
CG_SEGMENT_INTERSECTION_TYPE
@ SEG_NO_INTERSECTION
@ SEG_ERROR
@ SEG_COLINEAR
@ SEG_TOUCH_LEFT
@ SEG_CROSS_RIGHT
@ SEG_CROSS_LEFT
@ SEG_TOUCH_RIGHT
int lwline_split_by_point_to(const LWLINE *ln, const LWPOINT *pt, LWMLINE *to)
Split a line by a point and push components to the provided multiline.
int lw_segment_intersects(const POINT2D *p1, const POINT2D *p2, const POINT2D *q1, const POINT2D *q2)
returns the kind of CG_SEGMENT_INTERSECTION_TYPE behavior of lineseg 1 (constructed from p1 and p2) a...
Definition: lwalgorithm.c:378
int lwtriangle_is_clockwise(LWTRIANGLE *triangle)
Definition: lwtriangle.c:113
char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2)
Definition: ptarray.c:484
double gbox_angular_width(const GBOX *gbox)
Returns the angular width (longitudinal span) of the box in radians.
Definition: lwgeodetic.c:215
char lwline_same(const LWLINE *p1, const LWLINE *p2)
Definition: lwline.c:141
void ptarray_remove_repeated_points_in_place(POINTARRAY *pa, double tolerance, uint32_t min_points)
Definition: ptarray.c:1539
double lwtriangle_perimeter(const LWTRIANGLE *triangle)
Definition: lwtriangle.c:201
POINT4D * lwmpoint_extract_points_4d(const LWMPOINT *g, uint32_t *npoints, int *input_empty)
double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result)
Determines the center of the circle defined by the three given points.
Definition: lwalgorithm.c:234
int lwpoint_is_empty(const LWPOINT *point)
void ptarray_simplify_in_place(POINTARRAY *pa, double tolerance, uint32_t minpts)
Definition: ptarray.c:1721
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
Definition: lwalgorithm.c:287
LWLINE * lwline_force_dims(const LWLINE *lwline, int hasz, int hasm, double zval, double mval)
Definition: lwline.c:486
double lwcompound_length(const LWCOMPOUND *comp)
Definition: lwcompound.c:112
LWCOLLECTION * lwcollection_clone_deep(const LWCOLLECTION *lwgeom)
Deep clone LWCOLLECTION object.
Definition: lwcollection.c:151
LWCOLLECTION * lwcollection_force_dims(const LWCOLLECTION *lwcol, int hasz, int hasm, double zval, double mval)
Definition: lwcollection.c:476
char lwpoint_same2d(const LWPOINT *p1, const LWPOINT *p2)
Definition: lwpoint.c:271
int lw_arc_side(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *Q)
Definition: lwalgorithm.c:184
void ptarray_grid_in_place(POINTARRAY *pa, gridspec *grid)
Snap to grid.
Definition: ptarray.c:2099
double lw_seg_length(const POINT2D *A1, const POINT2D *A2)
Returns the length of a linear segment.
Definition: lwalgorithm.c:80
void * lwalloc0(size_t sz)
Definition: lwutil.c:234
void lwtriangle_force_clockwise(LWTRIANGLE *triangle)
Definition: lwtriangle.c:106
void affine_invert(AFFINE *affine)
double ptarray_arc_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY, using circular arc interpolation between each coordinate ...
Definition: ptarray.c:1813
POINTARRAY * ptarray_remove_repeated_points(const POINTARRAY *in, double tolerance)
Definition: ptarray.c:1532
int project_pt(const POINT2D *P, double distance, double azimuth, POINT2D *R)
Azimuth is angle in radians from vertical axis.
Definition: measures.c:2522
int p3dz_same(const POINT3DZ *p1, const POINT3DZ *p2)
Definition: lwalgorithm.c:49
void ptarray_scale(POINTARRAY *pa, const POINT4D *factor)
WARNING, make sure you send in only 16-member double arrays or obviously things will go pear-shaped f...
Definition: ptarray.c:2066
void ptarray_affine(POINTARRAY *pa, const AFFINE *affine)
Affine transform a pointarray.
Definition: ptarray.c:1898
int lwpsurface_is_closed(const LWPSURFACE *psurface)
Definition: lwpsurface.c:99
int lwtriangle_is_empty(const LWTRIANGLE *triangle)
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
Return LW_INSIDE if the point is inside the POINTARRAY, LW_OUTSIDE if it is outside,...
Definition: ptarray.c:751
int ptarrayarc_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
Definition: ptarray.c:862
double lwcurvepoly_perimeter(const LWCURVEPOLY *poly)
Definition: lwcurvepoly.c:147
uint32_t lwpoly_count_vertices(const LWPOLY *poly)
Definition: lwpoly.c:418
int lw_pt_in_seg(const POINT2D *P, const POINT2D *A1, const POINT2D *A2)
Returns true if P is between A1/A2.
Definition: lwalgorithm.c:101
int lwpoly_is_empty(const LWPOLY *poly)
char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2)
Definition: lwpoly.c:339
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
Definition: lwcompound.c:172
int ptarray_isccw(const POINTARRAY *pa)
Definition: ptarray.c:1051
int ptarray_has_z(const POINTARRAY *pa)
Definition: ptarray.c:37
double lwline_length(const LWLINE *line)
Definition: lwline.c:513
int gserialized_peek_gbox_p(const GSERIALIZED *g, GBOX *gbox)
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
Definition: lwgeom.c:354
void lwcollection_reserve(LWCOLLECTION *col, uint32_t ngeoms)
Ensure the collection can hold at least up to ngeoms geometries.
Definition: lwcollection.c:176
void lwpoly_force_clockwise(LWPOLY *poly)
Definition: lwpoly.c:268
uint32_t lwcollection_count_vertices(const LWCOLLECTION *col)
Definition: lwcollection.c:500
void ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2)
Swap ordinate values o1 and o2 on a given POINTARRAY.
Definition: ptarray.c:387
int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
LWPOLY * lwcurvepoly_stroke(const LWCURVEPOLY *curvepoly, uint32_t perQuad)
Definition: lwstroke.c:688
double lwpoly_perimeter_2d(const LWPOLY *poly)
Compute the sum of polygon rings length (forcing 2d computation).
Definition: lwpoly.c:485
int ptarray_npoints_in_rect(const POINTARRAY *pa, const GBOX *gbox)
Definition: ptarray.c:2179
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:70
int lwtin_is_closed(const LWTIN *tin)
Definition: lwtin.c:93
int gbox_centroid(const GBOX *gbox, POINT2D *out)
Computes the average(ish) center of the box and returns success.
Definition: lwgeodetic.c:267
int project_pt_pt(const POINT4D *A, const POINT4D *B, double distance, POINT4D *R)
Azimuth is angle in radians from vertical axis.
Definition: measures.c:2546
char ptarray_same2d(const POINTARRAY *pa1, const POINTARRAY *pa2)
Definition: ptarray.c:509
int lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt)
Definition: lwpoly.c:532
void closest_point_on_segment(const POINT4D *R, const POINT4D *A, const POINT4D *B, POINT4D *ret)
Definition: ptarray.c:1280
GBOX * gbox_clone(const GBOX *gbox)
Definition: gbox.c:45
char lwcircstring_same(const LWCIRCSTRING *p1, const LWCIRCSTRING *p2)
Definition: lwcircstring.c:131
LWPOLY * lwpoly_clone_deep(const LWPOLY *lwgeom)
Definition: lwpoly.c:228
double lwcircstring_length(const LWCIRCSTRING *circ)
Definition: lwcircstring.c:269
int point_interpolate(const POINT4D *p1, const POINT4D *p2, POINT4D *p, int hasz, int hasm, char ordinate, double interpolation_value)
Given two points, a dimensionality, an ordinate, and an interpolation value generate a new point that...
int lw_arc_is_pt(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns true if arc A is actually a point (all vertices are the same) .
Definition: lwalgorithm.c:111
double lwcurvepoly_area(const LWCURVEPOLY *curvepoly)
This should be rewritten to make use of the curve itself.
Definition: lwcurvepoly.c:133
LWCOLLECTION * lwcollection_clone(const LWCOLLECTION *lwgeom)
Clone LWCOLLECTION object.
Definition: lwcollection.c:125
void decode_geohash_bbox(char *geohash, double *lat, double *lon, int precision)
Definition: lwalgorithm.c:726
int lwpoly_is_closed(const LWPOLY *poly)
Definition: lwpoly.c:499
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
Definition: lwcollection.c:513
LWGEOM * lwgeom_force_dims(const LWGEOM *lwgeom, int hasz, int hasm, double zval, double mval)
Definition: lwgeom.c:817
LWPOLY * lwpoly_clone(const LWPOLY *lwgeom)
Definition: lwpoly.c:213
void ptarray_copy_point(POINTARRAY *pa, uint32_t from, uint32_t to)
Definition: lwgeom_api.c:394
int lw_pt_in_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns true if P is on the same side of the plane partition defined by A1/A3 as A2 is.
Definition: lwalgorithm.c:91
int ptarray_has_m(const POINTARRAY *pa)
Definition: ptarray.c:44
int lwcircstring_is_empty(const LWCIRCSTRING *circ)
int lwcollection_is_empty(const LWCOLLECTION *col)
double lwcurvepoly_perimeter_2d(const LWCURVEPOLY *poly)
Definition: lwcurvepoly.c:159
int lwprint_double(double d, int maxdd, char *buf)
Definition: lwprint.c:463
double lwpoly_perimeter(const LWPOLY *poly)
Compute the sum of polygon rings length.
Definition: lwpoly.c:467
int lw_arc_calculate_gbox_cartesian_2d(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, GBOX *gbox)
Definition: gbox.c:465
LWTRIANGLE * lwtriangle_clone(const LWTRIANGLE *lwgeom)
Definition: lwtriangle.c:99
char lwpoint_same(const LWPOINT *p1, const LWPOINT *p2)
Definition: lwpoint.c:264
LWCIRCSTRING * lwcircstring_clone(const LWCIRCSTRING *curve)
Definition: lwcircstring.c:124
LWPOLY * lwpoly_force_dims(const LWPOLY *lwpoly, int hasz, int hasm, double zval, double mval)
Definition: lwpoly.c:394
int p2d_same(const POINT2D *p1, const POINT2D *p2)
Definition: lwalgorithm.c:57
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032
int value
Definition: genraster.py:62
Snap-to-grid.
Definition: liblwgeom.h:1398