将sp转换为data.frame时,保留小数位-r

时间:2020-02-21 20:25:09

标签: r dataframe sp utm

我正在从在线平台以十进制形式导入空间数据。最终目标是转换成我已经完成的UTM。但是,我在过程中的某个位置丢失了小数位,这消除了我需要的高分辨率空间数据。有人知道如何调整代码,以便我在原始数据中保留5个小数位吗?

谢谢!

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

0 个答案:

没有答案