Exercise
- In this exercise, we will create a dataframe comprising the names of Irish cities and towns, with their ITM coordinates.
- The first coordinate column shall contain the Eastings and the second shall contain the Northings
Create the dataset
Location <- c("Dublin","Cork","Mullingar","Ballymahon","Sligo","Doolin")
Easting <- c(715830,567469,643675,615785,568294,507565)
Northing <- c(734697,572117,753075,756895,835814,697069)
Ireland <- data.frame(Location,Easting,Northing)Inspect the dataframe
head(Ireland)## Location Easting Northing
## 1 Dublin 715830 734697
## 2 Cork 567469 572117
## 3 Mullingar 643675 753075
## 4 Ballymahon 615785 756895
## 5 Sligo 568294 835814
## 6 Doolin 507565 697069
class(Ireland)## [1] "data.frame"
Convert our dataframe to an {sf} object
This will transform our data set into a Simple feature collection
Ireland <- st_as_sf(Ireland, coords = c('Easting', 'Northing'), crs = 2157)Again, we will inspect the data
head(Ireland)## Simple feature collection with 6 features and 1 field
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 507565 ymin: 572117 xmax: 715830 ymax: 835814
## Projected CRS: IRENET95 / Irish Transverse Mercator
## Location geometry
## 1 Dublin POINT (715830 734697)
## 2 Cork POINT (567469 572117)
## 3 Mullingar POINT (643675 753075)
## 4 Ballymahon POINT (615785 756895)
## 5 Sligo POINT (568294 835814)
## 6 Doolin POINT (507565 697069)
class(Ireland)## [1] "sf" "data.frame"
Transform the CRS to WGS84
Ireland2 <- Ireland %>%
st_transform(crs = "+proj=longlat +datum=WGS84")head(Ireland2)## Simple feature collection with 6 features and 1 field
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -9.377611 ymin: 51.90025 xmax: -6.260248 ymax: 54.27015
## Geodetic CRS: +proj=longlat +datum=WGS84
## Location geometry
## 1 Dublin POINT (-6.260248 53.34979)
## 2 Cork POINT (-8.472711 51.90025)
## 3 Mullingar POINT (-7.341315 53.52582)
## 4 Ballymahon POINT (-7.761738 53.56173)
## 5 Sligo POINT (-8.486748 54.27015)
## 6 Doolin POINT (-9.377611 53.01633)
A quick Plot
library(ggplot2)
ggplot(Ireland2) + geom_sf()