PostGIS  2.3.7dev-r@@SVN_REVISION@@
LWGEOM* lwgeom_linemerge ( const LWGEOM geom1)

Definition at line 654 of file liblwgeom/lwgeom_geos.c.

References COLLECTIONTYPE, LWGEOM::flags, FLAGS_GET_Z, GEOS2LWGEOM(), lwcollection_construct_empty(), LWDEBUG, LWDEBUGF, lwerror(), LWGEOM2GEOS(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_has_m(), lwgeom_is_empty(), lwnotice(), and LWGEOM::srid.

Referenced by linemerge(), lwt_AddLine(), and test_geos_linemerge().

655 {
656  LWGEOM *result ;
657  GEOSGeometry *g1, *g3 ;
658  int is3d = FLAGS_GET_Z(geom1->flags);
659  int srid = geom1->srid;
660 
661  /* Empty.Linemerge() == Empty */
662  if ( lwgeom_is_empty(geom1) )
663  return (LWGEOM*)lwcollection_construct_empty( COLLECTIONTYPE, srid, is3d,
664  lwgeom_has_m(geom1) );
665 
666  initGEOS(lwnotice, lwgeom_geos_error);
667 
668  LWDEBUG(3, "linemerge() START");
669 
670  g1 = LWGEOM2GEOS(geom1, 0);
671  if ( 0 == g1 ) /* exception thrown at construction */
672  {
673  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
674  return NULL ;
675  }
676 
677  LWDEBUG(3, " constructed geometrys - calling geos");
678  LWDEBUGF(3, " g1 = %s", GEOSGeomToWKT(g1));
679  /*LWDEBUGF(3, "g1 is valid = %i",GEOSisvalid(g1)); */
680 
681  g3 = GEOSLineMerge(g1);
682 
683  LWDEBUG(3, " linemerge finished");
684 
685  if (g3 == NULL)
686  {
687  GEOSGeom_destroy(g1);
688  lwerror("Error performing linemerge: %s",
690  return NULL; /* never get here */
691  }
692 
693  LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
694 
695  GEOSSetSRID(g3, srid);
696 
697  result = GEOS2LWGEOM(g3, is3d);
698 
699  if (result == NULL)
700  {
701  GEOSGeom_destroy(g1);
702  GEOSGeom_destroy(g3);
703  lwerror("Error performing linemerge: GEOS2LWGEOM: %s",
705  return NULL ; /* never get here */
706  }
707 
708  GEOSGeom_destroy(g1);
709  GEOSGeom_destroy(g3);
710 
711  return result ;
712 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:89
uint8_t flags
Definition: liblwgeom.h:396
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
int32_t srid
Definition: liblwgeom.h:398
void lwgeom_geos_error(const char *fmt,...)
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, int autofix)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1310
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:856
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
#define COLLECTIONTYPE
Definition: liblwgeom.h:90

Here is the call graph for this function:

Here is the caller graph for this function: