PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_linemerge()

LWGEOM* lwgeom_linemerge ( const LWGEOM geom1)

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

684 {
685  LWGEOM *result ;
686  GEOSGeometry *g1, *g3 ;
687  int is3d = FLAGS_GET_Z(geom1->flags);
688  int srid = geom1->srid;
689 
690  /* Empty.Linemerge() == Empty */
691  if ( lwgeom_is_empty(geom1) )
692  return (LWGEOM*)lwcollection_construct_empty( COLLECTIONTYPE, srid, is3d,
693  lwgeom_has_m(geom1) );
694 
695  initGEOS(lwnotice, lwgeom_geos_error);
696 
697  LWDEBUG(3, "linemerge() START");
698 
699  g1 = LWGEOM2GEOS(geom1, 0);
700  if ( 0 == g1 ) /* exception thrown at construction */
701  {
702  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
703  return NULL ;
704  }
705 
706  LWDEBUG(3, " constructed geometrys - calling geos");
707  LWDEBUGF(3, " g1 = %s", GEOSGeomToWKT(g1));
708  /*LWDEBUGF(3, "g1 is valid = %i",GEOSisvalid(g1)); */
709 
710  g3 = GEOSLineMerge(g1);
711 
712  LWDEBUG(3, " linemerge finished");
713 
714  if (g3 == NULL)
715  {
716  GEOSGeom_destroy(g1);
717  lwerror("Error performing linemerge: %s",
719  return NULL; /* never get here */
720  }
721 
722  LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
723 
724  GEOSSetSRID(g3, srid);
725 
726  result = GEOS2LWGEOM(g3, is3d);
727 
728  if (result == NULL)
729  {
730  GEOSGeom_destroy(g1);
731  GEOSGeom_destroy(g3);
732  lwerror("Error performing linemerge: GEOS2LWGEOM: %s",
734  return NULL ; /* never get here */
735  }
736 
737  GEOSGeom_destroy(g1);
738  GEOSGeom_destroy(g3);
739 
740  return result ;
741 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
uint8_t flags
Definition: liblwgeom.h:397
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
int32_t srid
Definition: liblwgeom.h:399
void lwgeom_geos_error(const char *fmt,...)
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
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:1346
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:892
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
Here is the call graph for this function:
Here is the caller graph for this function: