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

Add km to units sf knows about #424

Merged
merged 2 commits into from Jul 17, 2017
Merged

Add km to units sf knows about #424

merged 2 commits into from Jul 17, 2017

Conversation

karldw
Copy link
Contributor

@karldw karldw commented Jul 16, 2017

Currently the CRS parsing code in crs_parameters doesn't know about projections in kilometers. Here's a quick demo, contrasting with a projection in meters.

library(sf)
km_crs <- "+init=epsg:5070 +units=km"
nc <- st_read(system.file("shape/nc.shp", package="sf")) 
nc_km <- st_transform(nc, "+init=epsg:5070 +units=km")
nc_m <- st_transform(nc, "+init=epsg:5070 +units=m")

sf:::crs_parameters(st_crs(nc_km))  # fails
sf:::crs_parameters(st_crs(nc_m))   # works

# spelling of "kilometre"
sf:::CPL_crs_parameters("+init=epsg:5070 +units=km")[[3]] == "kilometre"  # TRUE

@edzer edzer merged commit a33e0d2 into r-spatial:master Jul 17, 2017
edzer added a commit that referenced this pull request Jul 17, 2017
#424 gives an example where two crs return an identical epsg code, but under different units in their respective proj4strings. This then leads to loss of units when passing only the epsg back to gdal/proj.4.
@edzer
Copy link
Member

edzer commented Jul 17, 2017

Thanks, this revealed a larger problem: that sf assumed so far that a single epsg code always refers to a unique proj4string. Your example illustrates the opposite.

@edzer
Copy link
Member

edzer commented Jul 17, 2017

... and there are more units to convert:

cs2cs -lu
          km 1000.                Kilometer
           m 1.                   Meter
          dm 1/10                 Decimeter
          cm 1/100                Centimeter
          mm 1/1000               Millimeter
         kmi 1852.0               International Nautical Mile
          in 0.0254               International Inch
          ft 0.3048               International Foot
          yd 0.9144               International Yard
          mi 1609.344             International Statute Mile
        fath 1.8288               International Fathom
          ch 20.1168              International Chain
        link 0.201168             International Link
       us-in 1./39.37             U.S. Surveyor's Inch
       us-ft 0.304800609601219    U.S. Surveyor's Foot
       us-yd 0.914401828803658    U.S. Surveyor's Yard
       us-ch 20.11684023368047    U.S. Surveyor's Chain
       us-mi 1609.347218694437    U.S. Surveyor's Statute Mile
      ind-yd 0.91439523           Indian Yard
      ind-ft 0.30479841           Indian Foot
      ind-ch 20.11669506          Indian Chain

@etiennebr etiennebr mentioned this pull request Jul 17, 2017
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

Successfully merging this pull request may close these issues.

None yet

2 participants