PostGIS  2.5.7dev-r@@SVN_REVISION@@
lwgeom_geos_split.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 2011-2015 Sandro Santilli <strk@kbt.io>
22  *
23  **********************************************************************/
24 
25 #include "../postgis_config.h"
26 /*#define POSTGIS_DEBUG_LEVEL 4*/
27 #include "lwgeom_geos.h"
28 #include "liblwgeom_internal.h"
29 
30 #include <string.h>
31 #include <assert.h>
32 
33 static LWGEOM* lwline_split_by_line(const LWLINE* lwgeom_in, const LWGEOM* blade_in);
34 static LWGEOM* lwline_split_by_point(const LWLINE* lwgeom_in, const LWPOINT* blade_in);
35 static LWGEOM* lwline_split_by_mpoint(const LWLINE* lwgeom_in, const LWMPOINT* blade_in);
36 static LWGEOM* lwline_split(const LWLINE* lwgeom_in, const LWGEOM* blade_in);
37 static LWGEOM* lwpoly_split_by_line(const LWPOLY* lwgeom_in, const LWGEOM* blade_in);
38 static LWGEOM* lwcollection_split(const LWCOLLECTION* lwcoll_in, const LWGEOM* blade_in);
39 static LWGEOM* lwpoly_split(const LWPOLY* lwpoly_in, const LWGEOM* blade_in);
40 
41 /* Initializes and uses GEOS internally */
42 static LWGEOM*
43 lwline_split_by_line(const LWLINE* lwline_in, const LWGEOM* blade_in)
44 {
45  LWGEOM** components;
46  LWGEOM* diff;
47  LWCOLLECTION* out;
48  GEOSGeometry* gdiff; /* difference */
49  GEOSGeometry* g1;
50  GEOSGeometry* g2;
51  int ret;
52 
53  /* ASSERT blade_in is LINE or MULTILINE */
54  assert (blade_in->type == LINETYPE ||
55  blade_in->type == MULTILINETYPE ||
56  blade_in->type == POLYGONTYPE ||
57  blade_in->type == MULTIPOLYGONTYPE );
58 
59  /* Possible outcomes:
60  *
61  * 1. The lines do not cross or overlap
62  * -> Return a collection with single element
63  * 2. The lines cross
64  * -> Return a collection of all elements resulting from the split
65  */
66 
68 
69  g1 = LWGEOM2GEOS((LWGEOM*)lwline_in, 0);
70  if ( ! g1 )
71  {
72  lwerror("LWGEOM2GEOS: %s", lwgeom_geos_errmsg);
73  return NULL;
74  }
75  g2 = LWGEOM2GEOS(blade_in, 0);
76  if ( ! g2 )
77  {
78  GEOSGeom_destroy(g1);
79  lwerror("LWGEOM2GEOS: %s", lwgeom_geos_errmsg);
80  return NULL;
81  }
82 
83  /* If blade is a polygon, pick its boundary */
84  if ( blade_in->type == POLYGONTYPE || blade_in->type == MULTIPOLYGONTYPE )
85  {
86  gdiff = GEOSBoundary(g2);
87  GEOSGeom_destroy(g2);
88  if ( ! gdiff )
89  {
90  GEOSGeom_destroy(g1);
91  lwerror("GEOSBoundary: %s", lwgeom_geos_errmsg);
92  return NULL;
93  }
94  g2 = gdiff; gdiff = NULL;
95  }
96 
97  /* If interior intersecton is linear we can't split */
98  ret = GEOSRelatePattern(g1, g2, "1********");
99  if ( 2 == ret )
100  {
101  lwerror("GEOSRelatePattern: %s", lwgeom_geos_errmsg);
102  GEOSGeom_destroy(g1);
103  GEOSGeom_destroy(g2);
104  return NULL;
105  }
106  if ( ret )
107  {
108  GEOSGeom_destroy(g1);
109  GEOSGeom_destroy(g2);
110  lwerror("Splitter line has linear intersection with input");
111  return NULL;
112  }
113 
114 
115  gdiff = GEOSDifference(g1,g2);
116  GEOSGeom_destroy(g1);
117  GEOSGeom_destroy(g2);
118  if (gdiff == NULL)
119  {
120  lwerror("GEOSDifference: %s", lwgeom_geos_errmsg);
121  return NULL;
122  }
123 
124  diff = GEOS2LWGEOM(gdiff, FLAGS_GET_Z(lwline_in->flags));
125  GEOSGeom_destroy(gdiff);
126  if (NULL == diff)
127  {
128  lwerror("GEOS2LWGEOM: %s", lwgeom_geos_errmsg);
129  return NULL;
130  }
131 
132  out = lwgeom_as_lwcollection(diff);
133  if ( ! out )
134  {
135  components = lwalloc(sizeof(LWGEOM*)*1);
136  components[0] = diff;
137  out = lwcollection_construct(COLLECTIONTYPE, lwline_in->srid,
138  NULL, 1, components);
139  }
140  else
141  {
142  /* Set SRID */
143  lwgeom_set_srid((LWGEOM*)out, lwline_in->srid);
144  /* Force collection type */
145  out->type = COLLECTIONTYPE;
146  }
147 
148 
149  return (LWGEOM*)out;
150 }
151 
152 static LWGEOM*
153 lwline_split_by_point(const LWLINE* lwline_in, const LWPOINT* blade_in)
154 {
155  LWMLINE* out;
156 
157  out = lwmline_construct_empty(lwline_in->srid,
158  FLAGS_GET_Z(lwline_in->flags),
159  FLAGS_GET_M(lwline_in->flags));
160  if ( lwline_split_by_point_to(lwline_in, blade_in, out) < 2 )
161  {
162  lwmline_add_lwline(out, lwline_clone_deep(lwline_in));
163  }
164 
165  /* Turn multiline into collection */
166  out->type = COLLECTIONTYPE;
167 
168  return (LWGEOM*)out;
169 }
170 
171 static LWGEOM*
172 lwline_split_by_mpoint(const LWLINE* lwline_in, const LWMPOINT* mp)
173 {
174  LWMLINE* out;
175  uint32_t i, j;
176 
177  out = lwmline_construct_empty(lwline_in->srid,
178  FLAGS_GET_Z(lwline_in->flags),
179  FLAGS_GET_M(lwline_in->flags));
180  lwmline_add_lwline(out, lwline_clone_deep(lwline_in));
181 
182  for (i=0; i<mp->ngeoms; ++i)
183  {
184  for (j=0; j<out->ngeoms; ++j)
185  {
186  lwline_in = out->geoms[j];
187  LWPOINT *blade_in = mp->geoms[i];
188  int ret = lwline_split_by_point_to(lwline_in, blade_in, out);
189  if ( 2 == ret )
190  {
191  /* the point splits this line,
192  * 2 splits were added to collection.
193  * We'll move the latest added into
194  * the slot of the current one.
195  */
196  lwline_free(out->geoms[j]);
197  out->geoms[j] = out->geoms[--out->ngeoms];
198  }
199  }
200  }
201 
202  /* Turn multiline into collection */
203  out->type = COLLECTIONTYPE;
204 
205  return (LWGEOM*)out;
206 }
207 
208 int
209 lwline_split_by_point_to(const LWLINE* lwline_in, const LWPOINT* blade_in,
210  LWMLINE* v)
211 {
212  double mindist = -1;
213  POINT4D pt, pt_projected;
214  POINT4D p1, p2;
215  POINTARRAY *ipa = lwline_in->points;
216  POINTARRAY* pa1;
217  POINTARRAY* pa2;
218  uint32_t i, nsegs, seg = UINT32_MAX;
219 
220  /* Possible outcomes:
221  *
222  * 1. The point is not on the line or on the boundary
223  * -> Leave collection untouched, return 0
224  * 2. The point is on the boundary
225  * -> Leave collection untouched, return 1
226  * 3. The point is in the line
227  * -> Push 2 elements on the collection:
228  * o start_point - cut_point
229  * o cut_point - last_point
230  * -> Return 2
231  */
232 
233  getPoint4d_p(blade_in->point, 0, &pt);
234 
235  /* Find closest segment */
236  if ( ipa->npoints < 1 ) return 0; /* empty input line */
237  getPoint4d_p(ipa, 0, &p1);
238  nsegs = ipa->npoints - 1;
239  for ( i = 0; i < nsegs; i++ )
240  {
241  getPoint4d_p(ipa, i+1, &p2);
242  double dist;
243  dist = distance2d_pt_seg((POINT2D*)&pt, (POINT2D*)&p1, (POINT2D*)&p2);
244  LWDEBUGF(4, " Distance of point %g %g to segment %g %g, %g %g: %g", pt.x, pt.y, p1.x, p1.y, p2.x, p2.y, dist);
245  if (i==0 || dist < mindist )
246  {
247  mindist = dist;
248  seg=i;
249  if ( mindist == 0.0 ) break; /* can't be closer than ON line */
250  }
251  p1 = p2;
252  }
253 
254  LWDEBUGF(3, "Closest segment: %d", seg);
255  LWDEBUGF(3, "mindist: %g", mindist);
256 
257  /* No intersection */
258  if ( mindist > 0 ) return 0;
259 
260  /* empty or single-point line, intersection on boundary */
261  if ( seg == UINT32_MAX ) return 1;
262 
263  /*
264  * We need to project the
265  * point on the closest segment,
266  * to interpolate Z and M if needed
267  */
268  getPoint4d_p(ipa, seg, &p1);
269  getPoint4d_p(ipa, seg+1, &p2);
270  closest_point_on_segment(&pt, &p1, &p2, &pt_projected);
271  /* But X and Y we want the ones of the input point,
272  * as on some architectures the interpolation math moves the
273  * coordinates (see #3422)
274  */
275  pt_projected.x = pt.x;
276  pt_projected.y = pt.y;
277 
278  LWDEBUGF(3, "Projected point:(%g %g), seg:%d, p1:(%g %g), p2:(%g %g)", pt_projected.x, pt_projected.y, seg, p1.x, p1.y, p2.x, p2.y);
279 
280  /* When closest point == an endpoint, this is a boundary intersection */
281  if ( ( (seg == nsegs-1) && p4d_same(&pt_projected, &p2) ) ||
282  ( (seg == 0) && p4d_same(&pt_projected, &p1) ) )
283  {
284  return 1;
285  }
286 
287  /* This is an internal intersection, let's build the two new pointarrays */
288 
289  pa1 = ptarray_construct_empty(FLAGS_GET_Z(ipa->flags), FLAGS_GET_M(ipa->flags), seg+2);
290  /* TODO: replace with a memcpy ? */
291  for (i=0; i<=seg; ++i)
292  {
293  getPoint4d_p(ipa, i, &p1);
294  ptarray_append_point(pa1, &p1, LW_FALSE);
295  }
296  ptarray_append_point(pa1, &pt_projected, LW_FALSE);
297 
298  pa2 = ptarray_construct_empty(FLAGS_GET_Z(ipa->flags), FLAGS_GET_M(ipa->flags), ipa->npoints-seg);
299  ptarray_append_point(pa2, &pt_projected, LW_FALSE);
300  /* TODO: replace with a memcpy (if so need to check for duplicated point) ? */
301  for (i=seg+1; i<ipa->npoints; ++i)
302  {
303  getPoint4d_p(ipa, i, &p1);
304  ptarray_append_point(pa2, &p1, LW_FALSE);
305  }
306 
307  /* NOTE: I've seen empty pointarrays with loc != 0 and loc != 1 */
308  if ( pa1->npoints == 0 || pa2->npoints == 0 ) {
309  ptarray_free(pa1);
310  ptarray_free(pa2);
311  /* Intersection is on the boundary */
312  return 1;
313  }
314 
317  return 2;
318 }
319 
320 static LWGEOM*
321 lwline_split(const LWLINE* lwline_in, const LWGEOM* blade_in)
322 {
323  switch (blade_in->type)
324  {
325  case POINTTYPE:
326  return lwline_split_by_point(lwline_in, (LWPOINT*)blade_in);
327  case MULTIPOINTTYPE:
328  return lwline_split_by_mpoint(lwline_in, (LWMPOINT*)blade_in);
329 
330  case LINETYPE:
331  case MULTILINETYPE:
332  case POLYGONTYPE:
333  case MULTIPOLYGONTYPE:
334  return lwline_split_by_line(lwline_in, blade_in);
335 
336  default:
337  lwerror("Splitting a Line by a %s is unsupported",
338  lwtype_name(blade_in->type));
339  return NULL;
340  }
341  return NULL;
342 }
343 
344 /* Initializes and uses GEOS internally */
345 static LWGEOM*
346 lwpoly_split_by_line(const LWPOLY* lwpoly_in, const LWGEOM* blade_in)
347 {
348  LWCOLLECTION* out;
349  GEOSGeometry* g1;
350  GEOSGeometry* g2;
351  GEOSGeometry* g1_bounds;
352  GEOSGeometry* polygons;
353  const GEOSGeometry *vgeoms[1];
354  int i,n;
355  int hasZ = FLAGS_GET_Z(lwpoly_in->flags);
356 
357 
358  /* Possible outcomes:
359  *
360  * 1. The line does not split the polygon
361  * -> Return a collection with single element
362  * 2. The line does split the polygon
363  * -> Return a collection of all elements resulting from the split
364  */
365 
367 
368  g1 = LWGEOM2GEOS((LWGEOM*)lwpoly_in, 0);
369  if ( NULL == g1 )
370  {
371  lwerror("LWGEOM2GEOS: %s", lwgeom_geos_errmsg);
372  return NULL;
373  }
374  g1_bounds = GEOSBoundary(g1);
375  if ( NULL == g1_bounds )
376  {
377  GEOSGeom_destroy(g1);
378  lwerror("GEOSBoundary: %s", lwgeom_geos_errmsg);
379  return NULL;
380  }
381 
382  g2 = LWGEOM2GEOS(blade_in, 0);
383  if ( NULL == g2 )
384  {
385  GEOSGeom_destroy(g1);
386  GEOSGeom_destroy(g1_bounds);
387  lwerror("LWGEOM2GEOS: %s", lwgeom_geos_errmsg);
388  return NULL;
389  }
390 
391  vgeoms[0] = GEOSUnion(g1_bounds, g2);
392  if ( NULL == vgeoms[0] )
393  {
394  GEOSGeom_destroy(g1);
395  GEOSGeom_destroy(g2);
396  GEOSGeom_destroy(g1_bounds);
397  lwerror("GEOSUnion: %s", lwgeom_geos_errmsg);
398  return NULL;
399  }
400 
401  polygons = GEOSPolygonize(vgeoms, 1);
402  if ( NULL == polygons )
403  {
404  GEOSGeom_destroy(g1);
405  GEOSGeom_destroy(g2);
406  GEOSGeom_destroy(g1_bounds);
407  GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
408  lwerror("GEOSPolygonize: %s", lwgeom_geos_errmsg);
409  return NULL;
410  }
411 
412 #if PARANOIA_LEVEL > 0
413  if ( GEOSGeomTypeId(polygons) != COLLECTIONTYPE )
414  {
415  GEOSGeom_destroy(g1);
416  GEOSGeom_destroy(g2);
417  GEOSGeom_destroy(g1_bounds);
418  GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
419  GEOSGeom_destroy(polygons);
420  lwerror("%s [%s] Unexpected return from GEOSpolygonize", __FILE__, __LINE__);
421  return 0;
422  }
423 #endif
424 
425  /* We should now have all polygons, just skip
426  * the ones which are in holes of the original
427  * geometries and return the rest in a collection
428  */
429  n = GEOSGetNumGeometries(polygons);
431  hasZ, 0);
432  /* Allocate space for all polys */
433  out->geoms = lwrealloc(out->geoms, sizeof(LWGEOM*)*n);
434  assert(0 == out->ngeoms);
435  for (i=0; i<n; ++i)
436  {
437  GEOSGeometry* pos; /* point on surface */
438  const GEOSGeometry* p = GEOSGetGeometryN(polygons, i);
439  int contains;
440 
441  pos = GEOSPointOnSurface(p);
442  if ( ! pos )
443  {
444  GEOSGeom_destroy(g1);
445  GEOSGeom_destroy(g2);
446  GEOSGeom_destroy(g1_bounds);
447  GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
448  GEOSGeom_destroy(polygons);
449  lwerror("GEOSPointOnSurface: %s", lwgeom_geos_errmsg);
450  return NULL;
451  }
452 
453  contains = GEOSContains(g1, pos);
454  if ( 2 == contains )
455  {
456  GEOSGeom_destroy(g1);
457  GEOSGeom_destroy(g2);
458  GEOSGeom_destroy(g1_bounds);
459  GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
460  GEOSGeom_destroy(polygons);
461  GEOSGeom_destroy(pos);
462  lwerror("GEOSContains: %s", lwgeom_geos_errmsg);
463  return NULL;
464  }
465 
466  GEOSGeom_destroy(pos);
467 
468  if ( 0 == contains )
469  {
470  /* Original geometry doesn't contain
471  * a point in this ring, must be an hole
472  */
473  continue;
474  }
475 
476  out->geoms[out->ngeoms++] = GEOS2LWGEOM(p, hasZ);
477  }
478 
479  GEOSGeom_destroy(g1);
480  GEOSGeom_destroy(g2);
481  GEOSGeom_destroy(g1_bounds);
482  GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
483  GEOSGeom_destroy(polygons);
484 
485  return (LWGEOM*)out;
486 }
487 
488 static LWGEOM*
489 lwcollection_split(const LWCOLLECTION* lwcoll_in, const LWGEOM* blade_in)
490 {
491  LWGEOM** split_vector=NULL;
492  LWCOLLECTION* out;
493  size_t split_vector_capacity;
494  size_t split_vector_size=0;
495  size_t i,j;
496 
497  split_vector_capacity=8;
498  split_vector = lwalloc(split_vector_capacity * sizeof(LWGEOM*));
499  if ( ! split_vector )
500  {
501  lwerror("Out of virtual memory");
502  return NULL;
503  }
504 
505  for (i=0; i<lwcoll_in->ngeoms; ++i)
506  {
507  LWCOLLECTION* col;
508  LWGEOM* split = lwgeom_split(lwcoll_in->geoms[i], blade_in);
509  /* an exception should prevent this from ever returning NULL */
510  if ( ! split ) return NULL;
511 
512  col = lwgeom_as_lwcollection(split);
513  /* Output, if any, will always be a collection */
514  assert(col);
515 
516  /* Reallocate split_vector if needed */
517  if ( split_vector_size + col->ngeoms > split_vector_capacity )
518  {
519  /* NOTE: we could be smarter on reallocations here */
520  split_vector_capacity += col->ngeoms;
521  split_vector = lwrealloc(split_vector,
522  split_vector_capacity * sizeof(LWGEOM*));
523  if ( ! split_vector )
524  {
525  lwerror("Out of virtual memory");
526  return NULL;
527  }
528  }
529 
530  for (j=0; j<col->ngeoms; ++j)
531  {
532  col->geoms[j]->srid = SRID_UNKNOWN; /* strip srid */
533  split_vector[split_vector_size++] = col->geoms[j];
534  }
535  lwfree(col->geoms);
536  lwfree(col);
537  }
538 
539  /* Now split_vector has split_vector_size geometries */
540  out = lwcollection_construct(COLLECTIONTYPE, lwcoll_in->srid,
541  NULL, split_vector_size, split_vector);
542 
543  return (LWGEOM*)out;
544 }
545 
546 static LWGEOM*
547 lwpoly_split(const LWPOLY* lwpoly_in, const LWGEOM* blade_in)
548 {
549  switch (blade_in->type)
550  {
551  case MULTILINETYPE:
552  case LINETYPE:
553  return lwpoly_split_by_line(lwpoly_in, blade_in);
554  default:
555  lwerror("Splitting a Polygon by a %s is unsupported",
556  lwtype_name(blade_in->type));
557  return NULL;
558  }
559  return NULL;
560 }
561 
562 /* exported */
563 LWGEOM*
564 lwgeom_split(const LWGEOM* lwgeom_in, const LWGEOM* blade_in)
565 {
566  switch (lwgeom_in->type)
567  {
568  case LINETYPE:
569  return lwline_split((const LWLINE*)lwgeom_in, blade_in);
570 
571  case POLYGONTYPE:
572  return lwpoly_split((const LWPOLY*)lwgeom_in, blade_in);
573 
574  case MULTIPOLYGONTYPE:
575  case MULTILINETYPE:
576  case COLLECTIONTYPE:
577  return lwcollection_split((const LWCOLLECTION*)lwgeom_in, blade_in);
578 
579  default:
580  lwerror("Splitting of %s geometries is unsupported",
581  lwtype_name(lwgeom_in->type));
582  return NULL;
583  }
584 
585 }
586 
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
void lwgeom_geos_error(const char *fmt,...)
#define LW_FALSE
Definition: liblwgeom.h:77
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
#define MULTILINETYPE
Definition: liblwgeom.h:89
LWMLINE * lwmline_construct_empty(int srid, char hasz, char hasm)
Definition: lwmline.c:38
#define LINETYPE
Definition: liblwgeom.h:86
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
Definition: lwmline.c:46
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2332
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:237
void lwfree(void *mem)
Definition: lwutil.c:244
#define POLYGONTYPE
Definition: liblwgeom.h:87
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:123
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:328
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
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:156
void * lwalloc(size_t size)
Definition: lwutil.c:229
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:224
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
void lwgeom_set_srid(LWGEOM *geom, int srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
void lwline_free(LWLINE *line)
Definition: lwline.c:76
LWLINE * lwline_clone_deep(const LWLINE *lwgeom)
Definition: lwline.c:118
int p4d_same(const POINT4D *p1, const POINT4D *p2)
Definition: lwalgorithm.c:31
void closest_point_on_segment(const POINT4D *R, const POINT4D *A, const POINT4D *B, POINT4D *ret)
Definition: ptarray.c:1257
static LWGEOM * lwline_split_by_mpoint(const LWLINE *lwgeom_in, const LWMPOINT *blade_in)
static LWGEOM * lwpoly_split_by_line(const LWPOLY *lwgeom_in, const LWGEOM *blade_in)
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
static LWGEOM * lwline_split(const LWLINE *lwgeom_in, const LWGEOM *blade_in)
static LWGEOM * lwline_split_by_point(const LWLINE *lwgeom_in, const LWPOINT *blade_in)
static LWGEOM * lwpoly_split(const LWPOLY *lwpoly_in, const LWGEOM *blade_in)
int lwline_split_by_point_to(const LWLINE *lwline_in, const LWPOINT *blade_in, LWMLINE *v)
Split a line by a point and push components to the provided multiline.
static LWGEOM * lwline_split_by_line(const LWLINE *lwgeom_in, const LWGEOM *blade_in)
static LWGEOM * lwcollection_split(const LWCOLLECTION *lwcoll_in, const LWGEOM *blade_in)
#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
#define UINT32_MAX
Definition: lwin_wkt_lex.c:343
Datum contains(PG_FUNCTION_ARGS)
uint32_t ngeoms
Definition: liblwgeom.h:510
LWGEOM ** geoms
Definition: liblwgeom.h:512
int32_t srid
Definition: liblwgeom.h:509
uint8_t type
Definition: liblwgeom.h:399
int32_t srid
Definition: liblwgeom.h:402
uint8_t flags
Definition: liblwgeom.h:422
POINTARRAY * points
Definition: liblwgeom.h:425
uint8_t type
Definition: liblwgeom.h:421
int32_t srid
Definition: liblwgeom.h:424
LWLINE ** geoms
Definition: liblwgeom.h:486
uint8_t type
Definition: liblwgeom.h:480
uint32_t ngeoms
Definition: liblwgeom.h:484
uint32_t ngeoms
Definition: liblwgeom.h:471
LWPOINT ** geoms
Definition: liblwgeom.h:473
POINTARRAY * point
Definition: liblwgeom.h:414
uint8_t type
Definition: liblwgeom.h:410
uint8_t flags
Definition: liblwgeom.h:455
int32_t srid
Definition: liblwgeom.h:457
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355
uint32_t npoints
Definition: liblwgeom.h:374
uint8_t flags
Definition: liblwgeom.h:372
unsigned int uint32_t
Definition: uthash.h:78