[postgis-users] Snapping linestrings with given tolerance

Guillaume Drolet droletguillaume at gmail.com
Mon Nov 19 10:05:56 PST 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20121119/e7224a9f/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PointsToSnapInRed.bmp
Type: image/bmp
Size: 3322158 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20121119/e7224a9f/attachment-0001.bin>


More information about the postgis-users mailing list