[gdal-dev] OGRSFDriverRegistrar question

Frank Warmerdam warmerdam at pobox.com
Thu Feb 25 09:57:36 EST 2010


Alejandro Mostovoi wrote:
 > Hi All,
 >    How can make OGRSFDriverRegistrar::Open fails when trying to open an
 > ESRI Shapefile and the first parameter "/pszName" has extension
 > different to "shp"/?
 >
 > I know when extension is different to "shp", "dbf" and "shx" it fails,
 > but I need that also fails when extension is "dbf" or "shx".
 >
 > Any idea?

Alejandro,

You could modify OGRShapeDataSource::Open() in
gdal/ogr/ogrsf_frmts/shape/ogrshapedatasource.cpp so that is checks this.

change:

     if( VSI_ISREG(stat.st_mode) )
     {
         if( !OpenFile( pszNewName, bUpdate, bTestOpen ) )

to:

     if( VSI_ISREG(stat.st_mode) )
     {
         if( !EQUAL(CPLGetExtension(pszNewName),"shp")
             || !OpenFile( pszNewName, bUpdate, bTestOpen ) )

Best regards,

-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list