Skip to content

Commit

Permalink
Merge pull request #164 from jbouffard/int-params
Browse files Browse the repository at this point in the history
Int Params for Focal and Cost Distace
  • Loading branch information
echeipesh committed May 3, 2017
2 parents 6b9de12 + 33f492e commit d1c3fbd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
16 changes: 9 additions & 7 deletions geopyspark/geotrellis/rdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,10 @@ def focal(self, operation, neighborhood, param_1=None, param_2=None, param_3=Non
Args:
operation (str): The focal operation such as SUM, ASPECT, SLOPE, etc.
neighborhood (str): The type of neighborhood to use such as ANNULUS, SQUARE, etc.
param_1 (int, optional): If using SLOPE, then this is the zFactor, else it is the first
argument of the `neighborhood`.
param_2 (int, optional): The second argument of the `neighborhood`.
param_3 (int, optional): The third argument of the `neighborhood`.
param_1 (int, float, optional): If using ``SLOPE``, then this is the zFactor, else it
is the first argument of the ``neighborhood``.
param_2 (int, float, optional): The second argument of the `neighborhood`.
param_3 (int, float, optional): The third argument of the `neighborhood`.
Note:
Any `param` that is not set will default to 0.0.
Expand All @@ -524,7 +524,8 @@ def focal(self, operation, neighborhood, param_1=None, param_2=None, param_3=Non
if param_3 is None:
param_3 = 0.0

srdd = self.srdd.focal(operation, neighborhood, param_1, param_2, param_3)
srdd = self.srdd.focal(operation, neighborhood, float(param_1), float(param_2),
float(param_3))

return TiledRasterRDD(self.geopysc, self.rdd_type, srdd)

Expand Down Expand Up @@ -570,14 +571,15 @@ def cost_distance(self, geometries, max_distance):
Note:
All geometries must be in the same CRS as the TileLayer.
max_distance (int): The maximum ocst that a path may reach before operation.
max_distance (int, float): The maximum ocst that a path may reach before operation.
This value can be an ``int`` or ``float``.
Returns:
:class:`~geopyspark.geotrellis.rdd.TiledRasterRDD`
"""

wkts = [shapely.wkt.dumps(g) for g in geometries]
srdd = self.srdd.costDistance(self.geopysc.sc, wkts, max_distance)
srdd = self.srdd.costDistance(self.geopysc.sc, wkts, float(max_distance))

return TiledRasterRDD(self.geopysc, self.rdd_type, srdd)

Expand Down
11 changes: 11 additions & 0 deletions geopyspark/tests/costdistance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ def zero_one(kv):
point_distance = tile['data'][0][1][3]
self.assertEqual(point_distance, 0.0)

def test_costdistance_finite_int(self):
def zero_one(kv):
k = kv[0]
return (k['col'] == 0 and k['row'] == 1)

result = self.raster_rdd.cost_distance(geometries=[Point(13, 13)], max_distance=144000)

tile = result.to_numpy_rdd().filter(zero_one).first()[1]
point_distance = tile['data'][0][1][3]
self.assertEqual(point_distance, 0.0)

def test_costdistance_infinite(self):
def zero_one(kv):
k = kv[0]
Expand Down
13 changes: 13 additions & 0 deletions geopyspark/tests/focal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,24 @@ def test_focal_sum(self):

self.assertTrue(result.to_numpy_rdd().first()[1]['data'][0][1][0] >= 6)

def test_focal_sum_int(self):
result = self.raster_rdd.focal(
operation=SUM,
neighborhood=SQUARE,
param_1=1)

self.assertTrue(result.to_numpy_rdd().first()[1]['data'][0][1][0] >= 6)

def test_focal_min(self):
result = self.raster_rdd.focal(operation=MIN, neighborhood=ANNULUS, param_1=2.0, param_2=1.0)

self.assertEqual(result.to_numpy_rdd().first()[1]['data'][0][0][0], -1)

def test_focal_min_int(self):
result = self.raster_rdd.focal(operation=MIN, neighborhood=ANNULUS, param_1=2, param_2=1)

self.assertEqual(result.to_numpy_rdd().first()[1]['data'][0][0][0], -1)


if __name__ == "__main__":
unittest.main()
Expand Down

0 comments on commit d1c3fbd

Please sign in to comment.