[R-sig-Geo] importing a shapefile stored on a server

Roger Bivand Roger.Bivand at nhh.no
Thu Mar 29 13:45:30 CEST 2007


On Thu, 29 Mar 2007, Stéphane Dray wrote:

> Dear all,
> I am just preparing a course on spatial analysis with R; The course is a 
> rnw file. In the file, I want to import a shapefile within R. The 
> shapefile is here : http://pbil.univ-lyon1.fr/R/donnees/francedep/
> 
> I have try :
> 
> > library(maptools)
> 
> Le chargement a nécessité le package : foreign
> 
> Le chargement a nécessité le package : sp
> 
> > library(shapefiles)
> 
> Attachement du package : 'shapefiles'
> 
>         The following object(s) are masked from package:foreign :
> 
>          read.dbf
> 
>         The following object(s) are masked from package:foreign :
> 
>          write.dbf
> 
> > read.shapefile("http://pbil.univ-lyon1.fr/R/donnees/francedep/dep_france_dom")Erreur dans get("read.dbf", "package:foreign")(dbf.name) :
> 
>         impossible d'ouvrir le fichier DBF
> 
> > read.shape("http://pbil.univ-lyon1.fr/R/donnees/francedep/dep_france_dom.shp")Erreur dans getinfo.shape(filen) : No such file
> 
> > readShapePoly("http://pbil.univ-lyon1.fr/R/donnees/francedep/dep_france_dom")
> 
> Erreur dans getinfo.shape(filen) : No such file
> 
> 
> Is there a way to read directly this file ? One solution would be to use 
> download.file and then read the shapefile but I wonder if it would be 
> possible to read directly the data from the url.

Almost certainly impossible. The shp and shx are binary files, not 
necessarily read sequentially. Even reading the bits in read.shp() etc. 
seems to be blocked. I think you'll find that the underlying code either 
rewinds or jumps about in the file(s). I tried seeing if readOGR() in 
rgdal would read a GML version:

http://spatial.nhh.no/misc/dep_france_dom.gml

but readOGR() wants a real file with a name. I don't think you have an 
option for shapefiles other than downloading, which does work, possibly to 
a temporary destfile.

Roger

> 
> Cheers.
> 
> 

-- 
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 nhh.no




More information about the R-sig-Geo mailing list