Barry,
 
Took your advice and wrote my own function to deal with the individual files.  Took more than four lines, but that is likely a reflection on my ugly code!  It does work on my own machine/internal browser. 
 
Now with local copies I can just use readOGR as intended.
 
Thanks again for the adivce Michael and Barry!
 
Cheers,
jeff
 
download.shapefile<-function(shape_url,dsn,outfile=dsn)
{
   #written by: jw hollister
   #Oct 10, 2012
  
   #set-up/clean-up variables
   if(length(grep("/$",shape_url))==0)
   {
      shape_url<-paste(shape_url,"/",sep="")
   }
   #creates vector of all possible shapefile extensions
   shapefile_ext<-c(".shp",".shx",".dbf",".prj",".sbn",".sbx",".shp.xml",".fbn",
                    ".fbx",".ain",".aih",".ixs",".mxs",".atx",".cpg")
   #Check which shapefile files exist
   if(require(RCurl))
   {
      xurl<-getURL(shape_url)
      xlogic<-NULL
      for(i in paste(dsn,shapefile_ext,sep=""))
      {
         xlogic<-c(xlogic,grepl(i,xurl))
      }
      #Set-up list of shapefiles to download
      shapefiles<-paste(shape_url,dsn,shapefile_ext,sep="")[xlogic]
      #Set-up output file names
      outfiles<-paste(outfile,shapefile_ext,sep="")[xlogic]
   }
   #Download all shapefiles
   for(i in 1:length(shapefiles))
   {
      download.file(shapefiles[i],outfiles[i],method="auto",mode="wb")
   }
}
 



***************************
Dr. Jeffrey W. Hollister
Research Ecologist
US EPA
Atlantic Ecology Division
27 Tarzwell Drive
Narragansett, RI 02882
(401) 782-9655
***************************


-----Michael Sumner <[email protected]> wrote: -----
To: Barry Rowlingson <[email protected]>
From: Michael Sumner <[email protected]>
Date: 10/09/2012 05:37PM
Cc: Jeff Hollister/NAR/USEPA/US@EPA, "[email protected]" <[email protected]>
Subject: Re: [R-sig-Geo] Reading a Shapefile from a website with readOGR?

Heh, good point!  There are so many options some times . . .

On Wed, Oct 10, 2012 at 8:23 AM, Barry Rowlingson
<[email protected]> wrote:
> On Tue, Oct 9, 2012 at 9:49 PM, Michael Sumner <[email protected]> wrote:
>> This can work with a combination of vsizip (or other) and vsicurl, but the
>> multiple files will have to be in an archive (zip or other).
>>
>> http://trac.osgeo.org/gdal/wiki/UserDocs/ReadInZip
>>
>> See examples near the bottom of the page for OGR. Keep the zip file name
>> the same as the shapefile/layer name and don't have subdirectories for the
>> simplest case.
>>
>> I am pretty sure this cannot work otherwise for a multifile format.
>
>  Neat, but I suspect in practice the underlying code is just
> downloading the zip and extracting to a temp file, which is about four
> lines of R code. If the shapefile components aren't zipped up, its
> just as easy.
>
>  I'd write a wrapper to do that.
>
> Barry



--
Michael Sumner
Hobart, Australia
e-mail: [email protected]
_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to