Skip to content

Commit

Permalink
Add return_back_azimuth: bool = False to allow compatibility betwee…
Browse files Browse the repository at this point in the history
…n the azimuth output of `fwd` and `fwd_intermediate` (`.. versionadded:: 3.5.0 return_back_azimuth`)
  • Loading branch information
idanmiara committed Oct 25, 2022
1 parent cf4403e commit 12b7f19
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 21 deletions.
4 changes: 4 additions & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Change Log
Latest
-------

3.5.0
-----
- ENH: Add `return_back_azimuth: bool` to allow compatibility between the azimuth output of `fwd` and `fwd_intermediate` (issue #1163)

3.4.1
-----
- BUG: Changed so that the setup.cfg depends on the version code in the __init__.py instead of the other way around (issuue #1155)
Expand Down
1 change: 1 addition & 0 deletions pyproj/_geod.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Geod:
out_lons: Any,
out_lats: Any,
out_azis: Any,
return_back_azimuth: bool,
) -> GeodIntermediateReturn: ...
def _line_length(self, lons: Any, lats: Any, radians: bool = False) -> float: ...
def _polygon_area_perimeter(
Expand Down
6 changes: 6 additions & 0 deletions pyproj/_geod.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ cdef class Geod:
object out_lons,
object out_lats,
object out_azis,
bint return_back_azimuth,
) -> GeodIntermediateReturn:
"""
.. versionadded:: 3.1.0
Expand Down Expand Up @@ -312,6 +313,11 @@ cdef class Geod:
lats_buff.data[iii] = plat2
lons_buff.data[iii] = plon2
if store_az:
if return_back_azimuth:
if pazi2 > 0:
pazi2 = pazi2 - 180.
elif pazi2 <= 0:
pazi2 = pazi2 + 180.
azis_buff.data[iii] = pazi2

return GeodIntermediateReturn(
Expand Down
13 changes: 13 additions & 0 deletions pyproj/geod.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ def npts(
out_lons=None,
out_lats=None,
out_azis=None,
return_back_azimuth=False,
)
return list(zip(res.lons, res.lats))

Expand All @@ -487,9 +488,11 @@ def inv_intermediate(
out_lons: Any = None,
out_lats: Any = None,
out_azis: Any = None,
return_back_azimuth: bool = False,
) -> GeodIntermediateReturn:
"""
.. versionadded:: 3.1.0
.. versionadded:: 3.5.0 return_back_azimuth
Given a single initial point and terminus point,
and the number of points, returns
Expand Down Expand Up @@ -598,6 +601,9 @@ def inv_intermediate(
az12(s) of the intermediate point(s)
If None then buffers would be allocated internnaly
unless requested otherwise by the flags
return_back_azimuth: bool, default=False
if True, out_azis will store the back azimuth,
Otherwise, out_azis will store the forward azimuth.
Returns
-------
Expand All @@ -618,6 +624,7 @@ def inv_intermediate(
out_lons=out_lons,
out_lats=out_lats,
out_azis=out_azis,
return_back_azimuth=return_back_azimuth,
)

def fwd_intermediate(
Expand All @@ -634,9 +641,11 @@ def fwd_intermediate(
out_lons: Any = None,
out_lats: Any = None,
out_azis: Any = None,
return_back_azimuth: bool = False,
) -> GeodIntermediateReturn:
"""
.. versionadded:: 3.1.0
.. versionadded:: 3.5.0 return_back_azimuth
Given a single initial point and azimuth, number of points (npts)
and delimiter distance between two successive points (del_s), returns
Expand Down Expand Up @@ -730,6 +739,9 @@ def fwd_intermediate(
az12(s) of the intermediate point(s)
If None then buffers would be allocated internnaly
unless requested otherwise by the flags
return_back_azimuth: bool, default=False
if True, out_azis will store the back azimuth,
Otherwise, out_azis will store the forward azimuth.
Returns
-------
Expand All @@ -750,6 +762,7 @@ def fwd_intermediate(
out_lons=out_lons,
out_lats=out_lats,
out_azis=out_azis,
return_back_azimuth=return_back_azimuth,
)

def line_length(self, lons: Any, lats: Any, radians: bool = False) -> float:
Expand Down
51 changes: 30 additions & 21 deletions test/test_geod.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from pyproj import Geod
from pyproj.geod import GeodIntermediateFlag
from pyproj.utils import reverse_azimuth_arr

try:
from shapely.geometry import (
Expand Down Expand Up @@ -230,27 +231,35 @@ def test_geod_inverse_transform():
assert_almost_equal(res.azis, azis_a)

print("test fwd_intermediate")
res = gg.fwd_intermediate(
out_lons=lons_b,
out_lats=lats_b,
out_azis=azis_b,
lon1=lon1pt,
lat1=lat1pt,
azi1=true_az12,
npts=point_count,
del_s=del_s,
initial_idx=0,
terminus_idx=0,
)
assert res.npts == point_count
assert_almost_equal(res.del_s, del_s)
assert_almost_equal(res.dist, dist)
assert_almost_equal(res.lons, lons_a)
assert_almost_equal(res.lats, lats_a)
assert_almost_equal(res.azis, azis_a)
assert res.lons is lons_b
assert res.lats is lats_b
assert res.azis is azis_b
for return_back_azimuth in [False, True]:
lons_b = np.empty(point_count)
lats_b = np.empty(point_count)
azis_b = np.empty(point_count)

res = gg.fwd_intermediate(
out_lons=lons_b,
out_lats=lats_b,
out_azis=azis_b,
lon1=lon1pt,
lat1=lat1pt,
azi1=true_az12,
npts=point_count,
del_s=del_s,
initial_idx=0,
terminus_idx=0,
return_back_azimuth=return_back_azimuth,
)
assert res.npts == point_count
assert_almost_equal(res.del_s, del_s)
assert_almost_equal(res.dist, dist)
assert_almost_equal(res.lons, lons_a)
assert_almost_equal(res.lats, lats_a)
if return_back_azimuth:
reverse_azimuth_arr(azis_b)
assert_almost_equal(res.azis, azis_a)
assert res.lons is lons_b
assert res.lats is lats_b
assert res.azis is azis_b

print("test inv_intermediate (by del_s)")
for del_s_fact, flags in (
Expand Down

0 comments on commit 12b7f19

Please sign in to comment.