Skip to content

Commit

Permalink
adding unique method to raster class
Browse files Browse the repository at this point in the history
  • Loading branch information
wbierbower committed Apr 30, 2015
1 parent 19b38e8 commit 2852d52
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fauxgeo/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ def std(self):
_, _, _, std = pygeo.get_statistics_from_uri(self.uri)
return std

def unique(self):
unique_vals_list = pygeo.unique_raster_values_uri(self.uri)
return unique_vals_list

def ones(self):
def ones_closure(nodata):
def ones(x):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def test_sum(self):
print raster
assert(raster.sum() == 8.0)


class TestRasterMinimum(unittest.TestCase):
def setUp(self):
self.shape = (4, 4)
Expand All @@ -428,5 +429,21 @@ def test_fminimum(self):
assert(min_raster.get_band(1).data[0, 1] == 2)


class TestRasterUnique(unittest.TestCase):
def setUp(self):
self.shape = (4, 4)
self.array = np.ones(self.shape)
self.affine = Affine(1, 0, 0, 0, -1, 4)
self.proj = 4326
self.datatype = gdal.GDT_Int16
self.nodata_val = -9999
self.factory = RasterFactory(
self.proj, self.datatype, self.nodata_val, *self.shape, affine=self.affine)

def test_unique(self):
raster = self.factory.horizontal_ramp(1, 4)
assert(raster.unique() == [1, 2, 3, 4])


if __name__ == '__main__':
unittest.main()

0 comments on commit 2852d52

Please sign in to comment.