@@ -27,9 +27,10 @@ import geotrellis.raster.io.geotiff.reader.GeoTiffReader.GeoTiffInfo
2727import geotrellis .spark .{KeyBounds , SpatialKey , TileLayerMetadata }
2828import geotrellis .spark .tiling .LayoutDefinition
2929import geotrellis .util .ByteReader
30+ import geotrellis .vector .Extent
3031
3132/**
32- * Utility mix in for generating a tlm from GeoTiff headers.
33+ * Utility mix- in for generating a tlm from GeoTiff headers.
3334 *
3435 * @since 5/4/18
3536 */
@@ -49,23 +50,44 @@ trait GeoTiffInfoSupport {
4950
5051 def extractGeoTiffLayout (reader : ByteReader ): (GeoTiffReader .GeoTiffInfo , TileLayerMetadata [SpatialKey ]) = {
5152 val info : GeoTiffInfo = Shims .readGeoTiffInfo(reader, false , true )
53+ // Some notes on GeoTiffInfo properties:
54+ // * `info.extent` is the actual geotiff extent
55+ // * `info.segmentLayout.tileLayout` contains the internal, regularized gridding of a tiled GeoTIFF
56+ // * `info.segmentLayout.tileLayout.{totalCols|totalRows}` is the largest number of possible cells in the internal gridding
57+ // * `info.segmentLayout.{totalCols|totalRows}` are the real dimensions of the GeoTIFF. This is likely smaller than
58+ // the total size of `info.segmentLayout.tileLayout.{totalCols|totalRows}`
59+ // * `info.rasterExtent.{cellwidth|cellheight}` is the per-pixel spatial resolution
60+ // * `info.extent` and `info.rasterExtent.extent` are the same thing
61+
62+
5263 val tlm = {
53- val layout = if (! info.segmentLayout.isTiled) {
64+ val tileLayout = if (info.segmentLayout.isTiled) {
65+ info.segmentLayout.tileLayout
66+ }
67+ else {
5468 val width = info.segmentLayout.totalCols
5569 val height = info.segmentLayout.totalRows
5670 defaultLayout(width, height)
5771 }
58- else {
59- info.segmentLayout.tileLayout
60- }
6172 val extent = info.extent
6273 val crs = info.crs
6374 val cellType = info.cellType
6475 val bounds = KeyBounds (
6576 SpatialKey (0 , 0 ),
66- SpatialKey (layout.layoutCols - 1 , layout.layoutRows - 1 )
77+ SpatialKey (tileLayout.layoutCols - 1 , tileLayout.layoutRows - 1 )
78+ )
79+
80+ val layoutExtentWidth = tileLayout.totalCols * info.rasterExtent.cellwidth
81+ val layoutExtentHeight = tileLayout.totalRows * info.rasterExtent.cellheight
82+
83+ val layoutExtent = Extent (
84+ extent.xmin,
85+ extent.ymin,
86+ extent.xmin + layoutExtentWidth,
87+ extent.ymin + layoutExtentHeight
6788 )
68- TileLayerMetadata (cellType, LayoutDefinition (extent, layout), extent, crs, bounds)
89+
90+ TileLayerMetadata (cellType, LayoutDefinition (layoutExtent, tileLayout), extent, crs, bounds)
6991 }
7092
7193 (info, tlm)
0 commit comments