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 have a point layer, that I'd like to return the Longitude, latitude using the qgis api. I assume I need to use QgsPoint

share|improve this question
up vote 4 down vote accepted

This works on the latest release 'Tethys'.

The point layer that I am interested in is the first layer in my layer list. The coordinate values will be in the units of the spatial reference system of the layer. If your layer is in lat/lon, remember that x=lon and y=lat...

Open the Python Console and type this:

from qgis.utils import iface

feat = QgsFeature()
mc = iface.mapCanvas()
layer = mc.layer(0)
provider = layer.dataProvider()

    geometry = feat.geometry()
    print "X Coord %d: " %geometry.asPoint().x()
    print "Y Coord %d: " %geometry.asPoint().y()
share|improve this answer

This requires your layer to be in a projection using lat/lon to return geographic coordinates:

provider = layer.dataProvider()
feat = QgsFeature()
    geom = feat.geometry()
    x = geom.asPoint().x()
    y = geom.asPoint().y()

(taken from Points2One Plugin by Pavol Kapusta & Goyo Diaz)

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.