Summary: ArcView shape files and GeoBUGS

Previous Topic Next Topic
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Summary: ArcView shape files and GeoBUGS

Tord Snäll-4
Thanks to you all for prompt replies!

As evident from the replies pasted below there are different solutions
to this problem.


"There are some tools avaiable to transform maps to \pkg{GeoBUGS}
format: the function \code{sp2WB} of package \pkg{maptools} can
transform \code{SpatialPolygons} object to the S-Plus mapin \pkg{R}
\citep{R}, or the ArcGIS extension of W. Thogmartin and colleagues what
helps users to develop adjacency

my tool (maps2winbugs) has other functions as well to prepare maps for
unfortunately it works just on MS Windows


all the best


If you are using R, you can use the function sp2WB in maptools to
convert your data into a format that WB can import from a shapefile.
Look at the manual page of sp2WB.

Hope this helps,


P.S: THis is the example in that manual page:

 xx <- readShapePoly(system.file("shapes/sids.shp",
      IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
     plot(xx, border="blue", axes=TRUE, las=1)
     sp2WB(as(xx, "SpatialPolygons"), filename="")
     x <- readAsciiGrid(system.file("grids/",
     xp <- as(x, "SpatialPixelsDataFrame")
     pp <- as.SpatialPolygons.SpatialPixels(xp)
     sp2WB(pp, filename="")


Tord. Have found the easiest way to address this issue is to read the shape
files into R, then convert them into splus format, which bugs will import.
Following is the code:

library(maptools) # loads sp library too

# read in shape files (single folder with all associated files, no
# display the shapefile
# convert the shape file into splus format to import into GeoBugs
sp2WB(x, "C:\\xxx\\xxxx\\xxxx\\xxxx.txt") # note '.txt' extension



Dear Tord,

You can use R to convert a shapefile into a format readable from
GeoBUGS. There are several R packages to handle geographical
information. An easy way to convert a .shp file into what GeoBUGS refers
to as SPLUS format  could be:

1) Load library maptools in R

2) Import the shapefile into R:
object.shp <- readShapePoly("C:/mydir/myshapefile.shp", IDvar="area_id")

3) Export it in Splus format
sp2WB(as(object.shp, "SpatialPolygons"), filename="myname.txt")

Hope this helps.

Hi, I had the same problem and one solution is download the program
maps2WinBUGS is free or you can look the libraries maps and maptools in
R  the maptools package allows the importation of ArcView shape files to
R (readShapePoly function) and also the export of maps to WinBUGS format
with the function sp2WB. Both spatstat and splancs have functionality
for mapping point process data.

Dear Tord,

Look at the example in the manual page of function sp2WB (package
maptools). I believe that it is what you need.

Hope this helps.


I think this is it:

#/09/23/03 The only different btw this convert.r and convert.s is that
#in convert.s, we us AsciiToInt("character")-AsciiToInt("0") to change
#character into numeric, in convert.r, we use type.convert("character")
#to do this.

#This version of convert.s corrects the problems found in convert2&3.s

#Tried every combination of options for scan, the following doesn't work.
#checking by comparing the number of observations in fortest and in .cgm file

#outfile <- "test.txt"

#This one works



#First tried rep(0,1000), but there is a polygon with 167 rows, so we get
#167*3*2=1002 coordinates in one polygon. Error occurs with NA output

for (i in 1:totpolyn) {
    write(paste( i, paste("grid",i,sep="")),outfile,append=T)

for (i in 1:length(fortest)){
  for(j in (1:nchar(fortest[i]))){
      #At first try to use AsciiToInt,stupid
      #if (AsciiToInt(letter)<=AsciiToInt("9")&
      #    AsciiToInt(letter)>=AsciiToInt("0"))
                         if (indicator==0) {count<-count+1;
                                            indicator<- 1
      #add the following else if statement because if and only when
      #a POLYGON_SET is encounted, polyn is increased by 1
      else if (letter=="P"){ polyn<-polyn+1;indicator<-0}

      #a CLOSEVIS is encounted, output the coordinates set, this is
      #done independently with increase of polyn since a POLYGON_SET may
      #consist of several small polygons
      else if(letter=="C"){

        if (polyn == 1) { write("",outfile,append=T)}
        else            { write(c(NA,NA,NA),outfile,append=T)}
        #the above statement is not right because 2 CLOSEVIS may lie in one
        #same polygon, but we output a polygon coordinates set whenever a
        #CLOSEVIS is encountered, although it may have the same label,
        #denoted by "grid&polyn" with previous or next coordinate sets.


      else        indicator<-0
Hi Tord,

I think you will find the extract you require in this paper

Search the document for Yue Cui and it will bring you to the page.

I have used the code myself and it does work.

Hope it helps.  

I believe that you are would like to convert a shapefile
into a BUGS map, correct?  If so, download maps2WinBugs and follow the tutorial
on how to do so. Just Google the program and it will pop right up.



Tord Sn?ll wrote:

> Dear all,
> I would like to read in ArcView (or ArcGIS) shape files from which I
> will pick information if fitting a geostatistical model using WinBUGS.
> In the GeoBUGS Used Manual it says
> "GeoBUGS does not have an option for loading ArcView shape files
> directly. However, Ms Yue Cui at the University of Minnesota has
> written programs in Splus and R for converting shape files into the
> GeoBUGS Splus format so that they can be loaded in GeoBUGS
> ( "
> Unfortunately this site is unavailable, and the Biostatstics homepage
> at University of Minnesota does not say anything about neither BUGS or
> Ms Yue Cui.
> Does anyone have this R code, or can point me to Ms Yue Cui?
> Thanks,
> Tord


Tord Sn?ll
Department of Ecology / Swedish Species Information Centre
Swedish University of Agricultural Sciences (SLU)
P.O. 7044, SE-750 07 Uppsala, Sweden
E-mail: tord.snall at

Reply | Threaded
Open this post in threaded view

Summary: ArcView shape files and GeoBUGS

Roger Bivand
On Thu, 5 Feb 2009, Tord Sn?ll wrote:

> Thanks to you all for prompt replies!
> As evident from the replies pasted below there are different solutions to
> this problem.
> cheers,
> Tord

Thanks for a very full summary, keeping the threaded information together.
Just two more comments - the next release of maptools will also have a
readSplus() function contributed by Virgilio G?mez Rubio to read maps
exported from WinBUGS into a SpatialPolygons object. Also, if the goal is
to create spatial weights in WinBUGS, you can export listw and nb objects
from spdep using listw2WB() and nb2WB(), maybe removing the need for
importing the map, having created the weights using one of the variants
in spdep.


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

Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway