PostGIS 3.6.2dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
lwline.c
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) 2012 Sandro Santilli <strk@kbt.io>
22 * Copyright (C) 2001-2006 Refractions Research Inc.
23 *
24 **********************************************************************/
25
26
27/* basic LWLINE functions */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include "liblwgeom_internal.h"
33#include "lwgeom_log.h"
34
35
36
37/*
38 * Construct a new LWLINE. points will *NOT* be copied
39 * use SRID=SRID_UNKNOWN for unknown SRID (will have 8bit type's S = 0)
40 */
41LWLINE *
42lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
43{
44 LWLINE *result = (LWLINE *)lwalloc(sizeof(LWLINE));
46 result->flags = points->flags;
47 FLAGS_SET_BBOX(result->flags, bbox?1:0);
48 result->srid = srid;
49 result->points = points;
50 result->bbox = bbox;
51 return result;
52}
53
54LWLINE *
55lwline_construct_empty(int32_t srid, char hasz, char hasm)
56{
57 LWLINE *result = lwalloc(sizeof(LWLINE));
58 result->type = LINETYPE;
59 result->flags = lwflags(hasz,hasm,0);
60 result->srid = srid;
61 result->points = ptarray_construct_empty(hasz, hasm, 1);
62 result->bbox = NULL;
63 return result;
64}
65
66
67void lwline_free (LWLINE *line)
68{
69 if ( ! line ) return;
70
71 if ( line->bbox )
72 lwfree(line->bbox);
73 if ( line->points )
74 ptarray_free(line->points);
75 lwfree(line);
76}
77
78
80{
81 lwnotice("LWLINE {");
82 lwnotice(" ndims = %i", (int)FLAGS_NDIMS(line->flags));
83 lwnotice(" srid = %i", (int)line->srid);
84 printPA(line->points);
85 lwnotice("}");
86}
87
88/* @brief Clone LWLINE object. Serialized point lists are not copied.
89 *
90 * @see ptarray_clone
91 */
92LWLINE *
94{
95 LWLINE *ret = lwalloc(sizeof(LWLINE));
96
97 LWDEBUGF(2, "lwline_clone called with %p", g);
98
99 memcpy(ret, g, sizeof(LWLINE));
100
101 ret->points = ptarray_clone(g->points);
102
103 if ( g->bbox ) ret->bbox = gbox_copy(g->bbox);
104 return ret;
105}
106
107/* Deep clone LWLINE object. POINTARRAY *is* copied. */
108LWLINE *
110{
111 LWLINE *ret = lwalloc(sizeof(LWLINE));
112
113 LWDEBUGF(2, "lwline_clone_deep called with %p", g);
114 memcpy(ret, g, sizeof(LWLINE));
115
116 if ( g->bbox ) ret->bbox = gbox_copy(g->bbox);
117 if ( g->points ) ret->points = ptarray_clone_deep(g->points);
119
120 return ret;
121}
122
123
124void
126{
128}
129
130
131LWLINE *
132lwline_segmentize2d(const LWLINE *line, double dist)
133{
134 POINTARRAY *segmentized = ptarray_segmentize2d(line->points, dist);
135 if ( ! segmentized ) return NULL;
136 return lwline_construct(line->srid, NULL, segmentized);
137}
138
139/* check coordinate equality */
140char
141lwline_same(const LWLINE *l1, const LWLINE *l2)
142{
143 return ptarray_same(l1->points, l2->points);
144}
145
146/*
147 * Construct a LWLINE from an array of point and line geometries
148 * LWLINE dimensions are large enough to host all input dimensions.
149 */
150LWLINE *
151lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms)
152{
153 uint32_t i;
154 int hasz = LW_FALSE;
155 int hasm = LW_FALSE;
156 POINTARRAY *pa;
157 LWLINE *line;
158 POINT4D pt;
159 LWPOINTITERATOR* it;
160
161 /*
162 * Find output dimensions, check integrity
163 */
164 for (i=0; i<ngeoms; i++)
165 {
166 if ( FLAGS_GET_Z(geoms[i]->flags) ) hasz = LW_TRUE;
167 if ( FLAGS_GET_M(geoms[i]->flags) ) hasm = LW_TRUE;
168 if ( hasz && hasm ) break; /* Nothing more to learn! */
169 }
170
171 /*
172 * ngeoms should be a guess about how many points we have in input.
173 * It's an underestimate for lines and multipoints */
174 pa = ptarray_construct_empty(hasz, hasm, ngeoms);
175
176 for ( i=0; i < ngeoms; i++ )
177 {
178 LWGEOM *g = geoms[i];
179
180 if ( lwgeom_is_empty(g) ) continue;
181
182 if ( g->type == POINTTYPE )
183 {
186 }
187 else if ( g->type == LINETYPE )
188 {
189 /*
190 * Append the new line points, de-duplicating against the previous points.
191 * Duplicated points internal to the linestring are untouched.
192 */
193 ptarray_append_ptarray(pa, ((LWLINE*)g)->points, -1);
194 }
195 else if ( g->type == MULTIPOINTTYPE )
196 {
198 while(lwpointiterator_next(it, &pt))
199 {
201 }
203 }
204 else
205 {
206 ptarray_free(pa);
207 lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(g->type));
208 return NULL;
209 }
210 }
211
212 if ( pa->npoints > 0 )
213 line = lwline_construct(srid, NULL, pa);
214 else {
215 /* Is this really any different from the above ? */
216 ptarray_free(pa);
217 line = lwline_construct_empty(srid, hasz, hasm);
218 }
219
220 return line;
221}
222
223/*
224 * Construct a LWLINE from an array of LWPOINTs
225 * LWLINE dimensions are large enough to host all input dimensions.
226 */
227LWLINE *
228lwline_from_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points)
229{
230 uint32_t i;
231 int hasz = LW_FALSE;
232 int hasm = LW_FALSE;
233 POINTARRAY *pa;
234 LWLINE *line;
235 POINT4D pt;
236
237 /*
238 * Find output dimensions, check integrity
239 */
240 for (i=0; i<npoints; i++)
241 {
242 if ( points[i]->type != POINTTYPE )
243 {
244 lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(points[i]->type));
245 return NULL;
246 }
247 if ( FLAGS_GET_Z(points[i]->flags) ) hasz = LW_TRUE;
248 if ( FLAGS_GET_M(points[i]->flags) ) hasm = LW_TRUE;
249 if ( hasz && hasm ) break; /* Nothing more to learn! */
250 }
251
252 pa = ptarray_construct_empty(hasz, hasm, npoints);
253
254 for ( i=0; i < npoints; i++ )
255 {
256 if ( ! lwpoint_is_empty(points[i]) )
257 {
258 lwpoint_getPoint4d_p(points[i], &pt);
260 }
261 }
262
263 if ( pa->npoints > 0 )
264 line = lwline_construct(srid, NULL, pa);
265 else
266 line = lwline_construct_empty(srid, hasz, hasm);
267
268 return line;
269}
270
271/*
272 * Construct a LWLINE from a LWMPOINT
273 */
274LWLINE *
275lwline_from_lwmpoint(int32_t srid, const LWMPOINT *mpoint)
276{
277 uint32_t i;
278 POINTARRAY *pa = NULL;
279 LWGEOM *lwgeom = (LWGEOM*)mpoint;
280 POINT4D pt;
281
282 char hasz = lwgeom_has_z(lwgeom);
283 char hasm = lwgeom_has_m(lwgeom);
284 uint32_t npoints = mpoint->ngeoms;
285
286 if ( lwgeom_is_empty(lwgeom) )
287 {
288 return lwline_construct_empty(srid, hasz, hasm);
289 }
290
291 pa = ptarray_construct(hasz, hasm, npoints);
292
293 for (i=0; i < npoints; i++)
294 {
295 getPoint4d_p(mpoint->geoms[i]->point, 0, &pt);
296 ptarray_set_point4d(pa, i, &pt);
297 }
298
299 LWDEBUGF(3, "lwline_from_lwmpoint: constructed pointarray for %d points", mpoint->ngeoms);
300
301 return lwline_construct(srid, NULL, pa);
302}
303
308LWPOINT*
309lwline_get_lwpoint(const LWLINE *line, uint32_t where)
310{
311 POINT4D pt;
312 LWPOINT *lwpoint;
313 POINTARRAY *pa;
314
315 if ( lwline_is_empty(line) || where >= line->points->npoints )
316 return NULL;
317
319 pt = getPoint4d(line->points, where);
321 lwpoint = lwpoint_construct(line->srid, NULL, pa);
322 return lwpoint;
323}
324
325
326int
327lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where)
328{
329 POINT4D pt;
330 getPoint4d_p(point->point, 0, &pt);
331
332 if ( ptarray_insert_point(line->points, &pt, where) != LW_SUCCESS )
333 return LW_FAILURE;
334
335 /* Update the bounding box */
336 if ( line->bbox )
337 {
339 }
340
341 return LW_SUCCESS;
342}
343
344
345
346LWLINE *
347lwline_removepoint(LWLINE *line, uint32_t index)
348{
349 POINTARRAY *newpa;
350 LWLINE *ret;
351
352 newpa = ptarray_removePoint(line->points, index);
353
354 ret = lwline_construct(line->srid, NULL, newpa);
355 lwgeom_add_bbox((LWGEOM *) ret);
356
357 return ret;
358}
359
360/*
361 * Note: input will be changed, make sure you have permissions for this.
362 */
363void
364lwline_setPoint4d(LWLINE *line, uint32_t index, POINT4D *newpoint)
365{
366 ptarray_set_point4d(line->points, index, newpoint);
367 /* Update the box, if there is one to update */
368 if ( line->bbox )
369 {
371 }
372}
373
378LWLINE*
379lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end)
380{
381 int i = 0;
382 int hasm = 0, hasz = 0;
383 int npoints = 0;
384 double length = 0.0;
385 double length_so_far = 0.0;
386 double m_range = m_end - m_start;
387 double m;
388 POINTARRAY *pa = NULL;
389 POINT3DZ p1, p2;
390
391 if ( lwline->type != LINETYPE )
392 {
393 lwerror("lwline_construct_from_lwline: only line types supported");
394 return NULL;
395 }
396
397 hasz = FLAGS_GET_Z(lwline->flags);
398 hasm = 1;
399
400 /* Null points or npoints == 0 will result in empty return geometry */
401 if ( lwline->points )
402 {
403 npoints = lwline->points->npoints;
404 length = ptarray_length_2d(lwline->points);
405 getPoint3dz_p(lwline->points, 0, &p1);
406 }
407
408 pa = ptarray_construct(hasz, hasm, npoints);
409
410 for ( i = 0; i < npoints; i++ )
411 {
412 POINT4D q;
413 POINT2D a, b;
414 getPoint3dz_p(lwline->points, i, &p2);
415 a.x = p1.x;
416 a.y = p1.y;
417 b.x = p2.x;
418 b.y = p2.y;
419 length_so_far += distance2d_pt_pt(&a, &b);
420 if ( length > 0.0 )
421 m = m_start + m_range * length_so_far / length;
422 /* #3172, support (valid) zero-length inputs */
423 else if ( length == 0.0 && npoints > 1 )
424 m = m_start + m_range * i / (npoints-1);
425 else
426 m = 0.0;
427 q.x = p2.x;
428 q.y = p2.y;
429 q.z = p2.z;
430 q.m = m;
431 ptarray_set_point4d(pa, i, &q);
432 p1 = p2;
433 }
434
435 return lwline_construct(lwline->srid, NULL, pa);
436}
437
438LWGEOM*
439lwline_remove_repeated_points(const LWLINE *lwline, double tolerance)
440{
441 return lwgeom_remove_repeated_points((LWGEOM*)lwline, tolerance);
442}
443
444int
446{
447 if (FLAGS_GET_Z(line->flags))
448 return ptarray_is_closed_3d(line->points);
449
450 return ptarray_is_closed_2d(line->points);
451}
452
453int
455{
456 if (!FLAGS_GET_M(line->flags))
457 {
458 lwnotice("Line does not have M dimension");
459 return LW_FALSE;
460 }
461
462 uint32_t n = line->points->npoints;
463
464 if (n < 2)
465 return LW_TRUE; /* empty or single-point are "good" */
466
467 double m = -1 * FLT_MAX;
468 for (uint32_t i = 0; i < n; ++i)
469 {
470 POINT3DM p;
471 if (!getPoint3dm_p(line->points, i, &p))
472 return LW_FALSE;
473 if (p.m <= m)
474 {
475 lwnotice(
476 "Measure of vertex %d (%g) not bigger than measure of vertex %d (%g)", i, p.m, i - 1, m);
477 return LW_FALSE;
478 }
479 m = p.m;
480 }
481
482 return LW_TRUE;
483}
484
485LWLINE*
486lwline_force_dims(const LWLINE *line, int hasz, int hasm, double zval, double mval)
487{
488 POINTARRAY *pdims = NULL;
489 LWLINE *lineout;
490
491 /* Return 2D empty */
492 if( lwline_is_empty(line) )
493 {
494 lineout = lwline_construct_empty(line->srid, hasz, hasm);
495 }
496 else
497 {
498 pdims = ptarray_force_dims(line->points, hasz, hasm, zval, mval);
499 lineout = lwline_construct(line->srid, NULL, pdims);
500 }
501 lineout->type = line->type;
502 return lineout;
503}
504
505uint32_t lwline_count_vertices(const LWLINE *line)
506{
507 assert(line);
508 if ( ! line->points )
509 return 0;
510 return line->points->npoints;
511}
512
513double lwline_length(const LWLINE *line)
514{
515 if ( lwline_is_empty(line) )
516 return 0.0;
517 return ptarray_length(line->points);
518}
519
520double lwline_length_2d(const LWLINE *line)
521{
522 if ( lwline_is_empty(line) )
523 return 0.0;
524 return ptarray_length_2d(line->points);
525}
526
527
528POINTARRAY* lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat) {
529 POINT4D pt;
530 uint32_t i;
531 uint32_t points_to_interpolate;
532 uint32_t points_found = 0;
533 double length;
534 double length_fraction_increment = length_fraction;
535 double length_fraction_consumed = 0;
536 char has_z = (char) lwgeom_has_z(lwline_as_lwgeom(line));
537 char has_m = (char) lwgeom_has_m(lwline_as_lwgeom(line));
538 const POINTARRAY* ipa = line->points;
539 POINTARRAY* opa;
540
541 /* Empty.InterpolatePoint == Point Empty */
542 if ( lwline_is_empty(line) )
543 {
544 return ptarray_construct_empty(has_z, has_m, 0);
545 }
546
547 /* If distance is one of the two extremes, return the point on that
548 * end rather than doing any computations
549 */
550 if ( length_fraction == 0.0 || length_fraction == 1.0 )
551 {
552 if ( length_fraction == 0.0 )
553 getPoint4d_p(ipa, 0, &pt);
554 else
555 getPoint4d_p(ipa, ipa->npoints-1, &pt);
556
557 opa = ptarray_construct(has_z, has_m, 1);
558 ptarray_set_point4d(opa, 0, &pt);
559
560 return opa;
561 }
562
563 /* Interpolate points along the line */
564 length = ptarray_length_2d(ipa);
565 points_to_interpolate = repeat ? (uint32_t) floor(1 / length_fraction) : 1;
566 opa = ptarray_construct(has_z, has_m, points_to_interpolate);
567
568 const POINT2D* p1 = getPoint2d_cp(ipa, 0);
569 for ( i = 0; i < ipa->npoints - 1 && points_found < points_to_interpolate; i++ )
570 {
571 const POINT2D* p2 = getPoint2d_cp(ipa, i+1);
572 double segment_length_frac = distance2d_pt_pt(p1, p2) / length;
573
574 /* If our target distance is before the total length we've seen
575 * so far. create a new point some distance down the current
576 * segment.
577 */
578 while ( length_fraction < length_fraction_consumed + segment_length_frac && points_found < points_to_interpolate )
579 {
580 POINT4D p1_4d = getPoint4d(ipa, i);
581 POINT4D p2_4d = getPoint4d(ipa, i+1);
582
583 double segment_fraction = (length_fraction - length_fraction_consumed) / segment_length_frac;
584 interpolate_point4d(&p1_4d, &p2_4d, &pt, segment_fraction);
585 ptarray_set_point4d(opa, points_found++, &pt);
586 length_fraction += length_fraction_increment;
587 }
588
589 length_fraction_consumed += segment_length_frac;
590
591 p1 = p2;
592 }
593
594 /* Return the last point on the line. This shouldn't happen, but
595 * could if there's some floating point rounding errors. */
596 if (points_found < points_to_interpolate) {
597 getPoint4d_p(ipa, ipa->npoints - 1, &pt);
598 ptarray_set_point4d(opa, points_found, &pt);
599 }
600
601 return opa;
602}
603
604extern LWPOINT *
606{
607 double length, slength, tlength;
608 POINTARRAY *ipa;
609 POINT4D pt;
610 int nsegs, i;
611 LWGEOM *geom = lwline_as_lwgeom(line);
612 int has_z = lwgeom_has_z(geom);
613 int has_m = lwgeom_has_m(geom);
614 ipa = line->points;
615
616 /* Empty.InterpolatePoint == Point Empty */
617 if (lwline_is_empty(line))
618 {
619 return lwpoint_construct_empty(line->srid, has_z, has_m);
620 }
621
622 /* If distance is one of the two extremes, return the point on that
623 * end rather than doing any expensive computations
624 */
625 if (distance == 0.0 || distance == 1.0)
626 {
627 if (distance == 0.0)
628 getPoint4d_p(ipa, 0, &pt);
629 else
630 getPoint4d_p(ipa, ipa->npoints - 1, &pt);
631
632 return lwpoint_make(line->srid, has_z, has_m, &pt);
633 }
634
635 /* Interpolate a point on the line */
636 nsegs = ipa->npoints - 1;
637 length = ptarray_length(ipa);
638 tlength = 0;
639 for (i = 0; i < nsegs; i++)
640 {
641 POINT4D p1, p2;
642 POINT4D *p1ptr = &p1, *p2ptr = &p2; /* don't break
643 * strict-aliasing rules
644 */
645
646 getPoint4d_p(ipa, i, &p1);
647 getPoint4d_p(ipa, i + 1, &p2);
648
649 /* Find the relative length of this segment */
650 slength = distance3d_pt_pt((POINT3D *)p1ptr, (POINT3D *)p2ptr) / length;
651
652 /* If our target distance is before the total length we've seen
653 * so far. create a new point some distance down the current
654 * segment.
655 */
656 if (distance < tlength + slength)
657 {
658 double dseg = (distance - tlength) / slength;
659 interpolate_point4d(&p1, &p2, &pt, dseg);
660 return lwpoint_make(line->srid, has_z, has_m, &pt);
661 }
662 tlength += slength;
663 }
664
665 /* Return the last point on the line. This shouldn't happen, but
666 * could if there's some floating point rounding errors. */
667 getPoint4d_p(ipa, ipa->npoints - 1, &pt);
668 return lwpoint_make(line->srid, has_z, has_m, &pt);
669}
670
671extern LWLINE *
672lwline_extend(const LWLINE *line, double distance_forward, double distance_backward)
673{
674 POINTARRAY *pa, *opa;
675 POINT4D p00, p01, p10, p11;
676 POINT4D p_start, p_end;
677 uint32_t i;
678 bool forward = false, backward = false;
679
680 if (distance_forward < 0 || distance_backward < 0)
681 lwerror("%s: distances must be non-negative", __func__);
682
683 if (!line || lwline_is_empty(line) || lwline_count_vertices(line) < 2)
684 {
685 lwerror("%s: line must have at least two points", __func__);
686 }
687
688 pa = line->points;
689 if (distance_backward > 0.0)
690 {
691 i = 0;
692 /* Get two distinct points at start of pointarray */
693 getPoint4d_p(pa, i++, &p00);
694 getPoint4d_p(pa, i, &p01);
695 while(p4d_same(&p00, &p01))
696 {
697 if (i == pa->npoints - 1)
698 {
699 lwerror("%s: line must have at least two distinct points", __func__);
700 }
701 i++;
702 getPoint4d_p(pa, i, &p01);
703 }
704 project_pt_pt(&p01, &p00, distance_backward, &p_start);
705 backward = true;
706 }
707
708 if (distance_forward > 0.0)
709 {
710 i = pa->npoints - 1;
711 /* Get two distinct points at end of pointarray */
712 getPoint4d_p(pa, i--, &p10);
713 getPoint4d_p(pa, i, &p11);
714 while(p4d_same(&p10, &p11))
715 {
716 if (i == 0)
717 {
718 lwerror("%s: line must have at least two distinct points", __func__);
719 }
720 i--;
721 getPoint4d_p(pa, i, &p11);
722 }
723 project_pt_pt(&p11, &p10, distance_forward, &p_end);
724 forward = true;
725 }
726
728
729 if (backward)
730 {
731 ptarray_append_point(opa, &p_start, true);
732 }
733 ptarray_append_ptarray(opa, pa, -1.0);
734 if (forward)
735 {
736 ptarray_append_point(opa, &p_end, true);
737 }
738 return lwline_construct(line->srid, NULL, opa);
739}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition gbox.c:438
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition lwgeom.c:707
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition lwpoint.c:57
POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n)
Definition lwgeom_api.c:107
#define LW_FALSE
Definition liblwgeom.h:94
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition measures.c:2344
int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance)
Append a POINTARRAY, pa2 to the end of an existing POINTARRAY, pa1.
Definition ptarray.c:177
#define LW_FAILURE
Definition liblwgeom.h:96
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition ptarray.c:723
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition lwiterator.c:243
int lwpointiterator_next(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assign the next point in the iterator to p, and advances the iterator to the next point.
Definition lwiterator.c:210
#define LINETYPE
Definition liblwgeom.h:103
void interpolate_point4d(const POINT4D *A, const POINT4D *B, POINT4D *I, double F)
Find interpolation point I between point A and point B so that the len(AI) == len(AB)*F and I falls o...
Definition lwgeom_api.c:646
#define LW_SUCCESS
Definition liblwgeom.h:97
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
Definition lwpoint.c:129
#define MULTIPOINTTYPE
Definition liblwgeom.h:105
#define FLAGS_SET_BBOX(flags, value)
Definition liblwgeom.h:174
void printPA(POINTARRAY *pa)
Definition lwgeom_api.c:440
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition lwiterator.c:268
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition ptarray.c:59
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition ptarray.c:1963
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition lwgeom.c:934
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:102
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:165
void * lwalloc(size_t size)
Definition lwutil.c:227
int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where)
Insert a point into an existing POINTARRAY.
Definition ptarray.c:85
double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2)
int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point)
Definition lwgeom_api.c:215
void lwfree(void *mem)
Definition lwutil.c:248
#define FLAGS_NDIMS(flags)
Definition liblwgeom.h:179
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:339
POINTARRAY * ptarray_segmentize2d(const POINTARRAY *ipa, double dist)
Returns a modified POINTARRAY so that no segment is longer than the given distance (computed using 2d...
Definition ptarray.c:413
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoint.c:151
POINTARRAY * ptarray_removePoint(POINTARRAY *pa, uint32_t where)
Remove a point from a pointarray.
Definition ptarray.c:582
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:166
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition lwgeom_api.c:125
void ptarray_free(POINTARRAY *pa)
Definition ptarray.c:327
LWPOINT * lwpoint_make(int32_t srid, int hasz, int hasm, const POINT4D *p)
Definition lwpoint.c:206
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
Definition ptarray.c:147
#define FLAGS_SET_READONLY(flags, value)
Definition liblwgeom.h:176
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition ptarray.c:710
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
Definition lwutil.c:477
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:93
int getPoint3dm_p(const POINTARRAY *pa, uint32_t n, POINT3DM *point)
Definition lwgeom_api.c:268
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition lwgeom.c:468
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition lwgeom.c:941
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition lwgeom_api.c:369
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition lwgeom.c:695
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition ptarray.c:51
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition ptarray.c:643
LWGEOM * lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance)
Definition lwgeom.c:1534
int p4d_same(const POINT4D *p1, const POINT4D *p2)
Definition lwalgorithm.c:32
int lwline_is_empty(const LWLINE *line)
double ptarray_length(const POINTARRAY *pts)
Find the 3d/2d length of the given POINTARRAY (depending on its dimensionality)
Definition ptarray.c:1991
char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2)
Definition ptarray.c:484
int lwpoint_is_empty(const LWPOINT *point)
int ptarray_has_z(const POINTARRAY *pa)
Definition ptarray.c:37
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:2445
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
Definition ptarray.c:674
POINTARRAY * ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm, double zval, double mval)
Definition ptarray.c:1183
int ptarray_has_m(const POINTARRAY *pa)
Definition ptarray.c:44
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:106
void lwnotice(const char *fmt,...) __attribute__((format(printf
Write a notice out to the notice handler.
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition lwinline.h:97
double lwline_length_2d(const LWLINE *line)
Definition lwline.c:520
LWPOINT * lwline_interpolate_point_3d(const LWLINE *line, double distance)
Interpolate one point along a line in 3D.
Definition lwline.c:605
LWLINE * lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms)
Definition lwline.c:151
POINTARRAY * lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat)
Interpolate one or more points along a line.
Definition lwline.c:528
LWLINE * lwline_force_dims(const LWLINE *line, int hasz, int hasm, double zval, double mval)
Definition lwline.c:486
LWLINE * lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end)
Re-write the measure coordinate (or add one, if it isn't already there) interpolating the measure bet...
Definition lwline.c:379
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition lwline.c:309
int lwline_is_closed(const LWLINE *line)
Definition lwline.c:445
uint32_t lwline_count_vertices(const LWLINE *line)
Definition lwline.c:505
void lwline_release(LWLINE *lwline)
Definition lwline.c:125
void lwline_setPoint4d(LWLINE *line, uint32_t index, POINT4D *newpoint)
Definition lwline.c:364
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwline.c:42
LWLINE * lwline_clone_deep(const LWLINE *g)
Definition lwline.c:109
LWLINE * lwline_extend(const LWLINE *line, double distance_forward, double distance_backward)
Extend the ends of a line.
Definition lwline.c:672
LWGEOM * lwline_remove_repeated_points(const LWLINE *lwline, double tolerance)
Definition lwline.c:439
void printLWLINE(LWLINE *line)
Definition lwline.c:79
LWLINE * lwline_clone(const LWLINE *g)
Definition lwline.c:93
LWLINE * lwline_segmentize2d(const LWLINE *line, double dist)
Definition lwline.c:132
double lwline_length(const LWLINE *line)
Definition lwline.c:513
char lwline_same(const LWLINE *l1, const LWLINE *l2)
Definition lwline.c:141
LWLINE * lwline_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwline.c:55
LWLINE * lwline_removepoint(LWLINE *line, uint32_t index)
Definition lwline.c:347
int lwline_is_trajectory(const LWLINE *line)
Definition lwline.c:454
void lwline_free(LWLINE *line)
Definition lwline.c:67
LWLINE * lwline_from_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points)
Definition lwline.c:228
LWLINE * lwline_from_lwmpoint(int32_t srid, const LWMPOINT *mpoint)
Definition lwline.c:275
int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where)
Add a LWPOINT to an LWLINE.
Definition lwline.c:327
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032
uint8_t type
Definition liblwgeom.h:462
lwflags_t flags
Definition liblwgeom.h:485
GBOX * bbox
Definition liblwgeom.h:482
POINTARRAY * points
Definition liblwgeom.h:483
uint8_t type
Definition liblwgeom.h:486
int32_t srid
Definition liblwgeom.h:484
uint32_t ngeoms
Definition liblwgeom.h:538
LWPOINT ** geoms
Definition liblwgeom.h:533
POINTARRAY * point
Definition liblwgeom.h:471
double y
Definition liblwgeom.h:390
double x
Definition liblwgeom.h:390
double m
Definition liblwgeom.h:408
double z
Definition liblwgeom.h:396
double x
Definition liblwgeom.h:396
double y
Definition liblwgeom.h:396
double m
Definition liblwgeom.h:414
double x
Definition liblwgeom.h:414
double z
Definition liblwgeom.h:414
double y
Definition liblwgeom.h:414
lwflags_t flags
Definition liblwgeom.h:431
uint32_t npoints
Definition liblwgeom.h:427