2
2
These are diagnostic and debugging functions for basemap.
3
3
"""
4
4
5
+ def proj4_version ():
6
+ """
7
+ Gives the proj.4 library's version number. (requires pyproj to be installed)
8
+
9
+ returns string, so proj.4 version 4.9.3 will return "4.9.3"
10
+ """
11
+ import pyproj
12
+
13
+ # Get PROJ4 version in a floating point number
14
+ proj4_ver_num = pyproj .Proj (proj = 'latlong' ).proj_version
15
+
16
+ # reformats floating point number into string (4.90 becomes '4.9.0')
17
+ # Exploits single number version numbers for proj4,
18
+ # This will need likely need to be change at some point as proj.4 version 4.10.0???
19
+ return '.' .join ( str (int (proj4_ver_num * 100 )) )
20
+
21
+
5
22
def package_versions ():
6
23
"""
7
24
Gives version information for dependent packages.
@@ -13,7 +30,7 @@ def package_versions():
13
30
14
31
from matplotlib import __version__ as matplotlib_version
15
32
from numpy import __version__ as numpy_version
16
- import pyproj
33
+ from pyproj import __version__ as pyproj_version
17
34
from shapefile import __version__ as pyshp_version
18
35
19
36
import _geoslib
@@ -35,10 +52,6 @@ def package_versions():
35
52
pil_version = 'not installed'
36
53
pillow_version = 'not installed'
37
54
38
- # Get PROJ.4 version info in a floating point number
39
- proj_ver_num = pyproj .Proj (init = 'epsg:4326' ).proj_version
40
- # reformats floating point number into string (4.90 becomes '4.9.0')
41
- proj4_version = '.' .join (list (str (int (proj_ver_num * 100 ))))
42
55
43
56
BasemapPackageVersions = namedtuple (
44
57
'BasemapPackageVersions' ,
@@ -51,11 +64,45 @@ def package_versions():
51
64
basemap = basemap_version ,
52
65
matplotlib = matplotlib_version ,
53
66
numpy = numpy_version ,
54
- pyproj = pyproj . __version__ ,
67
+ pyproj = pyproj_version ,
55
68
pyshp = pyshp_version ,
56
- PROJ4 = proj4_version ,
69
+ PROJ4 = proj4_version () ,
57
70
GEOS = _geoslib .__geos_version__ ,
58
71
# optional dependencies below
59
72
OWSLib = OWSLib_version ,
60
73
PIL = pil_version ,
61
74
Pillow = pillow_version )
75
+
76
+ def check_proj_inv_hammer (segfault_protection = True ):
77
+ """
78
+ Check if the inverse of the hammer projection is supported by installed
79
+ version of PROJ4.
80
+
81
+ segfault_protection True (default) - test while protecting from segfault
82
+ False - testing that might cause Python to segfault.
83
+ BE CAREFUL setting this flag to False!
84
+ If it segfaults, this the inverse hammer is not supported.
85
+
86
+ returns True - inverse hammer is supported
87
+ False - inverse hammer is not supported
88
+ "Unknown" - support is Unknown
89
+ """
90
+ from distutils .version import LooseVersion
91
+ from pyproj import __version__ as pyproj_version
92
+
93
+ if LooseVersion (proj4_version ()) > LooseVersion ('4.9.2' ):
94
+ return True
95
+
96
+ if LooseVersion (pyproj_version ) > LooseVersion ('1.9.5.1' ) \
97
+ or segfault_protection is False :
98
+ from pyproj import Proj
99
+ hammer = Proj (proj = 'hammer' )
100
+
101
+ x , y = hammer (- 30.0 , 40.0 )
102
+ try :
103
+ lon , lat = hammer (x , y , inverse = True )
104
+ return True
105
+ except RuntimeError :
106
+ return False
107
+
108
+ return 'Unknown'
0 commit comments