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.

My problem is the following: i have a line shp (target layer) and a point shp (join layer). the second one (point layer) holds an attribute which i want to join with a line layer based on closest distance to the line. Points and lines are not intersecting

I can do this with arcgis and spatial join(match option: closest), but i don't know how can i achieve this in Qgis.

I'd really appreciate an answer for this.

Miha

share|improve this question
2  
There is a tool to do Join by location but it doesn't have an option "closest". I don't know if there is any workaround. In general please evaluate to support the development of your missing, favorite options/tools, it is also this way that users can help this piece of software grow. –  Giovanni Manghi Oct 16 '11 at 16:43
add comment

1 Answer

I don't think there's a 'core' QGIS function for this. However, install the MMQGIS plugin, and use the 'hub distance' tool. Chose your points as the "Source Points" layer, and your lines as the "Destination Hubs Layer" and set "Output Shape Type" to "Line to Hub." This will give you a shapefile of lines (with length) that join the closest features. Conveniently, it also adds the ID of the closest feature to the attribute table.

Edit/Comment: This approach works well if there are fewer points than lines, or else a one-to-one line-to-point situation. Having more points than lines complicates things. 'Hub Distance' tool adds the ID of the line feature to the point attribute table as 'HubName' along with the distance between the point and the center of the line as 'HubDist'. If there are more points than lines, additional work is required to determine within each subset of points (those multiple records linked to each line hub) which of those is the closest to each line, and/or which is one with the desired set of attributes to join to the line.

share|improve this answer
    
this should be marked as the answer, subject to minor edit of "lines" v "points" –  Willy May 10 '12 at 1:11
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.