[postgis-users] Snapping linestrings with given tolerance

Martin Feuchtwanger feumar at shaw.ca
Wed Nov 21 22:30:17 PST 2012


Hi, i'm a postgis beginner, too, but i think i see the problem, if not 
the exact solution:

Point 27 is the /first /point that postgis found that matched your 
search-and-snap criteria, not the /best/ (closest) point.

You need to somehow get all the candidate points (ones that match the 
criteria), sort (order by) by distance, and use the first one.
Easier said than done maybe, but that's my guess...

Martin Feuchtwanger  feumar at shaw.ca  604-254-0361
302 - 1429 E 4th Ave,  Vancouver, BC  V5N 1J6
http://members.shaw.ca/geomatics.developer

On 21/11/2012 1:50 PM, Guillaume Drolet wrote:
> Hi Nicolas,
>
> I didn't quite follow the tips in the "Closing Coutour" thread but got 
> some inspiration from it (I think it's a bit complicated for my 
> PostGIS level).
>
> I can now snap lines but some of them (see attached file) don't snap 
> at the right place. In the attached image, I want the last point of 
> the line in the southern area (the un-numbered point closest to the 
> north area in grey) to snap to point 26. Unfortunately, it is point 27 
> that snapped to 26. The second image shows another case where the snap 
> didn't do as I expected (multi snaps on the same line..). In some 
> other cases however, it did work alright.
>
> I'm sure this has to do with the conditions in my query below but I 
> don't understand what. Maybe you have some clues about it?
>
> DROP TABLE IF EXISTS hydrology.snappedlines;
> SELECT b.gid, ST_Snap(a.geom_intersections, b.geom_intersections, 50) geom
> INTO TABLE hydrology.snappedlines
> FROM hydrology.nhn_coursdeau_merge_test a, -- lines in the north area
>     hydrology.bdtq_20k_hydro_lo_merge_test b, -- lines in the south area
>     hydrology.test_north c, -- north area polygon
>     hydrology.test_south d      -- south area polygon
> WHERE ST_DWithin(a.geom_intersections, b.geom_intersections, 50) -- 
> units in meters
> AND ST_DWithin(a.geom_intersections, c.geom, 0.001)
> AND ST_DWithin(a.geom_intersections, d.geom, 0.001)
> AND ST_DWithin(b.geom_intersections, c.geom, 0.001)
> AND ST_DWithin(b.geom_intersections, d.geom, 0.001);
>
> Thanks for helping,
>
> Guillaume
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20121121/f5c5397e/attachment.html>


More information about the postgis-users mailing list