Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
    
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. –  Alexandre Neto Feb 19 '13 at 19:59
    
I got a error "no such function: ST_Snap". I am using QGIS 1.8 on Windows 7 64bit. –  GreyHippo Feb 19 '13 at 20:14
    
What Spatialite do you have? You can check it in QGIS > Help > About –  Alexandre Neto Feb 19 '13 at 21:54
    
"no such column: f.geom" - try with f.Geometry –  vinayan Feb 20 '13 at 3:21
    
My Spatialite version is 3.0.1 –  GreyHippo Feb 20 '13 at 13:17
show 3 more comments

3 Answers 3

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.

share|improve this answer
    
Where would I put the code "Select... From..."? What do mean by "using the feature identifier"? –  GreyHippo Feb 19 '13 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. –  Alexandre Neto Feb 19 '13 at 15:46
    
Alexandre, see update above. I exported file to two spatiallite files. –  GreyHippo Feb 19 '13 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. –  Alexandre Neto Feb 19 '13 at 17:04
add comment

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.

share|improve this answer
    
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 Feb 19 '13 at 14:43
1  
@GreyHippo, GRASS is opensource –  artwork21 Feb 19 '13 at 17:29
1  
I know GRASS is opensource but your other options are not. –  GreyHippo Feb 19 '13 at 18:56
add comment

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?

share|improve this answer
    
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 Feb 19 '13 at 13:59
    
no. i was blind. –  simplexio Feb 19 '13 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 Feb 19 '13 at 14:40
    
I didn't think you could use GRASS v.clean on two layers? –  GreyHippo Feb 20 '13 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. –  simplexio Feb 21 '13 at 7:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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