SlideShare une entreprise Scribd logo
1  sur  13
INTRODUCTION TO SPATIAL
DATA ANALYSIS IN R
Richard W Wamalwa1 - MSc., MBA(Finance), BSc.
1Directorate of Academic Quality Assurance,
JKUAT – 2011
RM 610-Environmental, Spatial, GIS, 2011
OUTLINE
Installation of Sp in R
Data export into R
Creating spatial patterns/spatial points
Changing the coordinate referencing system
Creating a SpatialPointsDataframe
Creating and manipulating SpatialLines objects
Create the Polygon Objects
References
ID x y z
1 1 1 21
2 1 2 20
3 1 3 20
4 1 4 21
5 2 3 24
6 3 2 21
7 3 6 21
8 3 7 23
9 4 1 19
10 4 3 21
11 4 4 24
12 4 7 18
13 5 6 21
14 6 2 18
15 6 7 25
16 7 3 20
17 7 5 17
CREATING SPATIAL PATTERN
env1<-
read.table("env1.csv",sep=,",",header=TRUE)
env1
attach(data)
library(sp)
data.sp<-env1
data.sp
coordinates(data.sp)<-~x+y
class(data.sp)
plot(data.sp)
plot(data.sp,axes=TRUE)
SPATIAL POINT
x<-c(1,1,1,2,2,2,3,3,3)
y<-c(1,2,3,1,2,3,1,2,3)
xy<-cbind(x,y)
s<-SpatialPoints(xy)
class(s)
str(s)
bbox(s)
proj4string(s)
coordinates(s)
plot(s)
SPATIAL POINT – CONT’D
x1<-c(2,4,8,3,6,9,2,3,7,9,4,6,8,6,8)
y1<-rep(seq(2,6),c(3,3,4,3,2))
data<-data.frame(x1,y1)
data1<-data
attach(data1)
coordinates(data1)<-~x1+y1
summary(data1)
class(data1)
str(data1)
bbox(data1)
proj4string(data1)
coordinates(data1)
CHANGING THE COORDINATE
REFERENCING SYSTEM
crsnew<-CRS("+proj=longlat +ellps=WGS84")
data2<-SpatialPoints(data,proj4string =crsnew)
class(data2)
summary(data2)
plot(data1,axes=TRUE,col="red",pch=1)
plot(data1,axes=TRUE,col="blue",pch="+")
CREATING A
SPATIALPOINTSDATAFRAME
x2<-c(1,2,3,3,4,4,5,5,6,6,7)
y2<-rep(seq(2,6),c(1,4,2,2,2))
z2<-c(10,30,45,60,70,100,80,130,150,170,190)
data3<-data.frame(x2,y2,z2)
Converting to spatial
plot(s)
gridded(s) <- TRUE
gridded(s)
class(s)
SPATIALPOINTSDATAFRAME – CONT’D
summary(s)
plot(s)
gridded(s) <- FALSE
gridded(s)
class(s)
# data.frame
data(meuse.grid)
coordinates(meuse.grid) <- ~x+y
gridded(meuse.grid) <- TRUE
plot(meuse.grid) # not much good
summary(meuse.grid)
#CREATING AND MANIPULATING
SPATIALLINES OBJECTS
x1=cbind(c(1,5,8),c(1,4,8))
x2=cbind(c(1,9),c(4,2))
x3=cbind(c(3,9),c(1,4))
L1 = Lines(list(Line(x1)), ID="N1")
L2 = Lines(list(Line(x2)), ID="N2")
L3 = Lines(list(Line(x3)), ID="M3")
mylines= SpatialLines(list(L1,L2,L3))
plot(mylines,axes=T,grid=T)
SPATIALLINES OBJECTS – CONT’D
x1=cbind(rnorm(n),rnorm(n,0,0.25))
x2=cbind(rnorm(n),rnorm(n,0,0.25))
x3=cbind(rnorm(n),rnorm(n,0,0.25))
L1=Lines(list(Line(x1)),ID="mp1")
L2=Lines(list(Line(x2)),ID="mp2")
L3=Lines(list(Line(x3)),ID="mp3")
s=SpatialLines(list(L1,L2,L3))
plot(s,axes=T)
#CREATE THE POLYGON OBJECTS
#Step 1: Create the Polygon Objects
Sr1 = Polygon(cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2)))
Sr2 = Polygon(cbind(c(5, 4, 2, 5), c(2, 3, 2, 2)))
Sr3 = Polygon(cbind(c(4, 4, 5, 10, 4), c(5, 3, 2, 5, 5)))
Sr4 = Polygon(cbind(c(5, 6, 6, 5, 5), c(4, 4, 3, 3, 4)),
hole = TRUE)
#Step 2: Creating
Srs1 = Polygons(list(Sr1), "s1")
Srs2 = Polygons(list(Sr2), "s2")
Srs3 = Polygons(list(Sr3, Sr4), "s3/4")
#Step 3: Creating a SpatialPolygons list object
SpP = SpatialPolygons(list(Srs1, Srs2, Srs3), 1:3)
plot(SpP, col = 1:3, pbg = "white")
REFERENCES
Gentleman, R., Hornik, K. and Parmigiani, G.
(2008). Applied Spatial Data Analysis with R.
ISBN 978-0-387-78170-9 e-ISBN 978-0-387-
78171-6 DOI 10.1007/978-0-387-78171-6.
Thomas N O Achia (2010). Environment, Spatial
statistics and GIS Notes.

