[GRASS-dev] Adding hexagonal rasters to GRASS

Vaclav Petras wenzeslaus at gmail.com
Wed Jul 26 17:56:15 PDT 2017


On Mon, Jul 24, 2017 at 11:16 AM, Luí­s Moreira de Sousa <
luis.de.sousa at protonmail.ch> wrote:

> - In theory, all raster modules can function in exactly the same way with
> both square and hexagons if all geometric and neighbourhood
> methods/properties/functions are abstracted correctly.
>
> - The risk here is breaking the existing r. modules by implementing the
> raster abstraction. Perhaps some sort of transition may be devised to avoid
> it
>

> - On my side, the next step is to dive into the code and study how
> practical these ideas may be. But please put forward your ideas in any case.
>

For start, I suggest implementing some prototypes from stretch rather than
rewriting/adopting existing code. Probably a conversion or visualization
module makes sense so that we can see the results. I'm sure you have much
better about this than I since you already went through that before.

I suggest that the modules store the hexagon map (maybe a correct name in
GRASS?) in raster map with some metadata on the side. I would ignore the
problem that a raster map which (perhaps) does not make any sense (for
raster modules) is created. The metadata may be stored in just in the
current directory (in future, they would go to the GRASS database).

You would need to use functions to modify computational region inside the
module to be able to store it properly (e.g. r.in.lidar modifies the
computational region for itself when -e flag is used). Standard way of
doing this is in C, but Python works as well and may be much simpler
(either through PyGRASS or ctypes directly). Importantly, this can be done
without changing the library or existing modules, so you can do any
experiments you want (e.g. in GRASS Addons, GRASS Sandbox or on GitHub).

Talking just about how this prototype could be implemented, here is an
example of user interaction and the results (the names are not final,
r.hex.to.rast would probably become h.to.rast in the future):

GRASS > g.list rast m=.
a_raster

GRASS > r.info raster_1 -g
...
res=2
...

GRASS > g.region raster=raster_1

GRASS > r.to.hex input=raster_1 output=hexagons

GRASS > g.list rast m=.
raster_1
hexagons

GRASS > r.info hexagon
something very unexpected here for the user
number of cells and perhaps even extent does not fit

GRASS > r.hex.info
raster hexagon processed as hexagons
output about hexagonal grid
(information from the raster and metadata on the side combined)

GRASS > r.hex.waterflow input=hexagons output=hexagonal_flow

GRASS > g.list rast m=.
raster_1
hexagons
hexagonal_flow

GRASS > g.list.hex m=.
hexagons
hexagonal_flow

GRASS > g.region res=0.1  # note much lower resolution

GRASS > r.hex.to.rast input=hexagonal_flow output=raster_2

GRASS > d.rast raster_2
no we see the hexagons because we oversampled them
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20170726/b0a3fb2f/attachment.html>


More information about the grass-dev mailing list