What is the best generic method to check whether an opened table is geographic or not using PyQgis ?

  • I'm not sure I follow the question...are you referring to the data and geographic coordinates? or are you referring to whether the table has an associated spatial element e.g. dbf in a shapefile? – spk578 Jun 23 '15 at 10:43
  • @spk578 Not sure to follow yours either ... lol ... i would answer : the second part of your question (whether the table has an associated spatial element ...) – snaileater Jun 23 '15 at 10:55

You can use the hasGeometryType() method from QgsVectorLayer.

To examinate whether the selected layer has an associated geometry you can run this code in the QGIS Python console:


If it is True, the layer has a geometry (i.e., it's an spatial table). If it is False, the layer is a table (i.e., the table is non explicitly spatial).

  • 1
    Yes ... in fact at first glance i thought that was not a very "generic" solution since it is only a method from QgsVectorLayer ... but then i noticed that when u open (for example) a .csv file it is considered as a QgsVectorLayer ... so this solution is working for me so far ... – snaileater Jun 26 '15 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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