为什么geopandas.read_file在Windows和Linux上返回不同的结果?

时间:2019-02-14 05:59:45

标签: python linux shapefile geopandas

我正在使用geopandas读取.shp文件。我的代码如下:

import geopandas as gpd

blocks = gpd.read_file('shp/block_shp/block.shp', encoding = 'utf-8')
print(blocks.columns)

在我的Windows计算机上,输出(geopandas数据框的列)是这样的:

Index(['ID', 'AREA', 'ID1', 'AREA1', 'NAME', 'DISTRICT', 'BLOCK_ID','geometry'],
  dtype='object')

我将相同的代码和包含.shp文件的文件夹复制到linux机器(centos 7)并运行代码。没有发生错误或警告,但打印结果不同:

Index(['geometry'], dtype='object')

它只会得到最后一列geometry,而错过所有其他列。读取过程比在Windows上快得多,我想知道它在读取时是否确实错过了那些专栏。 Windows计算机上的依赖程序包版本如下:

pip show show GDAL fiona rtree pyproj shapely geopandas

Name: GDAL
Version: 2.3.3
Summary: GDAL: Geospatial Data Abstraction Library
Home-page: http://www.gdal.org
Author: Frank Warmerdam
Author-email: warmerdam@pobox.com
License: MIT
Location: c:\users\lenovo\anaconda3\lib\site-packages
Requires:
Required-by:
---
Name: Fiona
Version: 1.8.4
Summary: Fiona reads and writes spatial data files
Home-page: http://github.com/Toblerity/Fiona
Author: Sean Gillies
Author-email: sean.gillies@gmail.com
License: BSD
Location: c:\users\lenovo\anaconda3\lib\site-packages
Requires: attrs, munch, click, click-plugins, cligj, six
Required-by:
---
Name: Rtree
Version: 0.8.3
Summary: R-Tree spatial index for Python GIS
Home-page: http://toblerity.github.com/rtree/
Author: Sean Gillies
Author-email: sean.gillies@gmail.com
License: LGPL
Location: c:\users\lenovo\anaconda3\lib\site-packages
Requires: setuptools
Required-by:
---
Name: pyproj
Version: 1.9.6
Summary: Python interface to PROJ.4 library
Home-page: https://github.com/jswhit/pyproj
Author: Jeff Whitaker
Author-email: jeffrey.s.whitaker@noaa.gov
License: OSI Approved
Location: c:\users\lenovo\anaconda3\lib\site-packages
Requires:
Required-by: geopandas
---
Name: Shapely
Version: 1.6.4.post1
Summary: Geometric objects, predicates, and operations
Home-page: https://github.com/Toblerity/Shapely
Author: Sean Gillies
Author-email: sean.gillies@gmail.com
License: BSD
Location: c:\users\lenovo\anaconda3\lib\site-packages
Requires:
Required-by:
---
Name: geopandas
Version: 0.4.0
Summary: Geographic pandas extensions
Home-page: http://geopandas.org
Author: GeoPandas contributors
Author-email: kjordahl@alum.mit.edu
License: BSD
Location: c:\users\lenovo\anaconda3\lib\site-packages
Requires: fiona, pyproj, shapely, pandas
Required-by:

以及Linux上的软件包版本:

pip3 show GDAL fiona rtree pyproj shapely geopandas

Name: GDAL
Version: 2.3.3
Summary: GDAL: Geospatial Data Abstraction Library
Home-page: http://www.gdal.org
Author: Frank Warmerdam
Author-email: warmerdam@pobox.com
License: MIT
Location: /usr/local/lib/python3.6/site-packages
Requires:
Required-by:
---
Name: Fiona
Version: 1.8.4
Summary: Fiona reads and writes spatial data files
Home-page: http://github.com/Toblerity/Fiona
Author: Sean Gillies
Author-email: sean.gillies@gmail.com
License: BSD
Location: /usr/local/lib/python3.6/site-packages
Requires: six, munch, cligj, click-plugins, attrs, click
Required-by:
---
Name: Rtree
Version: 0.8.3
Summary: R-Tree spatial index for Python GIS
Home-page: http://toblerity.github.com/rtree/
Author: Howard Butler
Author-email: hobu@hobu.net
License: LGPL
Location: /usr/local/lib/python3.6/site-packages
Requires: setuptools
Required-by:
---
Name: pyproj
Version: 1.9.6
Summary: Python interface to PROJ.4 library
Home-page: https://github.com/jswhit/pyproj
Author: Jeff Whitaker
Author-email: jeffrey.s.whitaker@noaa.gov
License: OSI Approved
Location: /usr/local/lib/python3.6/site-packages
Requires:
Required-by: geopandas
---
Name: Shapely
Version: 1.6.4
Summary: Geometric objects, predicates, and operations
Home-page: https://github.com/Toblerity/Shapely
Author: Sean Gillies
Author-email: sean.gillies@gmail.com
License: BSD
Location: /usr/local/lib/python3.6/site-packages
Requires:
Required-by:
---
Name: geopandas
Version: 0.4.0
Summary: Geographic pandas extensions
Home-page: http://geopandas.org
Author: GeoPandas contributors
Author-email: kjordahl@alum.mit.edu
License: BSD
Location: /usr/local/lib/python3.6/site-packages
Requires: pandas, shapely, fiona, pyproj
Required-by:

我不知道为什么会这样。有人可以告诉我如何解决此问题吗?谢谢您的关注。

运行fio info --indent 2 path_to_shp的结果给出不同的结果:

windows:

{
  "driver": "ESRI Shapefile",
  "schema": {
    "properties": {
      "ID": "int:10",
      "AREA": "float:10.2",
      "ID1": "int:10",
      "AREA1": "float:10.6",
      "NAME": "str:16",
      "DISTRICT": "str:16",
      "BLOCK_ID": "int:8"
    },
    "geometry": "Polygon"
  },
  "crs": "EPSG:4326",
  "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]",
  "bounds": [
    113.75219,
    22.447622,
    114.6233,
    22.86469
  ],
  "name": "block",
  "count": 74
}

linux:

{
  "driver": "ESRI Shapefile",
  "schema": {
    "properties": {},
    "geometry": "Polygon"
  },
  "crs": "EPSG:4326",
  "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY,AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.HORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]",
  "bounds": [
    113.75219,
    22.447622,
    114.6233,
    22.86469
  ],
  "name": "block",
  "count": 74
}

我确定.shp文件文件夹中的其他文件(.DBF,.prj,.shx和.geojson)都相同。

0 个答案:

没有答案