【问题标题】:Unable to translate to Mercator projection using geopandas无法使用 geopandas 转换为墨卡托投影
【发布时间】:2019-10-03 20:32:13
【问题描述】:

我正在尝试使用 Geopandas 和 Matplotlib 绘制西班牙地图。我正在使用您在下面看到的 GeoJSON 文件,其中几何位于地理坐标中 (EPSG 4326)

我想在墨卡托投影中绘制地图,但是当我尝试使用

转换单位时
df.to_crs({'init': 'epsg:3395'})

我收到一条错误消息:

RuntimeError: b'no arguments in initialization list'

我已按照http://geopandas.org/projections.html 中的说明进行操作。那里说,如果 geopandas 数据框不计入 CRS 的信息,则必须对其进行定义。但这不是这里的问题。

这是我目前的代码

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)

如果我运行以下命令:

df.crs

我收到以下响应(这意味着 geopandas DataFrame 有关于 CRS 的信息)

{'init': 'epsg:4326'}

然后

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

返回错误

我错过了什么?提前致谢。

【问题讨论】:

  • 与 matplotlib 无关。请不要发送垃圾邮件。删除标签
  • 您是如何安装 GeoPandas 的?这似乎是依赖关系的问题。为确保一切正常,建议通过 Conda 从 conda-forge 通道安装 GeoPandas 及其依赖项,如 geopandas.org/install.html 中所述。

标签: python geopandas pyproj


【解决方案1】:

看来您使用的是较旧版本的 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'}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    相关资源
    最近更新 更多