Skip to content

Some comments/suggestions concerning plotting and other funtionality (paletted geotiffs) #52

Description

@megies

I was trying out georasters today, specifically for plotting paletted geotiff files.

Here's a few comments, in no particular order.. i might not be able to help with PRs at this point, due to time restrictions and although because I'm not fully sure georasters will work for me (main blocker for me right now is lack of reprojection and deficiencies in downsampling, esp. with paletted data).
But I wanted to at least leave these comments to help with thoughts for improvements (compare gist linked at bottom).

1. Correct map extents

Most geotiffs I work with are in some metric coordinates and pixels are aligned rectangular in X and Y. Those plots should take into account map extent, which is trivial, extracted from data.geot. It's possible to manually do it and pass it in to data.plot(..., extent=..) but it could be done automatically. See gist.

2. Track transformation changes

Methods like .resize and .extract change the map extents (compare above). Derived georaster should have it's .geot attribute updated, otherwise it's not correct anymore (e.g. adjust the dx and dy on resize and adjust x/y boundaries when doing an extract)

3. Use paletted color map defined by geotiff

Some geotiffs use paletted colormaps and these won't plot correct with just a default divergent colormap. With gdal it's easy to extract paletted colors and create a matplotlib linear segmented colormap for the array plot (see gist).

4. Resize with paletted data

Calculating new pixel values from an array of old pixels might need some other measure to compute new pixel, like a mode measure for example.

5. self.shape should be a property

When modifying data.raster (e.g. in a multiband geotif getting rid of 3rd dimension in array by reducing to one band), self.shape breaks as it is not reflecting current state of the raster anymore. I think it should just return what self.raster.shape is currently saying.

6. Multiband files problems

Multiband files, like most interestingly 3-band RGB geotiffs, are not handled correctly right now. It only needs one line of numpy to plot them correctly, moving the band-axis to the rear. Above problems with cropping/resampling the data will apply as well, though and code might need some love to take third axis into account, I bet.
Gist for the Natural Earth RGB plot: https://gist.github.com/b1d03ec98cb54656644d95a8f7abffb8


Summary

  • plotting single band files, code should check if a color table is embedded (e.g. gdal.Open(filename).GetRasterBand(1).GetRasterColorTable()) and plot with a linear segmented custom colormap
  • plotting 3-band files, it might be good to plot it as RGB by default
  • extent should be set automatically on the matplotlib plot (that would also make it easier to plot into existing plots with correct map units)
  • cropping/resampling operations need to update data.geot
  • multi-band files (i.e. three dimensions in data array) should be handled correctly
  • self.shape should be read-only property linking to self.raster.shape I think, so that it doesn't get out of sync

For reference, here's my scripts I was playing around with..

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions