sf::st_transform silently failing

I create an sf object with lat long points in WGS84. It looks fine. Try to do a simple transform to projected coordinates, and it fails with no warning or error. I have tried multiple different projections, and none work. I am completely mystified.

library(tidyverse)

googlecrs <- 4326
Seattle <- "EPSG:2285"
Seattle <- "EPSG:32610"

df_test <- tribble( ~lat,       ~lon,    ~waypt,
 47.66206, -122.3062,     "Misc",  
 47.66186, -122.3066,  "plastic",  
 47.66170, -122.3064,  "plastic",  
 47.66205, -122.3062, "paper ff",  
 47.66168, -122.3067,  "plastic",  
 47.66203, -122.3062,     "mask"  
)

df_sf_test <- sf::st_as_sf(df_test, coords=c("lat","lon"), crs=googlecrs)

sf::st_transform(df_sf_test, crs=Seattle)

Simple feature collection with 6 features and 1 field (with 6 geometries empty)
Geometry type: POINT
Dimension: XY
Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: WGS 84 / UTM zone 10N

A tibble: 6 × 2

waypt geometry

  • <POINT [m]>
    1 Misc EMPTY
    2 plastic EMPTY
    3 plastic EMPTY
    4 paper ff EMPTY
    5 plastic EMPTY
    6 mask EMPTY

df_sf_test
Simple feature collection with 6 features and 1 field
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 47.66168 ymin: -122.3067 xmax: 47.66206 ymax: -122.3062
Geodetic CRS: WGS 84

A tibble: 6 × 2

waypt geometry

  • <POINT [°]>
    1 Misc (47.66206 -122.3062)
    2 plastic (47.66186 -122.3066)
    3 plastic (47.6617 -122.3064)
    4 paper ff (47.66205 -122.3062)
    5 plastic (47.66168 -122.3067)
    6 mask (47.66203 -122.3062)

What happens if you switch the order of "lat" and "lon"in this line?

Oh cr**. That's right. I always think lat-long in that order, but sf likes it long-lat. Thank you. I knew it had to be something simple I just wasn't seeing. I wish when sf printed out the contents it would label the coordinates in the geometry field. That would be helpful.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.