25 #include "../postgis_config.h"
86 gdiff = GEOSBoundary(g2);
94 g2 = gdiff; gdiff = NULL;
98 ret = GEOSRelatePattern(g1, g2,
"1********");
102 GEOSGeom_destroy(g1);
103 GEOSGeom_destroy(g2);
108 GEOSGeom_destroy(g1);
109 GEOSGeom_destroy(g2);
110 lwerror(
"Splitter line has linear intersection with input");
115 gdiff = GEOSDifference(g1,g2);
116 GEOSGeom_destroy(g1);
117 GEOSGeom_destroy(g2);
125 GEOSGeom_destroy(gdiff);
136 components[0] = diff;
138 NULL, 1, components);
182 for (i=0; i<mp->
ngeoms; ++i)
184 for (j=0; j<out->
ngeoms; ++j)
186 lwline_in = out->
geoms[j];
236 if ( ipa->
npoints < 1 )
return 0;
239 for ( i = 0; i < nsegs; i++ )
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 )
249 if ( mindist == 0.0 )
break;
254 LWDEBUGF(3,
"Closest segment: %d", seg);
255 LWDEBUGF(3,
"mindist: %g", mindist);
258 if ( mindist > 0 )
return 0;
275 pt_projected.
x = pt.
x;
276 pt_projected.
y = pt.
y;
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);
281 if ( ( (seg == nsegs-1) &&
p4d_same(&pt_projected, &p2) ) ||
282 ( (seg == 0) &&
p4d_same(&pt_projected, &p1) ) )
291 for (i=0; i<=seg; ++i)
301 for (i=seg+1; i<ipa->
npoints; ++i)
323 switch (blade_in->
type)
337 lwerror(
"Splitting a Line by a %s is unsupported",
351 GEOSGeometry* g1_bounds;
352 GEOSGeometry* polygons;
353 const GEOSGeometry *vgeoms[1];
374 g1_bounds = GEOSBoundary(g1);
375 if ( NULL == g1_bounds )
377 GEOSGeom_destroy(g1);
385 GEOSGeom_destroy(g1);
386 GEOSGeom_destroy(g1_bounds);
391 vgeoms[0] = GEOSUnion(g1_bounds, g2);
392 if ( NULL == vgeoms[0] )
394 GEOSGeom_destroy(g1);
395 GEOSGeom_destroy(g2);
396 GEOSGeom_destroy(g1_bounds);
401 polygons = GEOSPolygonize(vgeoms, 1);
402 if ( NULL == polygons )
404 GEOSGeom_destroy(g1);
405 GEOSGeom_destroy(g2);
406 GEOSGeom_destroy(g1_bounds);
407 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
412 #if PARANOIA_LEVEL > 0
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__);
429 n = GEOSGetNumGeometries(polygons);
438 const GEOSGeometry* p = GEOSGetGeometryN(polygons, i);
441 pos = GEOSPointOnSurface(p);
444 GEOSGeom_destroy(g1);
445 GEOSGeom_destroy(g2);
446 GEOSGeom_destroy(g1_bounds);
447 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
448 GEOSGeom_destroy(polygons);
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);
466 GEOSGeom_destroy(pos);
479 GEOSGeom_destroy(g1);
480 GEOSGeom_destroy(g2);
481 GEOSGeom_destroy(g1_bounds);
482 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
483 GEOSGeom_destroy(polygons);
491 LWGEOM** split_vector=NULL;
493 size_t split_vector_capacity;
494 size_t split_vector_size=0;
497 split_vector_capacity=8;
498 split_vector =
lwalloc(split_vector_capacity *
sizeof(
LWGEOM*));
499 if ( ! split_vector )
501 lwerror(
"Out of virtual memory");
505 for (i=0; i<lwcoll_in->
ngeoms; ++i)
510 if ( ! split )
return NULL;
517 if ( split_vector_size + col->
ngeoms > split_vector_capacity )
520 split_vector_capacity += col->
ngeoms;
522 split_vector_capacity *
sizeof(
LWGEOM*));
523 if ( ! split_vector )
525 lwerror(
"Out of virtual memory");
530 for (j=0; j<col->
ngeoms; ++j)
533 split_vector[split_vector_size++] = col->
geoms[j];
541 NULL, split_vector_size, split_vector);
549 switch (blade_in->
type)
555 lwerror(
"Splitting a Polygon by a %s is unsupported",
566 switch (lwgeom_in->
type)
580 lwerror(
"Splitting of %s geometries is unsupported",
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,...)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
LWMLINE * lwmline_construct_empty(int srid, char hasz, char hasm)
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
void * lwrealloc(void *mem, size_t size)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
#define FLAGS_GET_M(flags)
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
void ptarray_free(POINTARRAY *pa)
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
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,...
void * lwalloc(size_t size)
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
#define SRID_UNKNOWN
Unknown SRID value.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
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)
LWLINE * lwline_clone_deep(const LWLINE *lwgeom)
int p4d_same(const POINT4D *p1, const POINT4D *p2)
void closest_point_on_segment(const POINT4D *R, const POINT4D *A, const POINT4D *B, POINT4D *ret)
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,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Datum contains(PG_FUNCTION_ARGS)