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

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

830 {
831  GSERIALIZED *geom1;
832  GEOSGeometry *g1, *g3;
833  GSERIALIZED *result;
834  LWGEOM *lwgeom;
835  int srid;
836 
837 
838  geom1 = PG_GETARG_GSERIALIZED_P(0);
839 
840  /* Empty.Boundary() == Empty */
841  if ( gserialized_is_empty(geom1) )
842  PG_RETURN_POINTER(geom1);
843 
844  srid = gserialized_get_srid(geom1);
845 
846  lwgeom = lwgeom_from_gserialized(geom1);
847  if ( ! lwgeom ) {
848  lwpgerror("POSTGIS2GEOS: unable to deserialize input");
849  PG_RETURN_NULL();
850  }
851 
852  /* GEOS doesn't do triangle type, so we special case that here */
853  if (lwgeom->type == TRIANGLETYPE)
854  {
855  lwgeom->type = LINETYPE;
856  result = geometry_serialize(lwgeom);
857  lwgeom_free(lwgeom);
858  PG_RETURN_POINTER(result);
859  }
860 
861  initGEOS(lwpgnotice, lwgeom_geos_error);
862 
863  g1 = LWGEOM2GEOS(lwgeom, 0);
864  lwgeom_free(lwgeom);
865 
866  if ( 0 == g1 ) /* exception thrown at construction */
867  {
868  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
869  PG_RETURN_NULL();
870  }
871 
872  g3 = (GEOSGeometry *)GEOSBoundary(g1);
873 
874  if (g3 == NULL)
875  {
876  GEOSGeom_destroy(g1);
877  HANDLE_GEOS_ERROR("GEOSBoundary");
878  PG_RETURN_NULL(); /* never get here */
879  }
880 
881  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
882 
883  GEOSSetSRID(g3, srid);
884 
885  result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
886 
887  if (result == NULL)
888  {
889  GEOSGeom_destroy(g1);
890 
891  GEOSGeom_destroy(g3);
892  elog(NOTICE,"GEOS2POSTGIS threw an error (result postgis geometry formation)!");
893  PG_RETURN_NULL(); /* never get here */
894  }
895 
896  GEOSGeom_destroy(g1);
897  GEOSGeom_destroy(g3);
898 
899  PG_FREE_IF_COPY(geom1, 0);
900 
901  PG_RETURN_POINTER(result);
902 }
#define LINETYPE
Definition: liblwgeom.h:71
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
#define TRIANGLETYPE
Definition: liblwgeom.h:83
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:24
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:139
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:380
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:69

Here is the call graph for this function:

Here is the caller graph for this function: