juancar
juancar

Reputation: 327

Unable to translate to Mercator projection using geopandas

I am trying to plot a map of Spain using Geopandas and Matplotlib. I am using the GeoJSON file you see below in which the geometry is in geographical coordinates (EPSG 4326)

I would like to plot the map in Mercator projection but when I try to convert the units using

df.to_crs({'init': 'epsg:3395'})

I receive an error saying:

RuntimeError: b'no arguments in initialization list'

I have followed the instructions in http://geopandas.org/projections.html. There it says that if the geopandas dataframe does not count with the information of the CRS, you must define it. But this is not the problem here.

This is the code I have so far

import geopandas as gpd
%matplotlib inline
import matplotlib.pyplot as plt

geojson_url = 'https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/spain-provinces.geojson'
df = gpd.read_file(geojson_url)

If I run the following command:

df.crs

I receive the following response (which means that the geopandas DataFrame have the information about CRS)

{'init': 'epsg:4326'}

Then

df = df.to_crs({'init': 'epsg:3395'})

Returns an error

What am I missing? Thanks in advance.

Upvotes: 0

Views: 787

Answers (1)

snowman2
snowman2

Reputation: 711

It appears that you are using an older version of geopandas and pyproj. I would recommend upgrading to the newer versions where this works:

>>> import geopandas
>>> geopandas.__version__
'0.5.0'
>>> import pyproj
>>> pyproj.__version__
'2.2.0'
>>> geojson_url = 'https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/spain-provinces.geojson'
>>> df = geopandas.read_file(geojson_url)
>>> df.crs
{'init': 'epsg:4326'}
>>> df2 = df.to_crs({'init': 'epsg:3395'})
>>> df2.crs
{'init': 'epsg:3395'}

Upvotes: 0

Related Questions