python – How to Plot Lon/Lat Points on XY Map Using GeoPandas Without Manual Conversion

coordinate systemgeopandasplottingpythonreprojection-mathematics

I am data scientist not experienced in GIS and need to do some simple map plotting of the Netherlands. Using Geopandas everything works out nice and dandy for my purposes however I am stuck on 1 aspect:

The map I drew has the following CRS:

map_df__.crs
{'init': 'epsg:28992'} (this is what NL looks like to de dutch native)

plain image of the Netherlands

I want to plot a couple of points of which I get the lon/lat coordinates from Google Maps.

Muddling my way to understand projections on the fly I got to this code:

map_df.to_crs(epsg=4289).plot(edgecolor='black')

Which gives this map: (Red dot: Amsterdam is an example)

squased map

To a Dutch person this map looks a bit squashed. I am guessing because because of the projection.

How do I plot a lon/lat point (without manual conversion) on an XY map i.e. how can make the squashed map look like the 'stretched' version?


The suggested espg:
map_df.to_crs(epsg=3857).plot(edgecolor='black'), gives:

suggested eps 3857

Best Answer

I would put your point in a geodataframe and use the reprojection support built into geopandas.

That looks like this:

from matplotlib import pyplot
from shapely.geometry import Point
import geopandas

final_crs = {'init': 'epsg:28992'}
NL = (
    geopandas.read_file('nl_1km.shp')
        .to_crs(final_crs)
)

# note: always give `Point` x and then the y coord
amsterdamish = Point((4.9, 52.4))
gdf_am = geopandas.GeoSeries([amsterdamish], crs={'init': 'epsg:4326'})

fig, ax = pyplot.subplots(figsize=(6.5, 6.5))
NL.plot(ax=ax, facecolor='none', edgecolor='0.35')
gdf_am.to_crs(final_crs).plot(ax=ax)

And I get:

enter image description here


NB: my NL dataset is weird, but it came from here: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2/gis-files/netherlands-shapefile