shapefiles:在 R 中将点(多点)转换为点(PointZ)几何

shapefiles: convert Point (MultiPoint) to Point (PointZ) geometry in R

我在多点几何中有一个 shapefile (mult_point_example.shp):

# 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 package (v2.0.0)

于 2021-05-26 创建