Trim get_elev_raster by a shapefile
Closed this issue · 6 comments
I am trying to get elevation data for TX, and I have the shapefile. When I load the shapefile and run get_elev_raster I get this error about prj. I can not get it to work no matter what crs I input, and I'm pretty new at this, so any input would be awesome!
tex_bound <- st_read("State.shp")
tex_height <- get_elev_raster(locations = text_rast, prj = "+proj=longlat +datum=WGS84 +no_defs")
Error in sp::CRS(prj) :
PROJ4 argument-value pairs must begin with +: GEOGCRS["WGS 84 (with axis order normalized for visualization)",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["geodetic longitude (Lon)",east,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433,
ID["EPSG",9122]]],
AXIS["geodetic latitude (Lat)",north,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433,
ID["EPSG",9122]]]]
@BigBallerBenzie Sorry to hear you are having some issues.
First thing I see is that your shapefile is reading into tex_bound
, but you are pointing to a text_rast
in your get_elev_raster()
call. Also, I think you can avoid using the prj, as tex_bound
should have one from reading in the shapefile. Try this:
tex_height <- get_elev_raster(locations = tex_bound, z = 5, clip = "locations")
If that works, let me know. You'll need to pick a z value that works best for your application. 5 is pretty coarse, but should run quickly enough for Texas.
@jhollist After runing this line of code, I still get the same exact error that starts with:
Error in sp::CRS(prj) :
PROJ4 argument-value pairs must begin with +: GEOGCRS["WGS 84 (with axis order normalized for visualization)",
Tried with a wisc shapefile and got this error:
Error in sp::CRS(prj) :
PROJ4 argument-value pairs must begin with +: PROJCRS["NAD83(HARN) / Wisconsin Transverse Mercator",.....
After running code to replicate the error, this is what sessionInfo() gives me
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgdal_1.5-23 sf_0.9-7 elevatr_0.3.4 plotly_4.9.3 extrafont_0.17 scico_1.2.0 ggplot2_3.3.3
[8] rayshader_0.19.2 raster_3.3-13 sp_1.4-2
loaded via a namespace (and not attached):
Error in x[["Version"]] : subscript out of bounds
In addition: Warning message:
In FUN(X[[i]], ...) :
DESCRIPTION file of package 'testthat' is missing or broken
That did it!