Skip to content

Commit

Permalink
Merge pull request #125 from satellogic/geovector_rasterize_crs
Browse files Browse the repository at this point in the history
Support custom CRS in GeoVector.rasterize
  • Loading branch information
drnextgis authored Aug 16, 2018
2 parents a993b39 + 35bca1a commit 7c4d75e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions telluric/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ def rasterize(self, dest_resolution, *, polygonize_width=0, crs=WEB_MERCATOR_CRS
rasters = []
for feature in self:
rasters.append(feature.geometry.rasterize(
dest_resolution, fill_value=fill_value(feature), bounds=bounds, dtype=dtype)
dest_resolution, fill_value=fill_value(feature), bounds=bounds, dtype=dtype, crs=crs)
)

return merge_all(rasters, bounds, dest_resolution, merge_strategy=MergeStrategy.INTERSECTION)
return merge_all(rasters, bounds.reproject(crs), dest_resolution, merge_strategy=MergeStrategy.INTERSECTION)

else:
return rasterize(shapes, crs, bounds.get_shape(crs), dest_resolution, fill_value=fill_value, dtype=dtype)
Expand Down
4 changes: 2 additions & 2 deletions telluric/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ def reproject(self, new_crs):
new_shape = transform(self._shape, self._crs, new_crs)
return self.__class__(new_shape, new_crs)

def rasterize(self, dest_resolution, *, fill_value=None, bounds=None, dtype=None, **kwargs):
def rasterize(self, dest_resolution, *, fill_value=None, bounds=None, dtype=None, crs=None, **kwargs):
# Import here to avoid circular imports
from telluric import rasterization # noqa
crs = self.crs
crs = crs or self.crs
shapes = [self.get_shape(crs)]
if bounds is None:
bounds = self.envelope.get_shape(crs)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_geovector.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,18 @@ def test_rasterize_with_polygon_bounds(mock_rasterize):
mock_rasterize.assert_called_with(expected_shape, gv.crs,
expected_bounds, 0.00001,
fill_value=None, dtype=None)


@mock.patch('telluric.rasterization.rasterize')
def test_rasterize_with_crs(mock_rasterize):
gv = GeoVector(Polygon.from_bounds(0, 0, 1, 1))
expected_crs = WEB_MERCATOR_CRS
expected_bounds = Polygon.from_bounds(11132, 11132, 222639, 222684)
bounds = GeoVector(Polygon.from_bounds(0.1, 0.1, 2, 2))
gv.rasterize(1000, bounds=bounds, crs=WEB_MERCATOR_CRS)
expected_shape = [gv.get_shape(expected_crs)]

args, kwargs = mock_rasterize.call_args
assert args[0] == expected_shape
assert args[1] == expected_crs
assert args[2].almost_equals(expected_bounds, decimal=0)

0 comments on commit 7c4d75e

Please sign in to comment.