PostGIS  2.3.8dev-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-2012 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 
42 #if HAVE_IEEEFP_H
43 #include <ieeefp.h>
44 #endif
45 
46 #include <float.h>
47 
48 #include "liblwgeom.h"
49 
53 #define FP_TOLERANCE 1e-12
54 #define FP_IS_ZERO(A) (fabs(A) <= FP_TOLERANCE)
55 #define FP_MAX(A, B) (((A) > (B)) ? (A) : (B))
56 #define FP_MIN(A, B) (((A) < (B)) ? (A) : (B))
57 #define FP_ABS(a) ((a) < (0) ? -(a) : (a))
58 #define FP_EQUALS(A, B) (fabs((A)-(B)) <= FP_TOLERANCE)
59 #define FP_NEQUALS(A, B) (fabs((A)-(B)) > FP_TOLERANCE)
60 #define FP_LT(A, B) (((A) + FP_TOLERANCE) < (B))
61 #define FP_LTEQ(A, B) (((A) - FP_TOLERANCE) <= (B))
62 #define FP_GT(A, B) (((A) - FP_TOLERANCE) > (B))
63 #define FP_GTEQ(A, B) (((A) + FP_TOLERANCE) >= (B))
64 #define FP_CONTAINS_TOP(A, X, B) (FP_LT(A, X) && FP_LTEQ(X, B))
65 #define FP_CONTAINS_BOTTOM(A, X, B) (FP_LTEQ(A, X) && FP_LT(X, B))
66 #define FP_CONTAINS_INCL(A, X, B) (FP_LTEQ(A, X) && FP_LTEQ(X, B))
67 #define FP_CONTAINS_EXCL(A, X, B) (FP_LT(A, X) && FP_LT(X, B))
68 #define FP_CONTAINS(A, X, B) FP_CONTAINS_EXCL(A, X, B)
69 
70 
71 /*
72 * this will change to NaN when I figure out how to
73 * get NaN in a platform-independent way
74 */
75 #define NO_VALUE 0.0
76 #define NO_Z_VALUE NO_VALUE
77 #define NO_M_VALUE NO_VALUE
78 
79 
83 #define WKT_NO_TYPE 0x08 /* Internal use only */
84 #define WKT_NO_PARENS 0x10 /* Internal use only */
85 #define WKT_IS_CHILD 0x20 /* Internal use only */
86 
91 #define WKB_DOUBLE_SIZE 8 /* Internal use only */
92 #define WKB_INT_SIZE 4 /* Internal use only */
93 #define WKB_BYTE_SIZE 1 /* Internal use only */
94 
98 #define WKB_POINT_TYPE 1
99 #define WKB_LINESTRING_TYPE 2
100 #define WKB_POLYGON_TYPE 3
101 #define WKB_MULTIPOINT_TYPE 4
102 #define WKB_MULTILINESTRING_TYPE 5
103 #define WKB_MULTIPOLYGON_TYPE 6
104 #define WKB_GEOMETRYCOLLECTION_TYPE 7
105 #define WKB_CIRCULARSTRING_TYPE 8
106 #define WKB_COMPOUNDCURVE_TYPE 9
107 #define WKB_CURVEPOLYGON_TYPE 10
108 #define WKB_MULTICURVE_TYPE 11
109 #define WKB_MULTISURFACE_TYPE 12
110 #define WKB_CURVE_TYPE 13 /* from ISO draft, not sure is real */
111 #define WKB_SURFACE_TYPE 14 /* from ISO draft, not sure is real */
112 #define WKB_POLYHEDRALSURFACE_TYPE 15
113 #define WKB_TIN_TYPE 16
114 #define WKB_TRIANGLE_TYPE 17
115 
121 #define SIZE_GET(varsize) (((varsize) >> 2) & 0x3FFFFFFF)
122 #define SIZE_SET(varsize, size) (((varsize) & 0x00000003)|(((size) & 0x3FFFFFFF) << 2 ))
123 
130 #define SIGNUM(n) (((n) > 0) - ((n) < 0))
131 
135 #define EPSILON_SQLMM 1e-8
136 
137 /*
138  * Export functions
139  */
140 #define OUT_MAX_DOUBLE 1E15
141 #define OUT_SHOW_DIGS_DOUBLE 20
142 #define OUT_MAX_DOUBLE_PRECISION 15
143 #define OUT_MAX_DIGS_DOUBLE (OUT_SHOW_DIGS_DOUBLE + 2) /* +2 mean add dot and sign */
144 
145 
149 #define LW_INSIDE 1
150 #define LW_BOUNDARY 0
151 #define LW_OUTSIDE -1
152 
153 /*
154 * Internal prototypes
155 */
156 
157 /* Machine endianness */
158 #define XDR 0 /* big endian */
159 #define NDR 1 /* little endian */
160 extern char getMachineEndian(void);
161 
162 
163 /*
164 * Force dims
165 */
166 LWGEOM* lwgeom_force_dims(const LWGEOM *lwgeom, int hasz, int hasm);
167 LWPOINT* lwpoint_force_dims(const LWPOINT *lwpoint, int hasz, int hasm);
168 LWLINE* lwline_force_dims(const LWLINE *lwline, int hasz, int hasm);
169 LWPOLY* lwpoly_force_dims(const LWPOLY *lwpoly, int hasz, int hasm);
170 LWCOLLECTION* lwcollection_force_dims(const LWCOLLECTION *lwcol, int hasz, int hasm);
171 POINTARRAY* ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm);
172 
178 void ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2);
179 
180 /*
181 * Is Empty?
182 */
183 int lwpoly_is_empty(const LWPOLY *poly);
184 int lwcollection_is_empty(const LWCOLLECTION *col);
185 int lwcircstring_is_empty(const LWCIRCSTRING *circ);
186 int lwtriangle_is_empty(const LWTRIANGLE *triangle);
187 int lwline_is_empty(const LWLINE *line);
188 int lwpoint_is_empty(const LWPOINT *point);
189 
190 /*
191 * Number of vertices?
192 */
193 int lwline_count_vertices(LWLINE *line);
194 int lwpoly_count_vertices(LWPOLY *poly);
196 
197 /*
198 * Read from byte buffer
199 */
200 extern uint32_t lw_get_uint32_t(const uint8_t *loc);
201 extern int32_t lw_get_int32_t(const uint8_t *loc);
202 
203 /*
204 * DP simplification
205 */
206 
210 POINTARRAY* ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts);
211 LWLINE* lwline_simplify(const LWLINE *iline, double dist, int preserve_collapsed);
212 LWPOLY* lwpoly_simplify(const LWPOLY *ipoly, double dist, int preserve_collapsed);
213 LWCOLLECTION* lwcollection_simplify(const LWCOLLECTION *igeom, double dist, int preserve_collapsed);
214 
215 /*
216 * The possible ways a pair of segments can interact. Returned by lw_segment_intersects
217 */
219  SEG_ERROR = -1,
226 };
227 
228 /*
229 * Do the segments intersect? How?
230 */
231 int lw_segment_intersects(const POINT2D *p1, const POINT2D *p2, const POINT2D *q1, const POINT2D *q2);
232 
233 /*
234 * Get/Set an enumeratoed ordinate. (x,y,z,m)
235 */
236 double lwpoint_get_ordinate(const POINT4D *p, char ordinate);
237 void lwpoint_set_ordinate(POINT4D *p, char ordinate, double value);
238 
239 /*
240 * Generate an interpolated coordinate p given an interpolation value and ordinate to apply it to
241 */
242 int point_interpolate(const POINT4D *p1, const POINT4D *p2, POINT4D *p, int hasz, int hasm, char ordinate, double interpolation_value);
243 
244 
248 LWCOLLECTION *lwline_clip_to_ordinate_range(const LWLINE *line, char ordinate, double from, double to);
249 
253 LWCOLLECTION *lwmline_clip_to_ordinate_range(const LWMLINE *mline, char ordinate, double from, double to);
254 
258 LWCOLLECTION *lwmpoint_clip_to_ordinate_range(const LWMPOINT *mpoint, char ordinate, double from, double to);
259 
263 LWCOLLECTION *lwpoint_clip_to_ordinate_range(const LWPOINT *mpoint, char ordinate, double from, double to);
264 
265 /*
266 * Geohash
267 */
268 int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds);
269 char *geohash_point(double longitude, double latitude, int precision);
270 void decode_geohash_bbox(char *geohash, double *lat, double *lon, int precision);
271 
272 /*
273 * Point comparisons
274 */
275 int p4d_same(const POINT4D *p1, const POINT4D *p2);
276 int p3d_same(const POINT3D *p1, const POINT3D *p2);
277 int p2d_same(const POINT2D *p1, const POINT2D *p2);
278 
279 /*
280 * Area calculations
281 */
282 double lwpoly_area(const LWPOLY *poly);
283 double lwcurvepoly_area(const LWCURVEPOLY *curvepoly);
284 double lwtriangle_area(const LWTRIANGLE *triangle);
285 
290 extern int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox);
291 
292 /*
293 * Length calculations
294 */
295 double lwcompound_length(const LWCOMPOUND *comp);
296 double lwcompound_length_2d(const LWCOMPOUND *comp);
297 double lwline_length(const LWLINE *line);
298 double lwline_length_2d(const LWLINE *line);
299 double lwcircstring_length(const LWCIRCSTRING *circ);
300 double lwcircstring_length_2d(const LWCIRCSTRING *circ);
301 double lwpoly_perimeter(const LWPOLY *poly);
302 double lwpoly_perimeter_2d(const LWPOLY *poly);
303 double lwcurvepoly_perimeter(const LWCURVEPOLY *poly);
304 double lwcurvepoly_perimeter_2d(const LWCURVEPOLY *poly);
305 double lwtriangle_perimeter(const LWTRIANGLE *triangle);
306 double lwtriangle_perimeter_2d(const LWTRIANGLE *triangle);
307 
308 /*
309 * Segmentization
310 */
311 LWLINE *lwcircstring_stroke(const LWCIRCSTRING *icurve, uint32_t perQuad);
312 LWLINE *lwcompound_stroke(const LWCOMPOUND *icompound, uint32_t perQuad);
313 LWPOLY *lwcurvepoly_stroke(const LWCURVEPOLY *curvepoly, uint32_t perQuad);
314 
315 /*
316 * Affine
317 */
318 void ptarray_affine(POINTARRAY *pa, const AFFINE *affine);
319 
320 /*
321 * Scale
322 */
323 void ptarray_scale(POINTARRAY *pa, const POINT4D *factor);
324 
325 /*
326 * PointArray
327 */
328 int ptarray_has_z(const POINTARRAY *pa);
329 int ptarray_has_m(const POINTARRAY *pa);
330 double ptarray_signed_area(const POINTARRAY *pa);
331 
332 /*
333 * Clone support
334 */
335 LWLINE *lwline_clone(const LWLINE *lwgeom);
336 LWPOLY *lwpoly_clone(const LWPOLY *lwgeom);
337 LWTRIANGLE *lwtriangle_clone(const LWTRIANGLE *lwgeom);
340 POINTARRAY *ptarray_clone(const POINTARRAY *ptarray);
341 GBOX *box2d_clone(const GBOX *lwgeom);
342 LWLINE *lwline_clone_deep(const LWLINE *lwgeom);
343 LWPOLY *lwpoly_clone_deep(const LWPOLY *lwgeom);
345 GBOX *gbox_clone(const GBOX *gbox);
346 
347 /*
348 * Startpoint
349 */
350 int lwpoly_startpoint(const LWPOLY* lwpoly, POINT4D* pt);
351 int ptarray_startpoint(const POINTARRAY* pa, POINT4D* pt);
352 int lwcollection_startpoint(const LWCOLLECTION* col, POINT4D* pt);
353 
354 /*
355  * Write into *ret the coordinates of the closest point on
356  * segment A-B to the reference input point R
357  */
358 void closest_point_on_segment(const POINT4D *R, const POINT4D *A, const POINT4D *B, POINT4D *ret);
359 
360 /*
361 * Repeated points
362 */
363 POINTARRAY *ptarray_remove_repeated_points_minpoints(const POINTARRAY *in, double tolerance, int minpoints);
364 POINTARRAY *ptarray_remove_repeated_points(const POINTARRAY *in, double tolerance);
365 LWGEOM* lwmpoint_remove_repeated_points(const LWMPOINT *in, double tolerance);
366 LWGEOM* lwline_remove_repeated_points(const LWLINE *in, double tolerance);
367 LWGEOM* lwcollection_remove_repeated_points(const LWCOLLECTION *in, double tolerance);
368 LWGEOM* lwpoly_remove_repeated_points(const LWPOLY *in, double tolerance);
369 
370 /*
371 * Closure test
372 */
373 int lwline_is_closed(const LWLINE *line);
374 int lwpoly_is_closed(const LWPOLY *poly);
375 int lwcircstring_is_closed(const LWCIRCSTRING *curve);
376 int lwcompound_is_closed(const LWCOMPOUND *curve);
377 int lwpsurface_is_closed(const LWPSURFACE *psurface);
378 int lwtin_is_closed(const LWTIN *tin);
379 
387 typedef struct gridspec_t
388 {
389  double ipx;
390  double ipy;
391  double ipz;
392  double ipm;
393  double xsize;
394  double ysize;
395  double zsize;
396  double msize;
397 }
398 gridspec;
399 
400 LWGEOM* lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid);
401 LWCOLLECTION* lwcollection_grid(const LWCOLLECTION *coll, const gridspec *grid);
402 LWPOINT* lwpoint_grid(const LWPOINT *point, const gridspec *grid);
403 LWPOLY* lwpoly_grid(const LWPOLY *poly, const gridspec *grid);
404 LWLINE* lwline_grid(const LWLINE *line, const gridspec *grid);
405 LWCIRCSTRING* lwcircstring_grid(const LWCIRCSTRING *line, const gridspec *grid);
406 POINTARRAY* ptarray_grid(const POINTARRAY *pa, const gridspec *grid);
407 
408 /*
409 * What side of the line formed by p1 and p2 does q fall?
410 * Returns -1 for left and 1 for right and 0 for co-linearity
411 */
412 int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q);
413 int lw_arc_side(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *Q);
414 int lw_arc_calculate_gbox_cartesian_2d(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, GBOX *gbox);
415 double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result);
416 int lw_pt_in_seg(const POINT2D *P, const POINT2D *A1, const POINT2D *A2);
417 int lw_pt_in_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3);
418 int lw_arc_is_pt(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3);
419 double lw_seg_length(const POINT2D *A1, const POINT2D *A2);
420 double lw_arc_length(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3);
421 int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
422 int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt);
423 int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt);
424 int ptarray_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number);
425 int ptarrayarc_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number);
426 int lwcompound_contains_point(const LWCOMPOUND *comp, const POINT2D *pt);
427 int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt);
428 
439 int lwline_split_by_point_to(const LWLINE* ln, const LWPOINT* pt, LWMLINE* to);
440 
442 void lwcollection_reserve(LWCOLLECTION *col, int ngeoms);
443 
445 extern int lwcollection_allows_subtype(int collectiontype, int subtype);
446 
448 double gbox_angular_height(const GBOX* gbox);
449 double gbox_angular_width(const GBOX* gbox);
450 int gbox_centroid(const GBOX* gbox, POINT2D* out);
451 
452 /* Utilities */
453 extern void trim_trailing_zeros(char *num);
454 
455 extern uint8_t MULTITYPE[NUMTYPES];
456 
458 extern int _lwgeom_interrupt_requested;
459 #define LW_ON_INTERRUPT(x) { \
460  if ( _lwgeom_interrupt_callback ) { \
461  (*_lwgeom_interrupt_callback)(); \
462  } \
463  if ( _lwgeom_interrupt_requested ) { \
464  _lwgeom_interrupt_requested = 0; \
465  lwnotice("liblwgeom code interrupted"); \
466  x; \
467  } \
468 }
469 
470 int ptarray_npoints_in_rect(const POINTARRAY *pa, const GBOX *gbox);
471 int gbox_contains_point2d(const GBOX *g, const POINT2D *p);
472 int lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt);
473 
474 #endif /* _LIBLWGEOM_INTERNAL_H */
LWCIRCSTRING * lwcircstring_grid(const LWCIRCSTRING *line, const gridspec *grid)
Definition: lwcircstring.c:318
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:227
LWPOINT * lwpoint_force_dims(const LWPOINT *lwpoint, int hasz, int hasm)
Definition: lwpoint.c:253
int lwcollection_count_vertices(LWCOLLECTION *col)
Definition: lwcollection.c:507
POINTARRAY * ptarray_remove_repeated_points(const POINTARRAY *in, double tolerance)
Definition: ptarray.c:1499
LWPOLY * lwpoly_clone_deep(const LWPOLY *lwgeom)
Definition: lwpoly.c:208
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:105
double lwcircstring_length(const LWCIRCSTRING *circ)
Definition: lwcircstring.c:283
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:1881
int ptarray_npoints_in_rect(const POINTARRAY *pa, const GBOX *gbox)
Definition: ptarray.c:1882
GBOX * box2d_clone(const GBOX *lwgeom)
Definition: box2d.c:43
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
Definition: ptarray.c:658
int lwline_count_vertices(LWLINE *line)
Definition: lwline.c:533
int lw_arc_calculate_gbox_cartesian_2d(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, GBOX *gbox)
Definition: g_box.c:464
double lw_seg_length(const POINT2D *A1, const POINT2D *A2)
Returns the length of a linear segment.
Definition: lwalgorithm.c:74
int gbox_contains_point2d(const GBOX *g, const POINT2D *p)
Definition: g_box.c:362
LWPOLY * lwpoly_simplify(const LWPOLY *ipoly, double dist, int preserve_collapsed)
Definition: lwpoly.c:424
CG_SEGMENT_INTERSECTION_TYPE
LWLINE * lwline_clone(const LWLINE *lwgeom)
Definition: lwline.c:102
int lwtin_is_closed(const LWTIN *tin)
Definition: lwtin.c:93
void ptarray_scale(POINTARRAY *pa, const POINT4D *factor)
Scale a pointarray.
Definition: ptarray.c:1804
LWCOLLECTION * lwmpoint_clip_to_ordinate_range(const LWMPOINT *mpoint, char ordinate, double from, double to)
Clip a multi-point based on the from/to range of one of its ordinates.
void trim_trailing_zeros(char *num)
Definition: lwutil.c:252
int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt)
For POINTARRAYs representing CIRCULARSTRINGS.
Definition: ptarray.c:832
void() lwinterrupt_callback()
Install a callback to be called periodically during algorithm execution.
Definition: liblwgeom.h:263
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.
double lwtriangle_perimeter_2d(const LWTRIANGLE *triangle)
Definition: lwtriangle.c:218
double lwcircstring_length_2d(const LWCIRCSTRING *circ)
Definition: lwcircstring.c:288
LWTRIANGLE * lwtriangle_clone(const LWTRIANGLE *lwgeom)
Definition: lwtriangle.c:99
void decode_geohash_bbox(char *geohash, double *lat, double *lon, int precision)
Definition: lwalgorithm.c:703
int gbox_centroid(const GBOX *gbox, POINT2D *out)
Computes the average(ish) center of the box and returns success.
Definition: lwgeodetic.c:258
double lwline_length_2d(const LWLINE *line)
Definition: lwline.c:586
LWGEOM * lwmpoint_remove_repeated_points(const LWMPOINT *in, double tolerance)
Definition: lwmpoint.c:92
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
Definition: lwalgorithm.c:280
LWLINE * lwline_grid(const LWLINE *line, const gridspec *grid)
Definition: lwline.c:595
LWPOINT * lwpoint_grid(const LWPOINT *point, const gridspec *grid)
Definition: lwpoint.c:282
int lwcompound_is_closed(const LWCOMPOUND *curve)
Definition: lwcompound.c:35
LWPOLY * lwcurvepoly_stroke(const LWCURVEPOLY *curvepoly, uint32_t perQuad)
Definition: lwstroke.c:305
LWCOLLECTION * lwline_clip_to_ordinate_range(const LWLINE *line, char ordinate, double from, double to)
Clip a line based on the from/to range of one of its ordinates.
double lwtriangle_area(const LWTRIANGLE *triangle)
Find the area of the outer ring.
Definition: lwtriangle.c:186
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
Definition: ptarray.c:995
double lwtriangle_perimeter(const LWTRIANGLE *triangle)
Definition: lwtriangle.c:209
int lwtriangle_is_empty(const LWTRIANGLE *triangle)
Definition: lwtriangle.c:175
int p2d_same(const POINT2D *p1, const POINT2D *p2)
Definition: lwalgorithm.c:49
lwinterrupt_callback * _lwgeom_interrupt_callback
Definition: lwgeom_api.c:845
LWGEOM * lwcollection_remove_repeated_points(const LWCOLLECTION *in, double tolerance)
Definition: lwcollection.c:453
uint32_t lw_get_uint32_t(const uint8_t *loc)
Definition: lwgeom_api.c:582
int lwcompound_contains_point(const LWCOMPOUND *comp, const POINT2D *pt)
Definition: lwcompound.c:145
double lw_arc_length(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns the length of a circular arc segment.
Definition: lwalgorithm.c:118
double lwcompound_length_2d(const LWCOMPOUND *comp)
Definition: lwcompound.c:74
int lwcollection_is_empty(const LWCOLLECTION *col)
Definition: lwcollection.c:494
LWCOLLECTION * lwpoint_clip_to_ordinate_range(const LWPOINT *mpoint, char ordinate, double from, double to)
Clip a point based on the from/to range of one of its ordinates.
LWPOLY * lwpoly_force_dims(const LWPOLY *lwpoly, int hasz, int hasm)
Definition: lwpoly.c:381
void ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2)
Swap ordinate values o1 and o2 on a given POINTARRAY.
Definition: ptarray.c:388
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 lwpoly_is_closed(const LWPOLY *poly)
Definition: lwpoly.c:549
double lwcompound_length(const LWCOMPOUND *comp)
Definition: lwcompound.c:69
int lwcircstring_is_closed(const LWCIRCSTRING *curve)
Definition: lwcircstring.c:268
int ptarray_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
Definition: ptarray.c:739
LWCOLLECTION * lwmline_clip_to_ordinate_range(const LWMLINE *mline, char ordinate, double from, double to)
Clip a multi-line based on the from/to range of one of its ordinates.
LWCOLLECTION * lwcollection_simplify(const LWCOLLECTION *igeom, double dist, int preserve_collapsed)
Definition: lwcollection.c:519
int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds)
Definition: lwalgorithm.c:742
LWCIRCSTRING * lwcircstring_clone(const LWCIRCSTRING *curve)
Definition: lwcircstring.c:125
GBOX * gbox_clone(const GBOX *gbox)
Definition: g_box.c:56
uint8_t precision
Definition: cu_in_twkb.c:25
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
Definition: lwpoly.c:484
int lwpoly_is_empty(const LWPOLY *poly)
Definition: lwpoly.c:405
double lwcurvepoly_perimeter_2d(const LWCURVEPOLY *poly)
Definition: lwcurvepoly.c:159
POINTARRAY * ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm)
Definition: ptarray.c:1035
void lwpoint_set_ordinate(POINT4D *p, char ordinate, double value)
Given a point, ordinate number and value, set that ordinate on the point.
LWPOLY * lwpoly_grid(const LWPOLY *poly, const gridspec *grid)
Definition: lwpoly.c:602
#define NUMTYPES
Definition: liblwgeom.h:100
enum LWORD_T LWORD
Ordinate names.
int _lwgeom_interrupt_requested
Definition: lwgeom_api.c:835
struct gridspec_t gridspec
Snap to grid.
int lwpsurface_is_closed(const LWPSURFACE *psurface)
Definition: lwpsurface.c:99
char * geohash_point(double longitude, double latitude, int precision)
Definition: lwalgorithm.c:581
char getMachineEndian(void)
Definition: lwutil.c:358
int lwcollection_startpoint(const LWCOLLECTION *col, POINT4D *pt)
Definition: lwcollection.c:573
LWGEOM * lwgeom_force_dims(const LWGEOM *lwgeom, int hasz, int hasm)
Definition: lwgeom.c:727
LWCOLLECTION * lwcollection_clone_deep(const LWCOLLECTION *lwgeom)
Deep clone LWCOLLECTION object.
Definition: lwcollection.c:149
int lwpoly_startpoint(const LWPOLY *lwpoly, POINT4D *pt)
Definition: lwpoly.c:574
double lwpoly_perimeter_2d(const LWPOLY *poly)
Compute the sum of polygon rings length (forcing 2d computation).
Definition: lwpoly.c:535
int lwcircstring_is_empty(const LWCIRCSTRING *circ)
Definition: lwcircstring.c:276
double lwpoly_perimeter(const LWPOLY *poly)
Compute the sum of polygon rings length.
Definition: lwpoly.c:517
LWCOLLECTION * lwcollection_force_dims(const LWCOLLECTION *lwcol, int hasz, int hasm)
Definition: lwcollection.c:471
int ptarray_startpoint(const POINTARRAY *pa, POINT4D *pt)
Definition: ptarray.c:1826
int lwline_is_empty(const LWLINE *line)
Definition: lwline.c:525
LWGEOM * lwline_remove_repeated_points(const LWLINE *in, double tolerance)
Definition: lwline.c:456
int lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt)
Definition: lwpoly.c:582
LWGEOM * lwpoly_remove_repeated_points(const LWPOLY *in, double tolerance)
Definition: lwpoly.c:362
POINTARRAY * ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts)
Definition: ptarray.c:1554
double lwcurvepoly_perimeter(const LWCURVEPOLY *poly)
Definition: lwcurvepoly.c:147
LWLINE * lwline_force_dims(const LWLINE *lwline, int hasz, int hasm)
Definition: lwline.c:506
int lw_arc_side(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *Q)
Definition: lwalgorithm.c:178
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
Definition: lwgeom.c:277
int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
Definition: g_serialized.c:172
int ptarray_has_m(const POINTARRAY *pa)
Definition: ptarray.c:43
double lwline_length(const LWLINE *line)
Definition: lwline.c:579
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:85
LWLINE * lwcircstring_stroke(const LWCIRCSTRING *icurve, uint32_t perQuad)
Definition: lwstroke.c:206
POINTARRAY * ptarray_remove_repeated_points_minpoints(const POINTARRAY *in, double tolerance, int minpoints)
Definition: ptarray.c:1437
int lwline_is_closed(const LWLINE *line)
Definition: lwline.c:468
double gbox_angular_height(const GBOX *gbox)
GBOX utility functions to figure out coverage/location on the globe.
Definition: lwgeodetic.c:179
POINTARRAY * ptarray_grid(const POINTARRAY *pa, const gridspec *grid)
Definition: ptarray.c:1843
int lwpoint_is_empty(const LWPOINT *point)
Definition: lwpoint.c:273
int p3d_same(const POINT3D *p1, const POINT3D *p2)
Definition: lwalgorithm.c:40
LWCOLLECTION * lwcollection_grid(const LWCOLLECTION *coll, const gridspec *grid)
Definition: lwcollection.c:582
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:95
LWCOLLECTION * lwcollection_clone(const LWCOLLECTION *lwgeom)
Clone LWCOLLECTION object.
Definition: lwcollection.c:123
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
Return 1 if the point is inside the POINTARRAY, -1 if it is outside, and 0 if it is on the boundary...
Definition: ptarray.c:733
int value
Definition: genraster.py:61
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
Definition: lwcollection.c:536
int ptarray_has_z(const POINTARRAY *pa)
Definition: ptarray.c:36
LWLINE * lwcompound_stroke(const LWCOMPOUND *icompound, uint32_t perQuad)
Definition: lwstroke.c:258
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:64
int lwpoly_count_vertices(LWPOLY *poly)
Definition: lwpoly.c:412
void closest_point_on_segment(const POINT4D *R, const POINT4D *A, const POINT4D *B, POINT4D *ret)
Definition: ptarray.c:1255
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
Definition: lwcompound.c:129
int32_t lw_get_int32_t(const uint8_t *loc)
Definition: lwgeom_api.c:592
LWPOLY * lwpoly_clone(const LWPOLY *lwgeom)
Definition: lwpoly.c:193
LWLINE * lwline_clone_deep(const LWLINE *lwgeom)
Definition: lwline.c:118
int ptarrayarc_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
Definition: ptarray.c:838
double lwcurvepoly_area(const LWCURVEPOLY *curvepoly)
This should be rewritten to make use of the curve itself.
Definition: lwcurvepoly.c:133
LWLINE * lwline_simplify(const LWLINE *iline, double dist, int preserve_collapsed)
Definition: lwline.c:541
int p4d_same(const POINT4D *p1, const POINT4D *p2)
Definition: lwalgorithm.c:31
This library is the generic geometry handling section of PostGIS.
void ptarray_affine(POINTARRAY *pa, const AFFINE *affine)
Affine transform a pointarray.
Definition: ptarray.c:1753
void lwcollection_reserve(LWCOLLECTION *col, int ngeoms)
Ensure the collection can hold at least up to ngeoms geometries.
Definition: lwcollection.c:174
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.
double gbox_angular_width(const GBOX *gbox)
Returns the angular width (longitudinal span) of the box in radians.
Definition: lwgeodetic.c:206
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:371
Snap to grid.