[R] ESRI shape file import and time-space models

Fan xiao.gang.fan1 at libertysurf.fr
Sat Feb 15 16:35:03 CET 2003


For reading dBase file on Windows, one can use ODBC with the following 
wrapper function if fast loading is an important issue:

odbc.dbase <- function(dbf.file, rownames=FALSE)
{
  connstr <- paste("Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=", getwd(),
sep="")
  o <- odbcDriverConnect(connstr)
  ans <- sqlQuery(o, paste("select * from", basename(dbf.file)), rownames)
  odbcClose(o)
  ans
}

It's much faster than the R function read.dbf() of Benjamin, here's a little bench:

> system.time(read.dbf("xxx.dbf"))
[1]   NA   NA 25.2   NA   NA

> system.time(odbc.dbase("xxx.dbf"))
[1]   NA   NA 4.54   NA   NA

I have also a C implementation which is even more fast:
> system.time(read.dbase("xxx.dbf"))
[1]   NA   NA 1.83   NA   NA
But I think the odbc wrapper is suffisant enough and conceptually more
general (the same method can be used for Excel file, MS Access file).

Cheers
--
Fan

Benjamin.STABLER at odot.state.or.us:
> 
> Attached are some functions that I wrote to read and write shapefiles and
> dbfs easily from within R.  You do not need any additional libraries or C
> code.  I am still working out a few bugs but I have tested it with quite a
> few different files and it seems to be working pretty well.  There is little
> documentation at this point though.  I'd appreciate any comments about the
> code.  Thanks.
> 
> Benjamin Stabler
> Transportation Planning Analysis Unit
> Oregon Department of Transportation
> 555 13th Street NE, Suite 2
> Salem, OR 97301  Ph: 503-986-4104
> 
> >Dear R user,
> >I am running R under Windows 2000.
> 
> >I am looking for a routine for importing
> 
> 
> 
> >        shape files (ESRI) into R
> 
> >        dbase files (FOXPRO) into R
> 
> >and I am looking for time-space models for description and prediction of
> >Bernoulli-, Binomial- and Poissonvaraibles.
> 
> >Thank's a lot for a reply.
> 
> >Sincerely yours,
> 
> >Ekkehardt Altpeter
> 
> >Swiss Federal Office of Public Health.
> 
>   ------------------------------------------------------------------------------------------
>                    Name: shapefiles.R
>    shapefiles.R    Type: fichier R (application/x-unknown-content-type-R_auto_file)
>                Encoding: quoted-printable




More information about the R-help mailing list