Skip to content

Commit 7497b6e

Browse files
committed
rf_spatial_index python one arg variant; expand unit tests
Signed-off-by: Jason T. Brown <[email protected]>
1 parent bed8036 commit 7497b6e

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

pyrasterframes/src/main/python/pyrasterframes/rasterfunctions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,12 @@ def rf_geometry(proj_raster_col):
586586
return _apply_column_function('rf_geometry', proj_raster_col)
587587

588588

589-
def rf_spatial_index(geom_col, crs_col):
589+
def rf_spatial_index(geom_col, crs_col=None):
590590
"""Constructs a XZ2 index in WGS84 from either a Geometry, Extent, ProjectedRasterTile, or RasterSource and its CRS"""
591-
return _apply_column_function('rf_spatial_index', geom_col, crs_col)
591+
if crs_col is not None:
592+
return _apply_column_function('rf_spatial_index', geom_col, crs_col)
593+
else:
594+
return _apply_column_function('rf_spatial_index', geom_col)
592595

593596
# ------ GeoMesa Functions ------
594597

pyrasterframes/src/main/python/tests/RasterFunctionsTests.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,6 @@ def test_render_composite(self):
323323
# Look for the PNG magic cookie
324324
self.assertEqual(png_bytes[0:8], bytearray([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]))
325325

326-
327-
328-
329326
def test_rf_interpret_cell_type_as(self):
330327
from pyspark.sql import Row
331328
from pyrasterframes.rf_types import Tile
@@ -359,3 +356,15 @@ def test_rf_local_data_and_no_data(self):
359356

360357
result_d = result['ld']
361358
assert_equal(result_d.cells, np.invert(t.cells.mask))
359+
360+
def test_rf_spatial_index(self):
361+
from pyspark.sql.functions import min as F_min
362+
result_one_arg = self.df.select(rf_spatial_index('tile').alias('ix')) \
363+
.agg(F_min('ix')).first()[0]
364+
print(result_one_arg)
365+
366+
result_two_arg = self.df.select(rf_spatial_index(rf_extent('tile'), rf_crs('tile')).alias('ix')) \
367+
.agg(F_min('ix')).first()[0]
368+
369+
self.assertEqual(result_two_arg, result_one_arg)
370+
self.assertEqual(result_one_arg, 55179438768) # this is a bit more fragile but less important

pyrasterframes/src/main/python/tests/VectorTypesTests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,4 @@ def test_spatial_index(self):
162162
expected = {22858201775, 38132946267, 38166922588, 38180072113}
163163
indexes = {x[0] for x in df.collect()}
164164
self.assertSetEqual(indexes, expected)
165+

pyrasterframes/src/main/python/tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ def create_layer(self):
9494
self.rf = rf.withColumn('tile2', rf_convert_cell_type('tile', 'float32')) \
9595
.drop('tile') \
9696
.withColumnRenamed('tile2', 'tile').as_layer()
97+
98+
df = self.spark.read.raster(self.img_uri)
99+
self.df = df.withColumn('tile', rf_convert_cell_type('proj_raster', 'float32')) \
100+
.drop('proj_raster')

0 commit comments

Comments
 (0)