PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum boundary ( PG_FUNCTION_ARGS  )

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

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.

Referenced by test_rect_tree_contains_point().

630 {
631  GSERIALIZED *geom1;
632  GEOSGeometry *g1, *g3;
633  GSERIALIZED *result;
634  LWGEOM *lwgeom;
635  int srid;
636 
637 
638  geom1 = PG_GETARG_GSERIALIZED_P(0);
639 
640  /* Empty.Boundary() == Empty */
641  if ( gserialized_is_empty(geom1) )
642  PG_RETURN_POINTER(geom1);
643 
644  srid = gserialized_get_srid(geom1);
645 
646  lwgeom = lwgeom_from_gserialized(geom1);
647  if ( ! lwgeom ) {
648  lwpgerror("POSTGIS2GEOS: unable to deserialize input");
649  PG_RETURN_NULL();
650  }
651 
652  /* GEOS doesn't do triangle type, so we special case that here */
653  if (lwgeom->type == TRIANGLETYPE)
654  {
655  lwgeom->type = LINETYPE;
656  result = geometry_serialize(lwgeom);
657  lwgeom_free(lwgeom);
658  PG_RETURN_POINTER(result);
659  }
660 
661  initGEOS(lwpgnotice, lwgeom_geos_error);
662 
663  g1 = LWGEOM2GEOS(lwgeom, 0);
664  lwgeom_free(lwgeom);
665 
666  if (!g1)
667  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
668 
669  g3 = (GEOSGeometry *)GEOSBoundary(g1);
670 
671  if (!g3)
672  {
673  GEOSGeom_destroy(g1);
674  HANDLE_GEOS_ERROR("GEOSBoundary");
675  }
676 
677  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
678 
679  GEOSSetSRID(g3, srid);
680 
681  result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
682 
683  if (!result)
684  {
685  GEOSGeom_destroy(g1);
686  GEOSGeom_destroy(g3);
687  elog(NOTICE,
688  "GEOS2POSTGIS threw an error (result postgis geometry "
689  "formation)!");
690  PG_RETURN_NULL(); /* never get here */
691  }
692 
693  GEOSGeom_destroy(g1);
694  GEOSGeom_destroy(g3);
695 
696  PG_FREE_IF_COPY(geom1, 0);
697 
698  PG_RETURN_POINTER(result);
699 }
#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:1137
#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, int autofix)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:395
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: