Skip to content

adjacency matrix

8 messages · Luc Anselin, Roger Bivand, Orlando Zacarias +3 more

#
Your question is not really clear because:

- I don't know what 'convert.r' do
- I don't know where 'transf.cgm' is (BTW, 'cgm' is not the usual extension
for shapefiles which is 'shp'). Check if it is really in your current
directory.

but, yes, if what you want is to import shapefiles in R, it's easy. Look at
the 'maptools' package on CRAN (there is also a 'shapefiles' package).

And if you want to build an adjacency matrix for a map of polygons (as I
guess from the header of you mail), look at the 'spdep' package, too. It is
then possible to write a text file with your data as a list readable by
WinBUGS.

(I send a copy of my answer to the the R-SIG-GEO mailing list which can be
of interest to you).

Hope it helps.

Christophe
--
Christophe DECLERCQ, MD
Observatoire R?gional de la Sant? Nord-Pas-de-Calais
13, rue Faidherbe 59046 LILLE Cedex FRANCE
Phone +33 3 20 15 49 24
Fax   +33 3 20 55 92 30
E-mail c.declercq at orsnpdc.org
#
Another alternative would be to use the "Tools" in GeoDa
(free from http://sal.agecon.uiuc.edu/csiss/geoda.html ).
This creates contiguity and distance based sparse weights
files (in ascii format) directly from point and polygon shape
files. The spdep package contains functions to read and
manipulate these weights files. I'm not familiar with the
format used by WinBUGS, but I doubt it can be very different.
L.
On Wednesday, October 22, 2003, at 09:19 AM, Christophe Declercq wrote:

            
#
On Wed, 22 Oct 2003, Luc Anselin wrote:

            
GeoBUGS manual, their format can be generated, but looks a bit naive as 
is. We could implement it, and/or talk to the GeoBUGS developers about 
using GeoDa (and maybe R/spdep) as a convenient front end - then they 
would avoid having to generate the weights internally. Since they are 
Windows, and WinBUGS is closed source, GeoDa could be a useful 
pre-processing tool (also for spdep weights).

Roger

  
    
1 day later
#
Hi once again,
Now i have been trying to run the R changed example from Maptools package
manual, and errors occur underlined bellow. It is really troublesome....
Please assist,
Orlando.
---------------------------------------------------
shp <- try(library(shapefiles))  
Error in library(maptools) : There is no package called 'shapefiles'
+ ShapeDir <- system.file("shapes", package="maptools")[1]
+ try1 <- read.shapefile(paste(ShapeDir, "shapes", sep="/"))
+ shppolys <- shape2poly(try1, as.character(try1$dbf$dbf$NEIGNO))
+ plotpolys(shppolys)
+ title(main="Polygons for Vermani from shapefiles package")
+ }
+ package="maptools/man")[1])
Error: couldn't find function "read.shape"
Error: couldn't find function "Map2poly"
Error: couldn't find function "plotpolys"
Error in title(main = "Polygons for Vermani from maptools package") : 
        plot.new has not been called yet
+ plotpolys(shppolys)
+ plotpolys(mappolys, add=TRUE, border="red", lty="dotted")
+ title(main="Polygons for Vermani overplotted from both packages")
+ }
------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/c5da4174/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 41982 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/c5da4174/attachment.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 1738 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/c5da4174/attachment-0001.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 494 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/c5da4174/attachment-0002.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 3937 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/c5da4174/attachment-0003.gif>
#
Have you install the shapefiles library on your computer ??
At 12:56 23/10/2003, Orlando Zacarias wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/c8518e77/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a77632.gif
Type: image/gif
Size: 41982 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/c8518e77/attachment.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a77678.gif
Type: image/gif
Size: 1738 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/c8518e77/attachment-0001.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a77683.gif
Type: image/gif
Size: 494 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/c8518e77/attachment-0002.gif>
#
Hi-
    As far as I know, some of the error messages results from the fact that you

either did not install the package or did not load the package.
    If you did not install the package, you can install from R's GUI (my 
experiences are based on the Windows Version), and load them by type library
(packagename). If you have already installed them, just type library
(packagename) and you will be good to go. For your specific case, after you 
started R, just type library(maptools), and you will be able to use all the 
functions such as read.shape, Map2poly, plotpolys, etc.

Quoting Orlando Zacarias <si-opz at dsv.su.se>:
#
The message is clear!
Did you forget:
before that?

Christophe
#
I have re-installed the maptools package in library-dir as required. But
there is still some error message on Test Version file for R as illustrated
bellow. Where do i change this "may be flag"??
Cheers,
Orlando.
-----------
shp <- try(library(maptools))  
Error in testRversion(descfields) : This package has not been installed properly See the Note in ?library
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/996f9ba3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 41982 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/996f9ba3/attachment.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 1738 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/996f9ba3/attachment-0001.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 494 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/996f9ba3/attachment-0002.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 3937 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20031023/996f9ba3/attachment-0003.gif>