"Detecting Uncertain Limbs" in spTransform in the rddal R Package

I am trying to convert geographic coordinates (degrees) to UTM coordinates (meters) and continue to receive the error message "Not finite conversion detected". Do you know how I can fix this? Here is the code I used:

> GPS.Points <- Gomer.Data[, c('Longitude', 'Latitude')] > head(GPS.Points) Longitude Latitude 1 23.85474 -19.52211 2 23.85531 -19.52243 3 23.85534 -19.52257 4 23.85580 -19.52346 5 23.85551 -19.52380 6 23.85513 -19.52360 > GPS.Points.Spatial.Data <- SpatialPoints(GPS.Points, proj4string=CRS("+proj=longlat +ellps=WGS84")) > GPS.Points.Spatial.Data[1] SpatialPoints: Longitude Latitude [1,] 23.85474 -19.52211 Coordinate Reference System (CRS) arguments: +proj=longlat +ellps=WGS84 > class(GPS.Points.Spatial.Data) [1] "SpatialPoints" attr(,"package") [1] "sp" > GPS.Points.UTM.Spatial.Data <- spTransform(GPS.Points.Spatial.Data, CRS("+proj=utm +south +zone=34 +ellps=WGS84")) non finite transformation detected: Longitude Latitude Error in spTransform(GPS.Points.Spatial.Data, CRS("+proj=utm +south +zone=34 +ellps=WGS84")) : failure in points In addition: Warning message: In spTransform(GPS.Points.Spatial.Data, CRS("+proj=utm +south +zone=34 +ellps=WGS84")) : 3 projected point(s) not finite 
+1
source share
1 answer

I would check the data you are trying to convert. I could not access the data that you have in your example, so I just used the first three coordinate points that you provided to try to reproduce the error and did not get the error. I also checked if the error could be caused by the fact that the indicated UTM zone does not include all points obtained by changing the zone number and the north / south parameter, and it still worked. I would perhaps create a loop that iterates through the data you want to convert to pieces to see where the problem is ...

 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")) 

As you asked, here is the code to iterate over pieces of data. If you get an error message, you at least know where in your data a problem arose 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")) } 
+4
source

Source: https://habr.com/ru/post/953518/


All Articles