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

Fixed handling of pyproj dependency #392

Merged
merged 2 commits into from
Nov 24, 2019
Merged
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
12 changes: 9 additions & 3 deletions geoviews/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import division

import sys
import warnings

import param
Expand Down Expand Up @@ -442,7 +443,6 @@ def proj_to_cartopy(proj):
-------
a cartopy.crs.Projection object
"""

import cartopy.crs as ccrs
try:
from osgeo import osr
Expand Down Expand Up @@ -521,6 +521,13 @@ def proj_to_cartopy(proj):
return cl(globe=globe, **kw_proj)


def is_pyproj(crs):
if 'pyproj' not in sys.modules:
return False
import pyproj
return isinstance(crs, pyproj.Proj)


def process_crs(crs):
"""
Parses cartopy CRS definitions defined in one of a few formats:
Expand All @@ -533,7 +540,6 @@ def process_crs(crs):
try:
import cartopy.crs as ccrs
import geoviews as gv # noqa
import pyproj
except:
raise ImportError('Geographic projection support requires GeoViews and cartopy.')

Expand All @@ -547,7 +553,7 @@ def process_crs(crs):
raise ValueError("Could not parse EPSG code as CRS, must be of the format 'EPSG: {code}.'")
elif isinstance(crs, int):
crs = ccrs.epsg(crs)
elif isinstance(crs, (basestring, pyproj.Proj)):
elif isinstance(crs, basestring) or is_pyproj(crs):
try:
crs = proj_to_cartopy(crs)
except:
Expand Down