Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to locate the coordinates of the middle point of a line feature in QGIS. I tried searching online but can't seem to find an easy way to do this.

share|improve this question
looks like you can do it in GRASS, see link – artwork21 Apr 15 '13 at 17:51

It is a pure geometry problem that can be solved in the Python console

The problem:


Find the midpoint of a segment x1,y1,x2,y2 is easy

x = (x1 + x2)/2
y = (y1 + y2)/2

so in the Python console

def mid(pt1, pt2):
   x = (pt1.x() + pt2.x())/2
   y = (pt1.y() + pt2.y())/2
   return QgsPoint(x,y)

def pair(list):
   '''Iterate over pairs in a list '''
    for i in range(1, len(list)):
        yield list[i-1], list[i]

def create_geometry(point,pr):
    # create geometry record 
    seg = QgsFeature()
    pr.addFeatures( [seg] )

# memory layer
pt_layer = QgsVectorLayer("Point", "midpoint", "memory")
pr = pt_layer.dataProvider()

for elem in mylayer.selectedFeatures():
    line = elem.geometry()
    for seg_start, seg_end in pair(line.asPolyline()):
       line_start = QgsPoint(seg_start)
       line_end = QgsPoint(seg_end)
       # midpoint 
       midpt= mid(line_start, line_end)
       # add midpoint point to layer




share|improve this answer
Just a note that this approach finds the mid point of each line segment, not the line itself. – Tim Sutton May 14 '14 at 20:49

If you bring your line feature into spatialite, you can use the Line_Interpolate_Point() function to find the mid point.

SELECT AsText(Line_Interpolate_Point(your_line.geomemtry, 0.5))

The second parameter 0.5 indicates the fraction of the line length where the point will be located.

share|improve this answer

Your Answer


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.