
geotrellis.spark.package.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geotrellis-spark_2.11 Show documentation
Show all versions of geotrellis-spark_2.11 Show documentation
GeoTrellis is an open source geographic data processing engine for high performance applications.
The newest version!
/*
* Copyright (c) 2014 DigitalGlobe.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package geotrellis
import geotrellis.raster._
import geotrellis.vector._
import geotrellis.proj4._
import geotrellis.util._
import geotrellis.spark.tiling._
import geotrellis.spark.ingest._
import geotrellis.spark.crop._
import geotrellis.spark.filter._
import org.apache.spark.Partitioner
import org.apache.spark.rdd._
import spire.syntax.cfor._
import monocle._
import monocle.syntax._
import scala.reflect.ClassTag
import scalaz.Functor
package object spark
extends buffer.Implicits
with crop.Implicits
with filter.Implicits
with join.Implicits
with mapalgebra.Implicits
with mapalgebra.local.Implicits
with mapalgebra.local.temporal.Implicits
with mapalgebra.focal.Implicits
with mapalgebra.focal.hillshade.Implicits
with mapalgebra.zonal.Implicits
with mask.Implicits
with merge.Implicits
with partition.Implicits
with resample.Implicits
with reproject.Implicits
with split.Implicits
with stitch.Implicits
with summary.polygonal.Implicits
with summary.Implicits
with tiling.Implicits {
type TileLayerRDD[K] = RDD[(K, Tile)] with Metadata[TileLayerMetadata[K]]
object TileLayerRDD {
def apply[K](rdd: RDD[(K, Tile)], metadata: TileLayerMetadata[K]): TileLayerRDD[K] =
new ContextRDD(rdd, metadata)
}
type MultibandTileLayerRDD[K] = RDD[(K, MultibandTile)] with Metadata[TileLayerMetadata[K]]
object MultibandTileLayerRDD {
def apply[K](rdd: RDD[(K, MultibandTile)], metadata: TileLayerMetadata[K]): MultibandTileLayerRDD[K] =
new ContextRDD(rdd, metadata)
}
type TileBounds = GridBounds
type SpatialComponent[K] = Component[K, SpatialKey]
type TemporalComponent[K] = Component[K, TemporalKey]
/** Auto wrap a partitioner when something is requestion an Option[Partitioner];
* useful for Options that take an Option[Partitioner]
*/
implicit def partitionerToOption(partitioner: Partitioner): Option[Partitioner] =
Some(partitioner)
implicit class WithContextWrapper[K, V, M](val rdd: RDD[(K, V)] with Metadata[M]) {
def withContext[K2, V2](f: RDD[(K, V)] => RDD[(K2, V2)]) =
new ContextRDD(f(rdd), rdd.metadata)
def mapContext[M2](f: M => M2) =
new ContextRDD(rdd, f(rdd.metadata))
}
implicit def tupleToRDDWithMetadata[K, V, M](tup: (RDD[(K, V)], M)): RDD[(K, V)] with Metadata[M] =
ContextRDD(tup._1, tup._2)
implicit class withContextRDDMethods[K: ClassTag, V: ClassTag, M](rdd: RDD[(K, V)] with Metadata[M])
extends ContextRDDMethods[K, V, M](rdd)
implicit class withTileLayerRDDMethods[K: SpatialComponent: ClassTag](val self: TileLayerRDD[K])
extends TileLayerRDDMethods[K]
implicit class withMultibandTileLayerRDDMethods[K: SpatialComponent: ClassTag](val self: MultibandTileLayerRDD[K])
extends MultibandTileLayerRDDMethods[K]
implicit class withCellGridLayoutRDDMethods[K: SpatialComponent: ClassTag, V <: CellGrid, M: GetComponent[?, LayoutDefinition]](val self: RDD[(K, V)] with Metadata[M])
extends CellGridLayoutRDDMethods[K, V, M]
implicit class withProjectedExtentRDDMethods[K: Component[?, ProjectedExtent], V <: CellGrid](val rdd: RDD[(K, V)]) {
def toRasters: RDD[(K, Raster[V])] =
rdd.mapPartitions({ partition =>
partition.map { case (key, value) =>
(key, Raster(value, key.getComponent[ProjectedExtent].extent))
}
}, preservesPartitioning = true)
}
implicit class withProjectedExtentTemporalTilerKeyMethods[K: Component[?, ProjectedExtent]: Component[?, TemporalKey]](val self: K) extends TilerKeyMethods[K, SpaceTimeKey] {
def extent = self.getComponent[ProjectedExtent].extent
def translate(spatialKey: SpatialKey): SpaceTimeKey = SpaceTimeKey(spatialKey, self.getComponent[TemporalKey])
}
implicit class withProjectedExtentTilerKeyMethods[K: Component[?, ProjectedExtent]](val self: K) extends TilerKeyMethods[K, SpatialKey] {
def extent = self.getComponent[ProjectedExtent].extent
def translate(spatialKey: SpatialKey) = spatialKey
}
implicit class withCollectMetadataMethods[K1, V <: CellGrid](rdd: RDD[(K1, V)]) extends Serializable {
def collectMetadata[K2: Boundable: SpatialComponent](crs: CRS, layoutScheme: LayoutScheme)
(implicit ev: K1 => TilerKeyMethods[K1, K2]): (Int, TileLayerMetadata[K2]) = {
TileLayerMetadata.fromRdd[K1, V, K2](rdd, crs, layoutScheme)
}
def collectMetadata[K2: Boundable: SpatialComponent](crs: CRS, layout: LayoutDefinition)
(implicit ev: K1 => TilerKeyMethods[K1, K2]): TileLayerMetadata[K2] = {
TileLayerMetadata.fromRdd[K1, V, K2](rdd, crs, layout)
}
def collectMetadata[K2: Boundable: SpatialComponent](layoutScheme: LayoutScheme)
(implicit ev: K1 => TilerKeyMethods[K1, K2], ev1: GetComponent[K1, ProjectedExtent]): (Int, TileLayerMetadata[K2]) = {
TileLayerMetadata.fromRdd[K1, V, K2](rdd, layoutScheme)
}
def collectMetadata[K2: Boundable: SpatialComponent](layout: LayoutDefinition)
(implicit ev: K1 => TilerKeyMethods[K1, K2], ev1: GetComponent[K1, ProjectedExtent]): TileLayerMetadata[K2] = {
TileLayerMetadata.fromRdd[K1, V, K2](rdd, layout)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy