PYTHON 联系笔记 GeoPandas(二)空间数据的读与写
目录
Reading and Writing Files读写文件
Reading Spatial Data 读取空间数据
geopandas can read almost any vector-based spatial data format including ESRI shapefile, GeoJSON files and more using the command:
geopandas可以使用以下命令读取几乎任何基于矢量的空间数据格式,包括ESRI shapefile,GeoJSON文件等等:
geopandas.read_file()
which returns a GeoDataFrame object. (This is possible because geopandas makes use of the great fiona library, which in turn makes use of a massive open-source program called GDAL/OGRdesigned to facilitate spatial data transformations).
它返回一个GeoDataFrame对象。 (这是可能的,因为geopandas使用了伟大的fiona库,后者又使用了一个名为GDAL / OGR设计的大型开源程序来促进空间数据转换)。
Any arguments passed to read_file()
after the file name will be passed directly to fiona.open
, which does the actual data importation. In general, read_file
is pretty smart and should do what you want without extra arguments, but for more help, type:
在文件名之后传递给read_file()的任何参数将直接传递给fiona.open,后者执行实际的数据输入。 一般来说,read_file非常聪明,可以在没有额外参数的情况下执行您想要的操作,但是为了获得更多帮助,请键入:
import fiona; help(fiona.open)
Among other things, one can explicitly set the driver (shapefile, GeoJSON) with the driver
keyword, or pick a single layer from a multi-layered file with the layer
keyword.
除此之外,可以使用driver关键字显式设置驱动程序(shapefile,GeoJSON),或者使用layer关键字从多层文件中选择单个图层。
Where supported in fiona
, geopandas can also load resources directly from a web URL, for example for GeoJSON files from geojson.xyz:
如果fiona支持,geopandas也可以直接从Web URL加载资源,例如geojson.xyz中的GeoJSON文件:
url = "http://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_110m_land.geojson" df = geopandas.read_file(url)
geopandas can also get data from a PostGIS database using the read_postgis()
command.
geopandas还可以使用read_postgis()命令从PostGIS数据库中获取数据。
Writing Spatial Data写空间数据
GeoDataFrames can be exported to many different standard formats using the GeoDataFrame.to_file()
method. For a full list of supported formats, type import fiona; fiona.supported_drivers
.
可以使用GeoDataFrame.to_file()方法将GeoDataFrames导出为许多不同的标准格式。 有关支持的格式的完整列表,请键入
import fiona;fiona.supported_drivers。
转载自:https://blog.csdn.net/gwj992/article/details/82746173