PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ boundary()

Datum boundary ( PG_FUNCTION_ARGS  )

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

696{
697 GSERIALIZED *geom1;
698 GEOSGeometry *g1, *g3;
699 GSERIALIZED *result;
700 LWGEOM *lwgeom;
701 int32_t srid;
702
703 geom1 = PG_GETARG_GSERIALIZED_P(0);
704
705 /* Empty.Boundary() == Empty */
706 if ( gserialized_is_empty(geom1) )
707 PG_RETURN_POINTER(geom1);
708
709 srid = gserialized_get_srid(geom1);
710
711 lwgeom = lwgeom_from_gserialized(geom1);
712 if ( ! lwgeom ) {
713 lwpgerror("POSTGIS2GEOS: unable to deserialize input");
714 PG_RETURN_NULL();
715 }
716
717 /* GEOS doesn't do triangle type, so we special case that here */
718 if (lwgeom->type == TRIANGLETYPE)
719 {
720 lwgeom->type = LINETYPE;
721 result = geometry_serialize(lwgeom);
722 lwgeom_free(lwgeom);
723 PG_RETURN_POINTER(result);
724 }
725
726 initGEOS(lwpgnotice, lwgeom_geos_error);
727
728 g1 = LWGEOM2GEOS(lwgeom, 0);
729 lwgeom_free(lwgeom);
730
731 if (!g1)
732 HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
733
734 g3 = GEOSBoundary(g1);
735
736 if (!g3)
737 {
738 GEOSGeom_destroy(g1);
739 HANDLE_GEOS_ERROR("GEOSBoundary");
740 }
741
742 POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
743
744 GEOSSetSRID(g3, srid);
745
746 result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
747
748 if (!result)
749 {
750 GEOSGeom_destroy(g1);
751 GEOSGeom_destroy(g3);
752 elog(NOTICE,
753 "GEOS2POSTGIS threw an error (result postgis geometry "
754 "formation)!");
755 PG_RETURN_NULL(); /* never get here */
756 }
757
758 GEOSGeom_destroy(g1);
759 GEOSGeom_destroy(g3);
760
761 PG_FREE_IF_COPY(geom1, 0);
762
763 PG_RETURN_POINTER(result);
764}
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)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
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
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
#define HANDLE_GEOS_ERROR(label)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition liblwgeom.h:448

References 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(), TRIANGLETYPE, and LWGEOM::type.

Here is the call graph for this function: