PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ lwgeom_union()

LWGEOM* lwgeom_union ( const LWGEOM geom1,
const LWGEOM geom2 
)

Definition at line 968 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 geos_geomunion(), and lwt_AddLine().

969 {
970  int is3d;
971  int srid;
972  GEOSGeometry *g1, *g2, *g3;
973  LWGEOM *result;
974 
975  LWDEBUG(2, "in geomunion");
976 
977  /* A.Union(empty) == A */
978  if ( lwgeom_is_empty(geom1) )
979  return lwgeom_clone_deep(geom2);
980 
981  /* B.Union(empty) == B */
982  if ( lwgeom_is_empty(geom2) )
983  return lwgeom_clone_deep(geom1);
984 
985 
986  /* ensure srids are identical */
987  srid = (int)(geom1->srid);
988  error_if_srid_mismatch(srid, (int)(geom2->srid));
989 
990  is3d = (FLAGS_GET_Z(geom1->flags) || FLAGS_GET_Z(geom2->flags)) ;
991 
992  initGEOS(lwnotice, lwgeom_geos_error);
993 
994  g1 = LWGEOM2GEOS(geom1, 0);
995 
996  if ( 0 == g1 ) /* exception thrown at construction */
997  {
998  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
999  return NULL;
1000  }
1001 
1002  g2 = LWGEOM2GEOS(geom2, 0);
1003 
1004  if ( 0 == g2 ) /* exception thrown at construction */
1005  {
1006  GEOSGeom_destroy(g1);
1007  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1008  return NULL;
1009  }
1010 
1011  LWDEBUGF(3, "g1=%s", GEOSGeomToWKT(g1));
1012  LWDEBUGF(3, "g2=%s", GEOSGeomToWKT(g2));
1013 
1014  g3 = GEOSUnion(g1,g2);
1015 
1016  LWDEBUGF(3, "g3=%s", GEOSGeomToWKT(g3));
1017 
1018  GEOSGeom_destroy(g1);
1019  GEOSGeom_destroy(g2);
1020 
1021  if (g3 == NULL)
1022  {
1023  lwerror("GEOSUnion: %s", lwgeom_geos_errmsg);
1024  return NULL; /* never get here */
1025  }
1026 
1027 
1028  GEOSSetSRID(g3, srid);
1029 
1030  result = GEOS2LWGEOM(g3, is3d);
1031 
1032  GEOSGeom_destroy(g3);
1033 
1034  if (result == NULL)
1035  {
1036  lwerror("Error performing union: GEOS2LWGEOM: %s",
1038  return NULL; /*never get here */
1039  }
1040 
1041  return result;
1042 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:89
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:446
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:369
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:1310
#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:102
Here is the call graph for this function:
Here is the caller graph for this function: