PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum linemerge ( PG_FUNCTION_ARGS  )

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

References GEOS2POSTGIS(), gserialized_get_srid(), gserialized_has_z(), lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), POSTGIS2GEOS(), and result.

3339 {
3340  GSERIALIZED *geom1;
3341  GEOSGeometry *g1, *g3;
3343 
3344  geom1 = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
3345 
3346  initGEOS(lwnotice, lwgeom_geos_error);
3347 
3348  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
3349 
3350  if ( 0 == g1 ) /* exception thrown at construction */
3351  {
3352  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
3353  PG_RETURN_NULL();
3354  }
3355 
3356  g3 = GEOSLineMerge(g1);
3357 
3358  if (g3 == NULL)
3359  {
3360  elog(ERROR,"GEOS LineMerge() threw an error!");
3361  GEOSGeom_destroy(g1);
3362  PG_RETURN_NULL(); /*never get here */
3363  }
3364 
3365 
3366  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
3367 
3368  GEOSSetSRID(g3, gserialized_get_srid(geom1));
3369 
3370  result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
3371 
3372  if (result == NULL)
3373  {
3374  GEOSGeom_destroy(g1);
3375  GEOSGeom_destroy(g3);
3376  elog(ERROR,"GEOS LineMerge() threw an error (result postgis geometry formation)!");
3377  PG_RETURN_NULL(); /*never get here */
3378  }
3379  GEOSGeom_destroy(g1);
3380  GEOSGeom_destroy(g3);
3381 
3382 
3383  /* compressType(result); */
3384 
3385  PG_FREE_IF_COPY(geom1, 0);
3386 
3387  PG_RETURN_POINTER(result);
3388 }
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:25
char ** result
Definition: liblwgeom.h:218
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
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:70

Here is the call graph for this function: