RMarkdown document to show how to transform coordinates from state-plane to lat-long.
knitr::opts_chunk$set(echo = TRUE)
library(ggmap)
library(tidyverse)
library(readxl)
library(here)
library(rgdal)
First I read the data from the Excel spreadsheet. The data is formatted in three columns: Identifier, Longitude, and Latitude in State Plane coordinates. Next we transform the data from state-plane coordinates to lat long so ggmap can use it. Note the inline comments that indicate what each command does.
dat <- read_excel(here("Tamiami.xlsx"), sheet = "Coords")
# Convert the coordinates to a spatial object:
coordinates(dat) <- ~ Easting + Northing
# Specify the projection of the original data:
# This should be given with the dataset, or go to:
# http://spatialreference.org/ref/?search=florida and search
proj4string(dat) <- CRS("+init=epsg:2236") # NAD_1983_StatePlane_Florida_East_FIPS_0901_Feet
# Specify the transformation you want (i.e., the projection of the data you want to convert to)
# Note that lat/long (WGS84) is epsg:4326
dat <- spTransform(dat, CRS("+init=epsg:4326")) #WGS84
dat <- as.data.frame(dat) %>%
mutate(lon = Easting, lat = Northing) %>%
select(-Easting, -Northing)
# Show the data summary and provide general location of the points by taking the mean of the lat and long
datum <- dat %>%
summarize(lon = mean(lon), lat = mean(lat))
The first map is a general overview location map to show where the project is located in Florida. The second map is zoomed in and labels are added.
mymap <- get_map(location = c(datum$lon, datum$lat),
zoom = 9,
maptype = "satellite",
source = "google")
ggmap(mymap, extent = "device") +
geom_point(data = dat,
aes(x = lon, y = lat),
color = "yellow",
size = 1)
mymap <- get_map(location = c(datum$lon, datum$lat),
zoom = 12,
maptype = "satellite",
source = "google")
ggmap(mymap, extent = "device") +
geom_point(data = dat,
aes(x = lon, y = lat),
color = "yellow",
size = 1) +
geom_text(
data = dat,
aes(x = lon, y = lat, label = RTU_Identifier),
color = "yellow",
size = 2,
nudge_y = c(0.005, -0.005, 0.005, 0.005, 0.005, -0.005)
)