How to get adjacency matrix from WINBUGS with ARCVIEW(.shp) files
What you need on your computer
Arcview3.2a
- As pointed out by a student in Dr. Carlin's class, this conversion program
"does NOT handle the case of ArcView 9.x, since in this new version of
the software the .shp file has been replaced by some other format." Warning
from Dr. Carlin is "this approach only works with ArcView 8.x or earlier (ie,
you need .shp and .cgm files)."
Splus or R
WINBUGS14
How to do it?
First get .cgm file from Arcview
- open your Arcview shape file in Arcview, for example, a.shp
- click "Export" in File menu
- choose from List Files of Type "CGM Clear Text" and save .cgm
file(e.g. a.cgm). This .cgm file is a text file and
can be opened with any word processor like Notepad.
Second, convert .cgm file into .txt file in Splus format
readible by WINBUGS
- Download convert.s, or
convert.r
, which defines a Splus function or R function called
"convert"
- Open Splus or R under the folder in which convert.s
is saved
- Read in source code of convert by type in
source("convert.s") in the command line
- Under command line, type in convert("filename"), then
filename.txt will be generated and saved under the current
folder. Here "filename" doesn't have .cgm in it.
e.g, when you
have a.cgm in folder, you should
submit convert("a") instead of convert("a.cgm")
Last, read .txt file into WINBUGS
- Open .txt file in WINBUGS using open in File menu,
remember to
choose Text[.txt] or Text[Dos encoding][.txt]
from File of type
option. Now WINBUGS will pop out a text editing windown showing
the .txt file.
- Click Map menu and choose Import Splus,
if the .txt file is in
correct Splus format, then a Save as window will
come out, and
you can now save it as a .map file ready for mapping,
e.g.
a.map. It the .txt has error in it, WINBUGS will beep
a sound and
no save as window is opened.
- Now close WINBUGS and restart it.
- Click map in WINBUGS window and choose Adjacency
Tool, in the
pop out window, choose the .map you just created from the
dropdown
list of maps, click on adj map and an Adjacency
Map window will
come out showing the map same as the one you exported out of
Arcview. Now you can click adj matrix icon in Adjacency
Tool to get adjacency matrix for this map.
How fast or slow is convert.s or convert.r
To convert Zip level map mnzip.cgm exported from Arcview to
mnzip.txt on goldeneye
using convert.s takes 15 minutes. The same task takes
convert.r 7 minutes
Remarks:
The .txt file in Splus format created by "convert.s" or "convert.r" may
contain
several sequential coordinate sets of polygons with the same label. It's
because
when the map file is exported from Arcview into a .cgm file, all
polygon regions
with the same label are placed in one polygon set (marked by statement
"POLYGON_SET") and delimited by a label "CLOSEVIS". And all regions with the
same label are treated in Arcview as one map unit. When written into Splus
form, those polygons of same label are also treated as one big single
polygon in WINBUGS.
Bugs
When I'm using the convert function on the world countries map country.shp
from
ESRI, the map displayed in WINBUGS shows that U.S, Canada, Russia, Antarctica
and Greenland are totally black. When I check the .cgm file, I find that
there are many coordinates marked by "INVIS" in POLYGON_SET, and the
POLYGON_SET having "INVIS" in it only has 5 pairs of coordinates to form
a very very small square. When filtering out those coordinates, those countries
used to be black are gone. So these countries are expressed in small squares.
Using Find in Notepad find that some of such coordinated pair also
appear
in some coordinate sets marked by "LINE". So it seems that Arcview grid some of
the regions and express it by grids and lines. By now, I still have no idea how
to extract those boundary points, or if those marked by "LINE" are right the
boundary line. But you need to check the .cgm file
if maps displayed in Arcview and WINBUGS mismatch.
Example
This example illustrates how to get adjacency matrix to be used in Baysian
modeling in the CureRate smoking projects.(???) (The data for Baysian analyis
can be found
here)
Download convert.s, or
convert.r
Download shape files for Rochester county.
Open theme2.shp in Arcview's Views window. From File,
choose Export... to active the Export window. In
Export window, choose "CGM Clear Text" in List Files of Type
and save the exported file as
theme2.cgm to where you save
convert.s or convert.r
Run Splus or R under the folder where you just saved theme2.cgm.
Under R, (or Splus) submit source("convert.r") (or
source("convert.s"))
Now submit convert("theme2"). It takes 2 minutes to run on
goldeneye. Now
theme2.txt will be in your current folder.
Open WINBUGS and click open in File menu.
choose Text[.txt] or Text[Dos encoding][.txt]
from File of type drop-down list. Open theme2.txt. Then
click
Map followed by Import Splus. Save it as theme.map
in the poped out Save As window. WINBUGS will save it under
Maps/Map under its own folder
(e.g. c:/Program Files/WINBUGS14/Maps/Map).
Close WINBUGS and restart it
Click Map and choose Adjacency Tool.... You can find
theme2 in the drop-down list of map. Click it and the
adj map icon below. Adjacency Map comes out showing
the Rochester county map in zips and now you can click the adj matrix
icon to get adjacency matrix
Another more complicated example