Basic GIS Functions and Spatial Stats in

Slides:



Advertisements
Similar presentations
NSF DUE ; Module 4.3. NSF DUE ; GeoTEd Partners Module name and number.
Advertisements

Geoprocessing; Useful Tools You Should Know in ArcToolbox Unlock the hidden secrets of ArcToolbox to discover tools that make your work easier and analysis.
GIS UPDATE? ARE YOU TAKING NOTES? How will you remember what you did if you do not take notes. Lab 9 this week: Music Festival 3: Vector Analysis.
GIS Level 2 MIT GIS Services
Border around project area Everything else is hardly noticeable… but it’s there Big circles… and semi- transparent Color distinction is clear.
Lecture by Austin Troy © 2005 Lecture 13: Introduction to Raster Spatial Analysis Using GIS-- Introduction to GIS Lecture Notes by Austin Troy, University.
NR 422: GIS Review Jim Graham Fall What is GIS? Geographic Information System? Geographic Information Science? A system that provides the ability.
NR 322: Single Layer Analysis Jim Graham Fall 2008 Chapter 8 & 9.
19 th Advanced Summer School in Regional Science An introduction to GIS using ArcGIS.
©2005 Austin Troy Lecture 9: Introduction to GIS 1.Vector Geoprocessing Lecture by Austin Troy, University of Vermont.
What Geoprocessing? Geoprocessing is the processing of geographic information. Commonly used to describe a process when geographic objects are manipulated.
Let’s pretty it up!. Border around project area Everything else is hardly noticeable… but it’s there Big circles… and semi- transparent Color distinction.
Intro. To GIS Lecture 6 Spatial Analysis April 8th, 2013
@ 2007 Austin Troy. Geoprocessing Introduction to GIS Geoprocessing is the processing of geographic information. Perform spatial analysis and modeling.
Introduction to ArcGIS for Environmental Scientists Module 3 – GIS Analysis ArcGIS Toolbox.
Basic Spatial Analysis
Habitat Analysis in ArcGIS Use of Spatial Analysis to characterize used resources Thomas Bonnot
Raster Data Analysis Chapter 11. Introduction  Regular grid  Value in each cell corresponds to characteristic  Operations on individual, group, or.
Fundamentals of GIS Lecture Materials by Austin Troy except where noted © 2008 Lecture 13: Introduction to Raster Spatial Analysis Using GIS-- By.
Spatial data models (types)
ESRI GIS Software. Contents Data Types –ESRI Data Model –Shapefiles –Raster Data Digital Orthophoto Quadrangle Digital Elevation Model Digital Raster.
Working with cursors in Python GISDE Python Workshop Qiao Li.
Preparing Data for Analysis and Analyzing Spatial Data/ Geoprocessing Class 11 GISG 110.
ESRM 250 & CFR 520: Introduction to GIS © Phil Hurvitz, KEEP THIS TEXT BOX this slide includes some ESRI fonts. when you save this presentation,
Spatial Analysis (Vector I) Reading Assignment: Bolstad Chapter 9 (pp )
GIS2: Geo-processing and Metadata Treg Christopher.
Applied Cartography and Introduction to GIS GEOG 2017 EL
Major parts of ArcGIS ArcView -Basic mapping, editing and Analysis tools ArcEditor -all of ArcView plus Adds ability to deal with topological and network.
GIS concepts, skills and tools
School of Geography FACULTY OF ENVIRONMENT Introduction to ArcToolbox and Geoprocessing.
CHAPTER 12 RASTER DATA ANALYSIS 12.1 Data Analysis Environment
8. Geographic Data Modeling. Outline Definitions Data models / modeling GIS data models – Topology.
How do we represent the world in a GIS database?
Support the spread of “good practice” in generating, managing, analysing and communicating spatial information Introduction to GIS for the Purpose of Practising.
Introduction to Raster Spatial Analysis Using GIS-- Introduction to GIS Raster Query Map Calculation Zonal statistics Terrain functions Viewshed.
Copyright © 2006 by Maribeth H. Price 8-1 Chapter 8 Geoprocessing.
Intro to Raster GIS GTECH361 Lecture 11. CELL ROW COLUMN.
Raster Concepts.
Data Types Entities and fields can be transformed to the other type Vectors compared to rasters.
Fundamentals of GIS Lecture Materials by Austin Troy except where noted © 2008 Lecture 13: Introduction to Raster Spatial Analysis Using GIS-- By.
Advanced GIS Using ESRI ArcGIS 9.3 Spatial Analyst 2.
NR 143 Study Overview: part 1 By Austin Troy University of Vermont Using GIS-- Introduction to GIS.
1 Overview Importing data from generic raster files Creating surfaces from point samples Mapping contours Calculating summary attributes for polygon features.
Geographic Data in GIS. Components of geographic data Three general components to geographic information Three general components to geographic information.
Geoprocessing Geoprocessing is a fancy name for Spatial Operations So what is Geoprocessing? Processing or manipulating of geographic/spatial data to.
CFR 250/590 Introduction to GIS, Autumn 1999 Raster Analysis I © Phil Hurvitz, raster1.ppt 1  Overview Grid themes Setting grid theme and analysis.
DEM TRAINING (DIGITAL ELEVATION MODEL). STEP 1 OPEN GIS.
Environmental GIS Nicholas A. Procopio, Ph.D, GISP
Intro. To GIS Pre-Lab Spatial Analysis April 1 st, 2013.
Lesson 3 GIS Fundamentals MEASURE Evaluation PHFI Training of Trainers May 2011.
Lecture 18: Spatial Analysis Using Rasters Jeffery S. Horsburgh CEE 5190/6190 Geographic Information Systems for Civil Engineers Spring 2016.
Geospatial Data Abstraction Library(GDAL) Sabya Sachi.
Graduate Students, CEE-6190
Chapter 8 Raster Analysis.
GIS Analysis Queries Operations Non-spatial Spatial Vector Raster
GIS Institute Center for Geographic Analysis
Vector Analysis Ming-Chun Lee.
Lab 1 Introduction to ArcGIS Feb 17, 2016
Spatial Models – Raster Stacy Bogan
Lecture 2: Review of Raster Operations
Basic Spatial Analysis
Maps 1 EPID 799C Fall 2017.
GTECH 709 GIS Data Formats GIS data formats
Review- vector analyses
Maps 1 EPID 799C Fall 2018.
Learn R! GIS.
Raster Data Analysis.
GIS Institute Center for Geographic Analysis
Vector Geoprocessing.
GIS Institute Center for Geographic Analysis
Presentation transcript:

