[R-sig-Geo] polygon identifiers and nb classes
Roger Bivand
Roger.Bivand at nhh.no
Thu Apr 13 21:16:39 CEST 2006
On Thu, 13 Apr 2006, Larry Layne wrote:
> I use the following code from maptools and spdep to create a neighbors list
> of class nb from a shapefile:
>
> NMmap <- read.shape("CountyLevelData.shp")
> NMpolylist <- Map2poly(NMmap,region.id=NULL,quiet=TRUE)
> NMnb <- poly2nb(NMpolylist,queen=FALSE)
> print(is.symmetric.nb(NMnb))
>
> I can then use write.nb.gal to output the neighbors list to a txt file in
> GAL format:
>
> write.nb.gal(NMnb,file="E://zweightsGAL_county.txt",oldstyle=FALSE,shpfile=NULL,ind=NULL)
>
> I understand how to read the GAL format. What is the origin of the id's
> listed in the txt file (in this case the rweightsGAL_county.txt file). They
> look like they are the values from the FID field + 1 in the original shape
> file.
Yes, if no row.names= argument is given to poly2nb(), this is what they
will default to.
You can choose your own row.names= in poly2nb(), and setting
oldstyle=FALSE, it should work. You'll need to edit the first line, the
ArcGIS format is not GAL as far as I understand.
The col.gal.nb object in data(columbus) has region.id attributes set in
this way:
> summary(col.gal.nb)
Neighbour list object:
Number of regions: 49
Number of nonzero links: 230
Percentage nonzero weights: 9.579342
Average number of links: 4.693878
Link number distribution:
2 3 4 5 6 7 8 9 10
7 7 13 4 9 6 1 1 1
7 least connected regions:
1005 1008 1045 1047 1049 1048 1015 with 2 links
1 most connected region:
1017 with 10 links
> tmpfl <- tempfile()
> write.nb.gal(col.gal.nb, tmpfl, oldstyle=FALSE)
> system(paste("cat", tmpfl))
0 49 unknown unknown
1005 2
1001 1006
1001 3
1005 1006 1002
...
so then you'd need to change the header to name the DBF field with the IDs
correctly. For cross-checking in GeoDa, please set the shapefile= and ind=
arguments to the appropriate values.
A revision of write.nb.gal() is obviously possible here, I
would value feedback. Please also crosscheck whether the variance of
Moran's I agrees with moran.test here in the randomisation=TRUE
row-standardised weights case - it is known not to agree for fixed range
and inverse distance weights in ArcGIS, the results here (and in Stata)
are consistent, but those in ArcGIS are not.
It will be interesting to hear what you find!
Roger
>
> I want to use the information from the GAL format .txt file to create a
> spatial weights matrix file of the form I can use in ArcGIS on the same
> shapefile the data came from in the first place. (For instance, compute
> Moran's I using spatial statistics extension in ArcGIS using the binary
> weights connectivity matrix.) How do I know which field from the shapefile
> is being used in the construction of the neighbors list for the class nb
> and then being written to the txt file using write.nb.gal?
>
> Larry Layne
> ljlayne at unm.edu
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list