sf
package (simple features): https://r-spatial.github.io/sf/index.htmlsf
objects: https://r-spatial.github.io/sf/articles/sf1.htmlsf
geometries (e.g., union, intersection,
buffer): https://r-spatial.github.io/sf/articles/sf3.htmlsf
: https://r-spatial.github.io/sf/articles/sf4.htmlsp
vignettes: https://cran.r-project.org/web/packages/sp/index.htmlggmap
,
opencage
Also network, flows data, etc.
Moraga and
Lawson, Computational Statistics & Data Analysis, 2012
Moraga et al.,
Parasites & Vectors, 2015
Moraga and Montes, Statistics
in Medicine, 2011
unprojected or geographic: Latitude and
Longitude for referencing location on the ellipsoid Earth
(decimal degrees (DD) or degrees, minutes, and seconds (DMS))
projected: Easting and Northing for referencing
location on 2-dimensional representation of Earth
Common projection: Universal
Transverse Mercator (UTM)
Location is given by the zone number (60 zones), hemisphere (north or
south), and Easting and Northing coordinates in the zone in
meters
Spatial data can be represented as simple features (sf
)
or as spatial class (sp
).
Packages sf
and sp
can be used to work with
spatial data.
sf
objects are extensions of data frames. Each row is
one feature or spatial object that could have associated data.
SpatialPoints
and
SpatialPointsDataFrame
SpatialLines
and
SpatialLinesDataFrame
SpatialPolygons
and
SpatialPolygonsDataFrame
SpatialGrid
and SpatialGridDataFrame
SpatialPixel
and
SpatialPixelDataFrame
Geographic data can be represented using a data storage format called shapefile. A shapefile consists of a collection of related files:
.shp
: contains the geometry data,.shx
: is a positional index of the geometry data that
allows to seek forwards and backwards the .shp file,.dbf
: stores the attributes for each shape.Other files that can form a shapefile are the following:
.prj
: plain text file describing the projection,.sbn
and .sbx
: spatial index of the
geometry data,.shp.xml
: geospatial metadata in XML format.We can read shapefiles with rgdal::readOGR()
or
sf::st_read()
# name of the shapefile of North Carolina of the sf package
<- system.file("shape/nc.shp", package = "sf") nameshp
Exercise: Identify the folder of nc.shp
in your
computer.
# read shapefile with st_read()
library(sf)
## Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
<- st_read(nameshp, quiet = TRUE)
map class(map)
## [1] "sf" "data.frame"
head(map)
plot(map)
## Warning: plotting the first 10 out of 14 attributes; use max.plot = 14 to plot
## all
# read shapefile with readOGR()
library(rgdal)
## Loading required package: sp
## Please note that rgdal will be retired during 2023,
## plan transition to sf/stars/terra functions using GDAL and PROJ
## at your earliest convenience.
## See https://r-spatial.org/r/2022/04/12/evolution.html and https://github.com/r-spatial/evolution
## rgdal: version: 1.6-4, (SVN revision 1196)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.5.2, released 2022/09/02
## Path to GDAL shared files: C:/Users/MORAGAPE/AppData/Local/R/win-library/4.2/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ runtime: Rel. 8.2.1, January 1st, 2022, [PJ_VERSION: 821]
## Path to PROJ shared files: C:/Users/MORAGAPE/AppData/Local/R/win-library/4.2/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.5-1
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
<- rgdal::readOGR(nameshp, verbose = FALSE) map
## Warning: OGR support is provided by the sf and terra packages among others
## Warning: OGR support is provided by the sf and terra packages among others
## Warning: OGR support is provided by the sf and terra packages among others
## Warning: OGR support is provided by the sf and terra packages among others
## Warning: OGR support is provided by the sf and terra packages among others
## Warning: OGR support is provided by the sf and terra packages among others
## Warning: OGR support is provided by the sf and terra packages among others
class(map)
## [1] "SpatialPolygonsDataFrame"
## attr(,"package")
## [1] "sp"
head(map@data)
plot(map)
spplot(map, zcol = "BIR74")
https://www.paulamoraga.com/book-geospatial/sec-spatialdataandCRS.html#types-of-spatial-data
Exercises: