Skip to content

Commit

Permalink
Merge pull request #1624 from girder/adjust-bounds
Browse files Browse the repository at this point in the history
Some projected bounds in the rasterio source could be off
  • Loading branch information
manthey authored Sep 4, 2024
2 parents bd82c33 + ef0dff7 commit 80970f0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

- Harden converting sources that report varied tile bands ([#1615](../../pull/1615))
- Harden many of the sources from reading bad files ([#1623](../../pull/1623))
- Some projected bounds in the rasterio source could be off ([#1624](../../pull/1624))

## 1.29.6

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _reduceLogging():
'org/slf4j/LoggerFactory', 'getLogger',
'(Ljava/lang/String;)Lorg/slf4j/Logger;', rootLoggerName)
logLevel = javabridge.get_static_field(
'ch/qos/logback/classic/Level', 'ERROR', 'Lch/qos/logback/classic/Level;')
'ch/qos/logback/classic/Level', 'OFF', 'Lch/qos/logback/classic/Level;')
javabridge.call(rootLogger, 'setLevel', '(Lch/qos/logback/classic/Level;)V', logLevel)
except Exception:
pass
Expand Down
9 changes: 4 additions & 5 deletions sources/gdal/large_image_source_gdal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,11 @@ def getBounds(self, srs=None):
keys = ('ll', 'ul', 'lr', 'ur')
for key in keys:
bounds[key]['y'] = max(min(bounds[key]['y'], yBound), -yBound)
while any(bounds[key]['x'] > 180 for key in keys):
dx = min(bounds[key]['x'] for key in keys)
if dx < -180 or dx >= 180:
dx = ((dx + 180) % 360 - 180) - dx
for key in keys:
bounds[key]['x'] -= 360
while any(bounds[key]['x'] < -180 for key in keys):
for key in keys:
bounds[key]['x'] += 360
bounds[key]['x'] += dx
if any(bounds[key]['x'] >= 180 for key in keys):
bounds['ul']['x'] = bounds['ll']['x'] = -180
bounds['ur']['x'] = bounds['lr']['x'] = 180
Expand Down
13 changes: 6 additions & 7 deletions sources/rasterio/large_image_source_rasterio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,14 @@ def getBounds(self, crs=None, **kwargs):
for k in bounds:
bounds[k]['y'] = max(min(bounds[k]['y'], yBounds), -yBounds)

# for each corner rotate longitude until it's within -180, 180
while any(v['x'] > 180 for v in bounds.values()):
# rotate longitude so the western-most corner is within [-180, 180)
dx = min(v['x'] for v in bounds.values())
if dx < -180 or dx >= 180:
dx = ((dx + 180) % 360 - 180) - dx
for k in bounds:
bounds[k]['x'] -= 180
while any(v['x'] < -180 for v in bounds.values()):
for k in bounds:
bounds[k]['x'] += 360
bounds[k]['x'] += dx

# if one of the corner is > 180 set all the corner to world width
# if one of the corner is >= 180 set all the corners to world width
if any(v['x'] >= 180 for v in bounds.values()):
bounds['ul']['x'] = bounds['ll']['x'] = -180
bounds['ur']['x'] = bounds['lr']['x'] = 180
Expand Down
4 changes: 3 additions & 1 deletion sources/rasterio/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def prerelease_local_scheme(version):
],
install_requires=[
f'large-image{limit_version}',
'rasterio>=1.3', # to get the statistics attribute (<=> gdalinfo)
'rasterio>=1.3,<1.3.11 ; python_version < "3.9"',
# We need rasterio > 1.3 to get the statistics attribute (<=> gdalinfo)
'rasterio>=1.3 ; python_version >= "3.9"',
'packaging',
],
extras_require={
Expand Down

0 comments on commit 80970f0

Please sign in to comment.