Basic GIS Functions and Spatial Stats in

Packages Needed Today Require command will install packages and any packages it depends on What we need require(sp) require(rgdal) require(rgeos) require(raster) require(spatstat) require(spdep) require(RANN) require(gstat) require(adehabitatHR) require(ROCR) require(SDMTools)

Getting Started with Vector Data Packages: >library (sp) Provides classes and methods for spatial data >library (rgdal) Provides bindings to Frank Warmerdam's Geospatial Data Abstraction Library >library (rgeos) Provides geostatistical functions such as regression and basic shapefile operations Other Useful Vector Data Packages > library(maptools) > library(shapefiles) > library(spatstat) > library(splancs)

Getting Started with Vector Data Loading Sample Data OGR -> OpenGIS Simple Features Reference Implementation Dsn -> “data set name” Cactus Point file >cactus<- readOGR(dsn=getwd(), layer="Cactus") Streams Line File >strm<- readOGR(dsn=getwd(), layer="NHD_Streams") Study Area Polygon >stdy<- readOGR(dsn=getwd(), layer="StudyArea")

Plotting Vector Data >plot ( ) is basic R command Hundreds of ways to customize plots Plotting Our Shapefiles >plot(strm, col="blue") >plot(stdy, add=TRUE) >plot(cactus, add=TRUE, col="red")

Examining Attribute Tables View Command >View(cactus) >View(strm) >View(stdy)

Looking Under the Hood >str(stdy) 'slots' (data, polygons(or lines or coords), plotOrder, bbox, proj4string) These mimic the file structure of a shapefile @data = the *.dbf = the attribute table @polygons/lines/coords = *.shp = the geometries that define the spatial components @bbox = the extent of the object(s) in rectangular form @proj4string = *.prj = the projection file describing how to draw the coordinates in space

Examining Attribute Tables In this example we are retrieving the 5th line from the Stream Shapefile Attribute Table >strm[5,] We can plot this as well >plot(strm[5,]) This logic works for retrieving only the attribute table information. Thus @data is simply a data.frame() associated with spatial features >strm@data[5,]

Basic Spatial Analysis – Intersecting Geometries Intersect geometries Rgeos Intersect the study area streams cropped by the boundary >istrm<- gIntersection(strm, stdy, byid=TRUE) This is a set of streams that do not have attributes associated with them The byid=TRUE maintains each stream as unique feature instead of dissolving. Matching the attributes can be troublesome

