def import_glcf_tile(glcf_header, cell_num, tilefile):
glcfgrid = grids.GLCFGrid()
glcf_data = np.zeros((glcfgrid.cell_height, glcfgrid.cell_width, 1),
dtype=np.uint8)
with tempfile.NamedTemporaryFile() as f:
# uncompress
with gzip.open(tilefile, 'rb') as f_in, open(f.name, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gdal_ds = gdal.Open(f.name)
assert gdal_ds is not None, "Failed to open GDAL dataset"
band = gdal_ds.GetRasterBand(1)
nodata_val = band.GetNoDataValue()
print "NoData : ", nodata_val
glcf_data[:, :, 0] = band.ReadAsArray()
glcf_header.write_frac((cell_num, 0), glcf_data)
print 'Finished %d' % cell_num
return True
评论列表
文章目录