Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround to overcome JPEG 2000 issue #139

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions telluric/georaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,11 @@ def get_window(self, window, bands=None,
:param masked: boolean, if `True` the return value will be a masked array. Default is True
:return: GeoRaster2 of tile
"""

# HACK: We have to overcome https://github.com/mapbox/rasterio/issues/1449 here
if self._filename.endswith('.jp2'):
masked = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if mask is false, and in the orginal there existed a mask, we are not supporting this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.jp2 doesn't support internal mask, so one of the possible way to mask all pixels that extend beyond the dataset's extent is overwriting masked to False: in this case crop returns np.core.ndarray and GeoRaster constructor converts it to masked array here. The drawback of this approach is that we masks legitimate 0 value pixels as well. The same issue you can observe while cropping GeoTIFF which doesn't contain any mask (internal, alpha or nodata).


bands = bands or list(range(1, self.num_bands + 1))

# requested_out_shape and out_shape are different for out of bounds window
Expand Down
Binary file added tests/data/raster/nomask.jp2
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/test_georaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,3 +742,12 @@ def test_georaster_save_emits_warning_if_uneven_mask(recwarn):
"Saving different masks per band is not supported, the union of the masked values will be performed."
in str(w.message)
)


def test_georaster_crop_jp2():
# https://github.com/mapbox/rasterio/issues/1449
raster = GeoRaster2.open("tests/data/raster/nomask.jp2")
bounds = [-6530057, -3574558, -6492196, -3639376]
roi = GeoVector(Polygon.from_bounds(*bounds), crs=WEB_MERCATOR_CRS)
cropped = raster.crop(roi)
assert(cropped.image.mask[0, -1, -1])