I devise an interactive map of Germany using official shape files as provided here http://www.bkg.bund.de. The plotting works perfectly with geopandas but for some reason the plotly figure is off.
Minimal example for a geopandas dataframe -df
- of length 1, where the shape information are contained in column geometry and looks as follows
POLYGON ((3531713.337678026 6077121.156487568, 3532465.753191419 6075813.698160076, 3532499.600608208 6073802.38080852, 3532628.620627062 6071581.931537509, 3531869.321592058 6071241.4429235915, 3530658.9527930534 6071452.139477672, 3529785.8865069808 6069639.599440108, 3528957.748991292 6069263.645501549, 3524438.372433494 6069362.957531026, 3523076.9337587883 6072388.279024946, 3525993.515925105 6073979.273399123, 3526059.8716776026 6077145.86655316, 3527321.4826777824 6077426.793668112, 3528119.236993772 6075749.876051087, 3527687.374944012 6074791.893603065, 3528096.1044506407 6073782.871432945, 3529905.083799622 6077114.618219143, 3531713.337678026 6077121.156487568))
The associated crs
<Derived Projected CRS: EPSG:31467>
Name: DHDN / 3-degree Gauss-Kruger zone 3
Axis Info [cartesian]:
- X[north]: Northing (metre)
- Y[east]: Easting (metre)
Area of Use:
- name: Germany - former West Germany onshore between 7°30'E and 10°30'E - states of Baden-Wurtemberg, Bayern, Bremen, Hamberg, Hessen, Niedersachsen, Nordrhein-Westfalen, Rhineland-Pfalz, Schleswig-Holstein.
- bounds: (7.5, 47.27, 10.51, 55.09)
Coordinate Operation:
- name: 3-degree Gauss-Kruger zone 3
- method: Transverse Mercator
Datum: Deutsches Hauptdreiecksnetz
- Ellipsoid: Bessel 1841
- Prime Meridian: Greenwich
The code I use for geopandas
df.geometry.plot()
and plotly
fig = px.choropleth(df, geojson=df.geometry, locations=df.index)
fig.show()
To rule out issued related to the PCS, I tested to change the crs from EPSG:31467 to EPSG:3395 and then to set projection='mercator' in the plotly.express.choropleth function. Still the depicted plot is off. I also tested to set the fitbounds input argument - with no success. I tested to transform the df.geometry column to a geojson verifying that the indices correspond to locations - again no success.
Since Plotly
uses (long, lat) in degrees for choropleth mapping. Your data in the form:-
POLYGON ((3531713.337678026 6077121.156487568, ...))
is clearly not ready but needs conversion to EPSG:4326
for what plotly requires. For geodataframe, here is the snippet code that you may need for such conversion.
df_4326 = df_original.to_crs(epsg='4326')
You can run
df_4326.crs
and get CRS information like this:-
Name: WGS 84 Axis Info [ellipsoidal]: - Lat[north]: Geodetic latitude (degree) - Lon[east]: Geodetic longitude (degree) Area of Use: - name: World - bounds: (-180.0, -90.0, 180.0, 90.0) Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich