Saturday 4 May 2019

r - Converting point to lat lon?



I have received a shapefile with measurement points to be analyzed, but no matter how I try, I can't find how to convert to lat lon. I suppose it would be good to know the projection but when I look into the file (with R and summary()) it says "Is projected: NA" and "proj4string : [NA]".


One measurement-point I know is close to the border Peru-Chile has x,y = 354521, 7997417.8.


How can I find out how to convert this point (and many others) to lat lon?


I tried to follow the instructions of similar questions here, but to no avail.



Answer



It looks like you are using R, so try the proj4 package. Using @mkennedy's guess of UTM zone 19S, you can query a proj4string, and use the package:


library(proj4)

proj4string <- "+proj=utm +zone=19 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs "

# Source data
xy <- data.frame(x=354521, y=7997417.8)

# Transformed data
pj <- project(xy, proj4string, inverse=TRUE)
latlon <- data.frame(lat=pj$y, lon=pj$x)
print(latlon)


Produces:


        lat       lon
1 -18.10714 -70.37495

Also, if you need more precision in the output, set options("digits"=12), and you will see more digits used to display the coordinates:


            lat            lon
1 -18.107144101 -70.3749500491

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...