PostGIS  3.0.6dev-r@@SVN_REVISION@@
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  */
41 LWLINE *
42 lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
43 {
44  LWLINE *result = (LWLINE *)lwalloc(sizeof(LWLINE));
45  result->type = LINETYPE;
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 
54 LWLINE *
55 lwline_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 
67 void 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 
79 void printLWLINE(LWLINE *line)
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  */
92 LWLINE *
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. */
108 LWLINE *
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);
118  FLAGS_SET_READONLY(ret->flags,0);
119 
120  return ret;
121 }
122 
123 
124 void
126 {
128 }
129 
130 
131 LWLINE *
132 lwline_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 */
140 char
141 lwline_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  */
150 LWLINE *
151 lwline_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  {
184  lwpoint_getPoint4d_p((LWPOINT*)g, &pt);
185  ptarray_append_point(pa, &pt, LW_TRUE);
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  {
197  it = lwpointiterator_create(g);
198  while(lwpointiterator_next(it, &pt))
199  {
200  ptarray_append_point(pa, &pt, LW_TRUE);
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  */
227 LWLINE *
228 lwline_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);
259  ptarray_append_point(pa, &pt, LW_TRUE);
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  */
274 LWLINE *
275 lwline_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 
308 LWPOINT*
309 lwline_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);
320  ptarray_append_point(pa, &pt, LW_TRUE);
321  lwpoint = lwpoint_construct(line->srid, NULL, pa);
322  return lwpoint;
323 }
324 
325 
326 int
327 lwline_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  {
338  lwgeom_refresh_bbox((LWGEOM*)line);
339  }
340 
341  return LW_SUCCESS;
342 }
343 
344 
345 
346 LWLINE *
347 lwline_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  */
363 void
364 lwline_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  {
370  lwgeom_refresh_bbox((LWGEOM*)line);
371  }
372 }
373 
378 LWLINE*
379 lwline_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 
438 LWGEOM*
439 lwline_remove_repeated_points(const LWLINE *lwline, double tolerance)
440 {
441  return lwgeom_remove_repeated_points((LWGEOM*)lwline, tolerance);
442 }
443 
444 int
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 
453 int
455 {
456  POINT3DM p;
457  int i, n;
458  double m = -1 * FLT_MAX;
459 
460  if ( ! FLAGS_GET_M(line->flags) ) {
461  lwnotice("Line does not have M dimension");
462  return LW_FALSE;
463  }
464 
465  n = line->points->npoints;
466  if ( n < 2 ) return LW_TRUE; /* empty or single-point are "good" */
467 
468  for (i=0; i<n; ++i) {
469  getPoint3dm_p(line->points, i, &p);
470  if ( p.m <= m ) {
471  lwnotice("Measure of vertex %d (%g) not bigger than measure of vertex %d (%g)",
472  i, p.m, i-1, m);
473  return LW_FALSE;
474  }
475  m = p.m;
476  }
477 
478  return LW_TRUE;
479 }
480 
481 
482 LWLINE*
483 lwline_force_dims(const LWLINE *line, int hasz, int hasm)
484 {
485  POINTARRAY *pdims = NULL;
486  LWLINE *lineout;
487 
488  /* Return 2D empty */
489  if( lwline_is_empty(line) )
490  {
491  lineout = lwline_construct_empty(line->srid, hasz, hasm);
492  }
493  else
494  {
495  pdims = ptarray_force_dims(line->points, hasz, hasm);
496  lineout = lwline_construct(line->srid, NULL, pdims);
497  }
498  lineout->type = line->type;
499  return lineout;
500 }
501 
503 {
504  assert(line);
505  if ( ! line->points )
506  return 0;
507  return line->points->npoints;
508 }
509 
510 double lwline_length(const LWLINE *line)
511 {
512  if ( lwline_is_empty(line) )
513  return 0.0;
514  return ptarray_length(line->points);
515 }
516 
517 double lwline_length_2d(const LWLINE *line)
518 {
519  if ( lwline_is_empty(line) )
520  return 0.0;
521  return ptarray_length_2d(line->points);
522 }
523 
524 
525 POINTARRAY* lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat) {
526  POINT4D pt;
527  uint32_t i;
528  uint32_t points_to_interpolate;
529  uint32_t points_found = 0;
530  double length;
531  double length_fraction_increment = length_fraction;
532  double length_fraction_consumed = 0;
533  char has_z = (char) lwgeom_has_z(lwline_as_lwgeom(line));
534  char has_m = (char) lwgeom_has_m(lwline_as_lwgeom(line));
535  const POINTARRAY* ipa = line->points;
536  POINTARRAY* opa;
537 
538  /* Empty.InterpolatePoint == Point Empty */
539  if ( lwline_is_empty(line) )
540  {
541  return ptarray_construct_empty(has_z, has_m, 0);
542  }
543 
544  /* If distance is one of the two extremes, return the point on that
545  * end rather than doing any computations
546  */
547  if ( length_fraction == 0.0 || length_fraction == 1.0 )
548  {
549  if ( length_fraction == 0.0 )
550  getPoint4d_p(ipa, 0, &pt);
551  else
552  getPoint4d_p(ipa, ipa->npoints-1, &pt);
553 
554  opa = ptarray_construct(has_z, has_m, 1);
555  ptarray_set_point4d(opa, 0, &pt);
556 
557  return opa;
558  }
559 
560  /* Interpolate points along the line */
561  length = ptarray_length_2d(ipa);
562  points_to_interpolate = repeat ? (uint32_t) floor(1 / length_fraction) : 1;
563  opa = ptarray_construct(has_z, has_m, points_to_interpolate);
564 
565  const POINT2D* p1 = getPoint2d_cp(ipa, 0);
566  for ( i = 0; i < ipa->npoints - 1 && points_found < points_to_interpolate; i++ )
567  {
568  const POINT2D* p2 = getPoint2d_cp(ipa, i+1);
569  double segment_length_frac = distance2d_pt_pt(p1, p2) / length;
570 
571  /* If our target distance is before the total length we've seen
572  * so far. create a new point some distance down the current
573  * segment.
574  */
575  while ( length_fraction < length_fraction_consumed + segment_length_frac && points_found < points_to_interpolate )
576  {
577  POINT4D p1_4d = getPoint4d(ipa, i);
578  POINT4D p2_4d = getPoint4d(ipa, i+1);
579 
580  double segment_fraction = (length_fraction - length_fraction_consumed) / segment_length_frac;
581  interpolate_point4d(&p1_4d, &p2_4d, &pt, segment_fraction);
582  ptarray_set_point4d(opa, points_found++, &pt);
583  length_fraction += length_fraction_increment;
584  }
585 
586  length_fraction_consumed += segment_length_frac;
587 
588  p1 = p2;
589  }
590 
591  /* Return the last point on the line. This shouldn't happen, but
592  * could if there's some floating point rounding errors. */
593  if (points_found < points_to_interpolate) {
594  getPoint4d_p(ipa, ipa->npoints - 1, &pt);
595  ptarray_set_point4d(opa, points_found, &pt);
596  }
597 
598  return opa;
599 }
600 
601 extern LWPOINT *
603 {
604  double length, slength, tlength;
605  POINTARRAY *ipa;
606  POINT4D pt;
607  int nsegs, i;
608  LWGEOM *geom = lwline_as_lwgeom(line);
609  int has_z = lwgeom_has_z(geom);
610  int has_m = lwgeom_has_m(geom);
611  ipa = line->points;
612 
613  /* Empty.InterpolatePoint == Point Empty */
614  if (lwline_is_empty(line))
615  {
616  return lwpoint_construct_empty(line->srid, has_z, has_m);
617  }
618 
619  /* If distance is one of the two extremes, return the point on that
620  * end rather than doing any expensive computations
621  */
622  if (distance == 0.0 || distance == 1.0)
623  {
624  if (distance == 0.0)
625  getPoint4d_p(ipa, 0, &pt);
626  else
627  getPoint4d_p(ipa, ipa->npoints - 1, &pt);
628 
629  return lwpoint_make(line->srid, has_z, has_m, &pt);
630  }
631 
632  /* Interpolate a point on the line */
633  nsegs = ipa->npoints - 1;
634  length = ptarray_length(ipa);
635  tlength = 0;
636  for (i = 0; i < nsegs; i++)
637  {
638  POINT4D p1, p2;
639  POINT4D *p1ptr = &p1, *p2ptr = &p2; /* don't break
640  * strict-aliasing rules
641  */
642 
643  getPoint4d_p(ipa, i, &p1);
644  getPoint4d_p(ipa, i + 1, &p2);
645 
646  /* Find the relative length of this segment */
647  slength = distance3d_pt_pt((POINT3D *)p1ptr, (POINT3D *)p2ptr) / length;
648 
649  /* If our target distance is before the total length we've seen
650  * so far. create a new point some distance down the current
651  * segment.
652  */
653  if (distance < tlength + slength)
654  {
655  double dseg = (distance - tlength) / slength;
656  interpolate_point4d(&p1, &p2, &pt, dseg);
657  return lwpoint_make(line->srid, has_z, has_m, &pt);
658  }
659  tlength += slength;
660  }
661 
662  /* Return the last point on the line. This shouldn't happen, but
663  * could if there's some floating point rounding errors. */
664  getPoint4d_p(ipa, ipa->npoints - 1, &pt);
665  return lwpoint_make(line->srid, has_z, has_m, &pt);
666 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: gbox.c:426
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoint.c:151
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:689
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:108
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:321
#define LW_FALSE
Definition: liblwgeom.h:108
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2397
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition: lwiterator.c:242
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:110
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:706
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:117
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:656
POINTARRAY * ptarray_removePoint(POINTARRAY *pa, uint32_t where)
Remove a point from a pointarray.
Definition: ptarray.c:553
#define LW_SUCCESS
Definition: liblwgeom.h:111
#define MULTIPOINTTYPE
Definition: liblwgeom.h:119
#define FLAGS_SET_BBOX(flags, value)
Definition: liblwgeom.h:188
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:626
void printPA(POINTARRAY *pa)
Definition: lwgeom_api.c:447
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition: lwiterator.c:267
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
LWGEOM * lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance)
Definition: lwgeom.c:1454
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition: ptarray.c:1700
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:916
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:116
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:179
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)
Definition: measures3d.c:1032
int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point)
Definition: lwgeom_api.c:215
void lwfree(void *mem)
Definition: lwutil.c:242
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:193
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:59
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:180
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:125
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:319
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
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define FLAGS_SET_READONLY(flags, value)
Definition: liblwgeom.h:190
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:693
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
Definition: lwutil.c:471
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
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:450
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:923
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:376
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:677
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:405
LWPOINT * lwpoint_make(int32_t srid, int hasz, int hasm, const POINT4D *p)
Definition: lwpoint.c:206
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:1728
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
Definition: ptarray.c:657
char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2)
Definition: ptarray.c:476
int lwpoint_is_empty(const LWPOINT *point)
POINTARRAY * ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm)
Definition: ptarray.c:1035
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
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:91
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:193
LWLINE * lwline_removepoint(LWLINE *line, uint32_t index)
Definition: lwline.c:347
double lwline_length_2d(const LWLINE *line)
Definition: lwline.c:517
LWPOINT * lwline_interpolate_point_3d(const LWLINE *line, double distance)
Interpolate one point along a line in 3D.
Definition: lwline.c:602
LWLINE * lwline_force_dims(const LWLINE *line, int hasz, int hasm)
Definition: lwline.c:483
LWLINE * lwline_segmentize2d(const LWLINE *line, double dist)
Definition: lwline.c:132
LWLINE * lwline_from_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:228
int lwline_is_closed(const LWLINE *line)
Definition: lwline.c:445
void lwline_release(LWLINE *lwline)
Definition: lwline.c:125
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
void lwline_setPoint4d(LWLINE *line, uint32_t index, POINT4D *newpoint)
Definition: lwline.c:364
LWGEOM * lwline_remove_repeated_points(const LWLINE *lwline, double tolerance)
Definition: lwline.c:439
POINTARRAY * lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat)
Interpolate one or more points along a line.
Definition: lwline.c:525
LWLINE * lwline_clone(const LWLINE *g)
Definition: lwline.c:93
void printLWLINE(LWLINE *line)
Definition: lwline.c:79
LWLINE * lwline_from_lwmpoint(int32_t srid, const LWMPOINT *mpoint)
Definition: lwline.c:275
double lwline_length(const LWLINE *line)
Definition: lwline.c:510
LWLINE * lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end)
Re-write the measure ordinate (or add one, if it isn't already there) interpolating the measure betwe...
Definition: lwline.c:379
char lwline_same(const LWLINE *l1, const LWLINE *l2)
Definition: lwline.c:141
LWLINE * lwline_clone_deep(const LWLINE *g)
Definition: lwline.c:109
int lwline_is_trajectory(const LWLINE *line)
Definition: lwline.c:454
void lwline_free(LWLINE *line)
Definition: lwline.c:67
LWLINE * lwline_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwline.c:55
LWLINE * lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:151
uint32_t lwline_count_vertices(LWLINE *line)
Definition: lwline.c:502
int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where)
Add a LWPOINT to an LWLINE.
Definition: lwline.c:327
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:309
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032
type
Definition: ovdump.py:42
uint8_t type
Definition: liblwgeom.h:448
lwflags_t flags
Definition: liblwgeom.h:471
GBOX * bbox
Definition: liblwgeom.h:468
POINTARRAY * points
Definition: liblwgeom.h:469
uint8_t type
Definition: liblwgeom.h:472
int32_t srid
Definition: liblwgeom.h:470
uint32_t ngeoms
Definition: liblwgeom.h:524
LWPOINT ** geoms
Definition: liblwgeom.h:519
POINTARRAY * point
Definition: liblwgeom.h:457
double y
Definition: liblwgeom.h:376
double x
Definition: liblwgeom.h:376
double m
Definition: liblwgeom.h:394
double z
Definition: liblwgeom.h:382
double x
Definition: liblwgeom.h:382
double y
Definition: liblwgeom.h:382
double m
Definition: liblwgeom.h:400
double x
Definition: liblwgeom.h:400
double z
Definition: liblwgeom.h:400
double y
Definition: liblwgeom.h:400
lwflags_t flags
Definition: liblwgeom.h:417
uint32_t npoints
Definition: liblwgeom.h:413