【发布时间】:2021-08-14 15:26:58
【问题描述】:
我正在尝试计算美国每个县的土地覆盖重新分配。 我已经使用 FedData 包(devtools 版本)获得了 Apache 县的 NLCD,并且我正在使用人口普查局的县 shapefile。
问题是我得到的面积比官方的和我的 shapefile 中指示的要大得多,即 51,000km^2 而不是官方的 29,0000km^2。对栅格对象一定有一些我不理解的地方,但是经过数小时的网络搜索后我感到非常困惑,感谢任何帮助。
下面描述了使用的代码和用于计算的方法。县级数据可在此处下载: https://www2.census.gov/geo/tiger/TIGER2016/COUNTY/
以下代码假定县 shapefile 已保存并解压缩。
- 获取和读取数据
#devtools::install_github("ropensci/FedData")
library(FedData)
library(rgdal)
library(dplyr)
#Get Apache polygone
counties<- readOGR('tl_2016_us_county/tl_2016_us_county.shp')
apache <- subset(counties,counties$GEOID=="04001")
# Get NCLD data
nlcd_data <- get_nlcd(apache,
year = 2011,
label = "Apache",
force.redo = TRUE)
nlcd_data #inspect the object, can see that number of cells is around 57 million
- 然后我提取了栅格的值并将它们放入频率表中。从那里我计算得到的面积。由于 NLCD 数据为 30m 分辨率,因此我将每个类别的单元数乘以 900,再除以 100 万,得到面积以平方公里为单位。
计算的总面积太大。
# Calculating the landcover repartition in County
landcover<-data.frame(x2011 = values(nlcd_data)) #Number of rows corresponds to number of cells
landcover_freq<-table(landcover)
df_landcover <- as.data.frame(landcover_freq)
res <- df_landcover %>%
mutate(area_type_sqm = Freq*900,
area_type_km=area_type_sqm/1e6,
area_sqkm = sum(area_type_km))%>%
group_by(landcover)%>%
mutate(pc_land =round(100*area_type_km/area_sqkm,1))
head(arrange(res,desc(pc_land)))
# A tibble: 6 x 6
# Groups: landcover [6]
landcover Freq area_type_sqm area_type_km area_sqkm pc_land
<fct> <int> <dbl> <dbl> <dbl> <dbl>
1 52 33455938 30110344200 30110. 51107. 58.9
2 42 16073820 14466438000 14466. 51107. 28.3
3 71 5999412 5399470800 5399. 51107. 10.6
4 31 488652 439786800 440. 51107. 0.9
5 21 362722 326449800 326. 51107. 0.6
6 22 95545 85990500 86.0 51107. 0.2
## Total area calculated from raster is 51,107 square km
apache_area <- as.data.frame(apache) %>%
mutate(AREA=(as.numeric(ALAND)+as.numeric(AWATER))/1e6) %>%
select(AREA)
apache_area$AREA
29055.47 #Official area of apache county (in square km)
- 对 shapefile 和光栅的目视检查:
差异似乎不足以证明差异是合理的
apache <- spTransform(apache,proj4string(nlcd_data))
plot(nlcd_data)
plot(apache,add=TRUE)
【问题讨论】: