How to get adjacency matrix from WINBUGS with ARCVIEW(.shp) files

What you need on your computer

  • Arcview3.2a
  • Splus or R
  • WINBUGS14

    How to do it?

  • First get .cgm file from Arcview
  • Second, convert .cgm file into .txt file in Splus format readible by WINBUGS
  • Last, read .txt file into WINBUGS

    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