PostGIS  2.1.10dev-r@@SVN_REVISION@@
LWGEOM* lwgeom_union ( const LWGEOM geom1,
const LWGEOM geom2 
)

Definition at line 707 of file liblwgeom/lwgeom_geos.c.

References error_if_srid_mismatch(), LWGEOM::flags, FLAGS_GET_Z, GEOS2LWGEOM(), LWDEBUG, LWDEBUGF, lwerror(), LWGEOM2GEOS(), lwgeom_clone_deep(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_is_empty(), lwnotice(), result, and LWGEOM::srid.

Referenced by geomunion().

708 {
709  int is3d;
710  int srid;
711  GEOSGeometry *g1, *g2, *g3;
712  LWGEOM *result;
713 
714  LWDEBUG(2, "in geomunion");
715 
716  /* A.Union(empty) == A */
717  if ( lwgeom_is_empty(geom1) )
718  return lwgeom_clone_deep(geom2);
719 
720  /* B.Union(empty) == B */
721  if ( lwgeom_is_empty(geom2) )
722  return lwgeom_clone_deep(geom1);
723 
724 
725  /* ensure srids are identical */
726  srid = (int)(geom1->srid);
727  error_if_srid_mismatch(srid, (int)(geom2->srid));
728 
729  is3d = (FLAGS_GET_Z(geom1->flags) || FLAGS_GET_Z(geom2->flags)) ;
730 
731  initGEOS(lwnotice, lwgeom_geos_error);
732 
733  g1 = LWGEOM2GEOS(geom1);
734 
735  if ( 0 == g1 ) /* exception thrown at construction */
736  {
737  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
738  return NULL;
739  }
740 
741  g2 = LWGEOM2GEOS(geom2);
742 
743  if ( 0 == g2 ) /* exception thrown at construction */
744  {
745  GEOSGeom_destroy(g1);
746  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
747  return NULL;
748  }
749 
750  LWDEBUGF(3, "g1=%s", GEOSGeomToWKT(g1));
751  LWDEBUGF(3, "g2=%s", GEOSGeomToWKT(g2));
752 
753  g3 = GEOSUnion(g1,g2);
754 
755  LWDEBUGF(3, "g3=%s", GEOSGeomToWKT(g3));
756 
757  GEOSGeom_destroy(g1);
758  GEOSGeom_destroy(g2);
759 
760  if (g3 == NULL)
761  {
762  lwerror("GEOSUnion: %s", lwgeom_geos_errmsg);
763  return NULL; /* never get here */
764  }
765 
766 
767  GEOSSetSRID(g3, srid);
768 
769  result = GEOS2LWGEOM(g3, is3d);
770 
771  GEOSGeom_destroy(g3);
772 
773  if (result == NULL)
774  {
775  lwerror("Error performing union: GEOS2LWGEOM: %s",
777  return NULL; /*never get here */
778  }
779 
780  return result;
781 }
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:317
uint8_t flags
Definition: liblwgeom.h:353
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:389
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom)
char ** result
Definition: liblwgeom.h:218
int32_t srid
Definition: liblwgeom.h:355
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void lwgeom_geos_error(const char *fmt,...)
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1229
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55

Here is the call graph for this function:

Here is the caller graph for this function: