小编saQ*_*ist的帖子

将 Geopandas 数据框直接导出到压缩的 shapefile

我正在尝试将 Geopandas 数据框保存到直接写入压缩文件夹的 shapefile 中。

任何 shapefile 用户都知道,shapefile 不是单个文件,而是旨在一起读取的文件集合。所以呼吁 myGDF.to_file(filename='myshapefile.shp', driver='ESRI Shapefile')不仅创造myshapefile.shp而且myshapefile.prjmyshapefile.dbfmyshapefile.shxmyshapefile.cpg。这可能就是我努力在这里获得语法的原因。

例如,考虑一个虚拟的 Geopandas 数据框,例如:

import pandas as pd
import geopandas as gpd
from shapely.geometry import Point

data = pd.DataFrame({'name': ['a', 'b', 'c'],
    'property': ['foo', 'bar', 'foo'],
        'x': [173994.1578792833, 173974.1578792833, 173910.1578792833],
        'y': [444135.6032947102, 444186.6032947102, 444111.6032947102]})
geometry = [Point(xy) for xy in zip(data['x'], data['y'])]
myGDF = gpd.GeoDataFrame(data, geometry=geometry)
Run Code Online (Sandbox Code Playgroud)

我看到人们使用gzip,所以我尝试:

import geopandas as gpd
myGDF.to_file(filename='myshapefile.shp.gz', driver='ESRI Shapefile',compression='gzip')
Run Code Online (Sandbox Code Playgroud)

但它没有用。

然后我尝试了以下操作(在 …

python shapefile zipfile geopandas

6
推荐指数
2
解决办法
576
查看次数

标签 统计

geopandas ×1

python ×1

shapefile ×1

zipfile ×1