Unable to extract world clim data with specific coordinates

  Kiến thức lập trình

I’m running the geodata package in order to extract as high a resolution as I can for temperature and precipitation data for a few coordinates. My code below seems to run with no problem but my values table comes up entirely empty and filled with NaNs. I think my issue might be that I am using the wrong crs but I’ll be honest, I don’t use GIS so I don’t really know what it should be other than EPSG:4537 which comes up when I google “Toronto EPSG for GIS”.

Also, I just want a clean dataframe to come up for each coordinate and columns for temperature and then precipitation when I run this for the precipitation variable.

# library(sp)
# library(raster)
library(geodata)
library(dplyr)


# Save lat/long as a dataframe
coords <- read.csv("../CentroidLatsLongs.csv")
df <- as.data.frame(coords %>% select(Centroid_Longitude,Centroid_Latitude)) # make it long followed by lat (x,y)

# Download annual mean temperature for Canada
r <- worldclim_country("Canada", var="tavg", version="2.1", path=tempdir())

points <- vect(df, geom=c("Centroid_Longitude", "Centroid_Latitude"),
               crs = "EPSG:4537")  # for the Toronto area where the coordinates are around

values <- extract(r, points)

My table for some reason comes up with 107 rows, 13 columns, and is just filled with NA throughout. I was expecting 11 rows for the 11 coordinates, and a column for tavg.

> dput(df)
structure(list(Centroid_Longitude = c(-79.35296, -79.35296, -79.35296, 
-79.35296, -79.35296, -79.46594, -79.46269, -79.46269, -79.46269, 
-79.46269, -79.46269, -79.46269, -79.46269, -79.46269, -79.46269, 
-79.46269, -79.46269, -79.46269, -79.46269, -79.46269, -79.46269, 
-79.46269, -79.46269, -79.50596, -79.50596, -79.50596, -79.50596, 
-79.50596, -79.50596, -79.50596, -79.50596, -79.50596, -79.50596, 
-79.50596, -79.50596, -79.50596, -79.50596, -79.50596, -79.50596, 
-79.50596, -79.50596, -79.50596, -79.50596, -79.50596, -79.50596, 
-79.50596, -79.50596, -79.50596, -79.50596, -79.50596, -79.50596, 
-79.48454, -79.48454, -79.48454, -79.48454, -79.48454, -79.48454, 
-79.48454, -79.48454, -79.48454, -79.48454, -79.48454, -79.48454, 
-79.48454, -79.48454, -79.48454, -79.48454, -79.49268, -79.49268, 
-79.49268, -79.49268, -79.49268, -79.49268, -79.49268, -79.49268, 
-79.49268, -79.49268, -79.49268, -79.49268, -79.49268, -79.43033, 
-79.43033, -79.43033, -79.43033, -79.43033, -79.43033, -79.43033, 
-79.43033, -79.44999, -79.44999, -79.44999, -79.44999, -79.44999, 
-79.47789, -79.47789, -79.47789, -79.47789, -79.47789, -79.47789, 
-79.47789, -79.47896, -79.47896, -79.47896, -79.47896, -79.47896, 
-79.47896, -79.43732), Centroid_Latitude = c(43.71478, 43.71478, 
43.71478, 43.71478, 43.71478, 43.64642, 43.65197, 43.65197, 43.65197, 
43.65197, 43.65197, 43.65197, 43.65197, 43.65197, 43.65197, 43.65197, 
43.65197, 43.65197, 43.65197, 43.65197, 43.65197, 43.65197, 43.65197, 
43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 
43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 
43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 
43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 43.77266, 
43.74195, 43.74195, 43.74195, 43.74195, 43.74195, 43.74195, 43.74195, 
43.74195, 43.74195, 43.74195, 43.74195, 43.74195, 43.74195, 43.74195, 
43.74195, 43.74195, 43.7736, 43.7736, 43.7736, 43.7736, 43.7736, 
43.7736, 43.7736, 43.7736, 43.7736, 43.7736, 43.7736, 43.7736, 
43.7736, 43.75227, 43.75227, 43.75227, 43.75227, 43.75227, 43.75227, 
43.75227, 43.75227, 43.67143, 43.67143, 43.67143, 43.67143, 43.67143, 
43.75408, 43.75408, 43.75408, 43.75408, 43.75408, 43.75408, 43.75408, 
43.74743, 43.74743, 43.74743, 43.74743, 43.74743, 43.74743, 43.69517
)), class = "data.frame", row.names = c(NA, -107L))

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT