ARiisgaard / Thesis

0 stars 0 forks source link

Coloring raster in Bokeh #20

Open ARiisgaard opened 4 years ago

ARiisgaard commented 4 years ago

I have attempted to visualize my test raster file in Bokeh, however I have not succesfully loaded a colored file.

image

Only the nodata cases get visualised when I load the data in the same fasion, which Sarah originally did:

    src = gdal.Open('testRaster.tiff', gdal.GA_Update)
    band = src.GetRasterBand(1)
    imarray = np.array(band.ReadAsArray())
    output_file(r"testRaster.html")
    imarray = imarray[::-1]
    p = figure(x_range=(-180,180), y_range=(-60,85))
    p.image_rgba(image=[imarray], x=[-180], y=[-60], dw=[360], dh=[145],
    dilate=False)
    save(p)
    show(p)

I pressumed that the issue was similar to the mbtile issue (that values in the tiff goes beyond 255), so I tried using "gdaldem color-relief" to create a colored file, but I don't really know how to run the code above with multiple bands. I can do it using this approach, but that is treating the tiff like an image file, not a part of a map. Which might give some issues later on.

Another approach I attempted was using Rasterio, which do give a fine result, but these are not interactive. And I'm not sure if there is an easy approach to add them to a figure

crstn commented 4 years ago

Have you tried

band = src.GetRasterBand(0)

instead of

band = src.GetRasterBand(1)

?

crstn commented 4 years ago

I just came across GeoViews, might also be useful.

ARiisgaard commented 4 years ago

I just checked swapping the band - it returns 'NoneType' object has no attribute 'ReadAsArray'

Running "gdalinfo testRaster.tiff -mm" returns that the data in band 1 ranges from:

Band 1 Block=960x2 Type=Int32, ColorInterp=Gray Computed Min/Max=0.000,14663.000 NoData Value=-2147483648

There is no other bands in the file.

I'll check up on the GeoViews