13

I'd like to visualize where every coordinate system in QGIS is in the world. I can see the bounding box for them when I go to QGIS and select coordinate system:

example

But I'm trying to figure out how to load that as data. Any tips?

4 Answers 4

20

Yes, QGIS holds this information in an SQLite table.

Go the menu layer / data source manager and select Browser then go to where QGIS is installed (like C:\Program Files\QGIS 3.16\) and dig down to apps\qgis-ltr\resources\ (or \qgis-dev\) and at last open the srs.db and add tbl_bounds

enter image description here

To view the bounds as geometries, we will need a virtual layer.

Go the the menu layer / add layer / add-edit virtual layer and enter the following query.

select *, st_geomFromText('Polygon((' || west_bound_lon || ' ' || north_bound_lat || ',' || west_bound_lon || ' ' || south_bound_lat || ',' || east_bound_lon || ' ' || south_bound_lat || ',' || east_bound_lon || ' ' ||  north_bound_lat || ',' || west_bound_lon || ' ' || north_bound_lat ||'))') as geometry
from tbl_bounds;

You can then style the virtual layer, maybe with a transparent fill.

enter image description here

2
  • Thanks! Very cool. I appreciate the help. Jun 9, 2021 at 21:49
  • 1
    Great answer! Did not know about that database.
    – Encomium
    Jun 9, 2021 at 22:21
7

You can generate an entire QGIS project showing all SRS code from QGIS internal srs.db using PyQGIS. It adds all layers from srs.db. I also directly style the layer to get transparent bbox.

I've taken a similar approach to @JGH but fully automated on all platforms. The additional layers can be considered garbage or useful depending of your use case. My code could also benefit from simpler SQL query from @JGH but did not want to dive into it again (already done this project months ago).

from qgis.core import QgsVectorLayer, QgsProject
from osgeo import ogr

project_output_path = '/tmp/srs_demo.qgs'
iface.newProject()

srs_db_path = QgsApplication.srsDatabaseFilePath()
ds_srs_db = ogr.Open(srs_db_path)

srs_db_layers = [layer.GetName() for layer in ds_srs_db]

QgsProject.instance().addMapLayers([
    QgsVectorLayer(
        f"{srs_db_path}|layername={layer}",
        layer,
        'ogr'
    ) for layer in srs_db_layers
])

layer_input = f"ogr:{srs_db_path}|layername=tbl_bounds:tbl_bounds:UTF-8"
sql_query = """SELECT *, ST_GeomFromText('POLYGON((' ||
  cast("west_bound_lon" as text)|| ' ' || cast("north_bound_lat" as text) || ',' ||
  cast("east_bound_lon" as text)|| ' ' || cast("north_bound_lat" as text) || ',' ||
  cast("east_bound_lon" as text)|| ' ' || cast("south_bound_lat" as text) || ',' ||
  cast("west_bound_lon" as text)|| ' ' || cast("south_bound_lat" as text) || ',' ||
  cast("west_bound_lon" as text)|| ' ' || cast("north_bound_lat" as text)
  || '))', 4326) AS geom /*:polygon:4326*/ FROM tbl_bounds"""

vlayer = QgsVectorLayer( f"?layer={layer_input}&query={sql_query}", "QGIS srs bbox", "virtual" )
simpleSymbol = QgsFillSymbol.createSimple({
    'color':'#ffffff',
    'color_border': '35,35,35,255',
    'width_border': '0.1',
    'style': 'no'
})
vlayer.renderer().setSymbol(simpleSymbol)

QgsProject.instance().addMapLayer(vlayer)

QgsProject.instance().write(project_output_path)

You can look below to see how to execute the code (PS: we paste from the above code from our clipboard and type on "Return" keyboard key but you could also execute from a Python file from PyQGIS console)

enter image description here

6

There is no need to download EPSG database from epsg.org because the Proj library comes with a copy of that database since version 6.0 and therefore every QGIS user has it available. The name of this SQLite database if "proj.db" and it is located in the PROJ_DATA directory that is for example in OSGeo4W installations C:\OSGeo4W64\share\proj.

The EPSG database version that is included in proj.db can be checked from the release notes https://github.com/OSGeo/PROJ/releases and it can be queried directly from table "metadata" with any SQLite client.

enter image description here

The extents with the bounding coordinates are stored into table "extent"

enter image description here

Data from this table can be visualized in the same way than user @JHG showed in the answer that utilized the QGIS specific database "srs.db".

5

I can't speak to whether there's complete overlap between the two, but you can do this using EPSG's database. If you're not comfortable with SQL, I would just download the Access file (assuming you have that software), and load the table called 'Extent.' You'll find the four corners of the SRID's extent there, which you can then convert into a bounding box.

This is the table you want:

enter image description here

2
  • Mind that to access this db one has to either login or create free account on the site
    – Taras
    Jun 10, 2021 at 6:12
  • Proj comes with a copy of this database as a SQLite database "proj.db" so QGIS users do not need to download anything.
    – user30184
    Jun 10, 2021 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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