Skip to content

Commit

Permalink
Improve error from setting an invalid extent.
Browse files Browse the repository at this point in the history
Closes #703.
  • Loading branch information
ajdawson committed Dec 2, 2015
1 parent fc5fb8f commit 4513d3a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,18 @@ def set_extent(self, extents, crs=None):

if projected is None:
projected = self.projection.project_geometry(domain_in_crs, crs)
x1, y1, x2, y2 = projected.bounds
try:
# This might fail with an unhelpful error message ('need more
# than 0 values to unpack') if the specified extents fall outside
# the projection extents, so try and give a better error message.
x1, y1, x2, y2 = projected.bounds
except ValueError:
msg = ('Failed to determine the required bounds in projection '
'coordinates. Check that the values provided are within '
'the valid range (x_limits=[{xlim[0]}, {xlim[1]}], '
'y_limits=[{ylim[0]}, {ylim[1]}]).')
raise ValueError(msg.format(xlim=self.projection.x_limits,
ylim=self.projection.y_limits))
self.set_xlim([x1, x2])
self.set_ylim([y1, y2])

Expand Down

0 comments on commit 4513d3a

Please sign in to comment.