写入 ESRI shp 文件 geopandas.GeoDataFrame.to_file 时返回“InvalidVersion”错误

问题描述 投票:0回答:2

在编写我的 GeoDataFrame 来提交 GDAL 版本时遇到的问题。

我的 GeoDataFrame:

geoPoliDF
是 (12,2):


geoPoliDF

    pol_id  pol_geometry
0   14      POLYGON ((9.000 0.000, 9.000 2.000, 10.000 2.0...
1   15      POLYGON ((9.000 3.000, 9.000 5.000, 10.000 5.0...
2   17      POLYGON ((9.000 9.000, 9.000 11.000, 10.000 11...
3   18      POLYGON ((9.000 12.000, 9.000 14.000, 10.000 1...
4   24      POLYGON ((3.000 0.000, 3.000 2.000, 5.000 2.00...
5   25      POLYGON ((3.000 3.000, 3.000 5.000, 5.000 5.00...
6   27      POLYGON ((3.000 9.000, 3.000 11.000, 5.000 11....
7   28      POLYGON ((3.000 12.000, 3.000 14.000, 5.000 14...
8   29      POLYGON ((0.000 0.000, 0.000 2.000, 2.000 2.00...
9   30      POLYGON ((0.000 3.000, 0.000 5.000, 2.000 5.00...
10  32      POLYGON ((0.000 9.000, 0.000 11.000, 2.000 11....
11  33      POLYGON ((0.000 12.000, 0.000 14.000, 2.000 14...

它包含多边形 ID (

pol_id
) 及其几何形状 (
pol_geometry
):

geoPoliDF['pol_id'].dtype, geoPoliDF['pol_geometry'].dtype

(dtype('int32'), <geopandas.array.GeometryDtype at 0x22017b8d0a0>)

文件输入/输出目录:

base_dir = r'C:\Users\ucesemu\Documents\code\AutomatedPhase2\AutomatedPhase2.gdb'

polyOutFc = os.path.join(base_dir,r'wFlatPoly.shp')

将 geoDataFrame 写入 ESRI shapefile:

geoPoliDF.to_file(polyOutFc, driver='ESRI Shapefile',crs='EPSG:27700')

遇到的问题:

---------------------------------------------------------------------------
InvalidVersion                            Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_4624\2995218618.py in <cell line: 2>()
      1 polyOutFc = os.path.join(base_dir,r'wFlatPoly.shp')
----> 2 geoPoliDF.to_file(polyOutFc, driver='ESRI Shapefile',crs='EPSG:27700')

~\AppData\Local\ESRI\conda\envs\arcgispro-clone\lib\site-packages\geopandas\geodataframe.py in to_file(self, filename, driver, schema, index, **kwargs)
   1201         from geopandas.io.file import _to_file
   1202 
-> 1203         _to_file(self, filename, driver, schema, index, **kwargs)
   1204 
   1205     def set_crs(self, crs=None, epsg=None, inplace=False, allow_override=False):

~\AppData\Local\ESRI\conda\envs\arcgispro-clone\lib\site-packages\geopandas\io\file.py in _to_file(df, filename, driver, schema, index, mode, crs, engine, **kwargs)
    543 
    544     if engine == "fiona":
--> 545         _to_file_fiona(df, filename, driver, schema, crs, mode, **kwargs)
    546     elif engine == "pyogrio":
    547         _to_file_pyogrio(df, filename, driver, schema, crs, mode, **kwargs)

~\AppData\Local\ESRI\conda\envs\arcgispro-clone\lib\site-packages\geopandas\io\file.py in _to_file_fiona(df, filename, driver, schema, crs, mode, **kwargs)
    566         except AttributeError:
    567             gdal_version = "2.0.0"  # just assume it is not the latest
--> 568         if Version(gdal_version) >= Version("3.0.0") and crs:
    569             crs_wkt = crs.to_wkt()
    570         elif crs:

~\AppData\Local\ESRI\conda\envs\arcgispro-clone\lib\site-packages\packaging\version.py in __init__(self, version)
    195         match = self._regex.search(version)
    196         if not match:
--> 197             raise InvalidVersion(f"Invalid version: '{version}'")
    198 
    199         # Store the parsed out pieces of the version

InvalidVersion: Invalid version: '3.4.0e'

我检查了 crs 是否存在且正确,错误仍然存在。

我尝试了不同的路径和较短的形状文件名称,错误仍然存在。

我正在工作的环境是ArcGIS-pro的克隆。大多数库是在克隆时构建的 即:

gdal                      3.4.0           arcgispro_py39_17150  [arcgispro]  esri

[conda 列表:] (https://i.stack.imgur.com/Tn4dk.png)

geopandas gdal arcpy fiona
2个回答
0
投票

我有同样的错误。我的解决方案是在ArcGIS Pro克隆中卸载geopandas版本0.12.2并安装geopandas版本0.9.0

我想这与Python 3.9有关


0
投票

我也有同样的问题 - arcgis pro 3.1.2,并安装了 geopanads 0.12.2 它说 gdal 版本 > 3.00,(3.4) 并且版本无效。

© www.soinside.com 2019 - 2024. All rights reserved.