Skip to content

Instantly share code, notes, and snippets.

@rgwozdz
Created July 27, 2017 15:32
Show Gist options
  • Select an option

  • Save rgwozdz/16d0dcc473b4b5de7029a90affbca40d to your computer and use it in GitHub Desktop.

Select an option

Save rgwozdz/16d0dcc473b4b5de7029a90affbca40d to your computer and use it in GitHub Desktop.
sketch of getting cell values from geotrellis
val crs_coord_1 = ???
val crs_coord_2 = ???
// you first want to create a Raster
// assuming your rdd is a single tile representing the whole image, i.e. rdd.count == 1
val first = rdd.take(1)
val projExtent = first(0)._1
val tile = first(0)._2
// rgwozdz: My rdd isn't a single tile. On ingest my layer is tiled
// across zooms 0 - 6. Should I be reading a particular zoom level?
// Since I have more than one tile, how should above be adjusted?
val raster = Raster(tile, projExtent.extent)
// rgwozdz: The line above fails, because projExtent is of type
// SpatialKey and apparently field "extent" does not exist
// Then, `Raster` will give you access to `RasterExtent`, which contains a function to convert crs coordinates to underlying grid (pixel) coordinates:
val rasterExtent = raster.rasterExtent
// Finally, you can get value at specific row/columns from your tile
val (col, row) = rasterExtent.mapToGrid(crs_coord_1, crs_coord_2)
val pixelValue = raster.tile.get(col, row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment