Skip to content

Commit 27ee6ae

Browse files
committed
Added checks and look up options for epsg file.
Since version 2.0, pyproj comes with an internal data directory that is used in favor of the one set by the PROJ_LIB environment variable (or, on Linux, of the default proj folder set by PROJ.4). It appears this internal directory sometimes does not contain the epsg file (at least on Linux), which may however be found by looking up those other locations. This commit therefore adds attempts to look up for the epsg file when it cannot be found in pyproj's internal datadir.
1 parent f2079dd commit 27ee6ae

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,27 @@
149149
}
150150

151151
# create dictionary that maps epsg codes to Basemap kwargs.
152-
if hasattr(pyproj, 'datadir'):
153-
epsgf = open(os.path.join(pyproj.datadir.get_data_dir(), 'epsg'))
154-
else:
155-
epsgf = open(os.path.join(pyproj.pyproj_datadir, 'epsg'))
152+
if hasattr(pyproj, 'datadir'): # pyproj version 2+
153+
epsgf = os.path.join(pyproj.datadir.get_data_dir(), 'epsg')
154+
if not os.path.isfile(epsgf):
155+
if os.name == 'posix':
156+
epsgf = os.environ.get('PROJ_LIB', '/usr/share/proj')
157+
elif 'PROJ_LIB' in os.environ:
158+
epsgf = os.environ['PROJ_LIB']
159+
else:
160+
raise FileNotFoundError(
161+
("Cannot find '%s'" % epsgf)
162+
+ "and PROJ_LIB environment variable is not set."
163+
)
164+
epsgf = os.path.join(epsgf, 'epsg')
165+
if not os.path.isfile(epsgf):
166+
raise FileNotFoundError(
167+
("Cannot find '%s'" % epsgf)
168+
+ "nor epsg file under pyproj's internal datadir."
169+
)
170+
else: # older versions of pyproj
171+
epsgf = os.path.join(pyproj.pyproj_datadir, 'epsg')
172+
epsgf = open(epsgf)
156173
epsg_dict={}
157174
for line in epsgf:
158175
if line.startswith("#"):

0 commit comments

Comments
 (0)