Skip to content

Commit

Permalink
return HUGE_VAL in Proj instead of 1.e30 (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Nov 24, 2019
1 parent 770ae72 commit 8092db1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
2 changes: 2 additions & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Change Log
~~~~~
* Elevate +init= warning to FutureWarning (pull #486)
* Add UserWarning to :meth:`~pyproj.crs.CRS.to_proj4` (pull #486)
* BUG: Fix for 32-bit i686 plaforms (issue #481)
* Return 'inf' in Proj instead of 1.e30 (pull #491)

2.4.1
~~~~~
Expand Down
33 changes: 17 additions & 16 deletions pyproj/_proj.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ from pyproj._datadir cimport pyproj_context_initialize
from pyproj.compat import cstrencode, pystrdecode
from pyproj.exceptions import ProjError


# # version number string for PROJ
proj_version_str = "{0}.{1}.{2}".format(
PROJ_VERSION_MAJOR,
Expand Down Expand Up @@ -55,10 +54,10 @@ cdef class Proj:
forward transformation - lons,lats to x,y (done in place).
if errcheck=True, an exception is raised if the forward transformation is invalid.
if errcheck=False and the forward transformation is invalid, no exception is
raised and 1.e30 is returned.
raised and 'inf' is returned.
"""
cdef PJ_COORD projxyout
cdef PJ_COORD projlonlatin = proj_coord(0, 0, 0, float("inf"))
cdef PJ_COORD projlonlatin = proj_coord(0, 0, 0, HUGE_VAL)
cdef Py_ssize_t buflenx, bufleny, ndim, iii
cdef double *lonsdata
cdef double *latsdata
Expand All @@ -81,7 +80,8 @@ cdef class Proj:
for iii in range(ndim):
# if inputs are nan's, return big number.
if lonsdata[iii] != lonsdata[iii] or latsdata[iii] != latsdata[iii]:
lonsdata[iii]=1.e30; latsdata[iii]=1.e30
lonsdata[iii] = HUGE_VAL
latsdata[iii] = HUGE_VAL
if errcheck:
with gil:
raise ProjError("projection_undefined")
Expand Down Expand Up @@ -110,9 +110,9 @@ cdef class Proj:
projxyout.xy.x != projxyout.xy.x:
if errcheck:
with gil:
raise ProjError("projection_undefined")
lonsdata[iii] = 1.e30
latsdata[iii] = 1.e30
raise ProjError("Projection undefined.")
lonsdata[iii] = HUGE_VAL
latsdata[iii] = HUGE_VAL
elif proj_angular_output(self.projobj, PJ_FWD):
lonsdata[iii] = _RAD2DG * projxyout.xy.x
latsdata[iii] = _RAD2DG * projxyout.xy.y
Expand All @@ -129,12 +129,12 @@ cdef class Proj:
inverse transformation - x,y to lons,lats (done in place).
if errcheck=True, an exception is raised if the inverse transformation is invalid.
if errcheck=False and the inverse transformation is invalid, no exception is
raised and 1.e30 is returned.
raised and 'inf' is returned.
"""
if not self.has_inverse:
raise ProjError('inverse projection undefined')

cdef PJ_COORD projxyin = proj_coord(0, 0, 0, float("inf"))
cdef PJ_COORD projxyin = proj_coord(0, 0, 0, HUGE_VAL)
cdef PJ_COORD projlonlatout
cdef Py_ssize_t buflenx, bufleny, ndim, iii
cdef void *xdata
Expand All @@ -161,17 +161,18 @@ cdef class Proj:
for iii in range(ndim):
# if inputs are nan's, return big number.
if xdatab[iii] != xdatab[iii] or ydatab[iii] != ydatab[iii]:
xdatab[iii]=1.e30; ydatab[iii]=1.e30
xdatab[iii] = HUGE_VAL
ydatab[iii] = HUGE_VAL
if errcheck:
with gil:
raise ProjError("projection_undefined")
continue
if proj_angular_input(self.projobj, PJ_INV):
projxyin.uv.u = _DG2RAD * xdatab[iii]
projxyin.uv.v = _DG2RAD * ydatab[iii]
projxyin.xy.x = _DG2RAD * xdatab[iii]
projxyin.xy.y = _DG2RAD * ydatab[iii]
else:
projxyin.uv.u = xdatab[iii]
projxyin.uv.v = ydatab[iii]
projxyin.xy.x = xdatab[iii]
projxyin.xy.y = ydatab[iii]
projlonlatout = proj_trans(self.projobj, PJ_INV, projxyin)
errno = proj_errno(self.projobj)
if errcheck and errno:
Expand All @@ -192,8 +193,8 @@ cdef class Proj:
if errcheck:
with gil:
raise ProjError("projection_undefined")
xdatab[iii] = 1.e30
ydatab[iii] = 1.e30
xdatab[iii] = HUGE_VAL
ydatab[iii] = HUGE_VAL
elif proj_angular_output(self.projobj, PJ_INV):
xdatab[iii] = _RAD2DG * projlonlatout.uv.u
ydatab[iii] = _RAD2DG * projlonlatout.uv.v
Expand Down
7 changes: 3 additions & 4 deletions pyproj/base.pxi
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import math
from math import radians, degrees

cdef double _DG2RAD = math.radians(1.)
cdef double _RAD2DG = math.degrees(1.)
cdef double _DG2RAD = radians(1.)
cdef double _RAD2DG = degrees(1.)
cdef int _DOUBLESIZE = sizeof(double)

cdef extern from "math.h":
cdef enum:
HUGE_VAL
FP_NAN

cdef extern from "Python.h":
int PyObject_AsWriteBuffer(object, void **rbuf, Py_ssize_t *len)
Expand Down
4 changes: 2 additions & 2 deletions pyproj/proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Proj(_proj.Proj):
lon/lat is performed. If optional keyword 'errcheck' is True (default is
False) an exception is raised if the transformation is invalid.
If errcheck=False and the transformation is invalid, no
exception is raised and 1.e30 is returned. If the optional keyword
exception is raised and 'inf' is returned. If the optional keyword
'preserve_units' is True, the units in map projection coordinates
are not forced to be meters.
Expand Down Expand Up @@ -180,7 +180,7 @@ def __call__(self, *args, **kw):
lon/lat is performed. If optional keyword 'errcheck' is True (default is
False) an exception is raised if the transformation is invalid.
If errcheck=False and the transformation is invalid, no
exception is raised and 1.e30 is returned.
exception is raised and 'inf' is returned.
Inputs should be doubles (they will be cast to doubles if they
are not, causing a slight performance hit).
Expand Down

0 comments on commit 8092db1

Please sign in to comment.