
geotrellis.spark.io.GenericLayerReindexer.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!
package geotrellis.spark.io
import geotrellis.spark._
import geotrellis.spark.io.avro._
import geotrellis.spark.io.index._
import geotrellis.spark.io.json._
import geotrellis.util._
import org.apache.avro._
import org.joda.time.DateTime
import spray.json._
import scala.reflect.ClassTag
abstract class GenericLayerReindexer[Header:JsonFormat](
attributeStore: AttributeStore,
layerReader: LayerReader[LayerId],
layerWriter: LayerWriter[LayerId],
layerDeleter: LayerDeleter[LayerId],
layerCopier: LayerCopier[LayerId]
) extends LayerReindexer[LayerId] {
def getTmpId(id: LayerId): LayerId
def reindex[
K: AvroRecordCodec: Boundable: JsonFormat: ClassTag,
V: AvroRecordCodec: ClassTag,
M: JsonFormat: GetComponent[?, Bounds[K]]
](id: LayerId, keyIndex: KeyIndex[K]): Unit = {
if (!attributeStore.layerExists(id)) throw new LayerNotFoundError(id)
val tmpId = getTmpId(id)
layerWriter.write(tmpId, layerReader.read[K, V, M](id), keyIndex)
layerDeleter.delete(id)
layerCopier.copy[K, V, M](tmpId, id)
layerDeleter.delete(tmpId)
}
def reindex[
K: AvroRecordCodec: Boundable: JsonFormat: ClassTag,
V: AvroRecordCodec: ClassTag,
M: JsonFormat: GetComponent[?, Bounds[K]]
](id: LayerId, keyIndexMethod: KeyIndexMethod[K]): Unit = {
if (!attributeStore.layerExists(id)) throw new LayerNotFoundError(id)
val tmpId = getTmpId(id)
val index = attributeStore.readKeyIndex[K](id)
layerWriter.write(tmpId, layerReader.read[K, V, M](id), keyIndexMethod.createIndex(index.keyBounds))
layerDeleter.delete(id)
layerCopier.copy[K, V, M](tmpId, id)
layerDeleter.delete(tmpId)
}
}
object GenericLayerReindexer {
def apply[Header: JsonFormat](
attributeStore: AttributeStore,
layerReader: LayerReader[LayerId],
layerWriter: LayerWriter[LayerId],
layerDeleter: LayerDeleter[LayerId],
layerCopier: LayerCopier[LayerId]
): LayerReindexer[LayerId] =
new GenericLayerReindexer[Header](attributeStore, layerReader, layerWriter, layerDeleter, layerCopier) {
def getTmpId(id: LayerId): LayerId = id.copy(name = s"${id.name}-${DateTime.now.getMillis}")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy