20

I have two vector shapefiles: One file is points representing manholes and the other is a polyline file representing pipes leading to and from the manholes. I need to snap the lines within a specified distance to the closest manhole.

Is there an easy way to accomplish this without doing it manually?

lines -> points

Update

As per Alexandre, I have exported my shapefiles to spatialite format. Not sure what to next.

enter image description here

Update #2 I created a new db file and imported shapefiles into the new db using spatialite-gui, I adjusted my SQL query but as you can see I get an error "no such column: f.geom"

enter image description here

7
  • In a Spatialite spatial table(layer), the features geometries are saved in an attribute. The names can be different. In "pipe" table that attribute is called Geometry. I will update my answer assuming that mh also as a Geometry attribute. Commented Feb 19, 2013 at 19:59
  • I got a error "no such function: ST_Snap". I am using QGIS 1.8 on Windows 7 64bit.
    – GreyHippo
    Commented Feb 19, 2013 at 20:14
  • What Spatialite do you have? You can check it in QGIS > Help > About Commented Feb 19, 2013 at 21:54
  • "no such column: f.geom" - try with f.Geometry
    – vinayan
    Commented Feb 20, 2013 at 3:21
  • My Spatialite version is 3.0.1
    – GreyHippo
    Commented Feb 20, 2013 at 13:17

4 Answers 4

27

If you are willing to put your data in Postgis (or Spatialite), you could use ST_Snap to do what you want.

Just use lines layer\table as input, and your points layer as reference, and set the tolerance. Something like this:

SELECT
    f.gid as gid,
    ST_Snap(f.Geometry, g.Geometry, 2) as geom
FROM
    pipe as f,
    (SELECT ST_Collect(Geometry) as Geometry
     FROM mh) as g

The result is this:

enter image description here

You can then update your geometries using the feature identifier.

4
  • Where would I put the code "Select... From..."? What do mean by "using the feature identifier"?
    – GreyHippo
    Commented Feb 19, 2013 at 14:41
  • After importing your files in the database (postgis or spatialite), you can use DB Manager to see your database tables and run the SQL query (the code) in SQL Window, and then load it in your canvas. Tell me if that works for you, and then we will do the update part. Commented Feb 19, 2013 at 15:46
  • Alexandre, see update above. I exported file to two spatiallite files.
    – GreyHippo
    Commented Feb 19, 2013 at 16:45
  • You should put both files in the same Spatialite Database, just drag say "pipe" to the "mh.sqlite" database. After that update the SQL Code to change "points" to "mh", and "lines" to "pipe". Also adapt "gid" to your "pipe" id. After that you can Execute and load the results. Commented Feb 19, 2013 at 17:04
3

I don't know much about QGIS or GRASS, but some quick Googling has yielded v.clean in GRASS should do the trick.

Have a look at this post and this one.

Alternatives to QGIS and GRASS:

If I were to do this in ArcGIS, I would probably store my data in a Feature Dataset in a File Geodatabase and create a Topology to identify areas where the point layer was not on the endpoints of the lines. You can then fix the errors using the Error Inspector.

But, probably the quickest and easiest solution would be in FME. You could try using the Snapper Tool or better yet, the AnchoredSnapper Tool. If you use the AnchoredSnapper, make sure your snapping type is End Point Snapping. Of course, you will need a license for FME. But you can download a 14 day trial if you don't have one.

3
  • I looked at v.clean but it only uses one layer, I need to compare one layer to another. Also, I was more looking for an QGIS/opensource option.
    – GreyHippo
    Commented Feb 19, 2013 at 14:43
  • 1
    @GreyHippo, GRASS is opensource
    – artwork21
    Commented Feb 19, 2013 at 17:29
  • 1
    I know GRASS is opensource but your other options are not.
    – GreyHippo
    Commented Feb 19, 2013 at 18:56
1

In QGIS Snap Geometries to layer will do what you want. See this thread How to snap lines to nearest point?

-1

Manual way

Qgis -> Settings -> Snapping options (and I'm not sure but it might need CadTools extension) and enable topological editing.

Automatic way

v.clean which is in GRASS tools in SEXTANTE toolbox in QGIS. If you have PostGIS 2.0 then ST_Snap and ST_SnapToGrid() (And there is no reason why you cant use it, it's very good spatial tool)

Commercial way

FME and MRF tool (commercial extension, I had an evalution version. It vas very good).

Also I'm intrested about water pipe/sewer management with open source tools, do you have any hints?

7
  • I think that's what GreyHippo means by "doing it manually". Just using the Snapping options, you're going to have to move every dangling node by hand to activate the snapping. Or am I missing something?
    – Jake
    Commented Feb 19, 2013 at 13:59
  • no. i was blind. Commented Feb 19, 2013 at 14:32
  • Simplexio, I do NOT want to do it manually. I was hoping for a plugin or process I don't know about.
    – GreyHippo
    Commented Feb 19, 2013 at 14:40
  • I didn't think you could use GRASS v.clean on two layers?
    – GreyHippo
    Commented Feb 20, 2013 at 15:53
  • 1
    if i recall correcly it can fix too short lines. you see, problem you have is not that your manholes arent on right places, its that your sewer network is not topologically correct. And that needs only pipes layer. Every utility network system that i have seen assumes that there is manhole in every sewer intersection. This offcourse assumes that you want to have correct topology. Commented Feb 21, 2013 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.