PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ boundary()

Datum boundary ( PG_FUNCTION_ARGS  )

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

References convexhull(), geometry_serialize(), GEOS2POSTGIS(), gserialized_get_srid(), gserialized_has_z(), gserialized_is_empty(), HANDLE_GEOS_ERROR, LINETYPE, LWGEOM2GEOS(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_geos_error(), PG_FUNCTION_INFO_V1(), TRIANGLETYPE, and LWGEOM::type.

Referenced by symdifference().

615 {
616  GSERIALIZED *geom1;
617  GEOSGeometry *g1, *g3;
618  GSERIALIZED *result;
619  LWGEOM *lwgeom;
620  int srid;
621 
622  geom1 = PG_GETARG_GSERIALIZED_P(0);
623 
624  /* Empty.Boundary() == Empty */
625  if ( gserialized_is_empty(geom1) )
626  PG_RETURN_POINTER(geom1);
627 
628  srid = gserialized_get_srid(geom1);
629 
630  lwgeom = lwgeom_from_gserialized(geom1);
631  if ( ! lwgeom ) {
632  lwpgerror("POSTGIS2GEOS: unable to deserialize input");
633  PG_RETURN_NULL();
634  }
635 
636  /* GEOS doesn't do triangle type, so we special case that here */
637  if (lwgeom->type == TRIANGLETYPE)
638  {
639  lwgeom->type = LINETYPE;
640  result = geometry_serialize(lwgeom);
641  lwgeom_free(lwgeom);
642  PG_RETURN_POINTER(result);
643  }
644 
645  initGEOS(lwpgnotice, lwgeom_geos_error);
646 
647  g1 = LWGEOM2GEOS(lwgeom, 0);
648  lwgeom_free(lwgeom);
649 
650  if (!g1)
651  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
652 
653  g3 = GEOSBoundary(g1);
654 
655  if (!g3)
656  {
657  GEOSGeom_destroy(g1);
658  HANDLE_GEOS_ERROR("GEOSBoundary");
659  }
660 
661  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
662 
663  GEOSSetSRID(g3, srid);
664 
665  result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
666 
667  if (!result)
668  {
669  GEOSGeom_destroy(g1);
670  GEOSGeom_destroy(g3);
671  elog(NOTICE,
672  "GEOS2POSTGIS threw an error (result postgis geometry "
673  "formation)!");
674  PG_RETURN_NULL(); /* never get here */
675  }
676 
677  GEOSGeom_destroy(g1);
678  GEOSGeom_destroy(g3);
679 
680  PG_FREE_IF_COPY(geom1, 0);
681 
682  PG_RETURN_POINTER(result);
683 }
#define LINETYPE
Definition: liblwgeom.h:85
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define TRIANGLETYPE
Definition: liblwgeom.h:97
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:45
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:398
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
#define HANDLE_GEOS_ERROR(label)
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:99
Here is the call graph for this function:
Here is the caller graph for this function: