r - shapefiles:在 R 中将点(MultiPoint)转换为点(PointZ)几何
问题描述
我mult_point_example.shp
在多点几何中有一个 shapefile ( ):
# Packages
require(sf)
# get AOI
download.file(
"https://github.com/Leprechault/trash/raw/main/mult_point_example.zip",
zip_path <- tempfile(fileext = ".zip")
)
unzip(zip_path, exdir = tempdir())
# Open the files
setwd(tempdir())
my_multi_points <- sf::st_read("mult_point_example.shp")
#Reading layer `mult_point_example' from data source `C:\Users\fores\AppData\Local\Temp\RtmpmQybFP\mult_point_example.shp' using driver `ESRI Shapefile'
#Simple feature collection with 8 features and 10 fields
#Geometry type: MULTIPOINT
#Dimension: XYZ
#Bounding box: xmin: -52.73354 ymin: -19.79479 xmax: -52.72586 ymax: -19.79067
#z_range: zmin: 0 zmax: 0
#Geodetic CRS: WGS 84
但是,我想将多点对象转换为点几何。我需要一些帮助来将 ( my_multi_points
) 中的每个点转换为个人特征。
解决方案
使用st_cast(., "POINT")
. 但是,请注意,当您转换为 时POINT
,这些特征会重复,即在一个MULTIPOINT
(一行有多个特征)包含 20 个点的情况下,当您转换为时,POINT
您会得到 20 行POINT
与原始特征相同的行MULTIPOINT
:
# Packages
require(sf)
#> Loading required package: sf
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
# get AOI
download.file(
"https://github.com/Leprechault/trash/raw/main/mult_point_example.zip",
zip_path <- tempfile(fileext = ".zip")
)
unzip(zip_path, exdir = tempdir())
# Open the files
setwd(tempdir())
my_multi_points <- sf::st_read("mult_point_example.shp", quiet = TRUE)
my_multi_points
#> Simple feature collection with 8 features and 10 fields
#> Geometry type: MULTIPOINT
#> Dimension: XYZ
#> Bounding box: xmin: -52.73354 ymin: -19.79479 xmax: -52.72586 ymax: -19.79067
#> z_range: zmin: 0 zmax: 0
#> Geodetic CRS: WGS 84
#> Talhao Uso Especies Yoe DATA EventoClas POINT_X
#> 1 142 Plantio_Comercial EUUR 2012 2017-06-15 Pequeno -52.72675
#> 2 142 Plantio_Comercial EUUR 2012 2017-06-09 Pequeno -52.72843
#> 3 142 Plantio_Comercial EUUR 2012 2017-06-12 Pequeno -52.73070
#> 4 142 Plantio_Comercial EUUR 2012 2017-06-09 Meio_Quadrante -52.72847
#> 5 142 Plantio_Comercial EUUR 2012 2017-06-12 Meio_Quadrante -52.73066
#> 6 142 Plantio_Comercial EUUR 2012 2017-06-09 Um_Quadrante -52.72868
#> 7 142 Plantio_Comercial EUUR 2012 2017-06-12 Um_Quadrante -52.73065
#> 8 142 Plantio_Comercial EUUR 2012 2017-06-12 Carreiros -52.73217
#> POINT_Y Fazenda TS_m2 geometry
#> 1 -19.79296 Lobo 1 MULTIPOINT Z ((-52.72692 -1...
#> 2 -19.79197 Lobo 1 MULTIPOINT Z ((-52.731 -19....
#> 3 -19.79308 Lobo 1 MULTIPOINT Z ((-52.73354 -1...
#> 4 -19.79192 Lobo 6 MULTIPOINT Z ((-52.73086 -1...
#> 5 -19.79317 Lobo 6 MULTIPOINT Z ((-52.73345 -1...
#> 6 -19.79181 Lobo 10 MULTIPOINT Z ((-52.73075 -1...
#> 7 -19.79280 Lobo 10 MULTIPOINT Z ((-52.73343 -1...
#> 8 -19.79275 Lobo 1 MULTIPOINT Z ((-52.73217 -1...
# SOLUTION: Cast to points
my_points <- st_cast(my_multi_points, "POINT")
#> Warning in st_cast.sf(my_multi_points, "POINT"): repeating attributes for all
#> sub-geometries for which they may not be constant
my_points
#> Simple feature collection with 416 features and 10 fields
#> Geometry type: POINT
#> Dimension: XYZ
#> Bounding box: xmin: -52.73354 ymin: -19.79479 xmax: -52.72586 ymax: -19.79067
#> Geodetic CRS: WGS 84
#> First 10 features:
#> Talhao Uso Especies Yoe DATA EventoClas POINT_X
#> 1 142 Plantio_Comercial EUUR 2012 2017-06-15 Pequeno -52.72675
#> 1.1 142 Plantio_Comercial EUUR 2012 2017-06-15 Pequeno -52.72675
#> 1.2 142 Plantio_Comercial EUUR 2012 2017-06-15 Pequeno -52.72675
#> 2 142 Plantio_Comercial EUUR 2012 2017-06-09 Pequeno -52.72843
#> 2.1 142 Plantio_Comercial EUUR 2012 2017-06-09 Pequeno -52.72843
#> 2.2 142 Plantio_Comercial EUUR 2012 2017-06-09 Pequeno -52.72843
#> 2.3 142 Plantio_Comercial EUUR 2012 2017-06-09 Pequeno -52.72843
#> 2.4 142 Plantio_Comercial EUUR 2012 2017-06-09 Pequeno -52.72843
#> 2.5 142 Plantio_Comercial EUUR 2012 2017-06-09 Pequeno -52.72843
#> 2.6 142 Plantio_Comercial EUUR 2012 2017-06-09 Pequeno -52.72843
#> POINT_Y Fazenda TS_m2 geometry
#> 1 -19.79296 Lobo 1 POINT Z (-52.72692 -19.7930...
#> 1.1 -19.79296 Lobo 1 POINT Z (-52.72664 -19.7929...
#> 1.2 -19.79296 Lobo 1 POINT Z (-52.72657 -19.7928...
#> 2 -19.79197 Lobo 1 POINT Z (-52.731 -19.7914 0)
#> 2.1 -19.79197 Lobo 1 POINT Z (-52.73098 -19.7912...
#> 2.2 -19.79197 Lobo 1 POINT Z (-52.73075 -19.7914...
#> 2.3 -19.79197 Lobo 1 POINT Z (-52.73059 -19.7913...
#> 2.4 -19.79197 Lobo 1 POINT Z (-52.73052 -19.7920...
#> 2.5 -19.79197 Lobo 1 POINT Z (-52.73047 -19.7909 0)
#> 2.6 -19.79197 Lobo 1 POINT Z (-52.73046 -19.7909...
由reprex 包于 2021-05-26 创建 (v2.0.0 )
推荐阅读
- node.js - 快递中的按钮对我不起作用并且没有错误代码
- javascript - 打字稿说:“类型'“a”'和'“b”'没有重叠”。这是什么意思?
- python - 由于引号而无法在python中将字符串转换为dict
- intershop - 创建没有运输/交货的订单
- python - Python乌龟等待空格键
- angular - 生产中 Angular 2 中的路由问题
- debugging - magento 2中的LOCKED_RECORD_INFO_BLOCK
- c++ - 在函子中捕获要移动的值
- python - 如何使用 ThreadPoolExecutor 并发运行
- git - 与另一个项目一致的 Git 文件