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 want to use QGIS creating points along the line, but in specified distance. I found two GRASS tools in SEXTANTE Toolbox:

  • v.to.points
  • v.segment

I tried v.to.points, setting the maximum distance between points in map units to 100 and got this: points along the line close look

The second photo showed a close look from the upper one. The result was what I want, but I want to get less points, but even I set the maximum distance to 1000, or 1000000, the result was the same.

I tried to use v.segment, but I had no file containing segment rules.

Underdark gave me some advice, and I tried Densify geometries given an interval. First it gave me a polyline shapefile the same as I input, and then I used extract nodes to try to get those points. But the result was the same as I got using v.to.points, no matter what I set the distance interval.

How can I create points along the line, and in specified distance?

share|improve this question
2  
Have a look at this, let us know nathanw.net/2012/08/05/… –  Willy Jun 11 '13 at 11:02
    
Thanks for giving me this helpful advice! If I want to use your script, have I to install python? or in the new version QGIS 2.0, does it already have this function built in it? –  Heinz Dec 3 '13 at 8:58
    
There is a plugin for this now in QGIS 2.0, called QChainage. Fetch the plugin and install it. –  Willy Dec 8 '13 at 8:53
add comment

5 Answers

In the Python console:

1) create a memory layer class (complete class (without attributes) at crea_mem_layer.py)

class Create_vlayer(object):
    '''creation of a virtual layer''' 
     def __init__(self,nom,type):
         self.type=type
         self.name = nom
         self.layer =  QgsVectorLayer(self.type, self.name , "memory")
         self.pr =self.layer.dataProvider() 
     def create_point(self,geometry):
         # add point to the layer
         self.seg = QgsFeature()
         self.seg.setGeometry(QgsGeometry.fromPoint(geometry))
         self.pr.addFeatures([self.seg])
         self.layer.updateExtents()
     @property
     def display_layer(self):
         #end of layer and display layer 
         QgsMapLayerRegistry.instance().addMapLayers([self.couche])

2) vector algebra functions (from algèbre_vect_PyQGIS.py)

import math 
def mag(point):
    # magnitude of a vector
    return math.sqrt(point.x()**2 + point.y()**2)
def diff(point2, point1):
    # substraction betwen two vector
    return QgsPoint(point2.x()-point1.x(), point2.y() - point1.y())
def length(point1,point2):
    # with PyQGIS: sqrDist
    return math.sqrt(point1.sqrDist(point2))

3) direction cosines

def dircos(point):
    cosa = point.x() / mag(point)
    cosb = point.y()/ mag(point)
    return cosa,cosb

4) process line or line segments

def pairs(list):
    # list pairs iteration 
    for i in range(1, len(list)):
    yield list[i-1], list[i]

layer = qgis.utils.iface.activeLayer()
# interval between points
interval = 5 m
# create virtual layer
gen_pt  = Create_vlayer("mid5", "Point")

for elem in layer():
    line = elem.geometry()
    for seg_start, seg_end in pairs(line.asPolyline()):
       line_start = QgsPoint(seg_start)
       line_end = QgsPoint(seg_end)
       # mid point = vector coordinates [x2-x1,y2-y1]
       pointm =diff(line_end, line_start)
       # direction cosines of the segment
       cosa,cosb = dircos(pointm)
       # length of the segment
       lg = length(line_end, line_start)
       # generate and add points to the virtual layer 
       for i in range(interval,lg,interval):
           gen_pt.create_point(QgsPoint(line_start.x()  + (i * cosa), line_start.y() + (i*cosb)))

# display layer
gen_pt.display_layer

Results

polyline, equidistant point with Shapely or PyQGIS2, with direction cosines

polylineshapelyvector_algebra

Then just adjust the interval

share|improve this answer
add comment

I've written a script that changes the Sextante Densify geometries tool to accept a certain distance. It's called Densify geometries given an interval.

After running Densify, you can extract the points using Extract nodes tool.

You can get it from Github and install instructions are on my blog.

enter image description here

share|improve this answer
    
Hi, Anita, I have installed SEXTANTE Toolbox of version 1.0.9, and I tried this 'Densify geometries given an interval', but got a polyline output. Should I install the 1.0.8 version? –  Heinz Jun 12 '13 at 4:51
    
i think things are not quiet clear here. With underdarks tool, your just receive a new line layer, but with additional vertices, which are added to your original ones. But thats not what you are looking for, so i think the link in Willy's comment is the way to go (not out-of-the-box, but seems to be well explained) –  Bernd V. Jun 12 '13 at 9:56
1  
Sextante offers an "extract nodes" tool for that. –  underdark Jun 12 '13 at 17:09
1  
but then you still got your original vertices from the line feature which do not fit into the set distance scheme, right? I don't see a way to remove them easily from the point feature after extracting the nodes. I think he is asking for a chainage function just as described in Nathans blog linked by Willy above. –  Bernd V. Jun 12 '13 at 21:41
    
Yeah, I still got the same result from v.to.points, and the distance interval I set was not matter. –  Heinz Jun 13 '13 at 3:40
show 6 more comments

There is now a plugin called QChainage that does exactly what you want. You specify an interval distance and the plugin creates points along your line at the specified interval.

share|improve this answer
    
*Note that this won't capture your line nodes, so if you need them you will also need to use the geometry tool - extract nodes and append to your chainage points. –  Jason Jun 25 at 3:15
1  
Welcome to GIS SE! I think the information that you have appended here as a Comment would be better incorporated into your actual Answer by using the edit button beneath it. You can do this with a Copy/Paste and the delete your comment by clicking the little cross next to it. –  PolyGeo Jun 25 at 3:49
add comment

Well not sure if this is in the stable release, but in the sextante toolbox on 1.9 alpha under Geoalgorithims->Vector is the "Convert Lines to Points" option. Works a treat, be great if it added a field for distance along the line as well though.

Interesting it did add the NAME field from my vector layer though.

I tried getting that Python Script by Nathan Woodrow working, but I suck with python. And with code in general it seems. :p

share|improve this answer
add comment

If you don't want to horse around with python scripts you can simply install and use the "Profile from line" plugin and ignore / delete the raster value column. The chainage will be whatever you set teh sampling interval to be.

Neil

share|improve this answer
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.