Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct usage of crs in projectTo()?? #355

Open
achubaty opened this issue Sep 9, 2023 · 0 comments
Open

correct usage of crs in projectTo()?? #355

achubaty opened this issue Sep 9, 2023 · 0 comments

Comments

@achubaty
Copy link
Collaborator

achubaty commented Sep 9, 2023

projectTo() help file says argument projectTo should be created using sf_crs() but this fails because terra is expecting a character.
Using a character fails because it looks like projectTo() passes this character on to res(), which then fails.

d> coords <- matrix(c(-122.98, -116.1,
+                    -99.2, -106,
+                    -122.98, 59.9,
+                    65.73, 63.58,
+                    54.79, 59.9), ncol = 2)
d> center <- sf::st_multipoint(coords) |>
+   sf::st_centroid() |>
+   as.matrix()
d> studyArea <- SpaDES.tools::randomPolygon(center, area = 1e4) |>
+   sf::st_as_sf(crs = "epsg:4326")
Assuming matrix is in latitude/longitude
The CRS provided is not in meters; converting internally to UTM so area will be approximately correct.
d> rasTemplate <- terra::rast(terra::ext(studyArea), resolution = 1e-5, crs = "epsg:4326")
d> tsf <- SpaDES.tools::randomPolygons(rasTemplate, numTypes = 8) * 30
d> ## fails with st_crs()
d> reproducible::projectTo(tsf, projectTo = sf::st_crs("epsg:4326"))
    projecting...Error: [project] cannot get output boundaries
In addition: Warning messages:
1: [project,SpatRaster] argument y (the crs) should be a character value 
2: [project] Cannot set raster SRS: empty srs 
d> ## also fails with character
d> reproducible::projectTo(tsf, projectTo = "epsg:4326")
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for functionresfor signature"character"
d> packageVersion("reproducible")
[1] ‘2.0.8.9001d> packageVersion("sf")
[1] ‘1.0.14d> packageVersion("SpaDES.tools")
[1] ‘2.0.4.9000d> packageVersion("terra")
[1] ‘1.7.46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant