2

Hi, I'm new, graphing in R and I have the following problem.

I have some sample points in an XLSX file.

``````Latitud             Longitud    Altura
19°10'40.11"N   97°38'15.45"O   2362
19°10'37.85"N   97°38'28.32"O   2361
19°10'36.21"N   97°38'27.47"O   2359
``````

and my code is as follows

``````library(plotGoogleMaps)

data.xlsx <- read.xlsx("AreaPrueba1.xlsx", sheetIndex = 1,stringsAsFactors=FALSE)

data.xlsx\$Altura <-as.integer((as.character(data.xlsx\$Altura)))

# creamos esta función para transformar las coordenadas geográficas a decimal
geo2dec<-function(c) {
z<-sapply( strsplit(c, "[Â°\'\"]"), as.character )
dec<- as.numeric(z[1, ]) + as.numeric(z[3, ])/60 + as.numeric(z[4, ])/3600
if (z[5, ]=="N"||z[5, ]=="E") dec else -dec
}

data.xlsx\$Latitud<-geo2dec(data.xlsx\$Latitud)
data.xlsx\$Longitud<-geo2dec(data.xlsx\$Longitud)

#aqui el problema
pts <- data.frame(x=data.xlsx\$Longitud,y=data.xlsx\$Latitud)
coordinates(pts) <- ~x+y
proj4string(pts) <- CRS('+init=epsg:32614')

``````

My problem is that I do not understand how to translate the coordinates correctly so that I referenced the points well, change the + init = epsg: 32614 , for the area where the points are but the output map I get it wrong, it throws me into the sea.

asked by Hermes Fce 17.04.2018 в 00:29
source

1

Basically you have poorly defined projection, or rather you have not defined it. By doing this:

``````proj4string(pts) <- CRS('+init=epsg:32614')
proj4string(pts)

"+init=epsg:32614 +proj=utm +zone=14 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0"
``````

What happens is that the EPSG 32614 code has a projection `utm` ( `+proj=utm` ), when in fact, for the data we have understood, we should configure a projection by lat / long. A recommended configuration for google maps is this:

``````proj4string(pts) <- CRS('+init=epsg:4326')
``````