@@ -97,7 +97,7 @@ def some_point(g):
9797 pandas_df_out .poly_len .values
9898 )
9999
100- def test_rasterize (self ):
100+ def test_geometry_udf (self ):
101101 from geomesa_pyspark .types import PolygonUDT
102102 # simple test that raster contents are not invalid
103103
@@ -117,12 +117,25 @@ def area(g):
117117 area_result = area .collect ()
118118 self .assertTrue (all ([r [0 ] for r in area_result ]))
119119
120- cols = 194
121- rows = 250
122- with_raster = with_poly .withColumn ('rasterized' , rf_rasterize ('poly' , 'geometry' , lit (16 ), cols , rows ))
123- # expect a 4 by 4 cell
120+ def test_rasterize (self ):
121+ from geomesa_pyspark .types import PolygonUDT
122+
123+ @udf (PolygonUDT ())
124+ def buffer (g , d ):
125+ return g .buffer (d )
126+
127+ # start with known polygon, the tile extents, **negative buffered** by 10 cells
128+ buf_cells = 10
129+ with_poly = self .rf .withColumn ('poly' , buffer (self .rf .geometry , lit (- 15 * buf_cells ))) # cell res is 15x15
130+
131+ # rasterize value 16 into buffer shape.
132+ cols = 194 # from dims of tile
133+ rows = 250 # from dims of tile
134+ with_raster = with_poly .withColumn ('rasterized' ,
135+ rf_rasterize ('poly' , 'geometry' , lit (16 ), lit (cols ), lit (rows )))
124136 result = with_raster .select (rf_tile_sum (rf_local_equal_int (with_raster .rasterized , 16 )),
125137 rf_tile_sum (with_raster .rasterized ))
138+ #
126139 expected_burned_in_cells = (cols - 2 * buf_cells ) * (rows - 2 * buf_cells )
127140 self .assertEqual (result .first ()[0 ], float (expected_burned_in_cells ))
128141 self .assertEqual (result .first ()[1 ], 16. * expected_burned_in_cells )
0 commit comments