[R-sig-Geo] Problems with read.gal

Ann Hartell ahartell at gmail.com
Thu Mar 24 18:21:11 CET 2016


Hello All,

I'm having issues getting R to properly read a GAL file.  GeoDa is 
reading the file and correctly assigning neighbors, calculating various 
spatial statistics, etc.  I've checked the GAL file for any coding 
anomolies (using a short Perl program), and all seems well.

After the usual preliminaries of loading packages (e.g. spdep v. 
0.5-92), setting a working directory, reading in the SHP file . .  .

##  read into R as an nb object following the Usage in the spdep help file:

queen.nb <- read.gal("MyShapeFile.GAL", region.id=NULL, override.id=FALSE)


##Returns this error:

Error in read.gal("MyShapeFile.GAL", region.id = NULL, override.id = 
FALSE) : GAL file IDs and region.id differ

##In the past, I have had success following the example
## from Anselin linked in the spdep help at < 
https://geodacenter.asu.edu/system/files/rex1.pdf  >

queen.nb <- read.gal("MyShapeFile.GAL", override.id=TRUE)
queen.listW <- nb2listw(queen.nb, style="W", zero.policy = TRUE)
class(queen.listW)

[1] "listw" "nb"

summary(queen.listW)


Characteristics of weights list object:
Neighbour list object:
Number of regions: 39361
Number of nonzero links: 238004
Percentage nonzero weights: 0.01536215
Average number of links: 6.046696
Non-symmetric neighbours list
Link number distribution:

    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17
  217  640 2041 4804 8062 8752 7196 4194 1863


###. . . .  and so on . . . .

## Plotting a contiguity map reveals the trouble

plot(data, border="grey60")
title(main="Queen contiguity")
plot(queen.listW, coord, add=TRUE, col="green", pch=19, cex=0.6)

### Far flung spatial units are linked as neighbors, which is incorrect.
###  I get the same jumble results using:

queen.nb <- read.gal("MyShapeFile.GAL", region.id = NULL, override.id=TRUE)

### Then, following the example provided here: 
http://cran.at.r-project.org/web/packages/spdep/vignettes/nb.pdf

MyFile <- readShapeSpatial("MyShapeFile")
library(spdep)
queen.nb <- read.gal("MyShapeFile.GAL", region.id = row.names(MyFile))

## Returns:

Error in read.gal("MyShapeFile.GAL", region.id = row.names(test)) : GAL 
file IDs and region.id differ


#######End

So, an issue with the id variables between the two files, but I cannot 
work out how to resolve it.
Any insights or elaboration on the Usage and Arguments provided in the 
spdep help most appreciated.
Thanks,
Ann Hartell

-- 

WU/Vienna University of Economics and Business
Austria


	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list