A number of different options exist for spatial file format
shapefiles
started life as an old ESRI (makers of ArcGIS) formatAlternative is geojson
geojson
or json
geojson
files - in the usual folder are files rail.geojson
, weather_stations.geojson
and counties.geojson
library(tidyverse) # sf package uses this library(sf) # The 'sf' package handles geographical data rail <- st_read('rail.geojson') # Use 'st_read' from 'sf' to read some data
geojson
files - 1rainfall <- st_read('weather_stations.geojson') rainfall
## Simple feature collection with 5 features and 11 fields ## geometry type: POINT ## dimension: XY ## bbox: xmin: 181346.8 ymin: 393612.6 xmax: 181346.8 ymax: 393612.6 ## projected CRS: TM65 / Irish Grid ## Year Month Rainfall Station Elevation Easting Northing County Abbreviation ## 1 1850 Jan 169.0 Ardara 15 180787.7 394679 Donegal AR ## 2 1851 Jan 236.4 Ardara 15 180787.7 394679 Donegal AR ## 3 1852 Jan 249.7 Ardara 15 180787.7 394679 Donegal AR ## 4 1853 Jan 209.1 Ardara 15 180787.7 394679 Donegal AR ## 5 1854 Jan 188.5 Ardara 15 180787.7 394679 Donegal AR ## Source coast_dist geometry ## 1 Briffa 17.36709 POINT (181346.8 393612.6) ## 2 Briffa 17.36709 POINT (181346.8 393612.6) ## 3 Briffa 17.36709 POINT (181346.8 393612.6) ## 4 Briffa 17.36709 POINT (181346.8 393612.6) ## 5 Briffa 17.36709 POINT (181346.8 393612.6)
geometry
columngeojson
files - 2counties <- st_read('counties.geojson') counties
## Simple feature collection with 7 features and 2 fields ## geometry type: MULTIPOLYGON ## dimension: XY ## bbox: xmin: 44201.66 ymin: 19537.25 xmax: 348847.8 ymax: 453198.8 ## projected CRS: TM65 / Irish Grid ## County mean_rain geometry ## 1 Antrim 77.71545 MULTIPOLYGON (((324297.7 42... ## 2 Armagh 77.71545 MULTIPOLYGON (((306664.9 36... ## 3 Carlow County 92.14104 MULTIPOLYGON (((286891.9 18... ## 4 Cavan County 72.24133 MULTIPOLYGON (((205022.8 33... ## 5 Clare County 100.73245 MULTIPOLYGON (((127094 2124... ## 6 Cork City 100.00000 MULTIPOLYGON (((167246.6 75... ## 7 Cork County 107.23233 MULTIPOLYGON (((44246.91 37...
geometry
column - objects are MULTIPOLYGON
geojson
files - 3rail
## Simple feature collection with 7 features and 1 field ## geometry type: LINESTRING ## dimension: XY ## bbox: xmin: -8.947182 ymin: 51.84713 xmax: -7.510596 ymax: 53.46931 ## geographic CRS: WGS 84 ## LEN geometry ## 1 27.832735 LINESTRING (-7.510596 53.46... ## 2 3.601239 LINESTRING (-8.747836 53.25... ## 3 11.241874 LINESTRING (-7.996752 51.93... ## 4 13.993221 LINESTRING (-8.752088 52.57... ## 5 10.890816 LINESTRING (-8.29744 52.548... ## 6 14.080600 LINESTRING (-8.467084 51.91... ## 7 3.868733 LINESTRING (-8.299423 51.84...
geometry
column - objects are LINESTRING
By Hellerick - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=26737079
x
direction is longitude, y
is latitudeSource: https://open.lib.umn.edu/mapping/chapter/3-scale-and-projections/ (worth a read if interested in map projections)
crs
(Coordinate Reference System)
tmap
package is very usefultm_shape
sets working objecttm_borders
says what to do with itinstall.package(tmap)
library(tmap) tm_shape(counties) + tm_borders()
lwd
\(\rightarrow\) Line widthcol
\(\rightarrow\) Line colourtm_shape(counties) + tm_borders(col='red',lwd=2)
tm_shape
gives another overlaid objectPOINT
object and draw with tm_dots
# Pick out jan 1980 rain_jan80 <- filter(rainfall, Month=='Jan', Year==1980) # Now draw the counties and # the rain station locations. tm_shape(counties) + tm_borders() + tm_shape(rain_jan80) + tm_dots(col='darkblue',size=0.5)
tm_shape(counties) + tm_borders() + tm_shape(rain_jan80) + tm_dots(col='darkblue',size='Rainfall')
style='cont'
tm_shape(counties) + tm_borders() + tm_shape(rain_jan80) + tm_dots(col='Rainfall',size=0.7,style='cont')
tm_polygons
style='cont'
tm_polygons
draws borders and fills them intm_shape(counties) + tm_polygons(col='mean_rain',style='cont')
palette=...
tm_shape(counties) + tm_polygons(col='mean_rain', style='cont', palette='Blues')
style
tm_shape(counties) + tm_polygons(col='mean_rain', style='jenks', palette='Blues')
style
tm_shape(counties) + tm_polygons(col='mean_rain', style='quantile', palette='OrRd')
tmaptools::palette_explorer()
- it shows possibilitiestm_shape
objecttm_shape(counties) + tm_polygons(col='mean_rain') + tm_shape(rail) + tm_lines(col='darkgreen',lwd=2)
tmap_mode('view')
to start interactive modetmap_mode('view') tm_shape(counties) + tm_polygons(col='mean_rain',alpha=0.4)
Web Mercator, Google Web Mercator, Spherical Mercator, WGS 84 Web Mercator or WGS 84/Pseudo-Mercator is a variant of the Mercator projection and is the de facto standard for Web mapping applications. It rose to prominence when Google Maps adopted it in 2005. It is used by virtually all major online map providers, including Google Maps, Mapbox,Bing Maps, OpenStreetMap, Mapquest, Esri, and many others. Its official EPSG identifier is EPSG:3857, although others have been used historically.
st_transform
new_object <- st_transform(object,<epsg>)
tmap
plotstmap_mode('plot')
puts tmap
back in interactive moderainfall
converted to Web Mercator on the flytmap_mode('plot') counties_wm <- st_transform(counties,3857) tm_shape(counties_wm) + tm_borders() + tm_shape(rainfall) + tm_dots(size=0.5)
New general ideas
New techniques
Practical issues
tmap
packagetmap
chooses projectionsNext lecture - Analysing Geographical Data
This link may be useful for some of the ideas.