PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 1143 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(), POSTGIS_GEOS_VERSION, and LWGEOM::srid.

Referenced by ST_Snap().

1144 {
1145 #if POSTGIS_GEOS_VERSION < 33
1146  lwerror("The GEOS version this lwgeom library "
1147  "was compiled against (%d) doesn't support "
1148  "'Snap' function (3.3.0+ required)",
1150  return NULL;
1151 #else /* POSTGIS_GEOS_VERSION >= 33 */
1152 
1153  int srid, is3d;
1154  GEOSGeometry *g1, *g2, *g3;
1155  LWGEOM* out;
1156 
1157  srid = geom1->srid;
1158  error_if_srid_mismatch(srid, (int)(geom2->srid));
1159 
1160  is3d = (FLAGS_GET_Z(geom1->flags) || FLAGS_GET_Z(geom2->flags)) ;
1161 
1162  initGEOS(lwnotice, lwgeom_geos_error);
1163 
1164  g1 = (GEOSGeometry *)LWGEOM2GEOS(geom1);
1165  if ( 0 == g1 ) /* exception thrown at construction */
1166  {
1167  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1168  return NULL;
1169  }
1170 
1171  g2 = (GEOSGeometry *)LWGEOM2GEOS(geom2);
1172  if ( 0 == g2 ) /* exception thrown at construction */
1173  {
1174  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1175  GEOSGeom_destroy(g1);
1176  return NULL;
1177  }
1178 
1179  g3 = GEOSSnap(g1, g2, tolerance);
1180  if (g3 == NULL)
1181  {
1182  GEOSGeom_destroy(g1);
1183  GEOSGeom_destroy(g2);
1184  lwerror("GEOSSnap: %s", lwgeom_geos_errmsg);
1185  return NULL;
1186  }
1187 
1188  GEOSGeom_destroy(g1);
1189  GEOSGeom_destroy(g2);
1190 
1191  GEOSSetSRID(g3, srid);
1192  out = GEOS2LWGEOM(g3, is3d);
1193  if (out == NULL)
1194  {
1195  GEOSGeom_destroy(g3);
1196  lwerror("GEOSSnap() threw an error (result LWGEOM geometry formation)!");
1197  return NULL;
1198  }
1199  GEOSGeom_destroy(g3);
1200 
1201  return out;
1202 
1203 #endif /* POSTGIS_GEOS_VERSION >= 33 */
1204 }
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:317
uint8_t flags
Definition: liblwgeom.h:353
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom)
int32_t srid
Definition: liblwgeom.h:355
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void lwgeom_geos_error(const char *fmt,...)
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)

Here is the call graph for this function:

Here is the caller graph for this function: