geotrellis icon indicating copy to clipboard operation
geotrellis copied to clipboard

Add keyToGridBounds Method to MapKeyTransform

Open jbouffard opened this issue 6 years ago • 3 comments

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 SpatialKeys 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.

jbouffard avatar Aug 07 '18 12:08 jbouffard

You can use the following instead of apply methods:

mt.extentToBounds(mt.keyToExtent(key))

However, probably it makes sense to add keyToBounds function.

pomadchin avatar Aug 07 '18 12:08 pomadchin

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]

lossyrob avatar Aug 07 '18 12:08 lossyrob

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.

echeipesh avatar Sep 13 '18 15:09 echeipesh