Contenu connexe

Tendances

Monad presentation scala as a category
Monad presentation   scala as a categoryMonad presentation   scala as a category
Monad presentation scala as a category
samthemonad
 
Better Visualization of Trips through Agglomerative Clustering
Better Visualization of  Trips through     Agglomerative ClusteringBetter Visualization of  Trips through     Agglomerative Clustering
Better Visualization of Trips through Agglomerative Clustering
Anbarasan S
 
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
Computer Science Club
 

Tendances (20)

Grouping & Summarizing Data in R
Grouping & Summarizing Data in RGrouping & Summarizing Data in R
Grouping & Summarizing Data in R
 
Search with Polygons: Another Approach to Solr Geospatial Search
Search with Polygons: Another Approach to Solr Geospatial SearchSearch with Polygons: Another Approach to Solr Geospatial Search
Search with Polygons: Another Approach to Solr Geospatial Search
 
Link analysis
Link analysisLink analysis
Link analysis
 
Exploratory data analysis using r
Exploratory data analysis using rExploratory data analysis using r
Exploratory data analysis using r
 
Monad presentation scala as a category
Monad presentation   scala as a categoryMonad presentation   scala as a category
Monad presentation scala as a category
 
Spatial Data, KML, and the University Web
Spatial Data, KML, and the University WebSpatial Data, KML, and the University Web
Spatial Data, KML, and the University Web
 
R getting spatial
R getting spatialR getting spatial
R getting spatial
 
ClusterAnalysis
ClusterAnalysisClusterAnalysis
ClusterAnalysis
 
A Multidimensional Distributed Array Abstraction for PGAS (HPCC'16)
A Multidimensional Distributed Array Abstraction for PGAS (HPCC'16)A Multidimensional Distributed Array Abstraction for PGAS (HPCC'16)
A Multidimensional Distributed Array Abstraction for PGAS (HPCC'16)
 
Learning Kmap
Learning KmapLearning Kmap
Learning Kmap
 
Graph Regularised Hashing
Graph Regularised HashingGraph Regularised Hashing
Graph Regularised Hashing
 
Better Visualization of Trips through Agglomerative Clustering
Better Visualization of  Trips through     Agglomerative ClusteringBetter Visualization of  Trips through     Agglomerative Clustering
Better Visualization of Trips through Agglomerative Clustering
 
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
 
Unidata's Common Data Model
Unidata's Common Data ModelUnidata's Common Data Model
Unidata's Common Data Model
 
Machine learning using spark
Machine learning using sparkMachine learning using spark
Machine learning using spark
 
QA Fest 2018. Никита Кричко. Методология использования машинного обучения в н...
QA Fest 2018. Никита Кричко. Методология использования машинного обучения в н...QA Fest 2018. Никита Кричко. Методология использования машинного обучения в н...
QA Fest 2018. Никита Кричко. Методология использования машинного обучения в н...
 
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
 
Learning to Project and Binarise for Hashing-based Approximate Nearest Neighb...
Learning to Project and Binarise for Hashing-based Approximate Nearest Neighb...Learning to Project and Binarise for Hashing-based Approximate Nearest Neighb...
Learning to Project and Binarise for Hashing-based Approximate Nearest Neighb...
 
Building a Functional Stream in Scala
Building a Functional Stream in ScalaBuilding a Functional Stream in Scala
Building a Functional Stream in Scala
 
DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...
DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...
DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...
 

Similaire à Introduction to spatial data analysis in r

Introduction to spatstat
Introduction to spatstatIntroduction to spatstat
Introduction to spatstat
Richard Wamalwa
 

Similaire à Introduction to spatial data analysis in r (16)

Introduction to spatstat
Introduction to spatstatIntroduction to spatstat
Introduction to spatstat
 
HEPData
HEPDataHEPData
HEPData
 
Software-defined Networks as Databases
Software-defined Networks as DatabasesSoftware-defined Networks as Databases
Software-defined Networks as Databases
 
Neo4j
Neo4jNeo4j
Neo4j
 
MongoDB, Event Sourcing & Spark
MongoDB, Event Sourcing & SparkMongoDB, Event Sourcing & Spark
MongoDB, Event Sourcing & Spark
 
Apache Hadoop - A Deep Dive (Part 2 - MapReduce)
Apache Hadoop - A Deep Dive (Part 2 - MapReduce)Apache Hadoop - A Deep Dive (Part 2 - MapReduce)
Apache Hadoop - A Deep Dive (Part 2 - MapReduce)
 
Rattle Graphical Interface for R Language
Rattle Graphical Interface for R LanguageRattle Graphical Interface for R Language
Rattle Graphical Interface for R Language
 
Going Reactive with Relational Databases
Going Reactive with Relational DatabasesGoing Reactive with Relational Databases
Going Reactive with Relational Databases
 
Data integration and provenance-Chapter-14
Data integration and provenance-Chapter-14Data integration and provenance-Chapter-14
Data integration and provenance-Chapter-14
 
RichardPughspatial.ppt
RichardPughspatial.pptRichardPughspatial.ppt
RichardPughspatial.ppt
 
Reactive cocoa cocoaheadsbe_2014
Reactive cocoa cocoaheadsbe_2014Reactive cocoa cocoaheadsbe_2014
Reactive cocoa cocoaheadsbe_2014
 
Pivoting Data with SparkSQL by Andrew Ray
Pivoting Data with SparkSQL by Andrew RayPivoting Data with SparkSQL by Andrew Ray
Pivoting Data with SparkSQL by Andrew Ray
 
Machine Learning in R
Machine Learning in RMachine Learning in R
Machine Learning in R
 
Cio summit 20170223_v20
Cio summit 20170223_v20Cio summit 20170223_v20
Cio summit 20170223_v20
 
Sql Server 2008 Spatial Analysis
Sql Server 2008 Spatial AnalysisSql Server 2008 Spatial Analysis
Sql Server 2008 Spatial Analysis
 
Hadoop and Spark for the SAS Developer
Hadoop and Spark for the SAS DeveloperHadoop and Spark for the SAS Developer
Hadoop and Spark for the SAS Developer
 

Dernier

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

Introduction to spatial data analysis in r