boku-ilen / geodot-plugin

Godot plugin for loading geospatial data
GNU General Public License v3.0
108 stars 18 forks source link

Add ability to modify Raster datasets #69

Closed kb173 closed 1 year ago

kb173 commented 1 year ago

We need methods like set_pixel(x, y, value) with x and y as projected coordinates.

How such changes should be propagated to users of that data needs to be considered - probably with signals, similarly to the Vector editing functionality. We must probably directly modify the actual data in order to ensure that the updated data is returned regardless of extent, resolution, etc.

kb173 commented 1 year ago

GDAL's RasterIO needs to be used for this: https://gdal.org/doxygen/classGDALRasterBand.html#a75d4af97b3436a4e79d9759eedf89af4

We identified 3 different use-cases which could be handled by separate Geodot functions:

  1. replace a specific pixel with a new value (for modifying land-use values in a small region)
  2. blend an image (with Alpha) into an existing region (for drawing into the orthophoto or placing pre-defined vegetation structures into the land-use)
  3. smoothly increase/decrease pixels around a given center point (for terraforming the terrain)

Although we could let the user deal with everything manually and simply allow them to replace a section of a dataset with a different (altered) Image, this seems prone to errors and to decaying the dataset e.g. due to wrong resolutions being read and written back into the data; it might also cause code duplication across projects.

So we'll add three different functions for the use-cases described above:

  1. simply write a 1x1 region with a specific value into the dataset with RasterIO (alternatively also expose a size so that squares of different pixel sizes can be written)
  2. read a section from the dataset, replace by the values from the new image (weighted by Alpha), write result back into the dataset
  3. read a section from the dataset, add/multiply its values according to the desired "brush" (e.g. add X weighted by distance to center), write result back into the dataset
kb173 commented 1 year ago

All done with cb6117c and c51420c. Opportunities for major performance improvements are documented in https://github.com/boku-ilen/geodot-plugin/issues/72.