0

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.

4

1 回答 1

0

看来您使用的是旧版本的 geopandas 和 pyproj。我建议升级到适用的较新版本:

>>> 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'}
于 2019-06-10T01:09:06.263 回答