Skip to content

Commit

Permalink
rasterio source module (#1115)
Browse files Browse the repository at this point in the history
Co-authored-by: 12rambau <[email protected]>
Co-authored-by: Rambaud Pierrick <[email protected]>
Co-authored-by: David Manthey <[email protected]>
  • Loading branch information
4 people authored May 29, 2023
1 parent 26027f9 commit 1b8b8f4
Show file tree
Hide file tree
Showing 24 changed files with 2,601 additions and 1,505 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ commands:
# Piping through cat does less buffering of the output but can
# consume the exit code
# command: PYTEST_ADDOPTS=--forked tox -e << parameters.env >> | cat; test ${PIPESTATUS[0]} -eq 0
command: PYTEST_RERUNS=3 tox -e << parameters.env >> | cat; test ${PIPESTATUS[0]} -eq 0
command: PYTEST_ADDOPTS=--reruns=3 tox -e << parameters.env >> | cat; test ${PIPESTATUS[0]} -eq 0
switchpython:
description: "Upgrade python"
parameters:
Expand Down
2 changes: 2 additions & 0 deletions .circleci/make_wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ cd "$ROOTPATH/sources/openslide"
pip wheel . --no-deps -w ~/wheels && rm -rf build
cd "$ROOTPATH/sources/pil"
pip wheel . --no-deps -w ~/wheels && rm -rf build
cd "$ROOTPATH/sources/rasterio"
pip wheel . --no-deps -w ~/wheels && rm -rf build
cd "$ROOTPATH/sources/test"
pip wheel . --no-deps -w ~/wheels && rm -rf build
cd "$ROOTPATH/sources/tiff"
Expand Down
6 changes: 6 additions & 0 deletions .circleci/release_pypi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ cp "$ROOTPATH/LICENSE" .
python setup.py sdist
pip wheel . --no-deps -w dist
twine upload --verbose dist/*
cd "$ROOTPATH/sources/rasterio"
cp "$ROOTPATH/README.rst" .
cp "$ROOTPATH/LICENSE" .
python setup.py sdist
pip wheel . --no-deps -w dist
twine upload --verbose dist/*
cd "$ROOTPATH/sources/test"
cp "$ROOTPATH/README.rst" .
cp "$ROOTPATH/LICENSE" .
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ coverage.xml
# pyenv
.python-version

# IPython
profile_default/
ipython_config.py

# Jupyter Notebook
.ipynb_checkpoints

# dotenv
.env

Expand All @@ -64,3 +71,6 @@ docs/source/*
!docs/source/*.py
!docs/source/*.rst
.pre-commit-config.yaml

*.ipynb
NOTES.md
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
_build/large_image_source_openjpeg/modules
_build/large_image_source_openslide/modules
_build/large_image_source_pil/modules
_build/large_image_source_rasterio/modules
_build/large_image_source_test/modules
_build/large_image_source_tiff/modules
_build/large_image_source_tifffile/modules
Expand Down
1 change: 1 addition & 0 deletions docs/make_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sphinx-apidoc -f -o _build/large_image_source_ometiff ../sources/ometiff/large_i
sphinx-apidoc -f -o _build/large_image_source_openjpeg ../sources/openjpeg/large_image_source_openjpeg
sphinx-apidoc -f -o _build/large_image_source_openslide ../sources/openslide/large_image_source_openslide
sphinx-apidoc -f -o _build/large_image_source_pil ../sources/pil/large_image_source_pil
sphinx-apidoc -f -o _build/large_image_source_rasterio ../sources/rasterio/large_image_source_rasterio
sphinx-apidoc -f -o _build/large_image_source_test ../sources/test/large_image_source_test
sphinx-apidoc -f -o _build/large_image_source_tiff ../sources/tiff/large_image_source_tiff
sphinx-apidoc -f -o _build/large_image_source_tifffile ../sources/tifffile/large_image_source_tifffile
Expand Down
4 changes: 4 additions & 0 deletions large_image/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class SourcePriority:
'millimeter': 'mm',
'millimeters': 'mm',
'fraction': 'fraction',
'projection': 'projection',
'proj': 'projection',
'wgs84': 'proj4:EPSG:4326',
'4326': 'proj4:EPSG:4326',
}

# numpy dtype to pyvips GValue
Expand Down
29 changes: 11 additions & 18 deletions large_image/tilesource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,17 @@ def isGeospatial(path):
:param path: The path to the file
:returns: True if geospatial.
"""
try:
from osgeo import gdal, gdalconst
except ImportError:
# TODO: log a warning
return False
try:
ds = gdal.Open(str(path), gdalconst.GA_ReadOnly)
except Exception:
return False
if ds:
if ds.GetGCPs() and ds.GetGCPProjection():
return True
if ds.GetProjection():
return True
if ds.GetGeoTransform(can_return_null=True):
return True
if ds.GetDriver().ShortName in {'NITF', 'netCDF'}:
return True
if not len(AvailableTileSources):
loadTileSources()
for source in AvailableTileSources.values():
if hasattr(source, 'isGeospatial'):
result = None
try:
result = source.isGeospatial(path)
except Exception:
pass
if result in (True, False):
return result
return False


Expand Down
Loading

0 comments on commit 1b8b8f4

Please sign in to comment.