Skip to content

Commit

Permalink
Added try block in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
dscolby committed Feb 3, 2022
1 parent 5033825 commit 37738bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
27 changes: 17 additions & 10 deletions R/spacejamr.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Author: Darren Colby
# Date: 1/27/2022
# Date: 2/3/2022
# Purpose: To create a basic class and methods for "spacejamr" objects

# Constructor methods -----------------------------------------------------
Expand Down Expand Up @@ -31,19 +31,26 @@ validate_spacejamr <- function(path, guess_crs) {
# Sets the CRS if it is not already set
if (guess_crs) {

# Best projected crs
suggested_crs <- crsuggest::suggest_top_crs(shapefile)
# In case an appropriate CRS is not found
try({

# Transform shapefile to the best projected coordinate reference system
transformed_shapefile <- sf::st_transform(shapefile, suggested_crs)
# Best projected crs
suggested_crs <- crsuggest::suggest_top_crs(shapefile)

# Set the crs in the shapefile
transformed_shapefile <- suppressWarnings(sf::st_set_crs(shapefile,
suggested_crs))
# Transform shapefile to the best projected coordinate reference system
transformed_shapefile <- sf::st_transform(shapefile, suggested_crs)

window <- spatstat.geom::as.owin(transformed_shapefile)
# Set the crs in the shapefile
transformed_shapefile <- suppressWarnings(sf::st_set_crs(shapefile,
suggested_crs))

} else { # Case when the CRS is already set
window <- spatstat.geom::as.owin(transformed_shapefile)

})



} else { # Case when the CRS is already set or appropriate CRS is not found

window <- spatstat.geom::as.owin(window)

Expand Down
3 changes: 1 addition & 2 deletions man/as.spacejamr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 37738bf

Please sign in to comment.