“Non Finite Transformation Detected” in spTransform in rgdal R Package

后端 未结 1 1904
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 01:05

I am trying to convert geographic coordinates (degrees) into UTM coordinates (meters) and keep getting an error message that a \"Non finite transformation detected.\" Do you

相关标签:
1条回答
  • 2020-12-20 01:33

    I would check the data you are trying to convert. I was not able to access the data you have in your example so I just used the first 3 coordinate points you provided to try to replicate the error and did not get an error. I also checked to see if the error could be caused by having the UTM zone specified not include all points provided by changing the zone number and north/south parameter and still everything worked. I would perhaps create a loop that iterates through the data you want to convert in chunks to see where the problem lies...

    library(rgdal)
    
    GPS.Points=data.frame(Longitude=c(23.85474, 23.85531, 23.85534))
    GPS.Points=cbind(GPS.Points,Latitude=c(-19.52211, -19.52243, -19.52257))
    
    GPS.Points.Spatial.Data <- SpatialPoints(GPS.Points, 
    proj4string=CRS("+proj=longlat     +ellps=WGS84"))
    GPS.Points.Spatial.Data[1]
    
    class(GPS.Points.Spatial.Data)
    
    GPS.Points.UTM.Spatial.Data <- spTransform(GPS.Points.Spatial.Data,
                              CRS("+proj=utm +south +zone=34 +ellps=WGS84"))
    

    Since you asked, here is a code to iterate through parts of the data. If you get an error you will at least know where in your data the problem came from:

    library(rgdal)
    GPS.Points=data.frame(Longitude=c(23.85474, 23.85531, 23.85534, 23.85474, 
    23.85531, 23.85534, 23.85474, 23.85531, 23.85534))
    GPS.Points=cbind(GPS.Points,Latitude=c(-19.52211, -19.52243, -19.52257, -19.52211, 
    -19.52243, -19.52257, -19.52211, -19.52243, -19.52257))
    
    n_chunks=3 #number of pieces you will break you data into
    n.points=dim(GPS.Points)[1]
    breaks=seq(1,n.points, by=round(n.points/n_chunks))
    breaks=c(breaks, n.points) #make sure to include last points as well
    
    i=1
    for (i in 1:(length(breaks)-1)){
      cat('\n','converting points', breaks[i], "to", breaks[i+1])  
      temp.GPS.Points=GPS.Points[breaks[i]:breaks[i+1],]
      temp.GPS.Points.Spatial.Data <- SpatialPoints(temp.GPS.Points, 
    proj4string=CRS("+proj=longlat +ellps=WGS84"))
      temp.GPS.Points.UTM.Spatial.Data <- spTransform(temp.GPS.Points.Spatial.Data,
                                                 CRS("+proj=utm +south +zone=34 
    +ellps=WGS84"))
    }
    
    0 讨论(0)
提交回复
热议问题