USEPA / elevatr

An R package for accessing elevation data
Other
201 stars 26 forks source link

Trim get_elev_raster by a shapefile #46

Closed jbenzaquen42 closed 3 years ago

jbenzaquen42 commented 3 years ago

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]]]]
jhollist commented 3 years ago

@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.

jbenzaquen42 commented 3 years ago

@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",.....
jhollist commented 3 years ago

What do you get with sessionInfo()?

On Tue, Feb 23, 2021 at 3:35 PM BigBallerBenzie notifications@github.com wrote:

@jhollist https://github.com/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",.....

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jhollist/elevatr/issues/46#issuecomment-784493679, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJPYSY5JEF5J4IXY6MCBPTTAQGS3ANCNFSM4YCVGZIA .

-- Jeffrey W. Hollister email: jeff.w.hollister@gmail.com cell: 401 556 4087 https://jwhollister.com

jbenzaquen42 commented 3 years ago

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
jhollist commented 3 years ago

Try updating sp and raster. They are both a bit old and there have been a lot of changes recently to how reference systems are handled.

On Tue, Feb 23, 2021 at 5:01 PM BigBallerBenzie notifications@github.com wrote:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jhollist/elevatr/issues/46#issuecomment-784543267, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJPYS5NCQHZMBFHEQYOH23TAQQS7ANCNFSM4YCVGZIA .

-- Jeffrey W. Hollister email: jeff.w.hollister@gmail.com cell: 401 556 4087 https://jwhollister.com

jbenzaquen42 commented 3 years ago

That did it!