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

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

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

Referenced by symdifference().

866 {
867  GEOSGeometry *g1, *g2, *g3;
868  LWGEOM *result;
869  int is3d;
870  int srid;
871 
872  /* A.SymDifference(Empty) == A */
873  if ( lwgeom_is_empty(geom2) )
874  return lwgeom_clone_deep(geom1);
875 
876  /* Empty.DymDifference(B) == B */
877  if ( lwgeom_is_empty(geom1) )
878  return lwgeom_clone_deep(geom2);
879 
880  /* ensure srids are identical */
881  srid = (int)(geom1->srid);
882  error_if_srid_mismatch(srid, (int)(geom2->srid));
883 
884  is3d = (FLAGS_GET_Z(geom1->flags) || FLAGS_GET_Z(geom2->flags)) ;
885 
886  initGEOS(lwnotice, lwgeom_geos_error);
887 
888  g1 = LWGEOM2GEOS(geom1, 0);
889 
890  if ( 0 == g1 ) /* exception thrown at construction */
891  {
892  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
893  return NULL;
894  }
895 
896  g2 = LWGEOM2GEOS(geom2, 0);
897 
898  if ( 0 == g2 ) /* exception thrown at construction */
899  {
900  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
901  GEOSGeom_destroy(g1);
902  return NULL;
903  }
904 
905  g3 = GEOSSymDifference(g1,g2);
906 
907  if (g3 == NULL)
908  {
909  GEOSGeom_destroy(g1);
910  GEOSGeom_destroy(g2);
911  lwerror("GEOSSymDifference: %s", lwgeom_geos_errmsg);
912  return NULL; /*never get here */
913  }
914 
915  LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
916 
917  GEOSSetSRID(g3, srid);
918 
919  result = GEOS2LWGEOM(g3, is3d);
920 
921  if (result == NULL)
922  {
923  GEOSGeom_destroy(g1);
924  GEOSGeom_destroy(g2);
925  GEOSGeom_destroy(g3);
926  lwerror("GEOS symdifference() threw an error (result postgis geometry formation)!");
927  return NULL ; /*never get here */
928  }
929 
930  GEOSGeom_destroy(g1);
931  GEOSGeom_destroy(g2);
932  GEOSGeom_destroy(g3);
933 
934  return result;
935 }
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]
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: