Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, earth, polyline = False):
from pyproj.geodesic import Geodesic
self._earth = earth
self._area0 = 4 * math.pi * earth._c2
self._polyline = polyline
self._mask = Geodesic.DISTANCE
if not self._polyline:
self._mask |= Geodesic.AREA
self._areasum = Accumulator()
self._perimetersum = Accumulator()
self.Clear()
def __init__(self, earth, polyline = False):
from pyproj.geodesic import Geodesic
self._earth = earth
self._area0 = 4 * math.pi * earth._c2
self._polyline = polyline
self._mask = Geodesic.DISTANCE
if not self._polyline:
self._mask |= Geodesic.AREA
self._areasum = Accumulator()
self._perimetersum = Accumulator()
self.Clear()
B12 = - Geodesic.SinCosSeries(True, self._stau1 * c + self._ctau1 * s,
self._ctau1 * c - self._stau1 * s,
self._C1pa, Geodesic.nC1p_)
sig12 = tau12 - (B12 - self._B11)
ssig12 = math.sin(sig12); csig12 = math.cos(sig12)
# real omg12, lam12, lon12
# real ssig2, csig2, sbet2, cbet2, somg2, comg2, salp2, calp2
# sig2 = sig1 + sig12
ssig2 = self._ssig1 * csig12 + self._csig1 * ssig12
csig2 = self._csig1 * csig12 - self._ssig1 * ssig12
if outmask & (
Geodesic.DISTANCE | Geodesic.REDUCEDLENGTH | Geodesic.GEODESICSCALE):
if arcmode:
B12 = Geodesic.SinCosSeries(True, ssig2, csig2,
self._C1a, Geodesic.nC1_)
AB1 = (1 + self._A1m1) * (B12 - self._B11)
# sin(bet2) = cos(alp0) * sin(sig2)
sbet2 = self._calp0 * ssig2
# Alt: cbet2 = hypot(csig2, salp0 * ssig2)
cbet2 = math.hypot(self._salp0, self._calp0 * csig2)
if cbet2 == 0:
# I.e., salp0 = 0, csig2 = 0. Break the degeneracy in this case
cbet2 = csig2 = Geodesic.tiny_
# tan(omg2) = sin(alp0) * tan(sig2)
somg2 = self._salp0 * ssig2; comg2 = csig2 # No need to normalize
# tan(alp0) = cos(sig2)*tan(alp2)
salp2 = self._salp0; calp2 = self._calp0 * csig2 # No need to normalize
# omg12 = omg2 - omg1
omg12 = math.atan2(somg2 * self._comg1 - comg2 * self._somg1,
comg2 * self._comg1 + somg2 * self._somg1)
s12 = self._b * ((1 + self._A1m1) * sig12 + AB1)
else:
s12 = s12_a12
if outmask & Geodesic.LONGITUDE:
lam12 = omg12 + self._A3c * (
sig12 + (Geodesic.SinCosSeries(True, ssig2, csig2,
self._C3a, Geodesic.nC3_-1)
- self._B31))
lon12 = lam12 / Math.degree
# Can't use AngNormalize because longitude might have wrapped multiple
# times.
lon12 = lon12 - 360 * math.floor(lon12/360 + 0.5)
lon2 = Geodesic.AngNormalize(self._lon1 + lon12)
if outmask & Geodesic.LATITUDE:
lat2 = math.atan2(sbet2, self._f1 * cbet2) / Math.degree
if outmask & Geodesic.AZIMUTH:
# minus signs give range [-180, 180). 0- converts -0 to +0.
azi2 = 0 - math.atan2(-salp2, calp2) / Math.degree
if outmask & (Geodesic.REDUCEDLENGTH | Geodesic.GEODESICSCALE):
ssig1sq = Math.sq(self._ssig1)
ssig2sq = Math.sq( ssig2)
w1 = math.sqrt(1 + self._k2 * ssig1sq)
w2 = math.sqrt(1 + self._k2 * ssig2sq)
B22 = Geodesic.SinCosSeries(True, ssig2, csig2, self._C2a, Geodesic.nC2_)
AB2 = (1 + self._A2m1) * (B22 - self._B21)
J12 = (self._A1m1 - self._A2m1) * sig12 + (AB1 - AB2)
if outmask & Geodesic.REDUCEDLENGTH:
# Add parens around (_csig1 * ssig2) and (_ssig1 * csig2) to ensure
if outmask & (Geodesic.REDUCEDLENGTH | Geodesic.GEODESICSCALE):
ssig1sq = Math.sq(self._ssig1)
ssig2sq = Math.sq( ssig2)
w1 = math.sqrt(1 + self._k2 * ssig1sq)
w2 = math.sqrt(1 + self._k2 * ssig2sq)
B22 = Geodesic.SinCosSeries(True, ssig2, csig2, self._C2a, Geodesic.nC2_)
AB2 = (1 + self._A2m1) * (B22 - self._B21)
J12 = (self._A1m1 - self._A2m1) * sig12 + (AB1 - AB2)
if outmask & Geodesic.REDUCEDLENGTH:
# Add parens around (_csig1 * ssig2) and (_ssig1 * csig2) to ensure
# accurate cancellation in the case of coincident points.
m12 = self._b * ((w2 * (self._csig1 * ssig2) -
w1 * (self._ssig1 * csig2))
- self._csig1 * csig2 * J12)
if outmask & Geodesic.GEODESICSCALE:
M12 = csig12 + (self._k2 * (ssig2sq - ssig1sq) * ssig2 / (w1 + w2)
- csig2 * J12) * self._ssig1 / w1
M21 = csig12 - (self._k2 * (ssig2sq - ssig1sq) * self._ssig1 / (w1 + w2)
- self._csig1 * J12) * ssig2 / w2
if outmask & Geodesic.AREA:
B42 = Geodesic.SinCosSeries(False, ssig2, csig2, self._C4a, Geodesic.nC4_)
# real salp12, calp12
if self._calp0 == 0 or self._salp0 == 0:
# alp12 = alp2 - alp1, used in atan2 so no need to normalized
salp12 = salp2 * self._calp1 - calp2 * self._salp1
calp12 = calp2 * self._calp1 + salp2 * self._salp1
# The right thing appears to happen if alp1 = +/-180 and alp2 = 0, viz
# salp12 = -0 and alp12 = -180. However this depends on the sign being
# attached to 0 correctly. The following ensures the correct behavior.
if salp12 == 0 and calp12 < 0:
# sig2 = sig1 + sig12
ssig2 = self._ssig1 * csig12 + self._csig1 * ssig12
csig2 = self._csig1 * csig12 - self._ssig1 * ssig12
if outmask & (
Geodesic.DISTANCE | Geodesic.REDUCEDLENGTH | Geodesic.GEODESICSCALE):
if arcmode:
B12 = Geodesic.SinCosSeries(True, ssig2, csig2,
self._C1a, Geodesic.nC1_)
AB1 = (1 + self._A1m1) * (B12 - self._B11)
# sin(bet2) = cos(alp0) * sin(sig2)
sbet2 = self._calp0 * ssig2
# Alt: cbet2 = hypot(csig2, salp0 * ssig2)
cbet2 = math.hypot(self._salp0, self._calp0 * csig2)
if cbet2 == 0:
# I.e., salp0 = 0, csig2 = 0. Break the degeneracy in this case
cbet2 = csig2 = Geodesic.tiny_
# tan(omg2) = sin(alp0) * tan(sig2)
somg2 = self._salp0 * ssig2; comg2 = csig2 # No need to normalize
# tan(alp0) = cos(sig2)*tan(alp2)
salp2 = self._salp0; calp2 = self._calp0 * csig2 # No need to normalize
# omg12 = omg2 - omg1
omg12 = math.atan2(somg2 * self._comg1 - comg2 * self._somg1,
comg2 * self._comg1 + somg2 * self._somg1)
if outmask & Geodesic.DISTANCE:
if arcmode:
s12 = self._b * ((1 + self._A1m1) * sig12 + AB1)
else:
s12 = s12_a12
if outmask & Geodesic.LONGITUDE:
lam12 = omg12 + self._A3c * (
if outmask & Geodesic.LONGITUDE:
lam12 = omg12 + self._A3c * (
sig12 + (Geodesic.SinCosSeries(True, ssig2, csig2,
self._C3a, Geodesic.nC3_-1)
- self._B31))
lon12 = lam12 / Math.degree
# Can't use AngNormalize because longitude might have wrapped multiple
# times.
lon12 = lon12 - 360 * math.floor(lon12/360 + 0.5)
lon2 = Geodesic.AngNormalize(self._lon1 + lon12)
if outmask & Geodesic.LATITUDE:
lat2 = math.atan2(sbet2, self._f1 * cbet2) / Math.degree
if outmask & Geodesic.AZIMUTH:
# minus signs give range [-180, 180). 0- converts -0 to +0.
azi2 = 0 - math.atan2(-salp2, calp2) / Math.degree
if outmask & (Geodesic.REDUCEDLENGTH | Geodesic.GEODESICSCALE):
ssig1sq = Math.sq(self._ssig1)
ssig2sq = Math.sq( ssig2)
w1 = math.sqrt(1 + self._k2 * ssig1sq)
w2 = math.sqrt(1 + self._k2 * ssig2sq)
B22 = Geodesic.SinCosSeries(True, ssig2, csig2, self._C2a, Geodesic.nC2_)
AB2 = (1 + self._A2m1) * (B22 - self._B21)
J12 = (self._A1m1 - self._A2m1) * sig12 + (AB1 - AB2)
if outmask & Geodesic.REDUCEDLENGTH:
# Add parens around (_csig1 * ssig2) and (_ssig1 * csig2) to ensure
# accurate cancellation in the case of coincident points.
m12 = self._b * ((w2 * (self._csig1 * ssig2) -
w1 * (self._ssig1 * csig2))
cbet2 = csig2 = Geodesic.tiny_
# tan(omg2) = sin(alp0) * tan(sig2)
somg2 = self._salp0 * ssig2; comg2 = csig2 # No need to normalize
# tan(alp0) = cos(sig2)*tan(alp2)
salp2 = self._salp0; calp2 = self._calp0 * csig2 # No need to normalize
# omg12 = omg2 - omg1
omg12 = math.atan2(somg2 * self._comg1 - comg2 * self._somg1,
comg2 * self._comg1 + somg2 * self._somg1)
if outmask & Geodesic.DISTANCE:
if arcmode:
s12 = self._b * ((1 + self._A1m1) * sig12 + AB1)
else:
s12 = s12_a12
if outmask & Geodesic.LONGITUDE:
lam12 = omg12 + self._A3c * (
sig12 + (Geodesic.SinCosSeries(True, ssig2, csig2,
self._C3a, Geodesic.nC3_-1)
- self._B31))
lon12 = lam12 / Math.degree
# Can't use AngNormalize because longitude might have wrapped multiple
# times.
lon12 = lon12 - 360 * math.floor(lon12/360 + 0.5)
lon2 = Geodesic.AngNormalize(self._lon1 + lon12)
if outmask & Geodesic.LATITUDE:
lat2 = math.atan2(sbet2, self._f1 * cbet2) / Math.degree
if outmask & Geodesic.AZIMUTH:
# minus signs give range [-180, 180). 0- converts -0 to +0.
azi2 = 0 - math.atan2(-salp2, calp2) / Math.degree