PostGIS  2.2.7dev-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  * Copyright (C) 2011-2012 Sandro Santilli <strk@keybit.net>
7  * Copyright (C) 2011 Paul Ramsey <pramsey@cleverelephant.ca>
8  * Copyright (C) 2007-2008 Mark Cave-Ayland
9  * Copyright (C) 2001-2006 Refractions Research Inc.
10  *
11  * This is free software; you can redistribute and/or modify it under
12  * the terms of the GNU General Public Licence. See the COPYING file.
13  *
14  **********************************************************************/
15 
16 #ifndef _LIBLWGEOM_INTERNAL_H
17 #define _LIBLWGEOM_INTERNAL_H 1
18 
19 #include "../postgis_config.h"
20 
21 #include "lwgeom_log.h"
22 
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdint.h>
26 #include <stdio.h>
27 #include <string.h>
28 
29 #if HAVE_IEEEFP_H
30 #include <ieeefp.h>
31 #endif
32 
33 #include <float.h>
34 
35 #include "liblwgeom.h"
36 
40 #define FP_TOLERANCE 1e-12
41 #define FP_IS_ZERO(A) (fabs(A) <= FP_TOLERANCE)
42 #define FP_MAX(A, B) (((A) > (B)) ? (A) : (B))
43 #define FP_MIN(A, B) (((A) < (B)) ? (A) : (B))
44 #define FP_ABS(a) ((a) < (0) ? -(a) : (a))
45 #define FP_EQUALS(A, B) (fabs((A)-(B)) <= FP_TOLERANCE)
46 #define FP_NEQUALS(A, B) (fabs((A)-(B)) > FP_TOLERANCE)
47 #define FP_LT(A, B) (((A) + FP_TOLERANCE) < (B))
48 #define FP_LTEQ(A, B) (((A) - FP_TOLERANCE) <= (B))
49 #define FP_GT(A, B) (((A) - FP_TOLERANCE) > (B))
50 #define FP_GTEQ(A, B) (((A) + FP_TOLERANCE) >= (B))
51 #define FP_CONTAINS_TOP(A, X, B) (FP_LT(A, X) && FP_LTEQ(X, B))
52 #define FP_CONTAINS_BOTTOM(A, X, B) (FP_LTEQ(A, X) && FP_LT(X, B))
53 #define FP_CONTAINS_INCL(A, X, B) (FP_LTEQ(A, X) && FP_LTEQ(X, B))
54 #define FP_CONTAINS_EXCL(A, X, B) (FP_LT(A, X) && FP_LT(X, B))
55 #define FP_CONTAINS(A, X, B) FP_CONTAINS_EXCL(A, X, B)
56 
57 
58 /*
59 * this will change to NaN when I figure out how to
60 * get NaN in a platform-independent way
61 */
62 #define NO_VALUE 0.0
63 #define NO_Z_VALUE NO_VALUE
64 #define NO_M_VALUE NO_VALUE
65 
66 
70 #define WKT_NO_TYPE 0x08 /* Internal use only */
71 #define WKT_NO_PARENS 0x10 /* Internal use only */
72 #define WKT_IS_CHILD 0x20 /* Internal use only */
73 
78 #define WKB_DOUBLE_SIZE 8 /* Internal use only */
79 #define WKB_INT_SIZE 4 /* Internal use only */
80 #define WKB_BYTE_SIZE 1 /* Internal use only */
81 
85 #define WKB_POINT_TYPE 1
86 #define WKB_LINESTRING_TYPE 2
87 #define WKB_POLYGON_TYPE 3
88 #define WKB_MULTIPOINT_TYPE 4
89 #define WKB_MULTILINESTRING_TYPE 5
90 #define WKB_MULTIPOLYGON_TYPE 6
91 #define WKB_GEOMETRYCOLLECTION_TYPE 7
92 #define WKB_CIRCULARSTRING_TYPE 8
93 #define WKB_COMPOUNDCURVE_TYPE 9
94 #define WKB_CURVEPOLYGON_TYPE 10
95 #define WKB_MULTICURVE_TYPE 11
96 #define WKB_MULTISURFACE_TYPE 12
97 #define WKB_CURVE_TYPE 13 /* from ISO draft, not sure is real */
98 #define WKB_SURFACE_TYPE 14 /* from ISO draft, not sure is real */
99 #define WKB_POLYHEDRALSURFACE_TYPE 15
100 #define WKB_TIN_TYPE 16
101 #define WKB_TRIANGLE_TYPE 17
102 
108 #define SIZE_GET(varsize) (((varsize) >> 2) & 0x3FFFFFFF)
109 #define SIZE_SET(varsize, size) (((varsize) & 0x00000003)|(((size) & 0x3FFFFFFF) << 2 ))
110 
117 #define SIGNUM(n) (((n) > 0) - ((n) < 0))
118 
122 #define EPSILON_SQLMM 1e-8
123 
124 /*
125  * Export functions
126  */
127 #define OUT_MAX_DOUBLE 1E15
128 #define OUT_SHOW_DIGS_DOUBLE 20
129 #define OUT_MAX_DOUBLE_PRECISION 15
130 #define OUT_MAX_DIGS_DOUBLE (OUT_SHOW_DIGS_DOUBLE + 2) /* +2 mean add dot and sign */
131 
132 
136 #define LW_INSIDE 1
137 #define LW_BOUNDARY 0
138 #define LW_OUTSIDE -1
139 
140 /*
141 * Internal prototypes
142 */
143 
144 /* Machine endianness */
145 #define XDR 0 /* big endian */
146 #define NDR 1 /* little endian */
147 extern char getMachineEndian(void);
148 
149 
150 /*
151 * Force dims
152 */
153 LWGEOM* lwgeom_force_dims(const LWGEOM *lwgeom, int hasz, int hasm);
154 LWPOINT* lwpoint_force_dims(const LWPOINT *lwpoint, int hasz, int hasm);
155 LWLINE* lwline_force_dims(const LWLINE *lwline, int hasz, int hasm);
156 LWPOLY* lwpoly_force_dims(const LWPOLY *lwpoly, int hasz, int hasm);
157 LWCOLLECTION* lwcollection_force_dims(const LWCOLLECTION *lwcol, int hasz, int hasm);
158 POINTARRAY* ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm);
159 
165 void ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2);
166 
167 /*
168 * Is Empty?
169 */
170 int lwpoly_is_empty(const LWPOLY *poly);
171 int lwcollection_is_empty(const LWCOLLECTION *col);
172 int lwcircstring_is_empty(const LWCIRCSTRING *circ);
173 int lwtriangle_is_empty(const LWTRIANGLE *triangle);
174 int lwline_is_empty(const LWLINE *line);
175 int lwpoint_is_empty(const LWPOINT *point);
176 
177 /*
178 * Number of vertices?
179 */
180 int lwline_count_vertices(LWLINE *line);
181 int lwpoly_count_vertices(LWPOLY *poly);
183 
184 /*
185 * Read from byte buffer
186 */
187 extern uint32_t lw_get_uint32_t(const uint8_t *loc);
188 extern int32_t lw_get_int32_t(const uint8_t *loc);
189 
190 /*
191 * DP simplification
192 */
193 
197 POINTARRAY* ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts);
198 LWLINE* lwline_simplify(const LWLINE *iline, double dist, int preserve_collapsed);
199 LWPOLY* lwpoly_simplify(const LWPOLY *ipoly, double dist, int preserve_collapsed);
200 LWCOLLECTION* lwcollection_simplify(const LWCOLLECTION *igeom, double dist, int preserve_collapsed);
201 
202 /*
203 * The possible ways a pair of segments can interact. Returned by lw_segment_intersects
204 */
206  SEG_ERROR = -1,
213 };
214 
215 /*
216 * Do the segments intersect? How?
217 */
218 int lw_segment_intersects(const POINT2D *p1, const POINT2D *p2, const POINT2D *q1, const POINT2D *q2);
219 
220 /*
221 * Get/Set an enumeratoed ordinate. (x,y,z,m)
222 */
223 double lwpoint_get_ordinate(const POINT4D *p, char ordinate);
224 void lwpoint_set_ordinate(POINT4D *p, char ordinate, double value);
225 
226 /*
227 * Generate an interpolated coordinate p given an interpolation value and ordinate to apply it to
228 */
229 int point_interpolate(const POINT4D *p1, const POINT4D *p2, POINT4D *p, int hasz, int hasm, char ordinate, double interpolation_value);
230 
231 
235 LWCOLLECTION *lwline_clip_to_ordinate_range(const LWLINE *line, char ordinate, double from, double to);
236 
240 LWCOLLECTION *lwmline_clip_to_ordinate_range(const LWMLINE *mline, char ordinate, double from, double to);
241 
245 LWCOLLECTION *lwmpoint_clip_to_ordinate_range(const LWMPOINT *mpoint, char ordinate, double from, double to);
246 
250 LWCOLLECTION *lwpoint_clip_to_ordinate_range(const LWPOINT *mpoint, char ordinate, double from, double to);
251 
252 /*
253 * Geohash
254 */
255 int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds);
256 char *geohash_point(double longitude, double latitude, int precision);
257 void decode_geohash_bbox(char *geohash, double *lat, double *lon, int precision);
258 
259 /*
260 * Point comparisons
261 */
262 int p4d_same(const POINT4D *p1, const POINT4D *p2);
263 int p3d_same(const POINT3D *p1, const POINT3D *p2);
264 int p2d_same(const POINT2D *p1, const POINT2D *p2);
265 
266 /*
267 * Area calculations
268 */
269 double lwpoly_area(const LWPOLY *poly);
270 double lwcurvepoly_area(const LWCURVEPOLY *curvepoly);
271 double lwtriangle_area(const LWTRIANGLE *triangle);
272 
277 extern int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox);
278 
279 /*
280 * Length calculations
281 */
282 double lwcompound_length(const LWCOMPOUND *comp);
283 double lwcompound_length_2d(const LWCOMPOUND *comp);
284 double lwline_length(const LWLINE *line);
285 double lwline_length_2d(const LWLINE *line);
286 double lwcircstring_length(const LWCIRCSTRING *circ);
287 double lwcircstring_length_2d(const LWCIRCSTRING *circ);
288 double lwpoly_perimeter(const LWPOLY *poly);
289 double lwpoly_perimeter_2d(const LWPOLY *poly);
290 double lwcurvepoly_perimeter(const LWCURVEPOLY *poly);
291 double lwcurvepoly_perimeter_2d(const LWCURVEPOLY *poly);
292 double lwtriangle_perimeter(const LWTRIANGLE *triangle);
293 double lwtriangle_perimeter_2d(const LWTRIANGLE *triangle);
294 
295 /*
296 * Segmentization
297 */
298 LWLINE *lwcircstring_stroke(const LWCIRCSTRING *icurve, uint32_t perQuad);
299 LWLINE *lwcompound_stroke(const LWCOMPOUND *icompound, uint32_t perQuad);
300 LWPOLY *lwcurvepoly_stroke(const LWCURVEPOLY *curvepoly, uint32_t perQuad);
301 
302 /*
303 * Affine
304 */
305 void ptarray_affine(POINTARRAY *pa, const AFFINE *affine);
306 
307 /*
308 * Scale
309 */
310 void ptarray_scale(POINTARRAY *pa, const POINT4D *factor);
311 
312 /*
313 * PointArray
314 */
315 int ptarray_has_z(const POINTARRAY *pa);
316 int ptarray_has_m(const POINTARRAY *pa);
317 double ptarray_signed_area(const POINTARRAY *pa);
318 
319 /*
320 * Clone support
321 */
322 LWLINE *lwline_clone(const LWLINE *lwgeom);
323 LWPOLY *lwpoly_clone(const LWPOLY *lwgeom);
324 LWTRIANGLE *lwtriangle_clone(const LWTRIANGLE *lwgeom);
327 POINTARRAY *ptarray_clone(const POINTARRAY *ptarray);
328 GBOX *box2d_clone(const GBOX *lwgeom);
329 LWLINE *lwline_clone_deep(const LWLINE *lwgeom);
330 LWPOLY *lwpoly_clone_deep(const LWPOLY *lwgeom);
332 GBOX *gbox_clone(const GBOX *gbox);
333 
334 /*
335 * Startpoint
336 */
337 int lwpoly_startpoint(const LWPOLY* lwpoly, POINT4D* pt);
338 int ptarray_startpoint(const POINTARRAY* pa, POINT4D* pt);
339 int lwcollection_startpoint(const LWCOLLECTION* col, POINT4D* pt);
340 
341 /*
342  * Write into *ret the coordinates of the closest point on
343  * segment A-B to the reference input point R
344  */
345 void closest_point_on_segment(const POINT4D *R, const POINT4D *A, const POINT4D *B, POINT4D *ret);
346 
347 /*
348 * Repeated points
349 */
350 POINTARRAY *ptarray_remove_repeated_points_minpoints(POINTARRAY *in, double tolerance, int minpoints);
352 LWGEOM* lwmpoint_remove_repeated_points(LWMPOINT *in, double tolerance);
353 LWGEOM* lwline_remove_repeated_points(LWLINE *in, double tolerance);
355 LWGEOM* lwpoly_remove_repeated_points(LWPOLY *in, double tolerance);
356 
357 /*
358 * Closure test
359 */
360 int lwline_is_closed(const LWLINE *line);
361 int lwpoly_is_closed(const LWPOLY *poly);
362 int lwcircstring_is_closed(const LWCIRCSTRING *curve);
363 int lwcompound_is_closed(const LWCOMPOUND *curve);
364 int lwpsurface_is_closed(const LWPSURFACE *psurface);
365 int lwtin_is_closed(const LWTIN *tin);
366 
374 typedef struct gridspec_t
375 {
376  double ipx;
377  double ipy;
378  double ipz;
379  double ipm;
380  double xsize;
381  double ysize;
382  double zsize;
383  double msize;
384 }
385 gridspec;
386 
387 LWGEOM* lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid);
388 LWCOLLECTION* lwcollection_grid(const LWCOLLECTION *coll, const gridspec *grid);
389 LWPOINT* lwpoint_grid(const LWPOINT *point, const gridspec *grid);
390 LWPOLY* lwpoly_grid(const LWPOLY *poly, const gridspec *grid);
391 LWLINE* lwline_grid(const LWLINE *line, const gridspec *grid);
392 LWCIRCSTRING* lwcircstring_grid(const LWCIRCSTRING *line, const gridspec *grid);
393 POINTARRAY* ptarray_grid(const POINTARRAY *pa, const gridspec *grid);
394 
395 /*
396 * What side of the line formed by p1 and p2 does q fall?
397 * Returns -1 for left and 1 for right and 0 for co-linearity
398 */
399 int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q);
400 int lw_arc_side(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *Q);
401 int lw_arc_calculate_gbox_cartesian_2d(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, GBOX *gbox);
402 double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result);
403 int lw_pt_in_seg(const POINT2D *P, const POINT2D *A1, const POINT2D *A2);
404 int lw_pt_in_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3);
405 int lw_arc_is_pt(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3);
406 double lw_seg_length(const POINT2D *A1, const POINT2D *A2);
407 double lw_arc_length(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3);
408 int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
409 int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt);
410 int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt);
411 int ptarray_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number);
412 int ptarrayarc_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number);
413 int lwcompound_contains_point(const LWCOMPOUND *comp, const POINT2D *pt);
414 int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt);
415 
426 int lwline_split_by_point_to(const LWLINE* ln, const LWPOINT* pt, LWMLINE* to);
427 
429 void lwcollection_reserve(LWCOLLECTION *col, int ngeoms);
430 
432 extern int lwcollection_allows_subtype(int collectiontype, int subtype);
433 
435 double gbox_angular_height(const GBOX* gbox);
436 double gbox_angular_width(const GBOX* gbox);
437 int gbox_centroid(const GBOX* gbox, POINT2D* out);
438 
439 /* Utilities */
440 extern void trim_trailing_zeros(char *num);
441 
442 extern uint8_t MULTITYPE[NUMTYPES];
443 
445 extern int _lwgeom_interrupt_requested;
446 #define LW_ON_INTERRUPT(x) { \
447  if ( _lwgeom_interrupt_callback ) { \
448  (*_lwgeom_interrupt_callback)(); \
449  } \
450  if ( _lwgeom_interrupt_requested ) { \
451  _lwgeom_interrupt_requested = 0; \
452  lwnotice("liblwgeom code interrupted"); \
453  x; \
454  } \
455 }
456 
457 int ptarray_npoints_in_rect(const POINTARRAY *pa, const GBOX *gbox);
458 int gbox_contains_point2d(const GBOX *g, const POINT2D *p);
459 int lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt);
460 
461 #endif /* _LIBLWGEOM_INTERNAL_H */
LWCIRCSTRING * lwcircstring_grid(const LWCIRCSTRING *line, const gridspec *grid)
Definition: lwcircstring.c:305
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:213
LWPOINT * lwpoint_force_dims(const LWPOINT *lwpoint, int hasz, int hasm)
Definition: lwpoint.c:240
int lwcollection_count_vertices(LWCOLLECTION *col)
Definition: lwcollection.c:494
LWPOLY * lwpoly_clone_deep(const LWPOLY *lwgeom)
Definition: lwpoly.c:135
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:91
double lwcircstring_length(const LWCIRCSTRING *circ)
Definition: lwcircstring.c:270
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:1868
int ptarray_npoints_in_rect(const POINTARRAY *pa, const GBOX *gbox)
Definition: ptarray.c:1882
GBOX * box2d_clone(const GBOX *lwgeom)
Definition: box2d.c:17
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
Definition: ptarray.c:658
int lwline_count_vertices(LWLINE *line)
Definition: lwline.c:504
int lw_arc_calculate_gbox_cartesian_2d(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, GBOX *gbox)
Definition: g_box.c:429
double lw_seg_length(const POINT2D *A1, const POINT2D *A2)
Returns the length of a linear segment.
Definition: lwalgorithm.c:60
int gbox_contains_point2d(const GBOX *g, const POINT2D *p)
Definition: g_box.c:327
LWPOLY * lwpoly_simplify(const LWPOLY *ipoly, double dist, int preserve_collapsed)
Definition: lwpoly.c:351
CG_SEGMENT_INTERSECTION_TYPE
LWLINE * lwline_clone(const LWLINE *lwgeom)
Definition: lwline.c:89
int lwtin_is_closed(const LWTIN *tin)
Definition: lwtin.c:80
void ptarray_scale(POINTARRAY *pa, const POINT4D *factor)
Scale a pointarray.
Definition: ptarray.c:1804
POINTARRAY * ptarray_remove_repeated_points(POINTARRAY *in, double tolerance)
Definition: ptarray.c:1499
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:224
int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt)
For POINTARRAYs representing CIRCULARSTRINGS.
Definition: ptarray.c:832
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:205
double lwcircstring_length_2d(const LWCIRCSTRING *circ)
Definition: lwcircstring.c:275
LWTRIANGLE * lwtriangle_clone(const LWTRIANGLE *lwgeom)
Definition: lwtriangle.c:86
void decode_geohash_bbox(char *geohash, double *lat, double *lon, int precision)
Definition: lwalgorithm.c:689
int gbox_centroid(const GBOX *gbox, POINT2D *out)
Computes the average(ish) center of the box and returns success.
Definition: lwgeodetic.c:243
double lwline_length_2d(const LWLINE *line)
Definition: lwline.c:557
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
Definition: lwalgorithm.c:266
LWLINE * lwline_grid(const LWLINE *line, const gridspec *grid)
Definition: lwline.c:566
void( lwinterrupt_callback)()
Install a callback to be called periodically during algorithm execution.
Definition: liblwgeom.h:248
LWPOINT * lwpoint_grid(const LWPOINT *point, const gridspec *grid)
Definition: lwpoint.c:269
int lwcompound_is_closed(const LWCOMPOUND *curve)
Definition: lwcompound.c:22
POINTARRAY * ptarray_remove_repeated_points_minpoints(POINTARRAY *in, double tolerance, int minpoints)
Definition: ptarray.c:1437
LWPOLY * lwcurvepoly_stroke(const LWCURVEPOLY *curvepoly, uint32_t perQuad)
Definition: lwstroke.c:289
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:173
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:196
int lwtriangle_is_empty(const LWTRIANGLE *triangle)
Definition: lwtriangle.c:162
int p2d_same(const POINT2D *p1, const POINT2D *p2)
Definition: lwalgorithm.c:35
lwinterrupt_callback * _lwgeom_interrupt_callback
Definition: lwgeom_api.c:832
uint32_t lw_get_uint32_t(const uint8_t *loc)
Definition: lwgeom_api.c:569
int lwcompound_contains_point(const LWCOMPOUND *comp, const POINT2D *pt)
Definition: lwcompound.c:132
LWGEOM * lwline_remove_repeated_points(LWLINE *in, double tolerance)
Definition: lwline.c:427
double lw_arc_length(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns the length of a circular arc segment.
Definition: lwalgorithm.c:104
double lwcompound_length_2d(const LWCOMPOUND *comp)
Definition: lwcompound.c:61
int lwcollection_is_empty(const LWCOLLECTION *col)
Definition: lwcollection.c:481
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:308
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:476
double lwcompound_length(const LWCOMPOUND *comp)
Definition: lwcompound.c:56
int lwcircstring_is_closed(const LWCIRCSTRING *curve)
Definition: lwcircstring.c:255
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:506
int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds)
Definition: lwalgorithm.c:728
LWCIRCSTRING * lwcircstring_clone(const LWCIRCSTRING *curve)
Definition: lwcircstring.c:112
GBOX * gbox_clone(const GBOX *gbox)
Definition: g_box.c:41
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:411
int lwpoly_is_empty(const LWPOLY *poly)
Definition: lwpoly.c:332
double lwcurvepoly_perimeter_2d(const LWCURVEPOLY *poly)
Definition: lwcurvepoly.c:146
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:529
#define NUMTYPES
Definition: liblwgeom.h:86
enum LWORD_T LWORD
Ordinate names.
int _lwgeom_interrupt_requested
Definition: lwgeom_api.c:822
struct gridspec_t gridspec
Snap to grid.
int lwpsurface_is_closed(const LWPSURFACE *psurface)
Definition: lwpsurface.c:86
char * geohash_point(double longitude, double latitude, int precision)
Definition: lwalgorithm.c:567
char getMachineEndian(void)
Definition: lwutil.c:330
int lwcollection_startpoint(const LWCOLLECTION *col, POINT4D *pt)
Definition: lwcollection.c:560
LWGEOM * lwgeom_force_dims(const LWGEOM *lwgeom, int hasz, int hasm)
Definition: lwgeom.c:714
LWCOLLECTION * lwcollection_clone_deep(const LWCOLLECTION *lwgeom)
Deep clone LWCOLLECTION object.
Definition: lwcollection.c:136
int lwpoly_startpoint(const LWPOLY *lwpoly, POINT4D *pt)
Definition: lwpoly.c:501
double lwpoly_perimeter_2d(const LWPOLY *poly)
Compute the sum of polygon rings length (forcing 2d computation).
Definition: lwpoly.c:462
int lwcircstring_is_empty(const LWCIRCSTRING *circ)
Definition: lwcircstring.c:263
double lwpoly_perimeter(const LWPOLY *poly)
Compute the sum of polygon rings length.
Definition: lwpoly.c:444
LWCOLLECTION * lwcollection_force_dims(const LWCOLLECTION *lwcol, int hasz, int hasm)
Definition: lwcollection.c:458
int ptarray_startpoint(const POINTARRAY *pa, POINT4D *pt)
Definition: ptarray.c:1826
int lwline_is_empty(const LWLINE *line)
Definition: lwline.c:496
int lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt)
Definition: lwpoly.c:509
POINTARRAY * ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts)
Definition: ptarray.c:1554
LWGEOM * lwpoly_remove_repeated_points(LWPOLY *in, double tolerance)
Definition: lwpoly.c:289
double lwcurvepoly_perimeter(const LWCURVEPOLY *poly)
Definition: lwcurvepoly.c:134
LWLINE * lwline_force_dims(const LWLINE *lwline, int hasz, int hasm)
Definition: lwline.c:477
int lw_arc_side(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *Q)
Definition: lwalgorithm.c:164
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
Definition: lwgeom.c:264
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:158
int ptarray_has_m(const POINTARRAY *pa)
Definition: ptarray.c:43
double lwline_length(const LWLINE *line)
Definition: lwline.c:550
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:71
LWGEOM * lwmpoint_remove_repeated_points(LWMPOINT *in, double tolerance)
Definition: lwmpoint.c:79
LWLINE * lwcircstring_stroke(const LWCIRCSTRING *icurve, uint32_t perQuad)
Definition: lwstroke.c:190
int lwline_is_closed(const LWLINE *line)
Definition: lwline.c:439
double gbox_angular_height(const GBOX *gbox)
GBOX utility functions to figure out coverage/location on the globe.
Definition: lwgeodetic.c:164
POINTARRAY * ptarray_grid(const POINTARRAY *pa, const gridspec *grid)
Definition: ptarray.c:1843
int lwpoint_is_empty(const LWPOINT *point)
Definition: lwpoint.c:260
int p3d_same(const POINT3D *p1, const POINT3D *p2)
Definition: lwalgorithm.c:26
LWCOLLECTION * lwcollection_grid(const LWCOLLECTION *coll, const gridspec *grid)
Definition: lwcollection.c:569
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:81
LWCOLLECTION * lwcollection_clone(const LWCOLLECTION *lwgeom)
Clone LWCOLLECTION object.
Definition: lwcollection.c:110
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 lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
Definition: lwcollection.c:523
int ptarray_has_z(const POINTARRAY *pa)
Definition: ptarray.c:36
LWLINE * lwcompound_stroke(const LWCOMPOUND *icompound, uint32_t perQuad)
Definition: lwstroke.c:242
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:50
int lwpoly_count_vertices(LWPOLY *poly)
Definition: lwpoly.c:339
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:116
int32_t lw_get_int32_t(const uint8_t *loc)
Definition: lwgeom_api.c:579
LWPOLY * lwpoly_clone(const LWPOLY *lwgeom)
Definition: lwpoly.c:120
LWLINE * lwline_clone_deep(const LWLINE *lwgeom)
Definition: lwline.c:105
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:120
LWLINE * lwline_simplify(const LWLINE *iline, double dist, int preserve_collapsed)
Definition: lwline.c:512
int p4d_same(const POINT4D *p1, const POINT4D *p2)
Definition: lwalgorithm.c:17
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
LWGEOM * lwcollection_remove_repeated_points(LWCOLLECTION *in, double tolerance)
Definition: lwcollection.c:440
void lwcollection_reserve(LWCOLLECTION *col, int ngeoms)
Ensure the collection can hold at least up to ngeoms geometries.
Definition: lwcollection.c:161
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:191
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:357
Snap to grid.