PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ topologypreservesimplify()

Datum topologypreservesimplify ( PG_FUNCTION_ARGS  )

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

752 {
753  GSERIALIZED *geom1;
754  double tolerance;
755  GEOSGeometry *g1, *g3;
756  GSERIALIZED *result;
757  uint32_t type;
758 
759  geom1 = PG_GETARG_GSERIALIZED_P(0);
760  tolerance = PG_GETARG_FLOAT8(1);
761 
762  /* Empty.Simplify() == Empty */
763  type = gserialized_get_type(geom1);
764  if ( gserialized_is_empty(geom1) || type == TINTYPE || type == TRIANGLETYPE )
765  PG_RETURN_POINTER(geom1);
766 
767  initGEOS(lwpgnotice, lwgeom_geos_error);
768 
769  g1 = POSTGIS2GEOS(geom1);
770  if (!g1)
771  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
772 
773  g3 = GEOSTopologyPreserveSimplify(g1,tolerance);
774  GEOSGeom_destroy(g1);
775 
776  if (!g3) HANDLE_GEOS_ERROR("GEOSTopologyPreserveSimplify");
777 
778  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
779 
780  GEOSSetSRID(g3, gserialized_get_srid(geom1));
781 
782  result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
783  GEOSGeom_destroy(g3);
784 
785  if (!result)
786  {
787  elog(ERROR,"GEOS topologypreservesimplify() threw an error (result postgis geometry formation)!");
788  PG_RETURN_NULL(); /* never get here */
789  }
790 
791  PG_FREE_IF_COPY(geom1, 0);
792  PG_RETURN_POINTER(result);
793 }
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
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
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: g_serialized.c:86
void lwgeom_geos_error(const char *fmt,...)
#define TINTYPE
Definition: liblwgeom.h:99
#define TRIANGLETYPE
Definition: liblwgeom.h:98
type
Definition: ovdump.py:41
#define HANDLE_GEOS_ERROR(label)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
unsigned int uint32_t
Definition: uthash.h:78

References GEOS2POSTGIS(), gserialized_get_srid(), gserialized_get_type(), gserialized_has_z(), gserialized_is_empty(), HANDLE_GEOS_ERROR, lwgeom_geos_error(), POSTGIS2GEOS(), TINTYPE, TRIANGLETYPE, and ovdump::type.

Here is the call graph for this function: