0

Is there a way to extract/query latitude, longitude and elevation data from a tif file using RasterFrames (http://rasterframes.io/)?

Following the documentation, I did loadRF a tif file from the following site: https://visibleearth.nasa.gov/view.php?id=73934, however all I can see is generic information and don't know which RasterFunction to use in order to extract position and elevation or any other relevant information. I did try everything I can find in the API.

I did also try to extract temperature information using the following source as well: http://worldclim.org/version2

All I get is tile column with DoubleUserDefinedNoDataArrayTile and boundary (extend or crs).

RasterStack in R can extract this information according to this blog: https://www.benjaminbell.co.uk/2018/01/extracting-data-and-making-climate-maps.html

I need a more granular DataFrame such as lat,lon,temperature(or whatever data is embedded into the tif file).

Is this possible with RasterFrames or GeoTrellis?

metasim
  • 4,793
  • 3
  • 46
  • 70
Hako
  • 361
  • 1
  • 2
  • 9

2 Answers2

1

The long story short - yes, it is possible (at least with GeoTrellis). It is also possible with RasterFrames, I suppose, but will require some time to figure out how to extract this data. I can't answer more detailed since I need to know more about the dataset and about the pipeline you want to perform and apply.

DaunnC
  • 1,301
  • 15
  • 30
1

Currently you have to do it with a UDF and the relevant GeoTrellis method.

We have a ticket to implement as a first-class function, but in the meantime, this is the long form:

import org.apache.spark.sql._
import org.apache.spark.sql.functions._
import org.locationtech.rasterframes._
import org.locationtech.rasterframes.datasource.raster._
import org.locationtech.rasterframes.encoders.CatalystSerializer._
import geotrellis.raster._
import geotrellis.vector.Extent
import org.locationtech.jts.geom.Point

object ValueAtPoint extends App {

  implicit val spark = SparkSession.builder()
    .master("local[*]").appName("RasterFrames")
    .withKryoSerialization.getOrCreate().withRasterFrames
  spark.sparkContext.setLogLevel("ERROR")

  import spark.implicits._

  val example = "https://raw.githubusercontent.com/locationtech/rasterframes/develop/core/src/test/resources/LC08_B7_Memphis_COG.tiff"
  val rf = spark.read.raster.from(example).load()
  val point = st_makePoint(766770.000, 3883995.000)

  val rf_value_at_point = udf((extentEnc: Row, tile: Tile, point: Point) => {
    val extent = extentEnc.to[Extent]
    Raster(tile, extent).getDoubleValueAtPoint(point)
  })

  rf.where(st_intersects(rf_geometry($"proj_raster"), point))
    .select(rf_value_at_point(rf_extent($"proj_raster"), rf_tile($"proj_raster"), point) as "value")
    .show(false)

  spark.stop()
}
metasim
  • 4,793
  • 3
  • 46
  • 70