352{
354 GEOSGeometry* g1;
355 GEOSGeometry* g2;
356 GEOSGeometry* g1_bounds;
357 GEOSGeometry* polygons;
358 const GEOSGeometry *vgeoms[1];
359 int i,n;
361
362
363
364
365
366
367
368
369
370
372
374 if ( NULL == g1 )
375 {
377 return NULL;
378 }
379 g1_bounds = GEOSBoundary(g1);
380 if ( NULL == g1_bounds )
381 {
382 GEOSGeom_destroy(g1);
384 return NULL;
385 }
386
388 if ( NULL == g2 )
389 {
390 GEOSGeom_destroy(g1);
391 GEOSGeom_destroy(g1_bounds);
393 return NULL;
394 }
395
396 vgeoms[0] = GEOSUnion(g1_bounds, g2);
397 if ( NULL == vgeoms[0] )
398 {
399 GEOSGeom_destroy(g1);
400 GEOSGeom_destroy(g2);
401 GEOSGeom_destroy(g1_bounds);
403 return NULL;
404 }
405
406 polygons = GEOSPolygonize(vgeoms, 1);
407 if ( NULL == polygons )
408 {
409 GEOSGeom_destroy(g1);
410 GEOSGeom_destroy(g2);
411 GEOSGeom_destroy(g1_bounds);
412 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
414 return NULL;
415 }
416
417#ifndef NDEBUG
419 {
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 [%d] Unexpected return from GEOSpolygonize", __FILE__, __LINE__);
426 return 0;
427 }
428#endif
429
430
431
432
433
434 n = GEOSGetNumGeometries(polygons);
436 hasZ, 0);
437
440 for (i=0; i<n; ++i)
441 {
442 GEOSGeometry* pos;
443 const GEOSGeometry* p = GEOSGetGeometryN(polygons, i);
445
446 pos = GEOSPointOnSurface(p);
447 if ( ! pos )
448 {
449 GEOSGeom_destroy(g1);
450 GEOSGeom_destroy(g2);
451 GEOSGeom_destroy(g1_bounds);
452 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
453 GEOSGeom_destroy(polygons);
455 return NULL;
456 }
457
460 {
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);
468 return NULL;
469 }
470
471 GEOSGeom_destroy(pos);
472
474 {
475
476
477
478 continue;
479 }
480
482 }
483
484 GEOSGeom_destroy(g1);
485 GEOSGeom_destroy(g2);
486 GEOSGeom_destroy(g1_bounds);
487 GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]);
488 GEOSGeom_destroy(polygons);
489
491}
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
void lwgeom_geos_error(const char *fmt,...)
void(*) LWGEOM GEOS2LWGEOM)(const GEOSGeometry *geom, uint8_t want3d)
void * lwrealloc(void *mem, size_t size)
#define FLAGS_GET_Z(flags)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Datum contains(PG_FUNCTION_ARGS)
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.