walkerke / crsuggest

Get appropriate CRS suggestions for your spatial data in R
Other
128 stars 7 forks source link

Remove EPSG codes that aren't in the PROJ database #6

Closed walkerke closed 3 years ago

walkerke commented 3 years ago

In data pre-processing EPSG codes (e.g. 9300, the MML07 Grid) should be removed if they aren't found in the PROJ database (and in turn can't easily be used in R). Or, alternatively they can be kept in but filtered out by default so users only get them as options if they really want them. For example:

library(sf)
library(crsuggest)

london <- st_read("https://skgrange.github.io/www/data/london_boroughs.json")

suggest_crs(london)
# A tibble: 10 x 6
   crs_code crs_name          crs_type  crs_gcs crs_units crs_proj4                                  
   <chr>    <chr>             <chr>       <dbl> <chr>     <chr>                                      
 1 9373     MML07 Grid        projected    9372 NA        NA                                         
 2 9300     HS2 Survey Grid   projected    9299 NA        NA                                         
 3 27700    OSGB36 / British… projected    4277 m         +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.99960…
 4 5643     ED50 / SPBA LCC   projected    4230 m         +proj=lcc +lat_0=48 +lon_0=10 +lat_1=52.66…
 5 3035     ETRS89-extended … projected    4258 m         +proj=laea +lat_0=52 +lon_0=10 +x_0=432100…
 6 3034     ETRS89-extended … projected    4258 m         +proj=lcc +lat_0=52 +lon_0=10 +lat_1=35 +l…
 7 32630    WGS 84 / UTM zon… projected    4326 m         +proj=utm +zone=30 +datum=WGS84 +units=m +…
 8 32430    WGS 72BE / UTM z… projected    4324 m         +proj=utm +zone=30 +ellps=WGS72 +towgs84=0…
 9 32230    WGS 72 / UTM zon… projected    4322 m         +proj=utm +zone=30 +ellps=WGS72 +towgs84=0…
10 32631    WGS 84 / UTM zon… projected    4326 m         +proj=utm +zone=31 +datum=WGS84 +units=m +…

EPSG code 27700 makes sense for the top choice for London and even though the others technically are suitable they aren't directly usable for most R users. Perhaps something like a drop_na argument that defaults to TRUE and removes the CRSs that aren't directly usable, but allows users to look them up if doing so intentionally.

walkerke commented 3 years ago

In the dev version, we now get:

> suggest_crs(london)
# A tibble: 10 x 6
   crs_code crs_name          crs_type  crs_gcs crs_units crs_proj4                                  
   <chr>    <chr>             <chr>       <dbl> <chr>     <chr>                                      
 1 27700    OSGB36 / British… projected    4277 m         +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.99960…
 2 5643     ED50 / SPBA LCC   projected    4230 m         +proj=lcc +lat_0=48 +lon_0=10 +lat_1=52.66…
 3 3035     ETRS89-extended … projected    4258 m         +proj=laea +lat_0=52 +lon_0=10 +x_0=432100…
 4 3034     ETRS89-extended … projected    4258 m         +proj=lcc +lat_0=52 +lon_0=10 +lat_1=35 +l…
 5 32630    WGS 84 / UTM zon… projected    4326 m         +proj=utm +zone=30 +datum=WGS84 +units=m +…
 6 32430    WGS 72BE / UTM z… projected    4324 m         +proj=utm +zone=30 +ellps=WGS72 +towgs84=0…
 7 32230    WGS 72 / UTM zon… projected    4322 m         +proj=utm +zone=30 +ellps=WGS72 +towgs84=0…
 8 32631    WGS 84 / UTM zon… projected    4326 m         +proj=utm +zone=31 +datum=WGS84 +units=m +…
 9 32431    WGS 72BE / UTM z… projected    4324 m         +proj=utm +zone=31 +ellps=WGS72 +towgs84=0…
10 32231    WGS 72 / UTM zon… projected    4322 m         +proj=utm +zone=31 +ellps=WGS72 +towgs84=0…