crsuggest icon indicating copy to clipboard operation
crsuggest copied to clipboard

`crsuggest::suggest_crs()` hangs when units are specified and there is no match.

Open ericrobskyhuntley opened this issue 8 months ago • 0 comments

Causes a problem because US State Plane crses are sometimes in "ft", sometimes in "us-ft". Could probably be resolved by allowing multiple candidate units in units parameter. For an example breaking case...

d1<- sf::st_polygon(
  list(matrix(
    c(-73.90909,41.19984,
      -73.81354,41.19984,
      -73.81354,41.12057,
      -73.90909,41.12057,
      -73.90909,41.19984
      ),
    ncol=2, 
    byrow=TRUE
    ))
) |>
  sf::st_sfc(crs=4326) |>
  sf::st_as_sf()

# Works
crsuggest::suggest_crs(d1, limit = 3, units = "us-ft") |>
  dplyr::select(crs_code, crs_name)

# A tibble: 3 × 2
#  crs_code crs_name                              
#  <chr>    <chr>                                 
# 1 6537     NAD83(2011) / New York East (ftUS)    
# 2 3626     NAD83(NSRS2007) / New York East (ftUS)
# 3 32015    NAD27 / New York East    

# Hangs
crsuggest::suggest_crs(d1, units = "ft")

# ...

But the following returns fine with either unit:

d2 <- sf::st_polygon(
  list(matrix(
    c(-83.79956,42.32397,
      -83.67580,42.32397,
      -83.67580,42.22268,
      -83.79956,42.22268,
      -83.79956,42.32397
    ),
    ncol=2, 
    byrow=TRUE
  ))
) |>
  sf::st_sfc(crs=4326) |>
  sf::st_as_sf()

# Works
crsuggest::suggest_crs(d2, limit = 3, units = "us-ft") |>
  dplyr::select(crs_code, crs_name)

# A tibble: 3 × 2
#  crs_code crs_name              
#  <chr>    <chr>                 
# 1 6202     NAD27 / Michigan South
# 2 5623     NAD27 / Michigan East 
# 3 32167    NAD83 / BLM 17N (ftUS)

# Works
crsuggest::suggest_crs(d2, limit = 3, units = "ft") |>
  dplyr::select(crs_code, crs_name)

# A tibble: 3 × 2
#  crs_code crs_name                             
#  <chr>    <chr>                                
# 1 6499     NAD83(2011) / Michigan South (ft)    
# 2 3593     NAD83(NSRS2007) / Michigan South (ft)
# 3 2898     NAD83(HARN) / Michigan South (ft) 

My guess is that this is the culprit (similar to #8):

https://github.com/walkerke/crsuggest/blob/77f91d9d02122000717c87f70f069a960989de59/R/suggest_crs.R#L133-L143

There's a corresponding break on crsuggest::suggest_top_crs(), but because that seems to simply run crsuggest::suggest_crs(..., limit = 1, ...), fixing suggest_crs() would fix suggest_top_crs().

ericrobskyhuntley avatar May 05 '25 13:05 ericrobskyhuntley