[gdal-dev] open shapefile from server

Even Rouault even.rouault at mines-paris.org
Fri Feb 18 14:51:53 EST 2011


Le vendredi 18 février 2011 15:53:45, Mateusz Loskot a écrit :
> On 18/02/11 14:25, Chaitanya kumar CH wrote:
> > Rashad,
> > 
> > Read the documentation on VSIInstallCurlFileHandler() in the cpl_vsi.h
> > file documentation.
> > http://www.gdal.org/cpl__vsi_8h.html
> 
> Nice features indeedb, but it does not guarantee "without
> downloading the whole file", does it? It depends on what part of
> file is being read, doesn't it?

With GDAL 1.8.0, you can try :

poDS = OGRSFDriverRegistrar::Open("
/vsicurl/http://mywebsite.com/shapefiles/myshape.shp", FALSE );

Yes /vsicurl is no magic. If there's a VSIFReadL() call that reads the whole 
file in a single gulp, then the whole file would be downloaded of course, but 
most GDAL/OGR drivers try to only read the minimum necessary at open time. In 
the case of the shapefile driver, it will read essentially only the header of 
the .shp, .shx and .dbf files

Extra bonus: you can combine /vsizip with /vsicurl. For example, try :

ogrinfo -ro -so -al --debug on 
/vsizip/vsicurl/http://www.aprsworld.net/gisdata/world/world.zip

Expected result :

VSICURL: GetFileSize(http://www.aprsworld.net/gisdata/world/world.zip)=3436277  
response_code=200
VSICURL: Downloading 3424256-3440639 
(http://www.aprsworld.net/gisdata/world/world.zip)...
VSICURL: Downloading 3407872-3424255 
(http://www.aprsworld.net/gisdata/world/world.zip)...
VSICURL: Downloading 3391488-3407871 
(http://www.aprsworld.net/gisdata/world/world.zip)...
VSICURL: Downloading 3375104-3391487 
(http://www.aprsworld.net/gisdata/world/world.zip)...
VSICURL: Downloading 3358720-3375103 
(http://www.aprsworld.net/gisdata/world/world.zip)...
VSICURL: Downloading 0-16383 
(http://www.aprsworld.net/gisdata/world/world.zip)...
VSICURL: Downloading 16384-81919 
(http://www.aprsworld.net/gisdata/world/world.zip)...
OGR: 
OGROpen(/vsizip/vsicurl/http://www.aprsworld.net/gisdata/world/world.zip/0x1f35830) 
succeeded as ESRI Shapefile.
INFO: Open of 
`/vsizip/vsicurl/http://www.aprsworld.net/gisdata/world/world.zip'
      using driver `ESRI Shapefile' successful.
OGR: GetLayerCount() = 1


Layer name: world
Geometry: Polygon
Feature Count: 244
Extent: (-180.000000, -89.900000) - (180.000000, 83.674733)
Layer SRS WKT:
(unknown)
NAME: String (40.0)
CAPITAL: String (64.0)
APPROX: Real (15.0)
AREA: Real (20.15)
SOURCETHM: String (16.0)



> 
> Best regards,


More information about the gdal-dev mailing list