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

Definition at line 992 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(), and LWGEOM::srid.

Referenced by _lwt_AddLine(), and geos_geomunion().

993 {
994  int is3d;
995  int srid;
996  GEOSGeometry *g1, *g2, *g3;
997  LWGEOM *result;
998 
999  LWDEBUG(2, "in geomunion");
1000 
1001  /* A.Union(empty) == A */
1002  if ( lwgeom_is_empty(geom1) )
1003  return lwgeom_clone_deep(geom2);
1004 
1005  /* B.Union(empty) == B */
1006  if ( lwgeom_is_empty(geom2) )
1007  return lwgeom_clone_deep(geom1);
1008 
1009 
1010  /* ensure srids are identical */
1011  srid = (int)(geom1->srid);
1012  error_if_srid_mismatch(srid, (int)(geom2->srid));
1013 
1014  is3d = (FLAGS_GET_Z(geom1->flags) || FLAGS_GET_Z(geom2->flags)) ;
1015 
1016  initGEOS(lwnotice, lwgeom_geos_error);
1017 
1018  g1 = LWGEOM2GEOS(geom1, 0);
1019 
1020  if ( 0 == g1 ) /* exception thrown at construction */
1021  {
1022  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1023  return NULL;
1024  }
1025 
1026  g2 = LWGEOM2GEOS(geom2, 0);
1027 
1028  if ( 0 == g2 ) /* exception thrown at construction */
1029  {
1030  GEOSGeom_destroy(g1);
1031  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1032  return NULL;
1033  }
1034 
1035  LWDEBUGF(3, "g1=%s", GEOSGeomToWKT(g1));
1036  LWDEBUGF(3, "g2=%s", GEOSGeomToWKT(g2));
1037 
1038  g3 = GEOSUnion(g1,g2);
1039 
1040  LWDEBUGF(3, "g3=%s", GEOSGeomToWKT(g3));
1041 
1042  GEOSGeom_destroy(g1);
1043  GEOSGeom_destroy(g2);
1044 
1045  if (g3 == NULL)
1046  {
1047  lwerror("GEOSUnion: %s", lwgeom_geos_errmsg);
1048  return NULL; /* never get here */
1049  }
1050 
1051 
1052  GEOSSetSRID(g3, srid);
1053 
1054  result = GEOS2LWGEOM(g3, is3d);
1055 
1056  GEOSGeom_destroy(g3);
1057 
1058  if (result == NULL)
1059  {
1060  lwerror("Error performing union: GEOS2LWGEOM: %s",
1062  return NULL; /*never get here */
1063  }
1064 
1065  return result;
1066 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
uint8_t flags
Definition: liblwgeom.h:396
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:513
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:338
int32_t srid
Definition: liblwgeom.h:398
void lwgeom_geos_error(const char *fmt,...)
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, int autofix)
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:1386
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190

Here is the call graph for this function:

Here is the caller graph for this function: