INTRODUCTION TO SPATIALDATA ANALYSIS IN RRichard W Wamalwa1 - MSc., MBA(Finance), BSc.1Directorate of Academic Quality Ass...
OUTLINEInstallation of Sp in RData export into RCreating spatial patterns/spatial pointsChanging the coordinate referencin...
ID x y z1 1 1 212 1 2 203 1 3 204 1 4 215 2 3 246 3 2 217 3 6 218 3 7 239 4 1 1910 4 3 2111 4 4 2412 4 7 1813 5 6 2114 6 2...
CREATING SPATIAL PATTERNenv1<-read.table("env1.csv",sep=,",",header=TRUE)env1attach(data)library(sp)data.sp<-env1data.spco...
SPATIAL POINTx<-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)proj4str...
SPATIAL POINT – CONT’Dx1<-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...
CHANGING THE COORDINATEREFERENCING SYSTEMcrsnew<-CRS("+proj=longlat +ellps=WGS84")data2<-SpatialPoints(data,proj4string =c...
CREATING ASPATIALPOINTSDATAFRAMEx2<-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,...
SPATIALPOINTSDATAFRAME – CONT’Dsummary(s)plot(s)gridded(s) <- FALSEgridded(s)class(s)# data.framedata(meuse.grid)coordinat...
#CREATING AND MANIPULATINGSPATIALLINES OBJECTSx1=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 ...
SPATIALLINES OBJECTS – CONT’Dx1=cbind(rnorm(n),rnorm(n,0,0.25))x2=cbind(rnorm(n),rnorm(n,0,0.25))x3=cbind(rnorm(n),rnorm(n...
#CREATE THE POLYGON OBJECTS#Step 1: Create the Polygon ObjectsSr1 = Polygon(cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2)))Sr2 ...
REFERENCESGentleman, R., Hornik, K. and Parmigiani, G.(2008). Applied Spatial Data Analysis with R.ISBN 978-0-387-78170-9 ...
Upcoming SlideShare
Loading in...5
×

Introduction to spatial data analysis in r

803

Published on

Published in: Education, Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
803
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Introduction to spatial data analysis in r

  1. 1. INTRODUCTION TO SPATIALDATA ANALYSIS IN RRichard W Wamalwa1 - MSc., MBA(Finance), BSc.1Directorate of Academic Quality Assurance,JKUAT – 2011RM 610-Environmental, Spatial, GIS, 2011
  2. 2. OUTLINEInstallation of Sp in RData export into RCreating spatial patterns/spatial pointsChanging the coordinate referencing systemCreating a SpatialPointsDataframeCreating and manipulating SpatialLines objectsCreate the Polygon ObjectsReferences
  3. 3. ID x y z1 1 1 212 1 2 203 1 3 204 1 4 215 2 3 246 3 2 217 3 6 218 3 7 239 4 1 1910 4 3 2111 4 4 2412 4 7 1813 5 6 2114 6 2 1815 6 7 2516 7 3 2017 7 5 17
  4. 4. CREATING SPATIAL PATTERNenv1<-read.table("env1.csv",sep=,",",header=TRUE)env1attach(data)library(sp)data.sp<-env1data.spcoordinates(data.sp)<-~x+yclass(data.sp)plot(data.sp)plot(data.sp,axes=TRUE)
  5. 5. SPATIAL POINTx<-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)
  6. 6. SPATIAL POINT – CONT’Dx1<-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<-dataattach(data1)coordinates(data1)<-~x1+y1summary(data1)class(data1)str(data1)bbox(data1)proj4string(data1)coordinates(data1)
  7. 7. CHANGING THE COORDINATEREFERENCING SYSTEMcrsnew<-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="+")
  8. 8. CREATING ASPATIALPOINTSDATAFRAMEx2<-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 spatialplot(s)gridded(s) <- TRUEgridded(s)class(s)
  9. 9. SPATIALPOINTSDATAFRAME – CONT’Dsummary(s)plot(s)gridded(s) <- FALSEgridded(s)class(s)# data.framedata(meuse.grid)coordinates(meuse.grid) <- ~x+ygridded(meuse.grid) <- TRUEplot(meuse.grid) # not much goodsummary(meuse.grid)
  10. 10. #CREATING AND MANIPULATINGSPATIALLINES OBJECTSx1=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)
  11. 11. SPATIALLINES OBJECTS – CONT’Dx1=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)
  12. 12. #CREATE THE POLYGON OBJECTS#Step 1: Create the Polygon ObjectsSr1 = 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: CreatingSrs1 = Polygons(list(Sr1), "s1")Srs2 = Polygons(list(Sr2), "s2")Srs3 = Polygons(list(Sr3, Sr4), "s3/4")#Step 3: Creating a SpatialPolygons list objectSpP = SpatialPolygons(list(Srs1, Srs2, Srs3), 1:3)plot(SpP, col = 1:3, pbg = "white")
  13. 13. REFERENCESGentleman, 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, Spatialstatistics and GIS Notes.

×