Basic Spatial Analysis – Intersecting Geometries The Fix Strip off the 0 >row.names(istrm)<- as.character(sapply(row.names(istrm), FUN=function(x){strsplit(x, " ")[[1]][1]})) Match the attributes from the full set of streams with the intersected streams >istrm<- SpatialLinesDataFrame(istrm, data=strm@data[which(!is.na(match(row.names(strm), row.names(istrm)))),]) >View(istrm)

Basic Spatial Analysis – Intersecting Geometries Plot our new dataset >plot(istrm, col="blue") >plot(stdy, add=TRUE) >plot(cactus, add=TRUE, col="red")

Basic Spatial Analysis – Merge Now that we have practiced adding attributes back to an 'rgeos' derived vector layer We need to actually dissolve these streams into one feature for easier processing in future steps >istrm<- gLineMerge(istrm) The cool thing is that the clipped streams are in-memory. So, if you want to perform other stuff on the results, you can without having to store temporary shapefiles, etc...

Basic Spatial Analysis – Buffering Buffering points >pbuff<- gBuffer(cactus, byid=TRUE, width=1000) Now we have to add the attributes back to the buffers. This is a 1 to 1, so the attributes don't need manipulation >pbuff<- SpatialPolygonsDataFrame(pbuff, cactus@data, match.ID=TRUE) >plot(pbuff, add=TRUE)

Basic Spatial Analysis – Clipping Clip the areas from the study area that fall within the point buffer Rgeos Dissolve the buffered points first >pdis<- gUnaryUnion(pbuff) Get the geometric difference >pdiff<- gDifference(stdy, pdis) #; rgeos >plot(pdiff, col="red")

Basic Spatial Analysis – Building Polygons We are going to expand the study extent to match a buffer size and reduce the edge effect of zonal stats (for later) Let's build a polygon from scratch. To create a true polygon feature class, we need to deal with the spatial hierarchy >xs<- c((bbox(stdy)[1,1]-1000), (bbox(stdy)[1,2]+1000), (bbox(stdy)[1,2]+1000), (bbox(stdy)[1,1]-1000), (bbox(stdy)[1,1]- 1000)) >ys<- c((bbox(stdy)[2,1]-1000), (bbox(stdy)[2,1]-1000), (bbox(stdy)[2,2]+1000), (bbox(stdy)[2,2]+1000), (bbox(stdy)[2,1]- 1000))

Basic Spatial Analysis – Building Polygons Create a single polygon >rstdy<- Polygon(matrix(c(xs, ys), ncol=2)) Create a list of polygons (yes we only have one, but...) >rstdy<- Polygons(list(rstdy), ID="1") Now make it spatially aware >rstdy<- SpatialPolygons(list(rstdy), >proj4string=CRS(proj4string(stdy)))

Basic Spatial Analysis – Building Points Create random points and append them to our cactus points. Use the reduced extent >rp<- spsample(stdy, n=length(cactus[,1]), type="random") Add attribute table to random points >rp<- SpatialPointsDataFrame(rp, data=data.frame(PointID=1:nrow(cactus), Present=0)) Append the random points to the cactus points >cactus<- rbind(cactus, rp)

Basic Spatial Analysis – Building Points View the attributes >View(cactus@data) Map the points >plot(stdy) >plot(cactus, col=ifelse(cactus@data$Present==1, "black", "red"), add=TRUE)

Basic Spatial Analysis – Find distance between 2 geometries VECTOR method Transpose the returned matrix >pdist<- t(gDistance(cactus, istrm, byid=TRUE)) Get the average distance to the streams >mean(pdist) Get the minimum distance to the streams >min(pdist) Add the results to the in-memory point shapefile >cactus@data<- data.frame(cactus@data, StrmDist= pdist[match(rownames(cactus@data), rownames(pdist)),]) >View(cactus@data)

Basic Spatial Analysis – Raster Data First we need to read in the raster data >dem<- raster("DEM_30m.img") >plot(dem) >plot(stdy, add=TRUE, col="red")

Basic Spatial Analysis – Raster Data Now we need to clip it to our study area Crop versus Mask Crop = clip Mask will maintain full extent of original raster >cdem<- crop(dem, rstdy) >plot(cdem) >plot(rstdy, add=TRUE) >plot(cactus, add=TRUE, col=ifelse(cactus@data$Present==1, "black", "red"))

Basic Spatial Analysis – Raster Data Terrain Analysis Terrain Command has several functions Aspect, Slope, Focal, etc Elevation Data should be in Meters Uses 3x3 window Now calculate the slope using the DEM >slp<- terrain(cdem, opt="slope", unit="degrees", progress="text")

