PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ boundary()

Datum boundary ( PG_FUNCTION_ARGS  )

Definition at line 652 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(), and test_rect_tree_contains_point().

653 {
654  GSERIALIZED *geom1;
655  GEOSGeometry *g1, *g3;
656  GSERIALIZED *result;
657  LWGEOM *lwgeom;
658  int srid;
659 
660 
661  geom1 = PG_GETARG_GSERIALIZED_P(0);
662 
663  /* Empty.Boundary() == Empty */
664  if ( gserialized_is_empty(geom1) )
665  PG_RETURN_POINTER(geom1);
666 
667  srid = gserialized_get_srid(geom1);
668 
669  lwgeom = lwgeom_from_gserialized(geom1);
670  if ( ! lwgeom ) {
671  lwpgerror("POSTGIS2GEOS: unable to deserialize input");
672  PG_RETURN_NULL();
673  }
674 
675  /* GEOS doesn't do triangle type, so we special case that here */
676  if (lwgeom->type == TRIANGLETYPE)
677  {
678  lwgeom->type = LINETYPE;
679  result = geometry_serialize(lwgeom);
680  lwgeom_free(lwgeom);
681  PG_RETURN_POINTER(result);
682  }
683 
684  initGEOS(lwpgnotice, lwgeom_geos_error);
685 
686  g1 = LWGEOM2GEOS(lwgeom, 0);
687  lwgeom_free(lwgeom);
688 
689  if ( 0 == g1 ) /* exception thrown at construction */
690  {
691  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
692  PG_RETURN_NULL();
693  }
694 
695  g3 = (GEOSGeometry *)GEOSBoundary(g1);
696 
697  if (g3 == NULL)
698  {
699  GEOSGeom_destroy(g1);
700  HANDLE_GEOS_ERROR("GEOSBoundary");
701  PG_RETURN_NULL(); /* never get here */
702  }
703 
704  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
705 
706  GEOSSetSRID(g3, srid);
707 
708  result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
709 
710  if (result == NULL)
711  {
712  GEOSGeom_destroy(g1);
713 
714  GEOSGeom_destroy(g3);
715  elog(NOTICE,"GEOS2POSTGIS threw an error (result postgis geometry formation)!");
716  PG_RETURN_NULL(); /* never get here */
717  }
718 
719  GEOSGeom_destroy(g1);
720  GEOSGeom_destroy(g3);
721 
722  PG_FREE_IF_COPY(geom1, 0);
723 
724  PG_RETURN_POINTER(result);
725 }
#define LINETYPE
Definition: liblwgeom.h:86
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
#define TRIANGLETYPE
Definition: liblwgeom.h:98
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:179
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, int autofix)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:396
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:100
Here is the call graph for this function:
Here is the caller graph for this function: