Changing the CRS

The data in the database is using World Geodetic System 84 (WGS 84), latitude and longitude. What if you need the data out in European Petroleum Survey Group (EPSG) 3857? You can change the spatial reference in your query using ST_Transform(). The following code shows you how by using PostGIS functions:

cursor.execute("SELECT UpdateGeometrySRID('art_pieces','location',4326)")cursor.execute("SELECT Find_SRID('public','art_pieces','location')")cursor.fetchall()

The previous code makes two queries to the database:

  • Firstly, it assigns a spatial reference system identifier to the geometry column in the table using UpdateGeomtrySRID(). This needs to be done because the points were put in the table without any reference to an ...

Get Mastering Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.