Skip to content

Commit

Permalink
fixed initialization from non DerivedGeographicCRS (fixes #270) (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Apr 23, 2019
1 parent d8eb3f9 commit 7cae73f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
11 changes: 8 additions & 3 deletions pyproj/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion pyproj/proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 16 additions & 0 deletions test/test_proj.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 7cae73f

Please sign in to comment.