![]() ![]() In some cases this seems to make more sense than in others. ![]() Huh? Well, the first thing I learnt from the Python documentation is that for the = operator to return True the two objects aren’t always required to have the same type. > print(gdal_array.NumericTypeCodeToGDALTypeCode(my_data.dtype)) > print(gdal_array.NumericTypeCodeToGDALTypeCode(numpy.float32))īut it turns out that passing in the dtype attribute of a Numpy array doesn’t work: I found out that in the gdal_array module, there is a function called NumericTypeCodeToGDALTypeCode, which is supposed to translate a “numeric” type into a GDAL type code, for example: OK, it would be possible to guess - there aren’t that many of them - but shouldn’t there be a function? And that problem had me stumped for a moment. So what is needed is a general mapping from Numpy dtype objects to GDALDataType objects. If the final data is of a different type, 16-byte signed integers, say, or floating-point numbers, I could use one of the other GDAL data types.īut I’m writing a library and am therefore unlikely to know the data type beforehand. gdal.GDT_Byte refers to a code for GDAL’s Byte data type, that is, an 8-bit unsigned integer. But the problem arises on line 18, where the data type is passed to the Create() method. Thus far, there’s nothing difficult about it. Spatialreference = src_dataset.GetProjection()ĭst_dataset = driver.Create(, ncol, nrow, nband, gdal.GDT_Byte)ĭst_dataset.SetGeoTransform(geotransform)ĭst_dataset.SetProjection(spatialreference)ĭst_dataset.GetRasterBand(1).WriteArray(final_data) Geotransform = src_dataset.GetGeoTransform() # final_data is a 2-D Numpy array of the same dimensions as src_dataįinal_data = some_complicated_scientific_stuff(src_data, other_data. In the simplest case, if the data originates from another GeoTIFF file, has only one raster band, and we didn’t sub-set or re-scale it (geographically), we could do this : The details are described in the GDAL API tutorial and elsewhere on the web. Create a dataset object using GDAL’s “GTiff” driver, attach the spatial reference and geotransform, and write out the data. ![]() This, too, will be derived from the source data and whatever manipulations were subsequently carried out.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |