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

Definition at line 678 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 _lwt_AddLine(), linemerge(), and test_geos_linemerge().

679 {
680  LWGEOM *result ;
681  GEOSGeometry *g1, *g3 ;
682  int is3d = FLAGS_GET_Z(geom1->flags);
683  int srid = geom1->srid;
684 
685  /* Empty.Linemerge() == Empty */
686  if ( lwgeom_is_empty(geom1) )
687  return (LWGEOM*)lwcollection_construct_empty( COLLECTIONTYPE, srid, is3d,
688  lwgeom_has_m(geom1) );
689 
690  initGEOS(lwnotice, lwgeom_geos_error);
691 
692  LWDEBUG(3, "linemerge() START");
693 
694  g1 = LWGEOM2GEOS(geom1, 0);
695  if ( 0 == g1 ) /* exception thrown at construction */
696  {
697  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
698  return NULL ;
699  }
700 
701  LWDEBUG(3, " constructed geometrys - calling geos");
702  LWDEBUGF(3, " g1 = %s", GEOSGeomToWKT(g1));
703  /*LWDEBUGF(3, "g1 is valid = %i",GEOSisvalid(g1)); */
704 
705  g3 = GEOSLineMerge(g1);
706 
707  LWDEBUG(3, " linemerge finished");
708 
709  if (g3 == NULL)
710  {
711  GEOSGeom_destroy(g1);
712  lwerror("Error performing linemerge: %s",
714  return NULL; /* never get here */
715  }
716 
717  LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
718 
719  GEOSSetSRID(g3, srid);
720 
721  result = GEOS2LWGEOM(g3, is3d);
722 
723  if (result == NULL)
724  {
725  GEOSGeom_destroy(g1);
726  GEOSGeom_destroy(g3);
727  lwerror("Error performing linemerge: GEOS2LWGEOM: %s",
729  return NULL ; /* never get here */
730  }
731 
732  GEOSGeom_destroy(g1);
733  GEOSGeom_destroy(g3);
734 
735  return result ;
736 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
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:1386
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:930
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:90

Here is the call graph for this function:

Here is the caller graph for this function: