Project points to WGS84

This notebook shows how to use pyproj to transform coordinates, automatically handling a datum shift.

Import statements


In [40]:
import pyproj
from database.models import Site
import folium

Define coordinate systems


In [2]:
p1 = pyproj.Proj(init='EPSG:31254')
p2 = pyproj.Proj(init='EPSG:4326')

Pull a location from the database


In [19]:
hofgarten = Site.objects.get(name = 'Hofgarten')

In [28]:
print(hofgarten.shape.srs.pretty_wkt)


PROJCS["MGI / Austria GK West",
    GEOGCS["MGI",
        DATUM["Militar_Geographische_Institute",
            SPHEROID["Bessel 1841",6377397.155,299.1528128,
                AUTHORITY["EPSG","7004"]],
            TOWGS84[577.326,90.129,463.919,5.137,1.474,5.297,2.4232],
            AUTHORITY["EPSG","6312"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4312"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",10.33333333333333],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",-5000000],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AUTHORITY["EPSG","31254"]]

Transform coordinates


In [36]:
x1, y1 = hofgarten.shape.coords

In [37]:
x2, y2 = pyproj.transform(p1, p2, x1, y1)

In [38]:
x2


Out[38]:
11.397342199098112

In [39]:
y2


Out[39]:
47.272913066438164

Verify result on a map


In [57]:
map = folium.Map(location=[y2, x2], zoom_start=16)
m1 = folium.Marker(location=(y2, x2), popup=hofgarten.name).add_to(map)

In [58]:
map


Out[58]: