PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ boundary()

Datum boundary ( PG_FUNCTION_ARGS  )

Definition at line 577 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().

578 {
579  GSERIALIZED *geom1;
580  GEOSGeometry *g1, *g3;
581  GSERIALIZED *result;
582  LWGEOM *lwgeom;
583  int srid;
584 
585 
586  geom1 = PG_GETARG_GSERIALIZED_P(0);
587 
588  /* Empty.Boundary() == Empty */
589  if ( gserialized_is_empty(geom1) )
590  PG_RETURN_POINTER(geom1);
591 
592  srid = gserialized_get_srid(geom1);
593 
594  lwgeom = lwgeom_from_gserialized(geom1);
595  if ( ! lwgeom ) {
596  lwpgerror("POSTGIS2GEOS: unable to deserialize input");
597  PG_RETURN_NULL();
598  }
599 
600  /* GEOS doesn't do triangle type, so we special case that here */
601  if (lwgeom->type == TRIANGLETYPE)
602  {
603  lwgeom->type = LINETYPE;
604  result = geometry_serialize(lwgeom);
605  lwgeom_free(lwgeom);
606  PG_RETURN_POINTER(result);
607  }
608 
609  initGEOS(lwpgnotice, lwgeom_geos_error);
610 
611  g1 = LWGEOM2GEOS(lwgeom, 0);
612  lwgeom_free(lwgeom);
613 
614  if ( 0 == g1 ) /* exception thrown at construction */
615  {
616  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
617  PG_RETURN_NULL();
618  }
619 
620  g3 = (GEOSGeometry *)GEOSBoundary(g1);
621 
622  if (g3 == NULL)
623  {
624  GEOSGeom_destroy(g1);
625  HANDLE_GEOS_ERROR("GEOSBoundary");
626  PG_RETURN_NULL(); /* never get here */
627  }
628 
629  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
630 
631  GEOSSetSRID(g3, srid);
632 
633  result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
634 
635  if (result == NULL)
636  {
637  GEOSGeom_destroy(g1);
638 
639  GEOSGeom_destroy(g3);
640  elog(NOTICE,"GEOS2POSTGIS threw an error (result postgis geometry formation)!");
641  PG_RETURN_NULL(); /* never get here */
642  }
643 
644  GEOSGeom_destroy(g1);
645  GEOSGeom_destroy(g3);
646 
647  PG_FREE_IF_COPY(geom1, 0);
648 
649  PG_RETURN_POINTER(result);
650 }
#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:1063
#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:38
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:153
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:83
Here is the call graph for this function:
Here is the caller graph for this function: