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];
212 double mindist_sqr = -1;
236 if ( ipa->
npoints < 1 )
return 0;
239 for ( i = 0; i < nsegs; i++ )
243 LWDEBUGF(4,
"Distance (squared) of point %g %g to segment %g %g, %g %g: %g",
248 if (i == 0 || dist_sqr < mindist_sqr)
250 mindist_sqr = dist_sqr;
252 if (mindist_sqr == 0.0)
258 LWDEBUGF(3,
"Closest segment: %d", seg);
259 LWDEBUGF(3,
"mindist: %g", mindist_sqr);
280 pt_projected.
x = pt.
x;
281 pt_projected.
y = pt.
y;
283 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);
286 if ( ( (seg == nsegs-1) &&
p4d_same(&pt_projected, &p2) ) ||
287 ( (seg == 0) &&
p4d_same(&pt_projected, &p1) ) )
296 for (i=0; i<=seg; ++i)
306 for (i=seg+1; i<ipa->
npoints; ++i)
328 switch (blade_in->
type)
342 lwerror(
"Splitting a Line by a %s is unsupported",
356 GEOSGeometry* g1_bounds;
357 GEOSGeometry* polygons;
358 const GEOSGeometry *vgeoms[1];
379 g1_bounds = GEOSBoundary(g1);
380 if ( NULL == g1_bounds )
382 GEOSGeom_destroy(g1);
390 GEOSGeom_destroy(g1);
391 GEOSGeom_destroy(g1_bounds);
396 vgeoms[0] = GEOSUnion(g1_bounds, g2);
397 if ( NULL == vgeoms[0] )
399 GEOSGeom_destroy(g1);
400 GEOSGeom_destroy(g2);
401 GEOSGeom_destroy(g1_bounds);
406 polygons = GEOSPolygonize(vgeoms, 1);
407 if ( NULL == polygons )
409 GEOSGeom_destroy(g1);
410 GEOSGeom_destroy(g2);
411 GEOSGeom_destroy(g1_bounds);
412 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
417 #if PARANOIA_LEVEL > 0
420 GEOSGeom_destroy(g1);
421 GEOSGeom_destroy(g2);
422 GEOSGeom_destroy(g1_bounds);
423 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
424 GEOSGeom_destroy(polygons);
425 lwerror(
"%s [%s] Unexpected return from GEOSpolygonize", __FILE__, __LINE__);
434 n = GEOSGetNumGeometries(polygons);
443 const GEOSGeometry* p = GEOSGetGeometryN(polygons, i);
446 pos = GEOSPointOnSurface(p);
449 GEOSGeom_destroy(g1);
450 GEOSGeom_destroy(g2);
451 GEOSGeom_destroy(g1_bounds);
452 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
453 GEOSGeom_destroy(polygons);
461 GEOSGeom_destroy(g1);
462 GEOSGeom_destroy(g2);
463 GEOSGeom_destroy(g1_bounds);
464 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
465 GEOSGeom_destroy(polygons);
466 GEOSGeom_destroy(pos);
471 GEOSGeom_destroy(pos);
484 GEOSGeom_destroy(g1);
485 GEOSGeom_destroy(g2);
486 GEOSGeom_destroy(g1_bounds);
487 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
488 GEOSGeom_destroy(polygons);
496 LWGEOM** split_vector=NULL;
498 size_t split_vector_capacity;
499 size_t split_vector_size=0;
502 split_vector_capacity=8;
503 split_vector =
lwalloc(split_vector_capacity *
sizeof(
LWGEOM*));
504 if ( ! split_vector )
506 lwerror(
"Out of virtual memory");
510 for (i=0; i<lwcoll_in->
ngeoms; ++i)
515 if ( ! split )
return NULL;
522 if ( split_vector_size + col->
ngeoms > split_vector_capacity )
525 split_vector_capacity += col->
ngeoms;
527 split_vector_capacity *
sizeof(
LWGEOM*));
528 if ( ! split_vector )
530 lwerror(
"Out of virtual memory");
535 for (j=0; j<col->
ngeoms; ++j)
538 split_vector[split_vector_size++] = col->
geoms[j];
546 NULL, split_vector_size, split_vector);
554 switch (blade_in->
type)
560 lwerror(
"Splitting a Polygon by a %s is unsupported",
571 switch (lwgeom_in->
type)
585 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,...)
void lwgeom_set_srid(LWGEOM *geom, int32_t srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
LWMLINE * lwmline_construct_empty(int32_t srid, char hasz, char hasm)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_Z(flags)
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
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.
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
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)
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
void ptarray_free(POINTARRAY *pa)
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 * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
#define SRID_UNKNOWN
Unknown SRID value.
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)