mirror of
https://github.com/rasterio/rasterio.git
synced 2026-02-01 14:34:43 +00:00
Raise a CRSError instead of ValueError + handling for '[]' and ''.
This commit is contained in:
parent
369a5923be
commit
36eab05e2c
@ -10,8 +10,11 @@
|
||||
# {'proj': 'longlat', 'ellps': 'WGS84', 'datum': 'WGS84', 'no_defs': True}
|
||||
#
|
||||
|
||||
|
||||
import json
|
||||
|
||||
from rasterio._base import is_geographic_crs, is_projected_crs, is_same_crs
|
||||
from rasterio.errors import CRSError
|
||||
from rasterio.five import string_types
|
||||
|
||||
|
||||
@ -57,8 +60,9 @@ def from_string(prjs):
|
||||
val = json.loads(prjs, strict=False)
|
||||
except ValueError:
|
||||
raise ValueError('crs appears to be JSON but is not valid')
|
||||
|
||||
if not val:
|
||||
raise ValueError("crs is empty JSON")
|
||||
raise CRSError("crs is empty JSON")
|
||||
else:
|
||||
return val
|
||||
|
||||
@ -86,7 +90,12 @@ def from_string(prjs):
|
||||
lambda kv: len(kv) == 2 and (kv[0], parse(kv[1])) or (kv[0], True),
|
||||
(p.split('=') for p in parts))
|
||||
|
||||
return dict((k, v) for k, v in items if k in all_proj_keys)
|
||||
out = dict((k, v) for k, v in items if k in all_proj_keys)
|
||||
|
||||
if not out:
|
||||
raise CRSError("crs is empty or invalid: {}".format(prjs))
|
||||
|
||||
return out
|
||||
|
||||
|
||||
def from_epsg(code):
|
||||
|
||||
@ -8,6 +8,7 @@ import rasterio
|
||||
from rasterio import crs
|
||||
from rasterio.crs import (
|
||||
is_geographic_crs, is_projected_crs, is_same_crs, is_valid_crs)
|
||||
from rasterio.errors import CRSError
|
||||
|
||||
|
||||
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
||||
@ -149,5 +150,9 @@ def test_is_valid():
|
||||
|
||||
|
||||
def test_empty_json():
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(CRSError):
|
||||
crs.from_string('{}')
|
||||
with pytest.raises(CRSError):
|
||||
crs.from_string('[]')
|
||||
with pytest.raises(CRSError):
|
||||
crs.from_string('')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user