简体   繁体   English

如何将 Corine 的土地覆盖类型分配和匹配到具有一组 lon lat 坐标的数据框?

[英]How to assign and match land cover type from Corine to a dataframe with a set of lon lat coordinates?

I'm trying to find out the land use type for a set of coordinates that define the location of plant species across Europe.我试图找出一组坐标的土地利用类型,这些坐标定义了欧洲植物物种的位置。 However I'm stuck in the process of assigning the land use to the respective coordinates.但是,我被困在将土地使用分配给各个坐标的过程中。 Any advice would be more than welcome!任何建议都将受到欢迎!

First, I download the land use raster file from here: https://land.copernicus.eu/pan-european/corine-land-cover首先,我从这里下载土地利用栅格文件: https ://land.copernicus.eu/pan-european/corine-land-cover

#Read raster file (year 2006 but could be any)
clc <- raster("U2006_CLC2000_V2020_20u1.tif")

Then, I read the Corine land use classes and rename the levels of the raster file with this classes然后,我阅读了 Corine 土地利用类并用这些类重命名了光栅文件的级别

#Read Corine classes
clc_classes <- foreign::read.dbf("CLC_1990/DATA/U2006_CLC2000_V2020_20u1.tif.vat.dbf",
                                 as.is = TRUE) %>%dplyr::select(value = Value,landcov = LABEL3)

This is a small subset of coordinates from my full list of coordinates (over 200.000 in total):这是我的完整坐标列表中的一小部分坐标(总共超过 200.000):

lon <- c("51.105", "51.195", "51.188", "51.239")
lat <- c("4.392", "4.395", "4.896", "4.468")
sp <- c("sp1","sp2", "sp3","sp4")
#Create minimal dataframe 
d <- data.frame(lon,lat,sp)

But now I really do not know how to proceed and create the final dataframe with land use type given the matching with the raster file但是现在我真的不知道如何继续并创建具有土地利用类型的最终数据框,因为它与栅格文件匹配

My intention is to add a 4th column as follows after the matching of my coordinates with the land use type of the raster file.我的意图是在我的坐标与栅格文件的土地利用类型匹配后添加如下第 4 列。

#Example of how this fourth column would be like:
d$land_use <- c("Olive groves", "Olive groves", "Vineyards", "Pastures")

The data (another file from the same website).数据(来自同一网站的另一个文件)。

library(terra)
r <- rast("U2018_CLC2018_V2020_20u1.tif")

As you can see, r knows about the class labels.如您所见, r知道类标签。

r
#class       : SpatRaster 
#dimensions  : 46000, 65000, 1  (nrow, ncol, nlyr)
#resolution  : 100, 100  (x, y)
#extent      : 9e+05, 7400000, 9e+05, 5500000  (xmin, xmax, ymin, ymax)
#coord. ref. : ETRS_1989_LAEA (EPSG:3035) 
#source      : U2018_CLC2018_V2020_20u1.tif 
#color table : 1 
#categories  : LABEL3, Red, Green, Blue, CODE_18 
#name        :                  LABEL3 
#min value   : Continuous urban fabric 
#max value   :                  NODATA 

head(cats(r)[[1]])
#  Value                                     LABEL3       Red     Green      Blue CODE_18
#1     1                    Continuous urban fabric 0.9019608 0.0000000 0.3019608     111
#2     2                 Discontinuous urban fabric 1.0000000 0.0000000 0.0000000     112
#3     3             Industrial or commercial units 0.8000000 0.3019608 0.9490196     121
#4     4 Road and rail networks and associated land 0.8000000 0.0000000 0.0000000     122
#5     5                                 Port areas 0.9019608 0.8000000 0.8000000     123
#6     6                                   Airports 0.9019608 0.8000000 0.9019608     124

Here are some example points for use with extract以下是一些与extract一起使用的示例点

pts <- matrix(c(3819069, 3777007, 3775822, 2267450, 2302403, 2331431), ncol=2)
extract(r, pts)    
#                        LABEL3
#1                Sea and ocean
#2 Complex cultivation patterns
#3           Natural grasslands

Or with your lon/lat points (you had the names reversed!), first transform these to the coordinate reference system of the land use raster:或者使用您的 lon/lat 点(您的名称颠倒了!),首先将它们转换为土地利用栅格的坐标参考系统:

lat <- c(51.105, 51.195, 51.188, 51.239)
lon <- c(4.392, 4.395, 4.896, 4.468)
xy <- cbind(lon, lat) 
v <- vect(xy, crs="+proj=longlat")
vv <- project(v, crs(r)) 

extract(r, vv)
#  ID                                     LABEL3
#1  1               Complex cultivation patterns
#2  2 Road and rail networks and associated land
#3  3                                   Pastures
#4  4             Industrial or commercial units

If you want the land use code instead如果您想要土地使用代码

activeCat(r) <- "CODE_18"
extract(r, vv)
#  ID CODE_18
#1  1     242
#2  2     122
#3  3     231
#4  4     121

The answer from Robert was really great helping someone with no clues like me.罗伯特的回答真的很棒,可以帮助像我这样没有线索的人。 However when I try to achieve the same, I get unexpected results.然而,当我尝试达到同样的效果时,我得到了意想不到的结果。

When I run当我跑

library(terra)
data <- rast("2018_CLC2018_V2020_20u1.tif")
data

I get no labels:我没有标签:

class       : SpatRaster 
dimensions  : 46000, 65000, 1  (nrow, ncol, nlyr)
resolution  : 100, 100  (x, y)
extent      : 9e+05, 7400000, 9e+05, 5500000  (xmin, xmax, ymin, ymax)
coord. ref. : ETRS_1989_LAEA (EPSG:3035) 
source      : U2018_CLC2018_V2020_20u1.tif 
name        : U2018_CLC2018_V2020_20u1 
min value   :                        1 
max value   :                       48 

And therefore the results from the extraction are in the 1 - 48 range.因此,提取的结果在 1 - 48 范围内。 This is the only file I found at the website that matches the naming.这是我在网站上找到的唯一与命名匹配的文件。 I'm sorry for adding this as an answer but I couldn't comment.很抱歉将此添加为答案,但我无法发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM