Skip to content

Commit

Permalink
Merge pull request #33 from johntruckenbrodt/osr2epsg
Browse files Browse the repository at this point in the history
improved EPSG code search
  • Loading branch information
johntruckenbrodt authored Sep 9, 2022
2 parents 51d0b91 + 9073c07 commit 65f76bc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist: focal
dist: jammy
language: python
sudo: required
cache:
Expand Down Expand Up @@ -26,7 +26,8 @@ python:
- '3.7'

install:
- pip install --ignore-installed six # install six inside the venv since the system version is too old
- mkdir -p ~/.cache/pip/wheels # remove warning "Url 'file:///home/travis/.cache/pip/wheels' is ignored: it is neither a file nor a directory."
- pip install --ignore-installed setuptools pip six certifi # install packages inside the venv if the system version is too old
- pip install numpy
- pip install GDAL==$(gdal-config --version) --global-option=build_ext --global-option="$(gdal-config --cflags)"
- pip install -r requirements.txt
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup, find_packages
from setuptools import setup, find_namespace_packages
import os

directory = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -10,7 +10,7 @@
requirements = req.read().split('\n')

setup(name='spatialist',
packages=find_packages(),
packages=find_namespace_packages(),
include_package_data=True,
setup_requires=['setuptools_scm'],
use_scm_version=True,
Expand Down
13 changes: 11 additions & 2 deletions spatialist/auxil.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def __osr2epsg(srs):
Parameters
----------
srs: :osgeo:class:`osr.SpatialReference`
a SRS to be converted
an SRS to be converted
Returns
-------
Expand All @@ -363,7 +363,16 @@ def __osr2epsg(srs):
"""
srs = srs.Clone()
try:
srs.AutoIdentifyEPSG()
try:
srs.AutoIdentifyEPSG()
except RuntimeError:
# Sometimes EPSG identification might fail
# but a match exists for which it does not.
matches = srs.FindMatches()
for srs, confidence in matches:
if confidence == 100:
srs.AutoIdentifyEPSG()
break
code = int(srs.GetAuthorityCode(None))
# make sure the EPSG code actually exists
srsTest = osr.SpatialReference()
Expand Down

0 comments on commit 65f76bc

Please sign in to comment.