Skip to content

Commit 7795f3a

Browse files
committed
Basic example of overview raster in docs.
1 parent f6e5370 commit 7795f3a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

pyrasterframes/src/main/python/docs/raster-write.pymd

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spark = create_rf_spark_session()
1616

1717
## Tile Samples
1818

19-
We have some convenience methods to quickly visualize _tile_s (see discussion of the RasterFrame @ref:[schema](raster-read.md#single-raster) for orientation to the concept) when inspecting a subset of the data in a Notebook.
19+
We have some convenience methods to quickly visualize tiles (see discussion of the RasterFrame @ref:[schema](raster-read.md#single-raster) for orientation to the concept) when inspecting a subset of the data in a Notebook.
2020

2121
In an IPython or Jupyter interpreter, a `Tile` object will be displayed as an image with limited metadata.
2222

@@ -25,7 +25,7 @@ def scene(band):
2525
b = str(band).zfill(2) # converts int 2 to '02'
2626
return 'https://modis-pds.s3.amazonaws.com/MCD43A4.006/11/08/2019059/' \
2727
'MCD43A4.A2019059.h11v08.006.2019072203257_B{}.TIF'.format(b)
28-
spark_df = spark.read.raster(scene(2), tile_dimensions=(128, 128))
28+
spark_df = spark.read.raster(scene(2), tile_dimensions=(256, 256))
2929
tile = spark_df.select(rf_tile('proj_raster').alias('tile')).first()['tile']
3030
tile
3131
```
@@ -51,7 +51,6 @@ samples = spark_df \
5151
samples
5252
```
5353

54-
5554
## GeoTIFFs
5655

5756
GeoTIFF is one of the most common file formats for spatial data, providing flexibility in data encoding, representation, and storage. RasterFrames provides a specialized Spark DataFrame writer for rendering a RasterFrame to a GeoTIFF.
@@ -85,6 +84,19 @@ If there are many _tile_ or projected raster columns in the DataFrame, the GeoTI
8584
os.remove(outfile)
8685
```
8786

87+
## Overview Rasters
88+
89+
In cases where writing and reading to/from a GeoTIFF isn't convenient, RasterFrames provides the `rf_agg_overview_raster` aggregate function, where you can construct a single raster (rendered as a tile) downsampled from all or a subset of the dataframe. This allows you to effectively construct the same operations the GeoTIFF writer performs, but without the file I/O.
90+
91+
Because a Dataframe may contain data with varying CRSs, and the rendered raster needs to have a single CRS, an "Area of Interest" (AOI) is required in a predetermined CRS. In the case of `rf_agg_reprojected_extent`, the AOI needs to be in commonly used ["web mercator"](https://en.wikipedia.org/wiki/Web_Mercator_projection) CRS.
92+
93+
```python, overview
94+
from pyrasterframes.rf_types import Extent
95+
target = spark_df.withColumn('extent', rf_extent('proj_raster')).withColumn('crs', rf_crs('proj_raster'))
96+
aoi = Extent.from_row(target.select(rf_agg_reprojected_extent('extent', 'crs', 'EPSG:3857')).first()[0])
97+
target.select(rf_agg_overview_raster(rf_tile('proj_raster'), 512, 512, aoi, 'extent', 'crs')).first()[0]
98+
```
99+
88100
## GeoTrellis Layers
89101

90102
[GeoTrellis][GeoTrellis] is one of the key libraries upon which RasterFrames is built. It provides a Scala language API for working with geospatial raster data. GeoTrellis defines a [tile layer storage](https://geotrellis.readthedocs.io/en/latest/guide/tile-backends.html) format for persisting imagery mosaics. RasterFrames can write data from a `RasterFrameLayer` into a [GeoTrellis Layer](https://geotrellis.readthedocs.io/en/latest/guide/tile-backends.html). RasterFrames provides a `geotrellis` DataSource that supports both @ref:[reading](raster-read.md#geotrellis-layers) and @ref:[writing](raster-write.md#geotrellis-layers) GeoTrellis layers.

0 commit comments

Comments
 (0)