PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ lwgeom_snap()

LWGEOM* lwgeom_snap ( const LWGEOM geom1,
const LWGEOM geom2,
double  tolerance 
)

Snap vertices and segments of a geometry to another using a given tolerance.

Parameters
geom1the geometry to snap
geom2the geometry to snap to
tolerancethe distance under which vertices and segments are snapped

Requires GEOS-3.3.0+

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

References error_if_srid_mismatch(), LWGEOM::flags, FLAGS_GET_Z, GEOS2LWGEOM(), lwerror(), LWGEOM2GEOS(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), and LWGEOM::srid.

Referenced by _lwt_toposnap(), and ST_Snap().

1501 {
1502  int srid, is3d;
1503  GEOSGeometry *g1, *g2, *g3;
1504  LWGEOM* out;
1505 
1506  srid = geom1->srid;
1507  error_if_srid_mismatch(srid, (int)(geom2->srid));
1508 
1509  is3d = (FLAGS_GET_Z(geom1->flags) || FLAGS_GET_Z(geom2->flags)) ;
1510 
1511  initGEOS(lwnotice, lwgeom_geos_error);
1512 
1513  g1 = (GEOSGeometry *)LWGEOM2GEOS(geom1, 0);
1514  if ( 0 == g1 ) /* exception thrown at construction */
1515  {
1516  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1517  return NULL;
1518  }
1519 
1520  g2 = (GEOSGeometry *)LWGEOM2GEOS(geom2, 0);
1521  if ( 0 == g2 ) /* exception thrown at construction */
1522  {
1523  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1524  GEOSGeom_destroy(g1);
1525  return NULL;
1526  }
1527 
1528  g3 = GEOSSnap(g1, g2, tolerance);
1529  if (g3 == NULL)
1530  {
1531  GEOSGeom_destroy(g1);
1532  GEOSGeom_destroy(g2);
1533  lwerror("GEOSSnap: %s", lwgeom_geos_errmsg);
1534  return NULL;
1535  }
1536 
1537  GEOSGeom_destroy(g1);
1538  GEOSGeom_destroy(g2);
1539 
1540  GEOSSetSRID(g3, srid);
1541  out = GEOS2LWGEOM(g3, is3d);
1542  if (out == NULL)
1543  {
1544  GEOSGeom_destroy(g3);
1545  lwerror("GEOSSnap() threw an error (result LWGEOM geometry formation)!");
1546  return NULL;
1547  }
1548  GEOSGeom_destroy(g3);
1549 
1550  return out;
1551 }
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]
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:369
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)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
Here is the call graph for this function:
Here is the caller graph for this function: