计算相交后的几何不一致
Geometry inconsistencies after computing intersection
我是地理空间方面的新手,我正在尝试将 shapefile 划分为网格块,然后计算网格上的交集。但是,我 运行 陷入了输出的一致性问题。这是一个最小的例子:
x <- st_read("https://data.sfgov.org/api/geospatial/rarb-5ahf?method=export&format=GeoJSON")
grids <- grids <- sf::st_make_grid(x, n = 40)
int <- st_intersection(x, grids)
我(预计)收到以下消息:
although coordinates are longitude/latitude, st_intersection assumes that they are planar
然后 运行 st_area
给出以下输出:
> sum(st_area(x))
600592318 m^2
> sum(st_area(int))
600594187 m^2
路口扩大了面积。根据我在世界上的位置,它有时会丢失区域。
我正在使用它的真实世界场景涉及一个 shapefile 和包含投影到 longlat
的整个世界的栅格。我还需要 longlat
.
中的输出
@Spacedman 的评论似乎是正确的。您可以使用程序包 smoothr
中的函数 densify
对多边形进行致密化测试:
library(sf)
library(smoothr)
x <- st_read("https://data.sfgov.org/api/geospatial/rarb-5ahf?method=export&format=GeoJSON")
grids <- grids <- sf::st_make_grid(x, n = 40)
int <- st_intersection(x, grids)
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
#> Warning: attribute variables are assumed to be spatially constant
#> throughout all geometries
sum(st_area(x))
#> 600592318 [m^2]
sum(st_area(int))
#> 600594187 [m^2]
grids_dense <- smoothr::densify(grids, n = 60)
x_dense <- smoothr::densify(x, n = 60)
int_dense <- st_intersection(x_dense, grids_dense)
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
#> Warning: attribute variables are assumed to be spatially constant
#> throughout all geometries
sum(st_area(x_dense))
#> 600594404 [m^2]
sum(st_area(int_dense))
#> 600594404 [m^2]
感谢所有回答的人。 densify
解决方案确实有效,但对我而言计算量太大。我尝试了其他库并找到了 rgeos
.
的解决方案
library(rgeos)
library(sf)
x <- sf::st_read("https://data.sfgov.org/api/geospatial/rarb-5ahf?method=export&format=GeoJSON")
grids <- sf::st_make_grid(x, n = 40)
int <- sf::st_intersection(x, grids)
> sum(st_area(x))
600592318 m^2
> sum(st_area(int))
600594187 m^2
> rgeos::gArea(sf::as_Spatial(x))
[1] 0.06140787
> rgeos::gArea(sf::as_Spatial(int))
[1] 0.06140787
这对我有用,因为我最关心的是面积的比例。
我是地理空间方面的新手,我正在尝试将 shapefile 划分为网格块,然后计算网格上的交集。但是,我 运行 陷入了输出的一致性问题。这是一个最小的例子:
x <- st_read("https://data.sfgov.org/api/geospatial/rarb-5ahf?method=export&format=GeoJSON")
grids <- grids <- sf::st_make_grid(x, n = 40)
int <- st_intersection(x, grids)
我(预计)收到以下消息:
although coordinates are longitude/latitude, st_intersection assumes that they are planar
然后 运行 st_area
给出以下输出:
> sum(st_area(x))
600592318 m^2
> sum(st_area(int))
600594187 m^2
路口扩大了面积。根据我在世界上的位置,它有时会丢失区域。
我正在使用它的真实世界场景涉及一个 shapefile 和包含投影到 longlat
的整个世界的栅格。我还需要 longlat
.
@Spacedman 的评论似乎是正确的。您可以使用程序包 smoothr
中的函数 densify
对多边形进行致密化测试:
library(sf)
library(smoothr)
x <- st_read("https://data.sfgov.org/api/geospatial/rarb-5ahf?method=export&format=GeoJSON")
grids <- grids <- sf::st_make_grid(x, n = 40)
int <- st_intersection(x, grids)
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
#> Warning: attribute variables are assumed to be spatially constant
#> throughout all geometries
sum(st_area(x))
#> 600592318 [m^2]
sum(st_area(int))
#> 600594187 [m^2]
grids_dense <- smoothr::densify(grids, n = 60)
x_dense <- smoothr::densify(x, n = 60)
int_dense <- st_intersection(x_dense, grids_dense)
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
#> Warning: attribute variables are assumed to be spatially constant
#> throughout all geometries
sum(st_area(x_dense))
#> 600594404 [m^2]
sum(st_area(int_dense))
#> 600594404 [m^2]
感谢所有回答的人。 densify
解决方案确实有效,但对我而言计算量太大。我尝试了其他库并找到了 rgeos
.
library(rgeos)
library(sf)
x <- sf::st_read("https://data.sfgov.org/api/geospatial/rarb-5ahf?method=export&format=GeoJSON")
grids <- sf::st_make_grid(x, n = 40)
int <- sf::st_intersection(x, grids)
> sum(st_area(x))
600592318 m^2
> sum(st_area(int))
600594187 m^2
> rgeos::gArea(sf::as_Spatial(x))
[1] 0.06140787
> rgeos::gArea(sf::as_Spatial(int))
[1] 0.06140787
这对我有用,因为我最关心的是面积的比例。