geotrellis
geotrellis copied to clipboard
Add keyToGridBounds Method to MapKeyTransform
The current conversion from a SpatialKey
to GridBounds
is kinda awkward as it forces the user to use two apply
methods consecutively: mapTransform(mapTransform(key))
. This is because MapKeyTransform
lacks a direct conversion between SpatialKey
s and GridBounds
. Adding a keyToGridBounds
method to MapKeyTransform
will not only make things look nicer, but it'll also make the code easier to read and reason about.
You can use the following instead of apply methods:
mt.extentToBounds(mt.keyToExtent(key))
However, probably it makes sense to add keyToBounds
function.
Makes more sense to me to add a GridBounds.apply method that takes a SpatialKey. There is no information necessary from a LayoutDefinition or a MapKeyTransform to convert a SpatialKey to a GridBounds, it can be constructed just with the information of the SpatialKey.
I wold type this generally as GridBounds.apply [K: SpatialComponent]
Just to be explicit:
val key: SpatialKey = ???
val e: Extent = mt.keyToExtent(key) // Map Extent covered by the key
val gb: GridBounds = mt.extentToBounds(e) // Key bounds covered by extent
So there is much more direct way to get this answer:
GridBounds(colMin = key.col, rowMin = key.row, colMin = key.col, rowMin = key.row)
Whats really unfortunate is that we use GridBounds
to represent both bounds in tile space and pixel space which makes the above transformation pretty ambiguous since it could be either in this context.