[postgis-users] Snapping linestrings with given tolerance

Nicolas Ribot nicolas.ribot at gmail.com
Tue Nov 20 01:44:22 PST 2012


Hi Guillaume,

You may find some tips in the "Closing Contour" thread.
One approach is to order linestrings so that you have the 2 closest
neighboors for each line (start and end point)
then explode linestrings into list of points, merge lists for close line
and rebuild linestrings from the new lists of points.

Nicolas


On 19 November 2012 19:05, Guillaume Drolet <droletguillaume at gmail.com>wrote:

> Dear Postgis Users,
>
> I could really do with your help here as I'm running out of ideas..
> Here's my problem:
>
> I have two hydrology layers (LINESTRINGS and POLYGONS): one layer has a
> spatial resolution of 1:20K and covers only the southern half of the
> area covered by the second one with a spatial resolution of 1:50K. I
> want to create a single layer made of the higher resolution cover in the
> South and of the coarser resolution in the North.
>
> Working on the LINESTRING layers first, I clipped each so that one
> covers the South and the other the North.
> They come together at the interface between the north and south (no
> overlap). Because both layers have different spatial resolutions, the
> same rivers are not quite connected at the north/south interface. I
> unioned both layers into a new table for which I tried to create a
> topology, thinking that the given tolerance would snap lines which are
> close from each other (50 m) within a distance from the north/south
> interface.
>
> Using the topology approach, I got errors ("curve not simple") when
> using a 50 m tolerance. I tried with smaller values and it seemed like
> it would work only with tolerance = 0 or a value small enough so that
> nothing would be within this distance.
>
> I gave up trying with the topology/tolerance approach and tried using
> the nodes from the topology create with no tolerance. So far I built a
> query that returns only the nodes that need to be snapped:
>
> SELECT DISTINCT ON (a.node_id) a.node_id, a.geom
> FROM mergedlinessimple_topo.node a, -- the topology of the unioned
> (north and south) layers
>       mergedlinessimple_topo.node b,
>       hydrology.test_north c, -- north polygon
>       hydrology.test_south d -- south polygon
> WHERE ST_DWithin(a.geom, b.geom, 50) AND a.node_id <> b.node_id
> AND ST_DWithin(a.geom, c.geom, 0.001) AND ST_DWithin(a.geom, d.geom, 0.001);
>
> I haven't found how to snap the selected nodes together. I tried with
> different queries, all using ST_Snap, but none worked. Maybe my approach
> so far is just wrong so I will appreciate any hint on how to proceed for
> getting the job done!
>
> Many thanks in advance for your help,
>
> 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/20121120/561b7ec4/attachment.html>


More information about the postgis-users mailing list