alex_bn_lee

导航

【746】读取geopandas文件gpkg & 写入gpkg文件(python & R)

一、Python

参考:geopandas库的基础学习

参考:Reading and Writing Files

代码 - read:

import pandas as pd
import geopandas as gpd

data=gpd.read_file('xxxxx.gpkg',layer='xxxxx',encoding='utf-8')	#layer参数为对应图层名称

代码 - write:

countries_gdf.to_file("package.gpkg", layer='countries', driver="GPKG")
cities_gdf.to_file("package.gpkg", layer='cities', driver="GPKG")

二、R

参考:Writing multiple layers to GeoPackage using writeOGR() in R?

代码 - read & write:

library(sf)

# read data
nc     <- st_read(system.file("shape/nc.shp", package="sf"))
storms <- st_read(system.file("shape/storms_xyz.shp", package="sf"))

# write data
st_write(nc,     "nc.gpkg", "nc")
st_write(storms, "nc.gpkg", "storms", append = TRUE)

st_layers("nc.gpkg")
## Driver: GPKG 
## Available layers:
##   layer_name  geometry_type features fields
## 1         nc  Multi Polygon      100     14
## 2     storms 3D Line String       71      0

 

posted on 2022-10-03 19:31  McDelfino  阅读(1227)  评论(0)    收藏  举报