locationtech / geotrellis

GeoTrellis is a geographic data processing engine for high performance applications.
http://geotrellis.io
Other
1.34k stars 360 forks source link

Add keyToGridBounds Method to MapKeyTransform #2785

Open jbouffard opened 6 years ago

jbouffard commented 6 years ago

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.

pomadchin commented 6 years ago

You can use the following instead of apply methods:

mt.extentToBounds(mt.keyToExtent(key))

However, probably it makes sense to add keyToBounds function.

lossyrob commented 6 years ago

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]

echeipesh commented 6 years ago

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.