Basic Spatial Analysis – Raster Data The raster package is the ability to stack rasters in-memory and perform functions on multiple rasters Each raster must have the exact same extent and cell size. Similar to Raster Calculator in ArcGIS Let’s Stack the slope raster on top of our 30m DEM >rs<- stack(cdem, slp)

Basic Spatial Analysis – Raster Data Creating a moving window/focal raster. Give it mean value of entire raster to reduce edge effects >ms<- focal(rs[[2]], w=matrix(1, ncol=3, nrow=3), fun=mean, pad=TRUE, padValue=3.673, progress="text") >names(ms)<- "MeanSlope" Add to the existing raster stack >rs<- stack(rs, ms)

Basic Spatial Analysis – Raster Data Exacting Raster Values to Points >e<- data.frame(extract(rs, cactus)) Now we can add the results to the in-memory point shapefile >cactus@data<- data.frame(cactus@data, e[match(rownames(cactus@data), rownames(e)),]) >View(cactus@data)

Basic Spatial Analysis – Raster Data Exploratory Statistics Graphing the relationships between point data and terrain data >plot(cactus@data$DEM_30m, cactus@data$slope) Examining correlations between Raster variables >cor(cactus@data$DEM_30m, cactus@data$slope, use="complete.obs") Summary Statistics >summary(cactus@data$DEM_30m) >summary(cactus@data$slope) >summary(cactus@data$MeanSlope)

Basic Spatial Analysis –Telemetry Repeated Measurements/GPS Collar Data: Homerange Analysis and Trajectories Load in pronghorn dataset >prong<- readOGR(dsn=getwd(), layer="ph10") Use a DEM to provide spatial context >pdem<- raster("DEMph.img") Make a map >plot(pdem) >plot(prong, add=TRUE)

Basic Spatial Analysis –Telemetry To perform many analyses, we need an accurate date-stamp. Just so you know, dbf files cannot store the date and time in same field. >View(prong@data) Date and time in funky format, we can fix this Create a vector combining the date, hour, min and second >dt<- paste(prong@data$DATE, " ", prong@data$HOURS, ":", prong@data$MINUTES, ":", prong@data$SECONDS, sep="") Convert to the R date/time format >dt<- as.POSIXct(strptime(dt, format="%Y.%m.%d %H:%M:%S", tz="UTC")) We choose UTC as the time zone so as to ignore DST while performing a calculation. Add the new column to our attribute table >prong@data<- data.frame(prong@data, TelemDate=dt)

Basic Spatial Analysis –Telemetry A great thing about R is the ability to iterate through rows of data and perform calculations. Determine the number of minutes between each relocation event using a loop Start at the 2nd row of data because we don't know anything prior to the 1st row of info Create a new column to store values >prong@data$TimeLag<- 0 >for(i in 2:nrow(prong)){ #start at 2nd row prong@data$TimeLag[i]<- round(as.numeric(difftime(prong@data$TelemDate[i], prong@data$TelemDate[(i-1)], units="mins"))) }

Basic Spatial Analysis –Telemetry Now value for 2nd row to the first row >prong@data$TimeLag[1]<- prong@data$TimeLag[2] >View(prong@data) >str(prong@data)

Basic Spatial Analysis –Telemetry Create a trajectory >l<- as.ltraj(xy=coordinates(prong), date=prong@data[,"TelemDate"], id=prong@data[1,"ID__"], burst=prong@data[1,"ID__"]) >plot(l) Convert trajetory to a line >tl<- ltraj2sldf(l) Give it the same projection >proj4string(tl)<- proj4string(prong) >plot(tl) Simplify the line >sl<- gSimplify(tl, tol=6000) #rgeos package >plot(sl, add=TRUE, col="red")

Basic Spatial Analysis –Telemetry Calculate home ranges Start Minimum Convex Polygon (MCP) >cp95 <- mcp(prong, percent = 95) Plot the results >plot(pdem) >plot(prong, add=TRUE, col="green") >plot(cp95, add=TRUE, border="red")

Other Useful Sites Cheat Sheet http://www.maths.lancs.ac.uk/~rowlings/Teaching/UseR2012/che atsheet.html Spatial data with R http://spatial.ly/r/ CRAN: Analysis of Spatial Data http://cran.r-project.org/web/views/Spatial.html Maps with R http://procomun.wordpress.com/2012/02/18/maps_with_r_1/