我已将shapefile读入GeoDataFrame并对其进行了一些修改:
import geopandas as gpd
# Read shapefile into geodataframe
geodf = gpd.read_file("shapefile.shp")
# Do some "pandas-like" modifications to shapefile
geodf = modify_geodf(geodf)但是,我还想在它上应用osgeo.ogr模块的一些功能:
from osgeo import ogr
# Read shapefile into ogr DataSource
ds=ogr.Open("shapefile.shp")
# Do some "gdal/ogr-like" modifications to shapefile
ds = modify_ds(ds)问题:是否有任何方法直接使用或转换已在内存中的shapefile (目前以GeoDataFrame的形式)作为osgeo.ogr.DataSource?
到目前为止,我所做的方法是将GeoDataFrame保存到to_file()中,然后再使用osgeo.ogr.Open(),但对我来说,这似乎是多余的。
发布于 2018-08-23 01:47:04
是的,这是可能的。您可以将GeoDataFrame以支持OGR矢量格式的GeoJson格式传递到ogr.Open。因此,不需要将临时文件保存到磁盘中:
import geopandas as gpd
from osgeo import ogr
# Read file into GeoDataFrame
data = gpd.read_file("my_shapefile.shp")
# Pass the GeoDataFrame into ogr as GeoJson
shp = ogr.Open(data.to_json())
# Do your stuff with ogr ...希望这能帮上忙!
发布于 2017-02-13 14:44:06
不是的。只有OGR支持的格式可以用ogr.Open()打开。
https://stackoverflow.com/questions/42206195
复制相似问题