@@ -921,7 +921,7 @@ st_as_stars.ncdfgeom <- function(.x, ..., sf_geometry = NA) {
921921 stop(" Data variable does not have X and/or Y axes" )
922922
923923 crs = if (is.null(var $ crs ))
924- " WGS84 " # If no grid_mapping, then data is lat-long, assuming WGS84 datum here,
924+ " OGC:CRS84 " # If no grid_mapping, then data is lat-long, assuming WGS84 datum here,
925925 else { # otherwise, tease the AUTHORITY out of the WKT2 string of the grid_mapping
926926 # This will often fail to identify an AUTHORITY because CF grid_mappings
927927 # are incomplete and a WKT2 thus has many "unknown"s.
@@ -936,19 +936,20 @@ st_as_stars.ncdfgeom <- function(.x, ..., sf_geometry = NA) {
936936
937937 raster = get_raster(dimensions = c(axes [[ axis_order [1 ] ]]$ name , axes [[ axis_order [2 ] ]]$ name ))
938938 dimensions = lapply(axes , function (ax ) {
939- switch (ax $ orientation ,
939+ switch (ax $ orientation ,
940940 X = create_dimension(values = ax $ coordinates , refsys = crs , is_raster = TRUE ),
941941 Y = create_dimension(values = ax $ coordinates , refsys = crs , is_raster = TRUE ),
942- T = {
943- time = ax $ time
944- if (time $ calendar $ name %in% CF_calendar_regular )
945- create_dimension(to = length(time $ offsets ), refsys = " POSIXct" ,
946- values = time $ as_timestamp(asPOSIX = TRUE ))
947- else
948- create_dimension(to = length(time ), refsys = " CFtime" , values = time )
949- },
950- create_dimension(values = ax $ coordinates ))
951- })
942+ T = create_dimension(to = length(time ), refsys = " CFtime" , values = ax $ time ),
943+ {
944+ v = ax $ coordinates
945+ u = ax $ attribute(" units" )
946+ if (! is.na(u ))
947+ units(v ) = try_as_units(u )
948+ create_dimension(values = v )
949+ }
950+ )
951+ }
952+ )
952953 create_dimensions(dimensions , raster )
953954}
954955
0 commit comments