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

Clean up old code by requiring somewhat new packages #1581

Merged
merged 1 commit into from
Jul 18, 2024
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
- Create or check large images for each item in a folder ([#1572](../../pull/1572))
- Support multiprocessing and pickling with a zarr sink ([#1551](../../pull/1551))

### Changes
- Remove old code that handled old pyproj packages ([#1581](../../pull/1581))

### Bug Fixes
- Harden marking S3 uploads as large images ([#1579](../../pull/1579))

Expand Down
20 changes: 6 additions & 14 deletions large_image/tilesource/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
from .base import FileTileSource
from .utilities import ImageBytes, JSONDict, getPaletteColors

try:
import pyproj
has_pyproj = True
_pyproj_under_6 = int(pyproj.proj_version_str.split('.')[0]) < 6
except Exception:
has_pyproj = False

# Inform the tile source cache about the potential size of this tile source
CacheProperties['tilesource']['itemExpectedSize'] = max(
CacheProperties['tilesource']['itemExpectedSize'],
Expand All @@ -27,9 +20,6 @@
ProjUnitsAcrossLevel0: Dict[str, float] = {}
ProjUnitsAcrossLevel0_MaxSize = 100

InitPrefix = ''
NeededInitPrefix = '+init=' if has_pyproj and _pyproj_under_6 else InitPrefix


def make_vsi(url: Union[str, pathlib.Path, Dict[Any, Any]], **options) -> str:
if str(url).startswith('s3://'):
Expand Down Expand Up @@ -251,14 +241,16 @@ def getPixelSizeInMeters(self) -> Optional[float]:

:returns: the pixel size in meters or None.
"""
bounds = self.getBounds(NeededInitPrefix + 'epsg:4326')
bounds = self.getBounds('epsg:4326')
if not bounds:
return None
if has_pyproj:
try:
import pyproj

geod = pyproj.Geod(ellps='WGS84')
computer = cast(Callable[[Any, Any, Any, Any], Tuple[Any, Any, float]], geod.inv)
else:
# Estimate based on great-cirlce distance
except Exception:
# Estimate based on great-circle distance
def computer(lon1, lat1, lon2, lat2) -> Tuple[Any, Any, float]:
from math import acos, cos, radians, sin
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
Expand Down
19 changes: 5 additions & 14 deletions sources/gdal/large_image_source_gdal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
from large_image.exceptions import (TileSourceError,
TileSourceFileNotFoundError,
TileSourceInefficientError)
from large_image.tilesource.geo import (GDALBaseFileTileSource, InitPrefix,
NeededInitPrefix,
from large_image.tilesource.geo import (GDALBaseFileTileSource,
ProjUnitsAcrossLevel0,
ProjUnitsAcrossLevel0_MaxSize)
from large_image.tilesource.utilities import JSONDict, _gdalParameters, _vipsCast, _vipsParameters
Expand Down Expand Up @@ -127,7 +126,7 @@ def __init__(self, path, projection=None, unitsPerPixel=None, **kwargs):
self.tileWidth = self.tileSize
self.tileHeight = self.tileSize
if projection and projection.lower().startswith('epsg:'):
projection = NeededInitPrefix + projection.lower()
projection = projection.lower()
if projection and not isinstance(projection, bytes):
projection = projection.encode()
self.projection = projection
Expand Down Expand Up @@ -230,7 +229,7 @@ def _initWithProjection(self, unitsPerPixel=None):
"""
Initialize aspects of the class when a projection is set.
"""
inProj = self._proj4Proj(NeededInitPrefix + 'epsg:4326')
inProj = self._proj4Proj('epsg:4326')
# Since we already converted to bytes decoding is safe here
outProj = self._proj4Proj(self.projection)
if outProj.crs.is_geographic:
Expand Down Expand Up @@ -293,7 +292,7 @@ def getProj4String(self):
if not wkt:
if (self.dataset.GetGeoTransform(can_return_null=True) or
hasattr(self, '_netcdf') or self._getDriver() in {'NITF'}):
return NeededInitPrefix + 'epsg:4326'
return 'epsg:4326'
return
proj = osr.SpatialReference()
proj.ImportFromWkt(wkt)
Expand Down Expand Up @@ -330,12 +329,7 @@ def _proj4Proj(proj):
if proj.lower().startswith('proj4:'):
proj = proj.split(':', 1)[1]
if proj.lower().startswith('epsg:'):
proj = NeededInitPrefix + proj.lower()
try:
if proj.startswith(InitPrefix) and int(pyproj.proj_version_str.split('.')[0]) >= 6:
proj = proj[len(InitPrefix):]
except Exception:
pass # failed to parse version
proj = proj.lower()
return pyproj.Proj(proj)

def toNativePixelCoordinates(self, x, y, proj=None, roundResults=True):
Expand Down Expand Up @@ -734,9 +728,6 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, **kwargs):
if not hasattr(self, '_warpSRS'):
self._warpSRS = (self.getProj4String(),
self.projection.decode())
if self._warpSRS[1].startswith(InitPrefix) and tuple(
int(p) for p in gdal.__version__.split('.')[:2]) >= (3, 1):
self._warpSRS = (self._warpSRS[0], self._warpSRS[1][len(InitPrefix):])
with self._getDatasetLock:
ds = gdal.Warp(
'', self.dataset, format='VRT',
Expand Down
2 changes: 1 addition & 1 deletion sources/gdal/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def prerelease_local_scheme(version):
f'large-image{limit_version}',
'gdal',
'packaging',
'pyproj>=2.2.0',
'pyproj>=3.5.0',
],
extras_require={
'girder': f'girder-large-image{limit_version}',
Expand Down
13 changes: 3 additions & 10 deletions sources/mapnik/large_image_source_mapnik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import mapnik
import PIL.Image
from large_image_source_gdal import GDALFileTileSource, InitPrefix
from large_image_source_gdal import GDALFileTileSource
from osgeo import gdal, gdalconst

from large_image.cache_util import LruCacheMetaclass, methodcache
Expand All @@ -38,13 +38,6 @@
mapnik.logger.set_severity(mapnik.severity_type.Debug)


try:
mapnik.Projection('epsg:3857')
NeededInitPrefix = ''
except RuntimeError:
NeededInitPrefix = InitPrefix


class MapnikFileTileSource(GDALFileTileSource, metaclass=LruCacheMetaclass):
"""
Provides tile access to geospatial files.
Expand Down Expand Up @@ -101,7 +94,7 @@ def __init__(self, path, projection=None, unitsPerPixel=None, **kwargs):
specify unitsPerPixel.
"""
if projection and projection.lower().startswith('epsg'):
projection = NeededInitPrefix + projection.lower()
projection = projection.lower()
super().__init__(
path, projection=projection, unitsPerPixel=unitsPerPixel, **kwargs)

Expand Down Expand Up @@ -138,7 +131,7 @@ def _checkNetCDF(self):
}
if not len(datasets):
try:
self.getBounds(NeededInitPrefix + 'epsg:3857')
self.getBounds('epsg:3857')
except RuntimeError:
self._bounds.clear()
del self._netcdf
Expand Down