[gdal-dev] Driver oddity
Even Rouault
even.rouault at spatialys.com
Sat Mar 7 05:25:54 PST 2015
Le samedi 07 mars 2015 14:09:28, Ari Jolma a écrit :
> The GDAL and OGR drivers are now basically the same but separate ones in
> Swig bindings, maybe it has something to do with this oddity.
>
> When I open GDAL driver "Memory", it does not advertise capability
> DCAP_RASTER
Yes, because it is the vector driver. It advertizes DCAP_VECTOR
> and CreateDataset silently fails.
Not sure what your Create/CreateDataset() maps into which GDAL call in the
Perl bindings, but what I can tell is that there's an emulation so that
GDALDriver::Create(hDrv, name, xsize, ysize, nBands, eDataType, options) maps
to OGRSFDriver::CreateDataSource(name, options) when it is an "old-style" OGR
driver and xsize = 0 and ysize = 0 and nBands = 0 and eDataType = GDT_Unknown
See:
$ python
>>> from osgeo import gdal
>>> ds = gdal.GetDriverByName('Memory').Create('', 0, 0, 0)
>>> ds.CreateLayer('foo')
<osgeo.ogr.Layer; proxy of <Swig Object of type 'OGRLayerShadow *' at
0x7f2c604586f0> >
>
> When I open GDAL driver "MEM", it advertises capability DCAP_RASTER and
> CreateDataset returns a valid object.
>
> When I open MEM driver and then Memory driver, both behave similarly.
Extremely weird. I cannt reproduce with Python. Isn't there some issue in the
perl bindings related to key hashing or something like that ?
even at even-desktop:~/gdal/svn/trunk/gdal$ python
Python 2.6.6 (r266:84292, Oct 29 2012, 23:09:05)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import gdal
>>> gdal.GetDriverByName('Memory').GetMetadata()
{'DMD_CREATIONFIELDDATATYPES': 'Integer Integer64 Real String Date DateTime
Time IntegerList Integer64List RealList StringList Binary', 'DMD_LONGNAME':
'Memory', 'DCAP_VECTOR': 'YES', 'OGR_DRIVER': 'YES', 'DCAP_OPEN': 'YES',
'DCAP_CREATE': 'YES'}
>>> gdal.GetDriverByName('Memory').GetMetadata()
{'DMD_CREATIONFIELDDATATYPES': 'Integer Integer64 Real String Date DateTime
Time IntegerList Integer64List RealList StringList Binary', 'DMD_LONGNAME':
'Memory', 'DCAP_VECTOR': 'YES', 'OGR_DRIVER': 'YES', 'DCAP_OPEN': 'YES',
'DCAP_CREATE': 'YES'}
>>>
even at even-desktop:~/gdal/svn/trunk/gdal$ python
Python 2.6.6 (r266:84292, Oct 29 2012, 23:09:05)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import gdal
>>> gdal.GetDriverByName('MEM').GetMetadata()
{'DMD_CREATIONOPTIONLIST': "<CreationOptionList> <Option name='INTERLEAVE'
type='string-select' default='BAND'> <Value>BAND</Value>
<Value>PIXEL</Value> </Option></CreationOptionList>", 'DMD_LONGNAME': 'In
Memory Raster', 'DMD_CREATIONDATATYPES': 'Byte Int16 UInt16 Int32 UInt32
Float32 Float64 CInt16 CInt32 CFloat32 CFloat64', 'DCAP_OPEN': 'YES',
'DCAP_RASTER': 'YES', 'DCAP_CREATE': 'YES'}
>>> gdal.GetDriverByName('Memory').GetMetadata()
{'DMD_CREATIONFIELDDATATYPES': 'Integer Integer64 Real String Date DateTime
Time IntegerList Integer64List RealList StringList Binary', 'DMD_LONGNAME':
'Memory', 'DCAP_VECTOR': 'YES', 'OGR_DRIVER': 'YES', 'DCAP_OPEN': 'YES',
'DCAP_CREATE': 'YES'}
>
> Both MEM and Memory are listed as GDAL drivers.
Yes, all drivers, new style or old style (i.e. still deriving from
OGRSFDriver), raster or vector, are seen as GDAL drivers.
>
> Cheers,
>
> Ari
>
> first run:
>
> perl x.pl Memory
> DCAP_CREATE => YES
> DCAP_OPEN => YES
> DCAP_VECTOR => YES
> DMD_CREATIONFIELDDATATYPES => Integer Integer64 Real String Date
> DateTime Time IntegerList Integer64List RealList StringList Binary
> DMD_LONGNAME => Memory
> OGR_DRIVER => YES
>
>
> DCAP_CREATE => YES
> DCAP_OPEN => YES
> DCAP_VECTOR => YES
> DMD_CREATIONFIELDDATATYPES => Integer Integer64 Real String Date
> DateTime Time IntegerList Integer64List RealList StringList Binary
> DMD_LONGNAME => Memory
> OGR_DRIVER => YES
>
> second run:
>
> perl x.pl MEM
> DCAP_CREATE => YES
> DCAP_OPEN => YES
> DCAP_RASTER => YES
> DMD_CREATIONDATATYPES => Byte Int16 UInt16 Int32 UInt32 Float32 Float64
> CInt16 CInt32 CFloat32 CFloat64
> DMD_CREATIONOPTIONLIST => <CreationOptionList> <Option
> name='INTERLEAVE' type='string-select' default='BAND'>
> <Value>BAND</Value> <Value>PIXEL</Value> </Option></CreationOptionList>
> DMD_LONGNAME => In Memory Raster
> Geo::GDAL::Dataset=HASH(0xd020a0)
>
> DCAP_CREATE => YES
> DCAP_OPEN => YES
> DCAP_RASTER => YES
> DMD_CREATIONDATATYPES => Byte Int16 UInt16 Int32 UInt32 Float32 Float64
> CInt16 CInt32 CFloat32 CFloat64
> DMD_CREATIONOPTIONLIST => <CreationOptionList> <Option
> name='INTERLEAVE' type='string-select' default='BAND'>
> <Value>BAND</Value> <Value>PIXEL</Value> </Option></CreationOptionList>
> DMD_LONGNAME => In Memory Raster
> Geo::GDAL::Dataset=HASH(0xd77df0)
>
> the program:
>
> use Geo::GDAL;
>
> $driver = shift @ARGV;
>
> $d = Geo::GDAL::Driver($driver);
> $m = $d->GetMetadata;
> for my $k (sort keys %$m) {
> print "$k => $m->{$k}\n";
> }
> $s = $d->Create();
> print $s,"\n";
>
> print "\n";
> $d = Geo::GDAL::Driver('Memory');
> $m = $d->GetMetadata;
> for my $k (sort keys %$m) {
> print "$k => $m->{$k}\n";
> }
> $s = $d->Create();
> print $s,"\n";
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list