PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum ST_UnaryUnion ( PG_FUNCTION_ARGS  )

Definition at line 757 of file postgis/lwgeom_geos.c.

References GEOS2POSTGIS(), gserialized_get_srid(), gserialized_has_z(), gserialized_is_empty(), lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), POSTGIS2GEOS(), POSTGIS_GEOS_VERSION, and result.

758 {
759 #if POSTGIS_GEOS_VERSION < 33
760  PG_RETURN_NULL();
761  lwerror("The GEOS version this PostGIS binary "
762  "was compiled against (%d) doesn't support "
763  "'GEOSUnaryUnion' function (3.3.0+ required)",
765  PG_RETURN_NULL();
766 #else /* POSTGIS_GEOS_VERSION >= 33 */
767  GSERIALIZED *geom1;
768  int is3d;
769  int srid;
770  GEOSGeometry *g1, *g3;
772 
773  POSTGIS_DEBUG(2, "in ST_UnaryUnion");
774 
775  geom1 = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
776 
777  /* UnaryUnion(empty) == (empty) */
778  if ( gserialized_is_empty(geom1) )
779  PG_RETURN_POINTER(geom1);
780 
781  is3d = ( gserialized_has_z(geom1) );
782 
783  srid = gserialized_get_srid(geom1);
784 
785  initGEOS(lwnotice, lwgeom_geos_error);
786 
787  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
788 
789  if ( 0 == g1 ) /* exception thrown at construction */
790  {
791  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
792  PG_RETURN_NULL();
793  }
794 
795  POSTGIS_DEBUGF(3, "g1=%s", GEOSGeomToWKT(g1));
796 
797  g3 = GEOSUnaryUnion(g1);
798 
799  POSTGIS_DEBUGF(3, "g3=%s", GEOSGeomToWKT(g3));
800 
801  GEOSGeom_destroy(g1);
802 
803  if (g3 == NULL)
804  {
805  lwerror("GEOSUnion: %s", lwgeom_geos_errmsg);
806  PG_RETURN_NULL(); /* never get here */
807  }
808 
809 
810  GEOSSetSRID(g3, srid);
811 
812  result = GEOS2POSTGIS(g3, is3d);
813 
814  GEOSGeom_destroy(g3);
815 
816  if (result == NULL)
817  {
818  elog(ERROR, "ST_UnaryUnion failed converting GEOS result Geometry to PostGIS format");
819  PG_RETURN_NULL(); /*never get here */
820  }
821 
822  /* compressType(result); */
823 
824  PG_FREE_IF_COPY(geom1, 0);
825 
826  PG_RETURN_POINTER(result);
827 #endif /* POSTGIS_GEOS_VERSION >= 33 */
828 }
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:25
char ** result
Definition: liblwgeom.h:218
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
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,...)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:70

Here is the call graph for this function: