/
package.scala
100 lines (77 loc) · 3.68 KB
/
package.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright 2016 Azavea
*
* 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.spark
import geotrellis.raster.io.geotiff.reader.GeoTiffReader
import geotrellis.spark.tiling.MapKeyTransform
import com.typesafe.config.Config
import scala.util.{Failure, Success, Try}
package object io
extends avro.codecs.Implicits
with json.Implicits {
implicit class ThreadConfig(config: Config) {
def getThreads(path: String): Int =
config.getString(path) match {
case "default" => Runtime.getRuntime.availableProcessors
case s => s.toInt
}
}
implicit class TryOption[T](option: Option[T]) {
def toTry(exception: => Throwable): Try[T] =
option match {
case Some(t) => Success(t)
case None => Failure(exception)
}
}
implicit class GeoTiffInfoMethods(that: GeoTiffReader.GeoTiffInfo) {
def mapTransform =
MapKeyTransform(
extent = that.extent,
layoutCols = that.segmentLayout.tileLayout.layoutCols,
layoutRows = that.segmentLayout.tileLayout.layoutRows)
}
// Custom exceptions
class LayerIOError(val message: String) extends Exception(message)
class LayerReadError(layerId: LayerId)
extends LayerIOError(s"LayerMetadata not found for layer $layerId")
class LayerExistsError(layerId: LayerId)
extends LayerIOError(s"Layer $layerId already exists in the catalog")
class LayerNotFoundError(layerId: LayerId)
extends LayerIOError(s"Layer $layerId not found in the catalog")
class InvalidLayerIdError(layerId: LayerId)
extends LayerIOError(s"Invalid layer name: $layerId")
class LayerWriteError(layerId: LayerId, message: String = "")
extends LayerIOError(s"Failed to write $layerId" + (if (message.nonEmpty) ": " + message else message))
class LayerUpdateError(layerId: LayerId, message: String = "")
extends LayerIOError(s"Failed to update $layerId $message" + (if (message.nonEmpty) ": " + message else message))
class LayerDeleteError(layerId: LayerId)
extends LayerIOError(s"Failed to delete $layerId")
class LayerReindexError(layerId: LayerId)
extends LayerIOError(s"Failed to reindex $layerId")
class LayerCopyError(from: LayerId, to: LayerId)
extends LayerIOError(s"Failed to copy $from to $to")
class LayerMoveError(from: LayerId, to: LayerId)
extends LayerIOError(s"Failed to move $from to $to")
class AttributeNotFoundError(attributeName: String, layerId: LayerId)
extends LayerIOError(s"Attribute $attributeName not found for layer $layerId")
class ValueNotFoundError(key: Any, layerId: LayerId)
extends LayerIOError(s"Value with key $key not found for layer $layerId")
class HeaderMatchError[T <: Product](layerId: LayerId, headerl: T, headerr: T)
extends LayerIOError(s"Layer $layerId Header data ($headerl) not matches ($headerr)")
class LayerOutOfKeyBoundsError(layerId: LayerId, bounds: KeyBounds[_])
extends LayerIOError(s"Updating rdd is out of the key index space for $layerId: $bounds. You must reindex this layer with large enough key bounds for this update.")
class LayerEmptyBoundsError(layerId: LayerId)
extends LayerIOError(s"Layer $layerId contains empty bounds; is this layer corrupt?")
}