2

I am importing spatial data from an online platform in decimals. The ultimate goal is to convert to UTM, which I have accomplished. However, I'm losing decimal places somewhere in the process, which eliminates the high resolution of spatial data I need. Does anyone know how to adjust the code so I maintain the 5 decimal places I have in the original data?

Thanks!

dput(head(merged_data))

structure(list(Date = c("2018-12-25 06:00", "2018-12-25 12:00", "2018-12-25 18:00", "2018-12-26 00:00", "2018-12-26 00:00", "2018-12-26 06:00"), 
    Lat = c(42.52938, 42.529, 42.53161, 42.53161, 42.59738, 42.53161
    ), Lon = c(-108.2620, -108.2650, -108.26611, -108.26611, 
    -108.86112, -108.26615)), row.names = c(NA, 6L), class = "data.frame")



#Lat and Lon currently character class. Convert to numeric
merged_data$Lon <- as.numeric(merged_data$Lon)
merged_data$Lat <- as.numeric(merged_data$Lat)
#convert data to spatialpointsdataframe
coords <- merged_data[ , c("Lon", "Lat")]   # coordinates
data   <- merged_data[ , 1:2]          # data
crs    <- CRS("+proj=longlat +datum=WGS84") # proj4string of coords
# make the spatial points data frame object
spdf <- SpatialPointsDataFrame(coords = coords,
                               data = data, 
                               proj4string = crs)
#convert to UTM
cord.UTM <- spTransform(spdf, CRS("+init=epsg:26913"))
plot(cord.UTM)

#Convert selected points class spatialpointsdataframe back to dataframe.
cord.UTM<-as.data.frame(cord.UTM)

Data:  
Date             Lat           Lon    
2018-12-25       42.52933      -108.26250

Output:
Date             Lat           Lon
2018-12-25       4599992       311244.7

  • Post your `merged_data` data - use `dput(head(merged_data))` and include this in the original question so that it stands alone. – Andrew Chisholm Feb 21 '20 at 20:28

0 Answers0