Created
March 26, 2013 11:11
-
-
Save jlehtoma/5244636 to your computer and use it in GitHub Desktop.
Transfrom WGS84 (lat/lon) coordinates into Estonian Coordinate System
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install dependencies if not present | |
deps <- c("ggmap", "sp", "rgdal", "XLConnect") | |
install.packages(deps) | |
for (dep in deps) { | |
library(dep, character.only=TRUE) | |
} | |
# Read the data | |
xlsx.file <- "/home/jlehtoma/temp/Points to be converted.xlsx" | |
dat <- readWorksheetFromFile(xlsx.file, "Sheet1") | |
# df is a data frame holding the coords (in WGS84 lat-lon) | |
sp.dat <- SpatialPointsDataFrame(dat[, c("Longitude", "Latitude")], dat, | |
proj4string = CRS("+proj=longlat +datum=WGS84")) | |
# Spatial data is now in lat/lon, check coordinates on google map | |
map <- qmap(c(lon=mean(sp.dat$Longitude), lat=mean(sp.dat$Latitude)), | |
source="google", zoom=10) | |
map + geom_point(aes(x=Longitude, y=Latitude, colour=Population), data=dat, | |
size=4) | |
# Estonian Coordinate System of 1997 (epsg:3301): http://bit.ly/104TO8u | |
# Project the spatial data to ECS | |
sp.data.ECS <- spTransform(sp.dat, CRS("+init=epsg:3301")) | |
# Write the data back to the original Excel file to a new worksheet | |
# "ECS_coordinates" | |
writeWorksheetToFile(xlsx.file, sp.data.ECS, "ECS_coordinates") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment