/
SinglebandGeoTiff.scala
144 lines (115 loc) · 5.23 KB
/
SinglebandGeoTiff.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* 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.raster.io.geotiff
import geotrellis.util.ByteReader
import geotrellis.raster._
import geotrellis.raster.io.geotiff.reader.GeoTiffReader
import geotrellis.vector.Extent
import geotrellis.proj4.CRS
import geotrellis.raster.crop.Crop
import geotrellis.raster.resample.ResampleMethod
case class SinglebandGeoTiff(
tile: Tile,
extent: Extent,
crs: CRS,
tags: Tags,
options: GeoTiffOptions,
overviews: List[SinglebandGeoTiff] = Nil
) extends GeoTiff[Tile] {
val cellType = tile.cellType
def mapTile(f: Tile => Tile): SinglebandGeoTiff =
SinglebandGeoTiff(f(tile), extent, crs, tags, options, overviews)
def withStorageMethod(storageMethod: StorageMethod): SinglebandGeoTiff =
SinglebandGeoTiff(tile, extent, crs, tags, options.copy(storageMethod = storageMethod), overviews)
def imageData: GeoTiffImageData =
tile match {
case gtt: GeoTiffTile => gtt
case _ => tile.toGeoTiffTile(options)
}
def crop(subExtent: Extent, options: Crop.Options): SinglebandGeoTiff = {
val raster: Raster[Tile] =
this.raster.crop(subExtent, options)
SinglebandGeoTiff(raster, subExtent, this.crs, this.tags, this.options, this.overviews)
}
def crop(colMax: Int, rowMax: Int): SinglebandGeoTiff =
crop(0, 0, colMax, rowMax)
def crop(colMin: Int, rowMin: Int, colMax: Int, rowMax: Int): SinglebandGeoTiff = {
val raster: Raster[Tile] =
this.raster.crop(colMin, rowMin, colMax, rowMax)
SinglebandGeoTiff(raster, raster._2, this.crs, this.tags, this.options, this.overviews)
}
def crop(subExtent: Extent): SinglebandGeoTiff = crop(subExtent, Crop.Options.DEFAULT)
def crop(subExtent: Extent, cellSize: CellSize, resampleMethod: ResampleMethod, strategy: OverviewStrategy): SinglebandRaster =
getClosestOverview(cellSize, strategy)
.crop(subExtent, Crop.Options(clamp = false))
.resample(RasterExtent(subExtent, cellSize), resampleMethod, strategy)
def resample(rasterExtent: RasterExtent, resampleMethod: ResampleMethod, strategy: OverviewStrategy): SinglebandRaster =
getClosestOverview(cellSize, strategy)
.raster
.resample(rasterExtent, resampleMethod)
}
object SinglebandGeoTiff {
def apply(
tile: Tile,
extent: Extent,
crs: CRS
): SinglebandGeoTiff =
SinglebandGeoTiff(tile, extent, crs, Tags.empty, GeoTiffOptions.DEFAULT)
/** Read a single-band GeoTIFF file from a byte array.
* The GeoTIFF will be fully decompressed and held in memory.
*/
def apply(bytes: Array[Byte]): SinglebandGeoTiff =
GeoTiffReader.readSingleband(bytes)
/** Read a single-band GeoTIFF file from a byte array.
* If decompress = true, the GeoTIFF will be fully decompressed and held in memory.
*/
def apply(bytes: Array[Byte], decompress: Boolean, streaming: Boolean): SinglebandGeoTiff =
GeoTiffReader.readSingleband(bytes, decompress, streaming)
/** Read a single-band GeoTIFF file from the file at the given path.
* The GeoTIFF will be fully decompressed and held in memory.
*/
def apply(path: String): SinglebandGeoTiff =
GeoTiffReader.readSingleband(path)
def apply(path: String, e: Extent): SinglebandGeoTiff =
GeoTiffReader.readSingleband(path, e)
def apply(path: String, e: Option[Extent]): SinglebandGeoTiff =
GeoTiffReader.readSingleband(path, e)
/** Read a single-band GeoTIFF file from the file at the given path.
* If decompress = true, the GeoTIFF will be fully decompressed and held in memory.
*/
def apply(path: String, decompress: Boolean, streaming: Boolean): SinglebandGeoTiff =
GeoTiffReader.readSingleband(path, decompress, streaming)
def apply(byteReader: ByteReader): SinglebandGeoTiff =
GeoTiffReader.readSingleband(byteReader)
def apply(byteReader: ByteReader, e: Extent): SinglebandGeoTiff =
GeoTiffReader.readSingleband(byteReader, e)
def apply(byteReader: ByteReader, e: Option[Extent]): SinglebandGeoTiff =
GeoTiffReader.readSingleband(byteReader, e)
/** Read a single-band GeoTIFF file from the file at the given path.
* The tile data will remain tiled/striped and compressed in the TIFF format.
*/
def compressed(path: String): SinglebandGeoTiff =
GeoTiffReader.readSingleband(path, false, false)
/** Read a single-band GeoTIFF file from a byte array.
* The tile data will remain tiled/striped and compressed in the TIFF format.
*/
def compressed(bytes: Array[Byte]): SinglebandGeoTiff =
GeoTiffReader.readSingleband(bytes, false, false)
def streaming(path: String): SinglebandGeoTiff =
GeoTiffReader.readSingleband(path, false, true)
def streaming(byteReader: ByteReader): SinglebandGeoTiff =
GeoTiffReader.readSingleband(byteReader, false, true)
}