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];
218 int i, nsegs, seg = -1;
238 for ( i = 0; i < nsegs; i++ )
243 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);
244 if (i==0 || dist < mindist )
248 if ( mindist == 0.0 )
break;
253 LWDEBUGF(3,
"Closest segment: %d", seg);
254 LWDEBUGF(3,
"mindist: %g", mindist);
257 if ( mindist > 0 )
return 0;
260 if ( seg < 0 )
return 1;
274 pt_projected.
x = pt.
x;
275 pt_projected.
y = pt.
y;
277 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);
280 if ( ( (seg == nsegs-1) &&
p4d_same(&pt_projected, &p2) ) ||
281 ( (seg == 0) &&
p4d_same(&pt_projected, &p1) ) )
290 for (i=0; i<=seg; ++i)
300 for (i=seg+1; i<ipa->
npoints; ++i)
322 switch (blade_in->
type)
336 lwerror(
"Splitting a Line by a %s is unsupported",
350 GEOSGeometry* g1_bounds;
351 GEOSGeometry* polygons;
352 const GEOSGeometry *vgeoms[1];
373 g1_bounds = GEOSBoundary(g1);
374 if ( NULL == g1_bounds )
376 GEOSGeom_destroy(g1);
384 GEOSGeom_destroy(g1);
385 GEOSGeom_destroy(g1_bounds);
390 vgeoms[0] = GEOSUnion(g1_bounds, g2);
391 if ( NULL == vgeoms[0] )
393 GEOSGeom_destroy(g1);
394 GEOSGeom_destroy(g2);
395 GEOSGeom_destroy(g1_bounds);
400 polygons = GEOSPolygonize(vgeoms, 1);
401 if ( NULL == polygons )
403 GEOSGeom_destroy(g1);
404 GEOSGeom_destroy(g2);
405 GEOSGeom_destroy(g1_bounds);
406 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
411 #if PARANOIA_LEVEL > 0 414 GEOSGeom_destroy(g1);
415 GEOSGeom_destroy(g2);
416 GEOSGeom_destroy(g1_bounds);
417 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
418 GEOSGeom_destroy(polygons);
419 lwerror(
"%s [%s] Unexpected return from GEOSpolygonize", __FILE__, __LINE__);
428 n = GEOSGetNumGeometries(polygons);
437 const GEOSGeometry* p = GEOSGetGeometryN(polygons, i);
440 pos = GEOSPointOnSurface(p);
443 GEOSGeom_destroy(g1);
444 GEOSGeom_destroy(g2);
445 GEOSGeom_destroy(g1_bounds);
446 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
447 GEOSGeom_destroy(polygons);
452 contains = GEOSContains(g1, pos);
455 GEOSGeom_destroy(g1);
456 GEOSGeom_destroy(g2);
457 GEOSGeom_destroy(g1_bounds);
458 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
459 GEOSGeom_destroy(polygons);
460 GEOSGeom_destroy(pos);
465 GEOSGeom_destroy(pos);
478 GEOSGeom_destroy(g1);
479 GEOSGeom_destroy(g2);
480 GEOSGeom_destroy(g1_bounds);
481 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
482 GEOSGeom_destroy(polygons);
490 LWGEOM** split_vector=NULL;
492 size_t split_vector_capacity;
493 size_t split_vector_size=0;
496 split_vector_capacity=8;
497 split_vector =
lwalloc(split_vector_capacity *
sizeof(
LWGEOM*));
498 if ( ! split_vector )
500 lwerror(
"Out of virtual memory");
504 for (i=0; i<lwcoll_in->
ngeoms; ++i)
509 if ( ! split )
return NULL;
516 if ( split_vector_size + col->
ngeoms > split_vector_capacity )
519 split_vector_capacity += col->
ngeoms;
521 split_vector_capacity *
sizeof(
LWGEOM*));
522 if ( ! split_vector )
524 lwerror(
"Out of virtual memory");
529 for (j=0; j<col->
ngeoms; ++j)
532 split_vector[split_vector_size++] = col->
geoms[j];
540 NULL, split_vector_size, split_vector);
548 switch (blade_in->
type)
553 lwerror(
"Splitting a Polygon by a %s is unsupported",
564 switch (lwgeom_in->
type)
578 lwerror(
"Splitting of %s geometries is unsupported",
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
static LWGEOM * lwline_split(const LWLINE *lwgeom_in, const LWGEOM *blade_in)
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
void ptarray_free(POINTARRAY *pa)
void lwline_free(LWLINE *line)
Datum contains(PG_FUNCTION_ARGS)
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
static LWGEOM * lwline_split_by_mpoint(const LWLINE *lwgeom_in, const LWMPOINT *blade_in)
static LWGEOM * lwline_split_by_line(const LWLINE *lwgeom_in, const LWGEOM *blade_in)
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
The old function nessecary for ptarray_segmentize2d in ptarray.c.
LWMLINE * lwmline_construct_empty(int srid, char hasz, char hasm)
static LWGEOM * lwcollection_split(const LWCOLLECTION *lwcoll_in, const LWGEOM *blade_in)
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
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, then a duplicate point will not be added.
void lwgeom_geos_error(const char *fmt,...)
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
#define SRID_UNKNOWN
Unknown SRID value.
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, int autofix)
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.
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
static LWGEOM * lwpoly_split(const LWPOLY *lwpoly_in, const LWGEOM *blade_in)
void * lwrealloc(void *mem, size_t size)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_M(flags)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
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 * lwalloc(size_t size)
void closest_point_on_segment(const POINT4D *R, const POINT4D *A, const POINT4D *B, POINT4D *ret)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
LWLINE * lwline_clone_deep(const LWLINE *lwgeom)
#define LWDEBUGF(level, msg,...)
static LWGEOM * lwpoly_split_by_line(const LWPOLY *lwgeom_in, const LWLINE *blade_in)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
int p4d_same(const POINT4D *p1, const POINT4D *p2)
static LWGEOM * lwline_split_by_point(const LWLINE *lwgeom_in, const LWPOINT *blade_in)