Zoe commited on
Commit
e35c61e
·
verified ·
1 Parent(s): b976f27

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +421 -114
README.md CHANGED
@@ -1,151 +1,458 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
- pretty_name: "GS-QA2: Question Answering over Raster–Vector Geospatial Data"
3
- license: odbl
4
- language:
5
- - en
6
- task_categories:
7
- - question-answering
8
- - text-generation
9
- tags:
10
- - geospatial
11
- - gis
12
- - spatial-reasoning
13
- - text-to-sql
14
- - openstreetmap
15
- - digital-elevation-model
16
- - raster
17
- - vector
18
- - benchmark
19
- - postgis
20
- size_categories:
21
- - 1K<n<10K
22
- configs:
23
- - config_name: vector
24
- data_files:
25
- - split: test
26
- path: data/vector-*.parquet
27
- - config_name: raster_only
28
- default: true
29
- data_files:
30
- - split: test
31
- path: data/raster_only.jsonl
32
- - config_name: raster_vector
33
- data_files:
34
- - split: test
35
- path: data/raster_vector.jsonl
36
- - config_name: extended
37
- data_files:
38
- - split: test
39
- path: data/extended.jsonl
40
  ---
41
 
42
- # GS-QA2: A Benchmark for Question Answering over Raster–Vector Data
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- GS-QA2 is a benchmark for **geospatial question answering over both vector and raster data**. It extends [GS-QA](https://arxiv.org/abs/2605.22811) — a vector-only benchmark built on OpenStreetMap features in a PostGIS database — with a U.S. Digital Elevation Model (DEM) raster layer and 25 new question templates that require terrain reasoning: elevation lookups, slope, aspect, ruggedness, and questions that combine vector filtering with raster analysis.
45
-
46
- Each record pairs a natural-language question with an **executable PostGIS SQL query** and its **ground-truth answer**, so every question is verifiable without manual annotation. This release contains the complete benchmark: the **2,800 vector-only pairs** (V1–V28, 100 per template) inherited from [GS-QA](https://arxiv.org/abs/2605.22811) by Saeedan, Rashid, Eldawy, and Hristidis, plus the **500 raster-related pairs** (25 templates × 20 questions) that GS-QA2 adds — **3,300 questions in total**.
47
 
48
- Code, ingestion scripts, generation pipeline, and baseline implementations live in the companion repository: **https://github.com/ZhuochengShang/QARV**
49
 
50
- ## Why this benchmark
51
 
52
- Existing geospatial QA benchmarks evaluate vector data only (points, lines, polygons), while vision-oriented raster benchmarks target perception over imagery rather than structured reasoning over raster values. GS-QA2 fills the gap: it measures whether LLM-based systems (Text2SQL, RAG, multi-stage SQL agents, code-writing GIS agents) can reason over continuous terrain surfaces and their interaction with discrete vector features. In the paper's evaluation, systems answered simple point-elevation queries reasonably well but accuracy dropped sharply on terrain derivatives (slope, aspect) and combined raster–vector operations — zonal and global raster operations collapsed to near zero for every baseline.
 
 
 
 
53
 
54
- ## Dataset structure
55
 
56
- Four configurations, mirroring the paper's template groups of increasing raster-reasoning complexity:
57
 
58
- | Config | Templates | Records | Description |
59
- |---|---|---|---|
60
- | `vector` | V1–V28 | 2,800 | Vector-only questions from the original GS-QA benchmark — range, nearest-neighbor, direction, towards, and intersects queries over OSM features, with entity-name, location, direction, count, distance, area, and length answers |
61
- | `raster_only` | R1–R11 | 220 | Direct DEM queries — elevation, slope, aspect, ruggedness, elevation thresholds — anchored at POIs and roads |
62
- | `raster_vector` | VR9–VR14 | 120 | New raster–vector templates requiring tight interaction: zonal aggregation, comparison, and ranking of POIs by terrain properties |
63
- | `extended` | VR1–VR8 | 160 | Standard vector queries augmented with a terrain condition or terrain output (e.g., range queries with elevation filters) |
64
 
65
- All 3,300 questions form a single evaluation set, published as the `test` split of each config. The `vector` config is stored as zstd-compressed Parquet (its ground-truth answer lists are large); the three raster configs are plain JSONL. Questions were instantiated from templates by sampling real geographic entities (POIs, roads, parks, regions across the contiguous United States), executing the paired SQL against the reference PostGIS database (OSM + 30 m DEM, 265,950 raster tiles), and retaining only questions with valid, non-empty ground truth.
 
 
 
66
 
67
- ### Data fields
 
 
 
68
 
69
- | Field | Type | Description |
70
- |---|---|---|
71
- | `id` | string | Unique ID: `{group}/{template}/{index}` |
72
- | `template_id` | string | Paper template ID: `V1`–`V28` (vector), `R1`–`R11` (raster-only), `VR1`–`VR8` (extended), `VR9`–`VR14` (raster–vector) |
73
- | `group` | string | `vector`, `raster_only`, `raster_vector`, or `extended` |
74
- | `template` | string | Template file name, e.g. `elevation+poi`, `slope+route`, `range+name+elevation_condition` |
75
- | `question` | string | Natural-language question |
76
- | `sql` | string | Executable PostGIS SQL query that produces the ground truth |
77
- | `answer_type` | string | Expected output type, e.g. `elevation - point based`, `slope`, `entity name` |
78
- | `answers` | string (JSON) | Ground-truth answer rows as a JSON-encoded list of objects. Keys vary by template (`elevation`, `slope_degrees`, `poi_name`, `distance_m`, …), so the list is serialized as a JSON string — parse with `json.loads` |
79
- | `question_entities` | string (JSON) | JSON-encoded metadata for the entities used to instantiate the template: display name, category, WKT geometry, and full OSM attributes |
80
 
81
- The untouched original template files (one JSONL per template, grouped by folder) are preserved under `raw/qa2/` for provenance. `raw/qa2/` additionally contains 9 exploratory templates (180 QA pairs — regional/area elevation and slope aggregates and an elevation-count template) that were generated during benchmark construction but are not part of the canonical 500-question evaluation set exposed in the configs above.
82
 
83
- ### Example record (`raster_only`, template `elevation+poi`)
 
84
 
85
- ```json
86
- {
87
- "question": "What is the elevation at Cousins Subs, Chicago, IL?",
88
- "sql": "SELECT ST_Value(rast, 1, ST_GeomFromText('POINT (-87.631702 41.88228)',4326)) AS elevation FROM public.dem_us WHERE ST_Intersects(rast, ST_GeomFromText('POINT (-87.631702 41.88228)',4326)) LIMIT 1;",
89
- "answers": [{"elevation": 286.0}],
90
- "answer_type": "elevation - point based"
91
- }
92
  ```
93
 
94
- ## Usage
 
 
95
 
96
- ```python
97
- import json
98
- from datasets import load_dataset
99
 
100
- ds = load_dataset("Zoe/GS-QA2", "raster_only", split="test")
101
 
102
- example = ds[0]
103
- print(example["question"])
104
- print(example["sql"])
105
- answers = json.loads(example["answers"]) # list of ground-truth rows
106
- entities = json.loads(example["question_entities"])
107
  ```
108
 
109
- To *execute* the SQL and reproduce ground truths or run the baselines, you need the reference PostGIS database (OSM vector tables + DEM raster tiles). Raw OSM extracts, DEM files, and database dumps are not included here — see the ingestion instructions in the [QARV repository](https://github.com/ZhuochengShang/QARV) (`GS-QA/ingestion/`).
 
 
110
 
111
- ## Evaluation
112
 
113
- Answers are scored per output type, following the paper (Tables 9–10): token-level F1 ≥ 0.8 for entity names, geodesic distance error ≤ 5 m for locations, circular angular error ≤ 5° for directions and aspect, absolute error ≤ 10 m for elevations, ≤ 5° for slope, and relative error ≤ 0.05 for areas, lengths, distances, and counts. Compound outputs are correct only when every component passes. Evaluation scripts are in `GS-QA/baselines/evaluation/` of the companion repository.
 
 
 
 
 
 
 
114
 
115
- ## Benchmark construction
116
 
117
- 1. **Template selection** 25 raster-related templates organized by Tomlin's map-algebra operation types (local, focal, zonal, global) plus spatial predicates (range, nearest neighbor, intersects, …).
118
- 2. **Parameter sampling** — placeholders (`[ANCH_POI]`, `[DISTANCE]`, `[ELEV_COND]`, …) filled with real entities and values sampled from the database.
119
- 3. **NL generation** — natural-language phrasing with grammar correction; duplicates removed via canonicalized SQL comparison.
120
- 4. **Ground-truth execution** — each paired SQL runs against the PostGIS reference database (120 s timeout); empty/invalid results are discarded and regenerated. 20 questions are kept per template.
121
 
122
- ## Source data and licensing
 
 
 
 
 
123
 
124
- - **Vector features:** © [OpenStreetMap](https://www.openstreetmap.org/copyright) contributors, available under the [Open Database License (ODbL)](https://opendatacommons.org/licenses/odbl/). Question text, entity metadata, and ground-truth answers are derived from OSM data, so this dataset is shared under ODbL.
125
- - **Terrain:** elevation values derive from the [Copernicus DEM](https://doi.org/10.5270/ESA-c5d3d65) (© ESA), 30 m resolution over the contiguous United States.
126
 
127
- ## Citation
128
 
129
- If you use the `vector` config (V1–V28), please also cite the original GS-QA benchmark:
130
 
131
- ```bibtex
132
- @article{saeedan2026gsqa,
133
- title = {GS-QA: A Benchmark for Geospatial Question Answering},
134
- author = {Saeedan, Majid and Shihab Rashid, Muhammad and Eldawy, Ahmed and Hristidis, Vagelis},
135
- journal = {arXiv preprint arXiv:2605.22811},
136
- year = {2026}
137
- }
138
  ```
139
 
140
- ```bibtex
141
- @inproceedings{shang2026gsqa2,
142
- title = {GS-QA2: A Benchmark for Question Answering over Raster--Vector Data},
143
- author = {Shang, Zhuocheng and Elmahallawy, Shahd and Al Nazi, Zabir and Hristidis, Vagelis and Eldawy, Ahmed},
144
- year = {2026},
145
- note = {Benchmark and code: https://github.com/ZhuochengShang/QARV}
146
- }
 
 
 
 
 
 
 
 
147
  ```
148
 
149
- ## Contact
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
- Zhuocheng Shang zshan011@ucr.edu University of California, Riverside
 
 
 
1
+ # Raster Processing with RDPro (GDAL / rasterio–style)
2
+
3
+ Raster data is one of the most common formats for geospatial analysis.
4
+ In libraries such as **GDAL** and **rasterio**, raster datasets are treated as
5
+ **multidimensional grids (images)** with spatial metadata such as coordinate
6
+ reference systems (CRS), resolution, and geographic extent.
7
+
8
+ **RDPro (Raster Distributed Processor)** follows the same conceptual model as
9
+ GDAL and rasterio, but executes raster operations **in parallel on Apache Spark**.
10
+ If you are familiar with GDAL or rasterio, you can think of RDPro as providing
11
+ the same raster operations—opening datasets, raster math, reprojection,
12
+ resampling, stacking, and writing outputs—at distributed scale.
13
+
14
+ This page describes the basic raster processing functionality provided by RDPro
15
+ in Beast.
16
+
17
+ ---
18
+
19
+ ## Setup
20
+
21
+ Before using RDPro, follow the [setup page](dev-setup.md) to configure your
22
+ project for Beast.
23
+
24
+ In Scala, import Beast features:
25
+
26
+ ```scala
27
+ import edu.ucr.cs.bdlab.beast._
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Raster Data Model (GDAL-style concepts)
33
+
34
+ RDPro explicitly models the same spatial concepts used implicitly in GDAL and
35
+ rasterio.
36
+
37
+ ### Grid space (pixel coordinates)
38
+
39
+ A raster is represented as a **2D pixel grid**:
40
+
41
+ - Width **W** (columns)
42
+ - Height **H** (rows)
43
+ - Origin **(0, 0)** at the **top-left corner**
44
+
45
+ Pixel coordinates are represented as `(i, j)` where `i` is the column index and
46
+ `j` is the row index. These coordinates are independent of geography, just like
47
+ array indexing in NumPy or rasterio.
48
+
49
+ ---
50
+
51
+ ### Raster tiles (distributed blocks)
52
+
53
+ For distributed processing, the raster grid is divided into **tiles**:
54
+
55
+ - Each tile has dimensions `(tileWidth × tileHeight)`
56
+ - Edge tiles may be smaller
57
+ - Each tile has a unique **tile ID**
58
+
59
+ This is analogous to block/window processing in GDAL, but exposed explicitly to
60
+ enable parallel execution.
61
+
62
+ ---
63
+
64
+ ### World space (geographic coordinates)
65
+
66
+ World space represents a rectangular geographic region on the Earth’s surface
67
+ defined by four coordinates:
68
+
69
+ ```
70
+ [x1, x2) × [y1, y2)
71
+ ```
72
+
73
+ Coordinates are expressed in the raster’s CRS, exactly as in GDAL datasets.
74
+
75
+ ---
76
+
77
+ ### Grid ↔ World transformations
78
+
79
+ - **Grid → World (G2W)**: affine transform from pixel coordinates to geographic
80
+ coordinates
81
+ - **World → Grid (W2G)**: inverse transform from geographic coordinates to pixel
82
+ indices
83
+
84
+ These correspond directly to GDAL’s geotransform and inverse geotransform.
85
+
86
+ ---
87
+
88
+ ## RDPro Data Abstractions
89
+
90
+ ### `ITile[T]` — atomic raster unit
91
+
92
+ An `ITile[T]` represents a single raster tile and is the smallest unit of
93
+ processing in RDPro.
94
+
95
+ ```scala
96
+ @tparam T Pixel value type
97
+ @param tileID Tile identifier
98
+ @param rasterMetadata Spatial metadata
99
+ @param rasterFeature Optional auxiliary attributes (e.g., filename, time)
100
+ ```
101
+
102
+ ---
103
+
104
+ ### `RasterMetadata` — dataset-level metadata
105
+
106
+ `RasterMetadata` holds the same information as a GDAL dataset’s spatial metadata:
107
+
108
+ ```scala
109
+ @param x1, y1, x2, y2 Geographic extent
110
+ @param tileWidth Tile width (pixels)
111
+ @param tileHeight Tile height (pixels)
112
+ @param srid CRS (e.g., EPSG:4326)
113
+ @param g2m Grid-to-world affine transform
114
+ ```
115
+
116
+ ---
117
+
118
+ ### `RasterRDD[T]`
119
+
120
+ `RasterRDD[T]` is an alias for `RDD[ITile[T]]` and represents a **distributed
121
+ raster dataset**, analogous to a GDAL or rasterio dataset, but partitioned across
122
+ Spark.
123
+
124
+ All examples below assume an initialized `SparkContext` named `sc`.
125
+
126
+ ---
127
+
128
+ ## Opening Raster Datasets (GeoTIFF / HDF)
129
+
130
+ In GDAL or rasterio, raster processing starts by **opening a dataset from disk**.
131
+ RDPro follows the same idea, except datasets are loaded as distributed
132
+ collections.
133
+
134
+ ```scala
135
+ // Load a GeoTIFF
136
+ val raster: RasterRDD[Int] = sc.geoTiff("glc2000_v1_1.tif")
137
+
138
+ // Load an HDF subdataset (similar to GDAL subdatasets)
139
+ val temperatureK: RasterRDD[Float] =
140
+ sc.hdfFile(
141
+ "MOD11A1.A2022173.h08v05.006.2022174092443.hdf",
142
+ "LST_Day_1km"
143
+ )
144
+ ```
145
+
146
+ The input can be a single file or a directory containing many files; in both
147
+ cases, the data are loaded into a single `RasterRDD`.
148
+
149
+ ---
150
+
151
+ ### Determining pixel data types
152
+
153
+ Similar to inspecting `dataset.dtypes` in rasterio, RDPro allows you to inspect
154
+ pixel types:
155
+
156
+ ```scala
157
+ val raster = sc.geoTiff("glc2000_v1_1.tif")
158
+ println(raster.first.pixelType)
159
+ ```
160
+
161
+ Example output:
162
+ ```
163
+ IntegerType
164
+ ```
165
+
166
+ Supported types:
167
+
168
+ | Pixel type | Loading statement |
169
+ |-----------------------------|------------------------------|
170
+ | IntegerType | `sc.geoTiff[Int]` |
171
+ | FloatType | `sc.geoTiff[Float]` |
172
+ | ArrayType(IntegerType,true) | `sc.geoTiff[Array[Int]]` |
173
+ | ArrayType(FloatType,true) | `sc.geoTiff[Array[Float]]` |
174
+
175
+ ---
176
+
177
+ ## Creating Raster Datasets Programmatically
178
+
179
+ In addition to reading files, rasters can be constructed directly from pixel
180
+ values, similar to manually creating arrays in NumPy.
181
+
182
+ ### Rasterizing grid coordinates
183
+
184
+ ```scala
185
+ val metadata = RasterMetadata.create(
186
+ x1 = -50, y1 = 40, x2 = -60, y2 = 30,
187
+ srid = 4326,
188
+ rasterWidth = 10, rasterHeight = 10,
189
+ tileWidth = 10, tileHeight = 10
190
+ )
191
+
192
+ val pixels = sc.parallelize(Seq(
193
+ (0, 0, 100),
194
+ (3, 4, 200),
195
+ (8, 9, 300)
196
+ ))
197
+
198
+ val raster = sc.rasterizePixels(pixels, metadata)
199
+ ```
200
+
201
  ---
202
+
203
+ ### Rasterizing geographic coordinates
204
+
205
+ Instead of grid indices, pixel values can be defined using geographic
206
+ coordinates:
207
+
208
+ ```scala
209
+ val pixels = sc.parallelize(Seq(
210
+ (-51.3, 30.4, 100),
211
+ (-55.2, 34.5, 200),
212
+ (-56.4, 39.2, 300)
213
+ ))
214
+
215
+ val raster = sc.rasterizePoints(pixels, metadata)
216
+ ```
217
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  ---
219
 
220
+ ## Pixel-wise Raster Operations
221
+
222
+ Pixel-level operations correspond to **element-wise raster math** in NumPy or
223
+ rasterio.
224
+
225
+ ### MapPixels (element-wise transform)
226
+
227
+ ```scala
228
+ val temperatureF: RasterRDD[Float] =
229
+ temperatureK.mapPixels(k => (k - 273.15f) * 9 / 5 + 32)
230
+ ```
231
+
232
+ This produces an output raster with the same shape and metadata.
233
 
234
+ ---
 
 
235
 
236
+ ### FilterPixels (masking)
237
 
238
+ Equivalent to masking raster values based on a condition:
239
 
240
+ ```scala
241
+ temperatureK
242
+ .filterPixels(_ > 300)
243
+ .saveAsGeoTiff("temperature_high")
244
+ ```
245
 
246
+ ---
247
 
248
+ ### Flatten (raster → samples)
249
 
250
+ `flatten` extracts all non-empty pixels into a non-raster RDD, similar to
251
+ converting a raster into point samples for global statistics.
 
 
 
 
252
 
253
+ ```scala
254
+ val histogram: Map[Int, Long] =
255
+ raster.flatten.map(_._4).countByValue().toMap
256
+ ```
257
 
258
+ Each output record contains:
259
+ - Pixel `(x, y)` indices
260
+ - Raster metadata
261
+ - Pixel value
262
 
263
+ ---
 
 
 
 
 
 
 
 
 
 
264
 
265
+ ## Stacking Rasters (Multi-band Datasets)
266
 
267
+ In GDAL, multiple rasters can be combined into a **multi-band dataset**.
268
+ RDPro provides the same functionality via `overlay`.
269
 
270
+ ```scala
271
+ val stacked: RasterRDD[Array[Int]] =
272
+ raster1.overlay(raster2)
 
 
 
 
273
  ```
274
 
275
+ All input rasters must have the same CRS, resolution, and tile size.
276
+
277
+ ---
278
 
279
+ ## Reshaping Rasters (GDAL Warp–style Operations)
 
 
280
 
281
+ ### Retile (change block layout)
282
 
283
+ ```scala
284
+ val retiled = raster.retile(64, 64)
285
+ retiled.saveAsGeoTiff("glc_retiled")
 
 
286
  ```
287
 
288
+ ---
289
+
290
+ ### Explode (tile-wise outputs)
291
 
292
+ Useful when each tile should be written as a separate file (e.g., ML pipelines):
293
 
294
+ ```scala
295
+ raster
296
+ .retile(64, 64)
297
+ .explode
298
+ .saveAsGeoTiff("glc_retiled", GeoTiffWriter.WriteMode -> "distributed")
299
+ ```
300
+
301
+ ---
302
 
303
+ ### Reproject (change CRS)
304
 
305
+ Equivalent to `gdal.Warp` with a new CRS:
 
 
 
306
 
307
+ ```scala
308
+ val temperature: RasterRDD[Float] =
309
+ sc.hdfFile("MOD11A1.A2022173.h08v05.006.2022174092443.hdf", "LST_Day_1km")
310
+
311
+ temperature.reproject(4326)
312
+ ```
313
 
314
+ ---
 
315
 
316
+ ### Rescale (change resolution)
317
 
318
+ Equivalent to GDAL resampling:
319
 
320
+ ```scala
321
+ val rescaled = raster.rescale(360, 180)
322
+ rescaled.saveAsGeoTiff("glc_small", GeoTiffWriter.WriteMode -> "compatibility")
 
 
 
 
323
  ```
324
 
325
+ ---
326
+
327
+ ### Reshape (general warp)
328
+
329
+ The most general operation for changing CRS, extent, resolution, and tile size
330
+ in one step:
331
+
332
+ ```scala
333
+ val reshaped =
334
+ RasterOperationsFocal.reshapeNN(
335
+ raster,
336
+ RasterMetadata.create(-124, 42, -114, 32, 4326, 1000, 1000, 100, 100)
337
+ )
338
+
339
+ reshaped.saveAsGeoTiff("glc_ca")
340
  ```
341
 
342
+ Supported interpolation methods:
343
+ - Nearest Neighbor (`reshapeNN`)
344
+ - Average (`reshapeAverage`)
345
+
346
+ ---
347
+
348
+ ## Raster–Vector Analysis (Raptor)
349
+
350
+ Raptor enables joint raster–vector processing, similar to zonal statistics in
351
+ GDAL.
352
+
353
+ ```scala
354
+ val raster: RasterRDD[Int] = sc.geoTiff[Int]("glc2000_v1_1.tif")
355
+ val trees = raster.filterPixels(lc => lc >= 1 && lc <= 10)
356
+ val countries = sc.shapefile("ne_10m_admin_0_countries.zip")
357
+
358
+ val result =
359
+ RaptorJoin.raptorJoinFeature(trees, countries, Seq())
360
+ .map(x => x.feature.getAs[String]("NAME"))
361
+ .countByValue()
362
+ .toMap
363
+ println(result)
364
+ ```
365
+
366
+ ---
367
+
368
+ ## Writing Raster Outputs (GeoTIFF)
369
+
370
+ Writing rasters follows the same model as rasterio write profiles.
371
+
372
+ ```scala
373
+ val temperatureK: RasterRDD[Float] =
374
+ sc.hdfFile("MOD11A1.A2022173.h08v05.006.2022174092443.hdf", "LST_Day_1km")
375
+ val temperatureF: RasterRDD[Float] =
376
+ temperatureK.mapPixels(k => (k-273.15f) * 9 / 5 + 32)
377
+ temperatureF.saveAsGeoTiff("temperature_f")
378
+ ```
379
+
380
+ ### Advanced GeoTIFF Options
381
+
382
+ For advanced options (compression, write mode, bit compaction), add imports:
383
+
384
+ ```scala
385
+ import edu.ucr.cs.bdlab.raptor.GeoTiffWriter
386
+ import edu.ucr.cs.bdlab.beast.io.tiff.TiffConstants
387
+ ```
388
+
389
+ #### Compression
390
+
391
+ ```scala
392
+ raster.saveAsGeoTiff("temperature_f",
393
+ GeoTiffWriter.Compression -> TiffConstants.COMPRESSION_LZW)
394
+
395
+ raster.saveAsGeoTiff("temperature_f",
396
+ GeoTiffWriter.Compression -> TiffConstants.COMPRESSION_DEFLATE)
397
+
398
+ raster.saveAsGeoTiff("temperature_f",
399
+ GeoTiffWriter.Compression -> TiffConstants.COMPRESSION_NONE)
400
+ ```
401
+
402
+ #### Write mode
403
+
404
+ Distributed mode writes one file per Spark partition (fast, Beast-friendly).
405
+ Compatibility mode writes a single GeoTIFF compatible with traditional GIS tools.
406
+
407
+ ```scala
408
+ raster.saveAsGeoTiff("temperature_f",
409
+ GeoTiffWriter.WriteMode -> "distributed")
410
+
411
+ raster.saveAsGeoTiff("temperature_f",
412
+ GeoTiffWriter.WriteMode -> "compatibility")
413
+ ```
414
+
415
+ Hint: Use `Seq` to pass multiple options.
416
+
417
+ ```scala
418
+ raster.saveAsGeoTiff("temperature_f",
419
+ Seq(
420
+ GeoTiffWriter.Compression -> TiffConstants.COMPRESSION_LZW,
421
+ GeoTiffWriter.WriteMode -> "compatibility"
422
+ )
423
+ )
424
+ ```
425
+
426
+ #### Bit compaction
427
+
428
+ ```scala
429
+ raster.saveAsGeoTiff("temperature_f", GeoTiffWriter.CompactBits -> true)
430
+ ```
431
+
432
+ #### BitsPerSample
433
+
434
+ ```scala
435
+ raster.saveAsGeoTiff("temperature_f", GeoTiffWriter.BitsPerSample -> "8,8,8")
436
+ ```
437
+
438
+ ---
439
+
440
+ ## Concept Mapping (for GDAL / rasterio users)
441
+
442
+ | GDAL / rasterio concept | RDPro |
443
+ |------------------------|-------|
444
+ | `gdal.Open` / `rasterio.open` | `sc.geoTiff` |
445
+ | HDF subdataset selection | `sc.hdfFile(path, dataset)` |
446
+ | Raster math (NumPy-style) | `mapPixels` |
447
+ | Masking | `filterPixels` |
448
+ | Band stacking / multi-band | `overlay` |
449
+ | Warp / resample | `reproject`, `rescale`, `reshape` |
450
+ | GeoTIFF write | `saveAsGeoTiff` |
451
+
452
+ ---
453
+
454
+ ## Takeaway
455
 
456
+ **RDPro implements the same raster operations as GDAL and rasterio**, but executes
457
+ them **at scale on Apache Spark**. This README intentionally uses GDAL-style
458
+ terminology so that both users and LLMs can immediately recognize the workflow.