[gdal-dev] How to consider data types when implementing IWriteBlock

Even Rouault even.rouault at spatialys.com
Tue Apr 12 11:01:13 PDT 2016


Le mardi 12 avril 2016 17:10:41, jramm a écrit :
> Hi
> I am adding write support for the Northwood Grid (Vertical Mapper/MapInfo
> format) driver.
> This format only allows 32 bit float as the datatype, and to make things
> more tricky it actually stores this on disk as either 16 or 32 bit ints,
> using scaling rules.
> 
> The current read driver applies the scaling to each pixel when reading, to
> return a buffer of 32 bit floats and I look to do the reverse when writing.
> 
> When implementing `WriteBlock`, is it OK to assume that pImage will always
> be of the correct type? (float 32).

Yes. The generic implementation of GDALRasterBand::IRasterIO() in 
gcore/rasterio.cpp will do type translation so that the user provided buffer 
gets translated to the eDataType of the target band.

> I've noticed in debugging using
> gdal_translate that if I dont specify the output data type, it carries on
> and passes the source buffer (which is not float 32) to IWriteBlock of the
> destination.

That would be surprising given what I said above.

> 
> Given that only allowing 32bit floats is quite restrictive, should I:
> 
> - raise an error in the `Create` method if the data type isnt GDT_Float32

Yes, that's reasonable. A possibility if you want to be more tolerant would be 
to implement CreateCopy() and acquire the data of the input dataset as 
Float32. Very very rough pseudo code :

output = Create( Float32 )
for line in lines:
	input->RasterIO( GF_Read, line, Float32, buffer )
	output->RasterIO( GF_Write, line, Float32, buffer )
// recopy geotransform and projection as well if supported

Actually as this is really generic stuff mostly implemented in 
GDALDriver::DefaultCreateCopy(), it would be nice to have it accept an 
optional argument to force the output data type.

> - Attempt to handle all gdal data type in IWriteBlock by storing the user
> requested data type in some variable (poDS->eUserDataType) and then using
> GDALCopyWords within IWriteBlock to first copy pImage to a buffer of 32 bit
> floats before proceeding?

No, if you really wanted to support several input data types, you should set 
the user requested data type in the band eDataType, so that IRasterIO() can do 
proper data type conversion.

> 
> Thanks
> 
> 
> 
> 
> --
> View this message in context:
> http://osgeo-org.1560.x6.nabble.com/How-to-consider-data-types-when-implem
> enting-IWriteBlock-tp5260901.html Sent from the GDAL - Dev mailing list
> archive at Nabble.com.
> _______________________________________________
> 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