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

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

629 {
630  LWGEOM *result ;
631  GEOSGeometry *g1, *g3 ;
632  int is3d = FLAGS_GET_Z(geom1->flags);
633  int srid = geom1->srid;
634 
635  /* Empty.Linemerge() == Empty */
636  if ( lwgeom_is_empty(geom1) )
637  return (LWGEOM*)lwcollection_construct_empty( COLLECTIONTYPE, srid, is3d,
638  lwgeom_has_m(geom1) );
639 
640  initGEOS(lwnotice, lwgeom_geos_error);
641 
642  LWDEBUG(3, "linemerge() START");
643 
644  g1 = LWGEOM2GEOS(geom1, 0);
645  if ( 0 == g1 ) /* exception thrown at construction */
646  {
647  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
648  return NULL ;
649  }
650 
651  LWDEBUG(3, " constructed geometrys - calling geos");
652  LWDEBUGF(3, " g1 = %s", GEOSGeomToWKT(g1));
653  /*LWDEBUGF(3, "g1 is valid = %i",GEOSisvalid(g1)); */
654 
655  g3 = GEOSLineMerge(g1);
656 
657  LWDEBUG(3, " linemerge finished");
658 
659  if (g3 == NULL)
660  {
661  GEOSGeom_destroy(g1);
662  lwerror("Error performing linemerge: %s",
664  return NULL; /* never get here */
665  }
666 
667  LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
668 
669  GEOSSetSRID(g3, srid);
670 
671  result = GEOS2LWGEOM(g3, is3d);
672 
673  if (result == NULL)
674  {
675  GEOSGeom_destroy(g1);
676  GEOSGeom_destroy(g3);
677  lwerror("Error performing linemerge: GEOS2LWGEOM: %s",
679  return NULL ; /* never get here */
680  }
681 
682  GEOSGeom_destroy(g1);
683  GEOSGeom_destroy(g3);
684 
685  return result ;
686 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:61
uint8_t flags
Definition: liblwgeom.h:381
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
int32_t srid
Definition: liblwgeom.h:383
void lwgeom_geos_error(const char *fmt,...)
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
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:1297
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:843
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76

Here is the call graph for this function:

Here is the caller graph for this function: