0

It is possible to get list/dictionary of "Recently used coordinate reference system" from QGIS by python?

Or get list of all "Coordinate reference systems of the world" also from QGIS by python.

1

The recently used projections are stored in your user settings. Here is an example of the keys and some sample values:

  • UI/recentProjections=932, 3452
  • UI/recentProjectionsProj4="+proj=aea +lat_1=55 +lat_2=65 +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +datum=NAD27 +units=us-ft +no_defs", "+proj=longlat +datum=WGS84 +no_defs"
  • UI/recentProjectionsAuthId=EPSG:2964, EPSG:4326

For example, you could get the AuthIds like so:

>>> QSettings().value('UI/recentProjectionsAuthId')
[u'EPSG:4326', u'EPSG:3338', u'EPSG:2964', u'EPSG:900913', u'EPSG:3035', u'EPSG:32733', u'EPSG:4267']

All of the coordinate systems are stored in the srs.db file found in the resources directory of your QGIS install. You can use the Python sqlite3 module to query this database and get a list of all the coordinate systems:

import sqlite3
con = sqlite3.connect(QgsApplication.srsDbFilePath())
cur = con.cursor()
cur.execute('select * from vw_srs')
rows = cur.fetchall()
for crs in rows:
  # do something...
  print crs
cur.close()
con.close()
  • How to from QSettings().value('UI/recentProjectionsAuthId') get list? I receive <PyQt4.QtCore.QVariant object at 0x0D27BB20> – user7172 Feb 20 '14 at 13:38
  • 1
    You must be using QGIS 1.8. Use the toString method on the QVariant object to extract the string. – gsherman Feb 22 '14 at 4:30
  • I use toString but string is empty. In 'Project Properties'>>> Recently used coordinate... I have a few entries.These are two different lists? (I use QGIS 1.8) – user7172 Feb 26 '14 at 22:09

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.