RasterFrames提取位置信息问题

时间:2019-07-06 11:24:09

标签: scala apache-spark tiff geotrellis

是否可以使用RasterFrames(http://rasterframes.io/)从tif文件中提取/查询纬度,经度和海拔数据?

根据文档,我从以下站点加载了一个tif文件:https://visibleearth.nasa.gov/view.php?id=73934,但是我所看到的只是一般信息,并且不知道使用哪个RasterFunction来提取位置和高程或任何其他内容。其他相关信息。我确实尝试了我可以在API中找到的所有内容。

我也尝试使用以下来源提取温度信息:http://worldclim.org/version2

我所得到的只是具有DoubleUserDefinedNoDataArrayTile和边界(扩展或crs)的图块列。

R中的RasterStack可以根据以下博客提取此信息:https://www.benjaminbell.co.uk/2018/01/extracting-data-and-making-climate-maps.html

我需要更细粒度的DataFrame,例如lat,lon,temperature(或将任何数据嵌入到tif文件中)。

RasterFrames或GeoTrellis是否可能?

2 个答案:

答案 0 :(得分:1)

长话短说-是的,这是可能的(至少对于GeoTrellis而言)。我想,使用RasterFrames也可以,但是需要一些时间才能弄清楚如何提取这些数据。由于需要了解有关数据集以及要执行和应用的管道的更多信息,所以我无法回答更详细的内容。

答案 1 :(得分:1)

目前您必须使用 UDF 和相关的 GeoTrellis 方法来完成。

我们有一张票要实现为一流的功能,但与此同时,这是一个长格式:

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()
}