[gdal-dev] Fail to open DBF without SHAPE_RESTORE_SHX options

Even Rouault even.rouault at spatialys.com
Wed May 15 05:20:14 PDT 2019


Vincent,

> Hello,
> 
> This mail is related to https://github.com/OSGeo/gdal/issues/1525
> 
> Quick recall :
> 
> We try to open DBF file using shapefile driver, but in our dataset we have
> empty SHP & SHX files (provided by customers, so we can't remove it). To be
> able to open it, we use the SHAPE_RESTORE_SHX option to bypass shp reading.
> 
> This option usage sounds to be a bit dirty workaround, especially when there
> are a parameter bForceSingleFileDataSource   on OGRShapeDataSource::Open()
> method.

Yes, a bit confusing. It means that you have a single layer dataset instead of 
opening a directory of several shapefiles.

> 
> https://github.com/OSGeo/gdal/blob/0d7d762895f268d0c3ddaed5ddac3605c727e501/
> gdal/ogr/ogrsf_frmts/shape/ogrshapedatasource.cpp#L150
> 
> Maybe an open option could help us to deal with this case ?
> (FORCE_SINGLE_FILE_DATA_SOURCE)

This is a super particular use case to have 0-byte large .shp & .shx files 
alongside a valid .dbf. Not sure we really want to support this, and I guess 
other implementations would probably not like such datasets.

Another possibility is that you copy the .dbf file in a temporary directory 
and open it. Or if you don't want to create a temporary file on the regular 
filesystem, you could ingest it into RAM in a /vsimem/temp.dbf file and open 
that one. You can use VSIIngestFile() for that.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list