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

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

Referenced by symdifference().

635 {
636  GEOSGeometry *g1, *g2, *g3;
637  LWGEOM *result;
638  int is3d;
639  int srid;
640 
641  /* A.SymDifference(Empty) == A */
642  if ( lwgeom_is_empty(geom2) )
643  return lwgeom_clone_deep(geom1);
644 
645  /* Empty.DymDifference(B) == B */
646  if ( lwgeom_is_empty(geom1) )
647  return lwgeom_clone_deep(geom2);
648 
649  /* ensure srids are identical */
650  srid = (int)(geom1->srid);
651  error_if_srid_mismatch(srid, (int)(geom2->srid));
652 
653  is3d = (FLAGS_GET_Z(geom1->flags) || FLAGS_GET_Z(geom2->flags)) ;
654 
655  initGEOS(lwnotice, lwgeom_geos_error);
656 
657  g1 = LWGEOM2GEOS(geom1);
658 
659  if ( 0 == g1 ) /* exception thrown at construction */
660  {
661  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
662  return NULL;
663  }
664 
665  g2 = LWGEOM2GEOS(geom2);
666 
667  if ( 0 == g2 ) /* exception thrown at construction */
668  {
669  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
670  GEOSGeom_destroy(g1);
671  return NULL;
672  }
673 
674  g3 = GEOSSymDifference(g1,g2);
675 
676  if (g3 == NULL)
677  {
678  GEOSGeom_destroy(g1);
679  GEOSGeom_destroy(g2);
680  lwerror("GEOSSymDifference: %s", lwgeom_geos_errmsg);
681  return NULL; /*never get here */
682  }
683 
684  LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
685 
686  GEOSSetSRID(g3, srid);
687 
688  result = GEOS2LWGEOM(g3, is3d);
689 
690  if (result == NULL)
691  {
692  GEOSGeom_destroy(g1);
693  GEOSGeom_destroy(g2);
694  GEOSGeom_destroy(g3);
695  lwerror("GEOS symdifference() threw an error (result postgis geometry formation)!");
696  return NULL ; /*never get here */
697  }
698 
699  GEOSGeom_destroy(g1);
700  GEOSGeom_destroy(g2);
701  GEOSGeom_destroy(g3);
702 
703  return result;
704 }
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]
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: