From 7cae73fd897dff48639d1c5774b090df2b008c37 Mon Sep 17 00:00:00 2001 From: "Alan D. Snow" Date: Mon, 22 Apr 2019 20:38:58 -0500 Subject: [PATCH] fixed initialization from non DerivedGeographicCRS (fixes #270) (#272) --- pyproj/crs.py | 11 ++++++++--- pyproj/proj.py | 4 +++- test/test_proj.py | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 test/test_proj.py diff --git a/pyproj/crs.py b/pyproj/crs.py index e1426be06..d00b8be86 100644 --- a/pyproj/crs.py +++ b/pyproj/crs.py @@ -41,18 +41,23 @@ def _dict2string(projparams): # convert a dict to a proj4 string. pjargs = [] + proj_inserted = False for key, value in projparams.items(): # the towgs84 as list if isinstance(value, (list, tuple)): value = ",".join([str(val) for val in value]) # issue 183 (+ no_rot) if value is None or value is True: - pjargs.append("+" + key + " ") + pjargs.append("+{key}".format(key=key)) elif value is False: pass + # make sure string starts with proj or init + elif not proj_inserted and key in ("init", "proj"): + pjargs.insert(0, "+{key}={value}".format(key=key, value=value)) + proj_inserted = True else: - pjargs.append("+" + key + "=" + str(value) + " ") - return "".join(pjargs) + pjargs.append("+{key}={value}".format(key=key, value=value)) + return " ".join(pjargs) class CRS(_CRS): diff --git a/pyproj/proj.py b/pyproj/proj.py index 1f6f1fa94..58be2bcab 100644 --- a/pyproj/proj.py +++ b/pyproj/proj.py @@ -143,7 +143,9 @@ def __init__(self, projparams=None, preserve_units=True, **kwargs): projstring += " +units=m" self.crs = CRS(projstring) super(Proj, self).__init__( - cstrencode(self.crs.to_proj4().replace("+type=crs", "").strip()) + cstrencode( + (self.crs.to_proj4() or self.crs.srs).replace("+type=crs", "").strip() + ) ) def __call__(self, *args, **kw): diff --git a/test/test_proj.py b/test/test_proj.py new file mode 100644 index 000000000..d78c05c81 --- /dev/null +++ b/test/test_proj.py @@ -0,0 +1,16 @@ +from pyproj import Proj + + +def test_initialize_proj_crs_no_proj4(): + proj = Proj( + { + "a": 6371229.0, + "b": 6371229.0, + "lon_0": -10.0, + "o_lat_p": 30.0, + "o_lon_p": 0.0, + "o_proj": "longlat", + "proj": "ob_tran", + } + ) + assert proj.srs.startswith("+proj=ob_tran")