On Thu, 18 Mar 2010, Gindo Tampubolon wrote:

Dear Roger and all,

Sorry for not putting a sample. Yes, Windows seems to be overloaded.
http://sites.google.com/site/tehtareknow/home/spatial-weight-matrix/

The *.swm file is a binary file in an unknown format. The DBF file can be read as follows:

library(foreign)
x <- read.dbf("spatialweightmatrix3.dbf")
from_IDs <- sort(unique(x$FID2))
to_IDs <- sort(unique(x$NID))
# find the IDs used
all.equal(from_IDs, to_IDs)
o <- order(x$FID2, x$NID)
# order the object
xx <- x[o,]
# convert manually to a spatial.neighbours representation
sn <- data.frame(from=match(xx$FID2, from_IDs), to=match(xx$NID+1,
  to_IDs), weihts=xx$WEIGHT)
attr(sn, "n") <- length(from_IDs)
attr(sn, "region.id") <- as.character(from_IDs)
class(sn) <- c("spatial.neighbour", class(sn))
library(spdep)
lw <- sn2listw(sn)
lw
summary(sapply(lw$weights, sum))
table(card(lw$neighbours))

There are only 1331 observations, so unconnected ones appear to be dropped, and are probably the "holes" in attr(lw, "region.id") which should span 0:1356, but is missing 25 values. The FID2 are probably the FID of the polygon objects.

Hope this helps,

Roger



Thanks for the tip and any more help much appreciated,
Gindo

-----Original Message-----
From: Roger Bivand [mailto:[email protected]]
Sent: 18 March 2010 14:23
To: Gindo Tampubolon
Cc: [email protected]
Subject: Re: [R-sig-Geo] Reading ArcGIS 9.3 spatial weight matrix [swm] file

On Thu, 18 Mar 2010, Gindo Tampubolon wrote:

Dear all,

Can anyone tell me how to read ArcGIS 9.3 generated .swm file [spatial
weight matrix] into R?

Well, make a number of small samples available on a website - most people
do not have access to Arc, so helping is hard. Is there an ESRI site with
shapefiles and matching sample *.swm files?


I am stumped at page 242 of the ASDAR book [Bivand et al 2008]. I use a
SpatialPolygonsDataFrame object and tried to generate neighbours list
using poly2nb(). It took more than 24 hours [European data NUTS level 3
about 1500 regions]. After finishing, the result is a null set.


Always try a subset first. Most likely you need the snap= argument, if the
boundaries do not touch but are close to each other. Almost certainly your
input map also had far too much detail in shorelines and river borders,
leading to your machine getting overloaded (Windows?). Displaying on such
a map would also be dominated by line detail.

So I generate a rook weight matrix in ArcGIS 9.3 [and convert it to a
table there]. How do I import this matrix to R?

Contribute by making sample files available. To read a matrix if you must,
use read.table().

Roger



I looked at RArcInfo and rgdal packages but could not find anything
obvious; I'm experimenting with read.gwt2nb() but ArcGIS created swm
based on numeric ID instead of NUTS_CODE alphanumeric; needs tweaking
perhaps.

Many thanks

Gindo

_______________________________________________
R-sig-Geo mailing list
[email protected]
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: [email protected]




--
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: [email protected]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to