PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ boundary()

Datum boundary ( PG_FUNCTION_ARGS  )

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

836 {
837  GSERIALIZED *geom1;
838  GEOSGeometry *g1, *g3;
840  LWGEOM *lwgeom;
841  int32_t srid;
842 
843  geom1 = PG_GETARG_GSERIALIZED_P(0);
844 
845  /* Empty.Boundary() == Empty */
846  if ( gserialized_is_empty(geom1) )
847  PG_RETURN_POINTER(geom1);
848 
849  srid = gserialized_get_srid(geom1);
850 
851  lwgeom = lwgeom_from_gserialized(geom1);
852  if ( ! lwgeom ) {
853  lwpgerror("POSTGIS2GEOS: unable to deserialize input");
854  PG_RETURN_NULL();
855  }
856 
857  /* GEOS doesn't do triangle type, so we special case that here */
858  if (lwgeom->type == TRIANGLETYPE)
859  {
860  lwgeom->type = LINETYPE;
861  result = geometry_serialize(lwgeom);
862  lwgeom_free(lwgeom);
863  PG_RETURN_POINTER(result);
864  }
865 
866  initGEOS(lwpgnotice, lwgeom_geos_error);
867 
868  g1 = LWGEOM2GEOS(lwgeom, 0);
869  lwgeom_free(lwgeom);
870 
871  if (!g1)
872  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
873 
874  g3 = GEOSBoundary(g1);
875 
876  if (!g3)
877  {
878  GEOSGeom_destroy(g1);
879  HANDLE_GEOS_ERROR("GEOSBoundary");
880  }
881 
882  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
883 
884  GEOSSetSRID(g3, srid);
885 
886  result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
887 
888  if (!result)
889  {
890  GEOSGeom_destroy(g1);
891  GEOSGeom_destroy(g3);
892  elog(NOTICE,
893  "GEOS2POSTGIS threw an error (result postgis geometry "
894  "formation)!");
895  PG_RETURN_NULL(); /* never get here */
896  }
897 
898  GEOSGeom_destroy(g1);
899  GEOSGeom_destroy(g3);
900 
901  PG_FREE_IF_COPY(geom1, 0);
902 
903  PG_RETURN_POINTER(result);
904 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:126
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
Definition: gserialized.c:174
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
void lwgeom_geos_error(const char *fmt,...)
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
#define LINETYPE
Definition: liblwgeom.h:117
#define TRIANGLETYPE
Definition: liblwgeom.h:129
#define HANDLE_GEOS_ERROR(label)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
uint8_t type
Definition: liblwgeom.h:476

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

Here is the call graph for this function: