RT_Resample takes a raster column and 2 numeric values and returns a raster column with the spatial resolution changed. The numeric values represent the cell size of the new raster in x,y-coordinates. You can optionally specify a resampling method that will set rules for aggregating or interpolating values across the new cell sizes. There are two options described below:
Nearest—Performs a nearest neighbor assignment and is the fastest of the interpolation methods. It is used primarily for discrete data, such as a land-use classification, since it will not change the values of the cells. The maximum spatial error will be one-half the cell size.
Bilinear—Performs a bilinear interpolation and determines the new value of a cell based on a weighted distance average of the four nearest input cell centers. It is useful for continuous data and will cause some smoothing of the data.
The default resampling method for a raster is determined by whether it uses a color map or contains an attribute table.
- Color-mapped rasters or rasters with an attribute table use the Nearest Neighbor resampling method by default. This cannot be overriden.
- Rasters without a color map and those without an attribute table default to the Bilinear resampling method.
This approach ensures that categorical data (such as classified images) maintain their integrity, while continuous data benefit from smoother transitions.
To learn more about color maps and attribute tables, see the topic about Color maps and Attribute table.
| Function | Syntax |
|---|---|
| Python | resample(raster |
| SQL | RT |
| Scala | resample(raster, world |
For more details, go to the GeoAnalytics Engine API reference for resample.
Examples
from geoanalytics.raster import functions as RT
# Create 10x10 raster with cell size of 1
data = [(list(range(100)), )]
df = spark.createDataFrame(data, ["pixels"]) \
.withColumn("raster", RT.create_raster("pixels", 10, 10, "float32"))
# Resample to create a raster with cell size of 5
df_resample = df.select(RT.resample("raster", cell_size_x=5, cell_size_y=5, method="Bilinear").alias("resample"))
# Show pixel values of resampled raster
df_resample.withColumn("resample_pixels", RT.band_values("resample", 1)).show(truncate=False)+-------------------------+------------------------+
|resample |resample_pixels |
+-------------------------+------------------------+
|SqlRaster(1x2x2, Float32)|[22.0, 27.0, 72.0, 77.0]|
+-------------------------+------------------------+Version table
| Release | Notes |
|---|---|
2.0.0 | Python, SQL, and Scala functions introduced |