class: center, middle, inverse, title-slide # Geography 13 ## Lecture 09: Spatial Data ### Mike Johnson --- <style type="text/css"> span.code { background:rgba(127,240,0, 0.2); border-radius: 5px 5px 5px 5px; padding-left:5px; padding-top:2px; padding-right:5px; padding-bottom:2px; color:#008000; } </style> <style type="text/css"> .remark-code{line-height: 2; font-size: 80%} </style> # Why R? - R has a strong, dedicated group (RStudio) committed to building tools for data manipulation (`dplyr`, `tidyr`) and visualization (`ggplot`) -- - [R](https://www.r-project.org/) is an object-oriented, functional programming language <span class = "code">specifically designed to interface to other software</spa>. -- - This is ideal for using libraries written in lower level languages like C, FORTRAN or Java. -- - Such libraries **will** help you avoid ‘ceiling’ imposed by GUI-based or proprietary geographic information systems. -- - Furthermore, R facilitates access to other languages: the packages Rcpp and reticulate enable access to C++ and Python code, for example. This means R can be used as a ‘bridge’ to a wide range of existing geospatial **programs**. <center> <img src="lec-img/09-osgeo-logo.png", width=35%> </center> -- --- # Spatial Data <img src="lec-img/09-vec-raster.jpg" width="50%" style="display: block; margin: auto;" /> <center> (https://mgimond.github.io/Spatial/feature-representation.html) </center> -- - To work in a GIS environment, real world features (objects or phenomena that can be recorded in 2D or 3D space) need to be reduced to spatial entities. -- - These spatial entities can be represented using as a vector data model or a raster data model. --- # Vector: - Vector features can be decomposed into three different `geometric` primitives: 1. `points` 2. `polylines` 3. `polygons` -- - Primitives can be thought of as the "building blocks" for all vector features -- - All primitives can be decomposed in to set(s) of numeric X-Y coordinates with a known grid (reference system) -- - These reference systems are known as PRØJections, reference systems, ect --- # Projections (think GEOG 12 if you've taken it!) -- - Projections can have angular units (lat/lon) - geographic coordinate systems (GCS) -- or -- - Projections can have distance units (m) - projected coordinate systems (PCS) -- <img src="lec-img/09-gcs-pcs.png" width="60%" style="display: block; margin: auto;" /> --- # Simple Features Model (think GEOG 178 if you've taken it!) <img src="lec-img/09-sf-model.png" width="75%" style="display: block; margin: auto;" /> --- # Points .pull-left[ - A point is composed of **one** coordinate pair in a specific coordinate system. - Points have no length or area. ] .pull-right[ ```r ggplot() + geom_point(aes(x = c(1,2,3), y = c(3,1,2))) + labs(x = "X", y = "Y") ``` <img src="lecture-09_files/figure-html/unnamed-chunk-6-1.png" width="432" style="display: block; margin: auto;" /> ] --- # Polyline .pull-left[ - A polyline is composed of a **ordered** sequence of two or more coordinate points - Points in a line are called vetices and explicitly define the connection between two points. - A line has length, but no area ] .pull-right[ ```r ggplot() + geom_line(aes(x = c(1,2,3), y = c(3,1,2))) + geom_point(aes(x = c(1,2,3), y = c(3,1,2)), col = "red") + labs(x = "X", y = "Y") ``` <img src="lecture-09_files/figure-html/unnamed-chunk-7-1.png" width="432" style="display: block; margin: auto;" /> ] --- # Polygon .pull-left[ - A polygon is composed of 4 or more points whose starting and ending point are the same. - Polygons have both length and area. ] .pull-right[ ```r ggplot() + geom_polygon(aes(x = c(1,2,3,1), y = c(3,1,2,3)), fill = "green", alpha = .5) + geom_line(aes(x = c(1,2,3), y = c(3,1,2))) + geom_point(aes(x = c(1,2,3), y = c(3,1,2)), col = "red") + labs(x = "X", y = "Y") ``` <img src="lecture-09_files/figure-html/unnamed-chunk-8-1.png" width="432" style="display: block; margin: auto;" /> ] --- # WKT: Well-Known-Text Well-known text is a text markup language for representing vector geometry objects. A binary equivalent, known as well-known binary, is used to transfer and store the same information in a more compact form convenient for computer processing. ``` Simple feature collection with 3 features and 0 fields Geometry type: POINT Dimension: XY Bounding box: xmin: -2032609 ymin: 1468446 xmax: 1833394 ymax: 2178657 Projected CRS: NAD83 / Conus Albers # A tibble: 3 x 1 geometry <POINT [m]> 1 (1833394 2178657) 2 (-2032609 1468446) 3 (684663.4 2122678) ``` --- # Attribute Tables - Vector objects can have 0 to many attributes associated with it. -- - For example a city (point or polygon) can have a name, population, year founded, ect. -- - In R, these attributes are stored in a `data.frame`, and the `geometry` is stored as unique field. ``` Simple feature collection with 3 features and 3 fields Geometry type: POINT Dimension: XY Bounding box: xmin: -2032609 ymin: 1468446 xmax: 1833394 ymax: 2178657 Projected CRS: NAD83 / Conus Albers # A tibble: 3 x 4 city state population geometry <chr> <chr> <dbl> <POINT [m]> 1 New York New York 19354922 (1833394 2178657) 2 Los Angeles California 12815475 (-2032609 1468446) 3 Chicago Illinois 8675982 (684663.4 2122678) ``` -- - In shapefiles, these attributes are stored in a `.dbf` file, the `geometry` is stored in a ".shp" file, and they are related through a ".shx" file. -- - Typically, these attribute values are what we use to make maps (think GEOG 183 if you've taken it!) --- # The simple feature S3 R object - Like `Date`, `factor`, and `POSIXct`, a spatial object is an `S3` class that extends core primitive types and structures. ```r nc = st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE) nc[1,] ``` ``` Simple feature collection with 1 feature and 14 fields Geometry type: MULTIPOLYGON Dimension: XY Bounding box: xmin: -81.74107 ymin: 36.23436 xmax: -81.23989 ymax: 36.58965 Geodetic CRS: NAD27 AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID 1 0.114 1.442 1825 1825 Ashe 37009 37009 5 BIR74 SID74 NWBIR74 BIR79 SID79 NWBIR79 1 1091 1 10 1364 0 19 geom 1 MULTIPOLYGON (((-81.47276 3... ``` ```r class(nc) ``` ``` [1] "sf" "data.frame" ``` ```r typeof(nc) ``` ``` [1] "list" ``` --- # The simple feature S3 R object ```r attributes(nc) ``` ``` $names [1] "AREA" "PERIMETER" "CNTY_" "CNTY_ID" [5] "NAME" "FIPS" "FIPSNO" "CRESS_ID" [9] "BIR74" "SID74" "NWBIR74" "BIR79" [13] "SID79" "NWBIR79" "geom" $row.names [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [15] 15 16 17 18 19 20 21 22 23 24 25 26 27 28 [29] 29 30 31 32 33 34 35 36 37 38 39 40 41 42 [43] 43 44 45 46 47 48 49 50 51 52 53 54 55 56 [57] 57 58 59 60 61 62 63 64 65 66 67 68 69 70 [71] 71 72 73 74 75 76 77 78 79 80 81 82 83 84 [85] 85 86 87 88 89 90 91 92 93 94 95 96 97 98 [99] 99 100 $class [1] "sf" "data.frame" $sf_column [1] "geom" $agr AREA PERIMETER CNTY_ CNTY_ID NAME FIPS <NA> <NA> <NA> <NA> <NA> <NA> FIPSNO CRESS_ID BIR74 SID74 NWBIR74 BIR79 <NA> <NA> <NA> <NA> <NA> <NA> SID79 NWBIR79 <NA> <NA> Levels: constant aggregate identity ``` --- # Drop the structure ```r (d = st_drop_geometry(nc) %>% head()) ``` ``` AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO 1 0.114 1.442 1825 1825 Ashe 37009 37009 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 0.143 1.630 1828 1828 Surry 37171 37171 4 0.070 2.968 1831 1831 Currituck 37053 37053 5 0.153 2.206 1832 1832 Northampton 37131 37131 6 0.097 1.670 1833 1833 Hertford 37091 37091 CRESS_ID BIR74 SID74 NWBIR74 BIR79 SID79 NWBIR79 1 5 1091 1 10 1364 0 19 2 3 487 0 10 542 3 12 3 86 3188 5 208 3616 6 260 4 27 508 1 123 830 2 145 5 66 1421 9 1066 1606 3 1197 6 46 1452 7 954 1838 5 1237 ``` ```r class(d) ``` ``` [1] "data.frame" ``` --- # Raster (think GEOG 115X if you've taken it!) .pull-left[ - The raster data model uses an array of cells (pixels) to represent continuous real-world phenomena. - Raster datasets are commonly used for representing and managing _imagery_, _climate data_, _elevation models_, and other entities. - Raster data is defined by a resolution (X and Y dimension of the cells), and reference systems. - Implicit in a raster data model is a **single** value associated with each cell or pixel. ] .pull-right[ ```r r = matrix(sample(1:100, 100, replace= TRUE), nrow = 10) plot(raster(r)) ``` <img src="lecture-09_files/figure-html/unnamed-chunk-14-1.png" width="25%" style="display: block; margin: auto;" /> ```r r3D = array(sample(1:100, 200, replace= TRUE), dim = c(10,10,2)) plot(brick(r3D)) ``` <img src="lecture-09_files/figure-html/unnamed-chunk-14-2.png" width="25%" style="display: block; margin: auto;" /> ] --- # The Open Source Geospatial Suite - Geospatial data applications are built on a foundation of libraries supported by a number of international, governing bodies -- - Things highlighted in <span class="code">green</span> are things we will discuss in detail through the quarter. -- - The rest is intended as a useful introduction into the community side of spatial data science. --- # Command line Tools - Most geospatial core libraries (those that deal with I/O, processing, geometries, PRØJections, ect) are **command line tools**. -- - The command line is a way to interact with files without the use of the GUI that your operating system provides. -- - You have already seen a command line tool! <img src="lec-img/09-git-logo.jpeg" width="133" style="display: block; margin: auto;" /> --- # Git - Git is a command line tools. -- - It is downloaded as an executable (exe) and its tools are accessible directly via the terminal: ```bash git --version ``` ``` git version 2.24.3 (Apple Git-128) ``` -- - Or through GUI (**g**raphical **u**ser **i**nterface) implementations like the RStudio Git tab. --- # Spatial Command Line Tools - Like `git`, a wide range of spatial tools are primarily `command lime tools` -- - for example ogr* from GDAL .. - OGR is the **O**pen**G**IS Simple Features **R**eference Implementation ```bash ogrinfo -so data/ca.shp ``` ``` INFO: Open of `data/ca.shp' using driver `ESRI Shapefile' successful. 1: ca (Polygon) ``` --- class: inverse, center, middle # Governing bodies --- ## **O**pen **S**ource **Geo**spatial Foundation (OSgeo) <img src="lec-img/09-osgeo-logo.png" width = "25%"> The Open Source Geospatial Foundation (OSGeo), is a non-profit, non-governmental, organization who supports the collaborative development of open geospatial technologies and data. The foundation was formed in 2006 to provide financial, organizational and legal support to the broader free and open-source geospatial community (FOSS). In addition to promoting software development, the organization promotes open access to government produced geospatial data and completely free geodata, such the [OpenStreetMap](OpenStreetMapwww.openstreetmap.org) PRØJect. https://www.osgeo.org/ --- ### **OSgeo**: Geospatial Libraries - FDO – API (C++, .Net) between GIS application and sources; for manipulating, defining and analyzing geospatial data. - <span class="code">GDAL/OGR</span> – Library between GIS application and sources; for reading and writing raster geospatial data formats (GDAL) and simple features vector data (OGR). - GeoTools – Open source GIS toolkit (Java); to enable the creation of interactive geographic visualization clients. - <span class="code">GEOS</span> – A C++ port of the Java Topology Suite (JTS), a geometry model. - MetaCRS – PRØJections and coordinate system technologies, including <span class="code">PRØJ</span> - Orfeo ToolBox (OTB) – Open source tools to process satellite images and extract information. - OSSIM Extensive geospatial image processing libraries with support for satellite and aerial sensors and common image formats. - <span class="code">PostGIS</span> – Spatial extensions for the PostgreSQL database, enabling geospatial queries. --- ### **OSgeo**: Desktop Applications - QGIS – Desktop GIS for data viewing, editing and analysis — Windows, Mac and Linux. - <span class="code">GRASS GIS</span> – extensible GIS for image processing and analysing raster, topological vector and graphic data. - OSSIM – Libraries and applications used to process imagery, maps, terrain, and vector data. - Marble – Virtual globe and world atlas. - gvSIG – Desktop GIS for data capturing, storing, handling, analysing and deploying. Includes map editing. --- ## **O**pen **G**eospatial **C**onsortium (OGC) <img src="lec-img/09-ogc-logo.png" width="25%" > THe OGC is an international standards organization, originated in 1994 following its predesssor the Open GRASS Foundation (OGF). From 1994 to 2004 the organization also used the name Open GIS Consortium. More than 500 commercial, governmental, nonprofit and research organizations collaborate in a consensus process aimed at developing (and implementing) open standards for geospatial content and services, sensor web and Internet of Things, GIS data processing and data sharing. Most OGC standards depend on a generalized architecture captured in a set of documents called **Abstract Specifications**, which describes a basic <span class="code"> data model </span> for representing geographic features. Atop the Abstract Specification members have developed and continue to develop a growing number of specifications, or **standards** to serve the of interoperable location and geospatial technology, including GIS. --- class: inverse, middle, center # Software & Standards --- ## **G**eometry **En**gine **O**pen **S**ource (GEOS) <img src="lec-img/09-geos-logo.png" width="50%"> <br> - GEOS is the C/C++ port of a subset of [JTS Topology Suite](https://www.osgeo.org/PRØJects/jts/) and selected functions. -- - JTS conforms to the **Simple Features** Specification for SQL published by the OGC. - It provides an object model for planar geometry and fundamental geometric functions. -- - Designed to be used as a core component of vector-based geomatics software such as GIS. --- ### GEOS Geometric functions - <span class="code">Topological validity checking</span> - <span class="code">Area and Distance functions</span> - <span class="code">Spatial Predicates</span> based on the Egenhofer [DE-9IM model](https://en.wikipedia.org/wiki/DE-9IM) - <span class="code">Overlay functions (including intersection, difference, union, symmetric difference)</span> - <span class="code">Buffer computation (including different cap and join types)</span> - Convex hull - <span class="code">Geometric simplification</span> including the Douglas–Peucker algorithm - Geometric densification - Linear referencing - Precision reduction - Delaunay triangulation and constrained Delaunay triangulation - <span class="code">Voronoi diagram generation</span> - Smallest enclosing rectangle - Discrete Hausdorff distance --- ### GEOS Spatial structures and algorithms - Robust line segment intersection - Efficient line arrangement intersection - Efficient point in polygon - Spatial index structures including quadtree and STR-tree - Planar graph structures and algorithms -- ### GEOS I/O capabilities - Reading and writing of <span class="code">Well-Known Text (WKT)</span>, <span class="code">Well-Known Binary (WKB)</span> and Geographic Markup Language (GML) formats --- ## PRØJ <img src="lec-img/09-proj-logo.png" width=160> - PRØJ transforms geospatial coordinates from one </span class="code">coordinate reference system (CRS)</span> to another including <span class="code">cartographic projections</span> and geodetic transformations. -- - In addition to the command line utilities, PRØJ also exposes an API that lets developers use the functionality of PRØJ in their own software. -- - PRØJ started purely as a cartography application but now supports datum shifts -- - Today PRØJ supports more than 100 different map PRØJections and can transform coordinates between datums using all but the most obscure geodetic techniques. --- # CLI Example: The default behavior of PRØJ is transforming geodetic coordinates to other projections. Here we pipe (`|`) the location of Santa Barbara (`-119.84 34.411`) through the `PRØJ` utility, asking the terminal to print (`echo`) the coordinates transformed to NAD83 / Conus Albers (EPSG:5070): ```bash echo -119.84 34.41 | proj +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=1,1,-1,0,0,0,0 +units=m +no_defs ``` ``` -2151748.73 1532126.80 ``` Or, more compactly using the epsg string: ```bash echo -119.8489 34.4140 | proj +init=epsg:5070 ``` ``` -2152424.03 1532761.60 ``` --- ## **G**eospatial **D**ata **A**bstraction **L**ibrary (GDAL) <img src="lec-img/09-gdal-logo.png" width=120> - GDAL provides a software library for reading and writing raster and vector data formats, and is released by OSGeo. -- - presents a single abstract data model to the calling application for all supported formats. -- - It may also be built with a variety of useful command line interface utilities for data translation and processing. -- - Projections and transformations are supported by the `PRØJ` library. -- - The related OGR library (OGR Simple Features) is part of the GDAL source tree and provides a similar ability for simple features vector graphics data. --- # GDAL Users <img src="lec-img/09-gdal-users.png" width="75%" style="display: block; margin: auto;" /> --- # CLI Example: - Read info from TIF ```bash gdalinfo data/goleta-nlcd.tif | head ``` ``` Driver: GTiff/GeoTIFF Files: data/goleta-nlcd.tif Size is 386, 250 Coordinate System is: BOUNDCRS[ SOURCECRS[ PROJCRS["unknown", BASEGEOGCRS["unknown", DATUM["Unknown_based_on_GRS80_ellipsoid", ELLIPSOID["GRS 1980",6378137,298.257222101004, ``` --- # CLI Example: - Tranform to GCS ```bash gdalwarp -t_srs "EPSG:4326" data/goleta-nlcd.tif data/out.tif ``` ``` Processing data/goleta-nlcd.tif [1/1] : 0Using internal nodata values (e.g. 255) for image data/goleta-nlcd.tif. ...10...20...30...40...50...60...70...80...90...100 - done. ``` -- ```bash gdalinfo data/goleta-nlcd.tif | head ``` ``` Driver: GTiff/GeoTIFF Files: data/goleta-nlcd.tif Size is 386, 250 Coordinate System is: BOUNDCRS[ SOURCECRS[ PROJCRS["unknown", BASEGEOGCRS["unknown", DATUM["Unknown_based_on_GRS80_ellipsoid", ELLIPSOID["GRS 1980",6378137,298.257222101004, ``` --- # Results: .pull-left[ ```r pcs = raster('data/goleta-nlcd.tif') sf::st_crs(pcs)$proj ``` ``` [1] "aea" ``` ```r plot(pcs) ``` <img src="lecture-09_files/figure-html/unnamed-chunk-24-1.png" width="432" /><img src="lecture-09_files/figure-html/unnamed-chunk-24-2.png" width="432" /> ] .pull-right[ ```r gcs = raster('data/out.tif') st_crs(gcs)$proj ``` ``` [1] "longlat" ``` ```r plot(gcs) ``` <img src="lecture-09_files/figure-html/unnamed-chunk-25-1.png" width="432" /><img src="lecture-09_files/figure-html/unnamed-chunk-25-2.png" width="432" /> ] --- ## PostGIS <img src="lec-img/09-postgis-logo.png" width=120> - `PostGIS` (POST-jis) follows the Simple Features for SQL specification from the OGC. -- - Software implementations like ArcGIS, CartoDB, GeoServer, GRASS, QGIS, and OpenStreetMap all use PostGIS as a database backend. -- - PostGIS adds support for geographic objects to the `PostgreSQL` object-relational database. --- # `PostgreSQL` <img src="lec-img/09-postgresql-logo.png" width=120> - also known as Postgres - is relational database management system (R/DBMS) emphasizing extensibility and `SQL` compliance. -- - `SQL` is a standard language for accessing and manipulating relational databases and stands for Structured Query Language. -- - SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987 -- - You have already seen SQL! <img src="lec-img/09-sql-joins.png" width="15%" style="display: block; margin: auto;" /> --- ## Simple features <img src="lec-img/09-ogc-sf-logo.png"> Simple Features (officially Simple Feature Access) is both an OGC and International Organization for Standardization (ISO) standard that specifies a common storage and access model of (mostly) two-dimensional geometries. --- ## Simple features **Part 1** ISO 19125-1 (SFA-CA for "common architecture"), defines a model for 2D simple features, with linear interpolation between vertices. The data model defined in SFA-CA is a hierarchy of classes. This part also defines representation using Well-Known Text (and Binary). *** **Part 2** of the standard, ISO 19125-2 (SFA-SQL), defines an implementation using `SQL.` The geometries are also associated with spatial reference systems. The standard also specifies attributes, methods and assertions with the geometries. - In general, a 2D geometry is simple if it contains no self-intersection. - The specification defines DE-9IM spatial predicates and several spatial operators that can be used to generate new geometries from existing geometries. --- class:inverse, middle, center # R as our GIS --- ## Simple features (sf) package The `sf` package implements the Simple Features standard for R -- - The `sf` package contains functions that bind - to `GDAL` for reading and writing data, - to `GEOS` for geometrical operations, and - to `PRØJ` for projection conversions and datum transformations ```r sf::sf_extSoftVersion() ``` ``` GEOS GDAL proj.4 GDAL_with_GEOS "3.8.1" "3.2.1" "7.2.1" "true" USE_PROJ_H PROJ "true" "7.2.1" ``` --- ## Simple features (sf) package - represents <span class="code">simple features</span> as records in a `data.frame` or `tibble` with a `geometry list-column` -- - represents all 17 <span class="code">simple feature types</span> for all dimensions (XY, XYZ, XYM, XYZM) nativity in R -- - interfaces to `GEOS` to support <span class="code">geometrical operations</span> including the DE9-IM -- - interfaces to `GDAL`, supporting all <span class="code">driver options</span>, <span class="code">Date</span> and <span class="code">POSIXct</span> and `list-columns` -- - interfaces to `PRØJ` for <span class="code">coordinate reference system</span> conversions and transformations -- - uses `WKB` serializations written in C++/Rcpp for fast I/O with `GDAL` and `GEOS` -- - reads and writes to spatial databases such as `PostGIS` using DBI -- - is extended by pkg `lwgeom` for further liblwgeom/PostGIS functions, including some <span class="code">spherical geometry</span> functions --- ## Simple features (sf) package <img src="lec-img/09-sf-depends.png" width="75%" style="display: block; margin: auto;" /> --- # Extend GDAL With respect to GDAL, some utilities are directly exposed by `sf` as can be seen in the available function signatures: ```r grep("gdal", ls("package:sf"), value = T) ``` ``` [1] "gdal_crs" "gdal_extract" [3] "gdal_inv_geotransform" "gdal_metadata" [5] "gdal_polygonize" "gdal_rasterize" [7] "gdal_read" "gdal_read_mdim" [9] "gdal_subdatasets" "gdal_utils" [11] "gdal_write" "gdal_write_mdim" ``` --- An external package `gdalUtilities` uses the slimmer version of GDAL provided by `sf` to expose a few additional utilities: ```r ##install.packages("gdalUtilities", force = TRUE) library(gdalUtilities) ls("package:gdalUtilities") ``` ``` [1] "gdal_grid" "gdal_rasterize" "gdal_translate" [4] "gdalbuildvrt" "gdaldem" "gdalinfo" [7] "gdalwarp" "gRasterize" "nearblack" [10] "ogr2ogr" ``` --- And another package, requires the full GDAL library to be installed on your machine, and, assuming it is, provides access to even more utilities ```r #install.packages("gdalUtils", force = TRUE) library(gdalUtils) ls("package:gdalUtils") ``` ``` [1] "align_rasters" "batch_gdal_translate" [3] "gdal_chooseInstallation" "gdal_cmd_builder" [5] "gdal_contour" "gdal_grid" [7] "gdal_rasterize" "gdal_setInstallation" [9] "gdal_translate" "gdaladdo" [11] "gdalbuildvrt" "gdaldem" [13] "gdalinfo" "gdallocationinfo" [15] "gdalmanage" "gdalsrsinfo" [17] "gdaltindex" "gdaltransform" [19] "gdalwarp" "get_subdatasets" [21] "is.Raster" "mosaic_rasters" [23] "nearblack" "ogr2ogr" [25] "ogrinfo" "ogrlineref" [27] "ogrtindex" "qm" [29] "remove_file_extension" ``` --- # Extending PRØJ ```r grep("proj_|crs", ls("package:sf"), value = T) ``` ``` [1] "gdal_crs" "NA_crs_" [3] "sf_add_proj_units" "sf_proj_info" [5] "sf_proj_network" "sf_proj_pipelines" [7] "sf_proj_search_paths" "st_crs" [9] "st_crs<-" "st_set_crs" ``` --- # Extending GEOS/Simple Featrues Access ```r grep("st_", ls("package:sf"), value = T) ``` ``` [1] "st_agr" "st_agr<-" [3] "st_area" "st_as_binary" [5] "st_as_grob" "st_as_s2" [7] "st_as_sf" "st_as_sfc" [9] "st_as_text" "st_axis_order" [11] "st_bbox" "st_bind_cols" [13] "st_boundary" "st_buffer" [15] "st_cast" "st_centroid" [17] "st_collection_extract" "st_combine" [19] "st_contains" "st_contains_properly" [21] "st_convex_hull" "st_coordinates" [23] "st_covered_by" "st_covers" [25] "st_crop" "st_crosses" [27] "st_crs" "st_crs<-" [29] "st_difference" "st_dimension" [31] "st_disjoint" "st_distance" [33] "st_drivers" "st_drop_geometry" [35] "st_equals" "st_equals_exact" [37] "st_filter" "st_geometry" [39] "st_geometry_type" "st_geometry<-" [41] "st_geometrycollection" "st_graticule" [43] "st_inscribed_circle" "st_interpolate_aw" [45] "st_intersection" "st_intersects" [47] "st_is" "st_is_empty" [49] "st_is_longlat" "st_is_simple" [51] "st_is_valid" "st_is_within_distance" [53] "st_jitter" "st_join" [55] "st_layers" "st_length" [57] "st_line_merge" "st_line_sample" [59] "st_linestring" "st_m_range" [61] "st_make_grid" "st_make_valid" [63] "st_multilinestring" "st_multipoint" [65] "st_multipolygon" "st_nearest_feature" [67] "st_nearest_points" "st_node" [69] "st_normalize" "st_overlaps" [71] "st_point" "st_point_on_surface" [73] "st_polygon" "st_polygonize" [75] "st_precision" "st_precision<-" [77] "st_read" "st_read_db" [79] "st_relate" "st_reverse" [81] "st_sample" "st_segmentize" [83] "st_set_agr" "st_set_crs" [85] "st_set_geometry" "st_set_precision" [87] "st_sf" "st_sfc" [89] "st_shift_longitude" "st_simplify" [91] "st_snap" "st_sym_difference" [93] "st_touches" "st_transform" [95] "st_triangulate" "st_union" [97] "st_viewport" "st_voronoi" [99] "st_within" "st_wrap_dateline" [101] "st_write" "st_write_db" [103] "st_z_range" "st_zm" ``` --- # Roadmap for the next few days: **Thursday**: WKT/WKB and Simple Feature Data Model (geometries) - How are they built - What are their implications - How are they handled in R --- # Roadmap for the next few days: **Monday**: Coordinate Reference Systems & projections - What is a PROJ string? - What is EPSG? - Review of PCS/GCS **Tuesday**: Uniary Geometric Operations - length, distance, area - geometry manipulation with union and combine **Wednesday**: Binary Geometric Operations (DE-9IM predicates) - Touches, intersects, overlaps **Thursday**: Joins, filters and Areal Interpolations --- # Roadmap for the next few days: **Monday**: On to raster data ... --- ## Now, we have one last hurdle before implementing our GIS in R... <center> <svg viewBox="0 0 512 512" style="height:1em;position:relative;display:inline-block;top:.1em;" xmlns="http://www.w3.org/2000/svg"> <path d="M304 48c0 26.51-21.49 48-48 48s-48-21.49-48-48 21.49-48 48-48 48 21.49 48 48zm-48 368c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zm208-208c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zM96 256c0-26.51-21.49-48-48-48S0 229.49 0 256s21.49 48 48 48 48-21.49 48-48zm12.922 99.078c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.491-48-48-48zm294.156 0c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.49-48-48-48zM108.922 60.922c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.491-48-48-48z"></path></svg> </center> --- ## Assignment Today is all about setting up your R interface to be a full-fleged GIS. To do that we need to download some packages: --- ## From CRAN: (use install.package("...") pattern) - `sf` - `units` - `raster` - `mapview` - `leaflet` - `gdalUtilities` --- ## From R-Forge `whitebox` has been temporarily taken down from CRAN due to policy violation (Downloads of WhiteboxTools binary as part of package installation). - `install.packages("whitebox", repos="http://R-Forge.R-project.org")` --- ## From GitHub: (use remotes::install_github("...") pattern) - `ropensci/USAboundaries` - `ropensci/USAboundariesData` - `ropenscilabs/rnaturalearthdata` --- class: middle, center # Submission: Once all packages are installed, please run the following and report your external software versions to Gauchospace: ```r sf::sf_extSoftVersion() ``` ``` GEOS GDAL proj.4 GDAL_with_GEOS "3.8.1" "3.2.1" "7.2.1" "true" USE_PROJ_H PROJ "true" "7.2.1" ``` It is OK if your results are different then the above as long as there is something 😄 --- class: middle, center, inverse # END