|
| 1 | +<!-- |
| 2 | + Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + or more contributor license agreements. See the NOTICE file |
| 4 | + distributed with this work for additional information |
| 5 | + regarding copyright ownership. The ASF licenses this file |
| 6 | + to you under the Apache License, Version 2.0 (the |
| 7 | + "License"); you may not use this file except in compliance |
| 8 | + with the License. You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, |
| 13 | + software distributed under the License is distributed on an |
| 14 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + KIND, either express or implied. See the License for the |
| 16 | + specific language governing permissions and limitations |
| 17 | + under the License. |
| 18 | + --> |
| 19 | + |
| 20 | +# GeoTiffInfo - GeoTIFF File Metadata |
| 21 | + |
| 22 | +GeoTiffInfo is a Spark data source that reads GeoTIFF file metadata without decoding pixel data, similar to [gdalinfo](https://gdal.org/en/stable/programs/gdalinfo.html). It returns one row per file with metadata including dimensions, coordinate system, band information, tiling, overviews, and compression. |
| 23 | + |
| 24 | +This is useful for: |
| 25 | + |
| 26 | +* Cataloging and inventorying large collections of raster files |
| 27 | +* Detecting Cloud Optimized GeoTIFFs (COGs) by checking tiling and overview status |
| 28 | +* Inspecting file properties before loading full raster data |
| 29 | +* Building spatial indexes over raster file collections |
| 30 | + |
| 31 | +## Read GeoTIFF metadata |
| 32 | + |
| 33 | +=== "Scala" |
| 34 | + |
| 35 | + ```scala |
| 36 | + val df = sedona.read.format("geotiffinfo").load("/path/to/rasters/") |
| 37 | + df.show() |
| 38 | + ``` |
| 39 | + |
| 40 | +=== "Java" |
| 41 | + |
| 42 | + ```java |
| 43 | + Dataset<Row> df = sedona.read().format("geotiffinfo").load("/path/to/rasters/"); |
| 44 | + df.show(); |
| 45 | + ``` |
| 46 | + |
| 47 | +=== "Python" |
| 48 | + |
| 49 | + ```python |
| 50 | + df = sedona.read.format("geotiffinfo").load("/path/to/rasters/") |
| 51 | + df.show() |
| 52 | + ``` |
| 53 | + |
| 54 | +You can also use glob patterns: |
| 55 | + |
| 56 | +```python |
| 57 | +df = sedona.read.format("geotiffinfo").load("/path/to/rasters/*.tif") |
| 58 | +``` |
| 59 | + |
| 60 | +Or load a single file: |
| 61 | + |
| 62 | +```python |
| 63 | +df = sedona.read.format("geotiffinfo").load("/path/to/image.tiff") |
| 64 | +``` |
| 65 | + |
| 66 | +## Output schema |
| 67 | + |
| 68 | +Each row represents one GeoTIFF file with the following columns: |
| 69 | + |
| 70 | +| Column | Type | Description | |
| 71 | +|--------|------|-------------| |
| 72 | +| `path` | String | File path | |
| 73 | +| `driver` | String | Format driver (`"GTiff"`) | |
| 74 | +| `fileSize` | Long | File size in bytes | |
| 75 | +| `width` | Int | Image width in pixels | |
| 76 | +| `height` | Int | Image height in pixels | |
| 77 | +| `numBands` | Int | Number of bands | |
| 78 | +| `srid` | Int | EPSG code (0 if unknown) | |
| 79 | +| `crs` | String | Coordinate Reference System as WKT | |
| 80 | +| `geoTransform` | Struct | Affine transform parameters | |
| 81 | +| `cornerCoordinates` | Struct | Bounding box | |
| 82 | +| `bands` | Array[Struct] | Per-band metadata | |
| 83 | +| `overviews` | Array[Struct] | Overview (pyramid) levels | |
| 84 | +| `metadata` | Map[String, String] | File-wide TIFF metadata tags | |
| 85 | +| `isTiled` | Boolean | Whether the file uses internal tiling | |
| 86 | +| `compression` | String | Compression type (e.g., `"LZW"`, `"Deflate"`) | |
| 87 | + |
| 88 | +### geoTransform struct |
| 89 | + |
| 90 | +| Field | Type | Description | |
| 91 | +|-------|------|-------------| |
| 92 | +| `upperLeftX` | Double | Origin X in world coordinates | |
| 93 | +| `upperLeftY` | Double | Origin Y in world coordinates | |
| 94 | +| `scaleX` | Double | Pixel size in X direction | |
| 95 | +| `scaleY` | Double | Pixel size in Y direction | |
| 96 | +| `skewX` | Double | Rotation/shear in X | |
| 97 | +| `skewY` | Double | Rotation/shear in Y | |
| 98 | + |
| 99 | +### cornerCoordinates struct |
| 100 | + |
| 101 | +| Field | Type | Description | |
| 102 | +|-------|------|-------------| |
| 103 | +| `minX` | Double | Minimum X (west) | |
| 104 | +| `minY` | Double | Minimum Y (south) | |
| 105 | +| `maxX` | Double | Maximum X (east) | |
| 106 | +| `maxY` | Double | Maximum Y (north) | |
| 107 | + |
| 108 | +### bands array element |
| 109 | + |
| 110 | +| Field | Type | Description | |
| 111 | +|-------|------|-------------| |
| 112 | +| `band` | Int | Band number (1-indexed) | |
| 113 | +| `dataType` | String | Data type (e.g., `"REAL_32BITS"`) | |
| 114 | +| `colorInterpretation` | String | Color interpretation (e.g., `"Gray"`, `"Red"`) | |
| 115 | +| `noDataValue` | Double | NoData value (null if not set) | |
| 116 | +| `blockWidth` | Int | Internal tile/block width | |
| 117 | +| `blockHeight` | Int | Internal tile/block height | |
| 118 | +| `description` | String | Band description | |
| 119 | +| `unit` | String | Unit type (e.g., `"meters"`) | |
| 120 | + |
| 121 | +### overviews array element |
| 122 | + |
| 123 | +| Field | Type | Description | |
| 124 | +|-------|------|-------------| |
| 125 | +| `level` | Int | Overview level (1, 2, 3, ...) | |
| 126 | +| `width` | Int | Overview width in pixels | |
| 127 | +| `height` | Int | Overview height in pixels | |
| 128 | + |
| 129 | +## Examples |
| 130 | + |
| 131 | +### Detect Cloud Optimized GeoTIFFs (COGs) |
| 132 | + |
| 133 | +A COG is a GeoTIFF that is internally tiled and has overview levels: |
| 134 | + |
| 135 | +```python |
| 136 | +df = sedona.read.format("geotiffinfo").load("/path/to/rasters/") |
| 137 | +cogs = df.filter("isTiled AND size(overviews) > 0") |
| 138 | +cogs.select("path", "compression", "overviews").show(truncate=False) |
| 139 | +``` |
| 140 | + |
| 141 | +### Inspect band information |
| 142 | + |
| 143 | +```python |
| 144 | +df = sedona.read.format("geotiffinfo").load("/path/to/image.tif") |
| 145 | +df.selectExpr("path", "explode(bands) as band").selectExpr( |
| 146 | + "path", |
| 147 | + "band.band", |
| 148 | + "band.dataType", |
| 149 | + "band.noDataValue", |
| 150 | + "band.blockWidth", |
| 151 | + "band.blockHeight", |
| 152 | +).show() |
| 153 | +``` |
| 154 | + |
| 155 | +### Filter by spatial extent |
| 156 | + |
| 157 | +```python |
| 158 | +df = sedona.read.format("geotiffinfo").load("/path/to/rasters/") |
| 159 | +df.filter("cornerCoordinates.minX > -120 AND cornerCoordinates.maxX < -100").select( |
| 160 | + "path", "width", "height", "srid" |
| 161 | +).show() |
| 162 | +``` |
| 163 | + |
| 164 | +### Get overview details |
| 165 | + |
| 166 | +```python |
| 167 | +df = sedona.read.format("geotiffinfo").load("/path/to/image.tif") |
| 168 | +df.selectExpr("path", "explode(overviews) as ovr").selectExpr( |
| 169 | + "path", "ovr.level", "ovr.width", "ovr.height" |
| 170 | +).show() |
| 171 | +``` |
| 172 | + |
| 173 | +### Select specific columns |
| 174 | + |
| 175 | +Select only the columns you need: |
| 176 | + |
| 177 | +```python |
| 178 | +df = ( |
| 179 | + sedona.read.format("geotiffinfo") |
| 180 | + .load("/path/to/rasters/") |
| 181 | + .select("path", "width", "height", "numBands") |
| 182 | +) |
| 183 | +df.show() |
| 184 | +``` |
0 commit comments