Last active
May 4, 2020 17:53
-
-
Save metasim/8b692afc8ee5da515f14f0c9e16ffd73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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).withTileDimensions(16, 16).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() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment