R Spatial Data: Read in SHP File

Rate this post

R Spatial Data 1: Read in SHP File

Here we use R and RStudio to read in a spatial data file (as a SHP file), read in a contiguity (GAL) file created in GeoDa, create the same queen contiguity matrix in R and check that the two are the same, and compute a Moran’s I.

Link to Data File: http://ift.tt/2wqs0Bo
Link to download R: http://ift.tt/1YrCQ2B
Link to Download RStudio: http://ift.tt/1gQO3cs

Here are the commands we used:
library(spdep)
library(rgdal)
NCVACO = readOGR(dsn = “.”, layer = “NCVACO”)
queen.nb=read.gal(“queen.gal”, region.id=NCVACO$FIPS)
summary(queen.nb)
queen.R.nb=poly2nb(NCVACO, row.names=NCVACO$FIPS)
#Rook would be rook.R.nb=poly2nb(NCVACO,queen=FALSE)
summary(queen.R.nb)
isTRUE(all.equal(queen.nb,queen.R.nb,check.attributes=FALSE))
#moran(variable, listw, no. regions, sum of weights)
moran(NCVACO$SALESPC,nb2listw(queen.nb), length(NCVACO$SALESPC), Szero(nb2listw(queen.nb)))
moran.test(NCVACO$SALESPC,nb2listw(queen.nb))

Check Also

07 Nov 2017 Customization in GIS by Shri Kamal Pandey

Customization in GIS

Rate this post 07 Nov 2017 Customization in GIS by Shri Kamal Pandey IIRS, ISRO ...

Leave a Reply

Your email address will not be published. Required fields are marked *