Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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):
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 * (( dn2 * (self._csig1 * ssig2) -
self._dn1 * (self._ssig1 * csig2))
- self._csig1 * csig2 * J12)
if outmask & Geodesic.GEODESICSCALE:
t = (self._k2 * (ssig2 - self._ssig1) *
(ssig2 + self._ssig1) / (self._dn1 + dn2))
M12 = csig12 + (t * ssig2 - csig2 * J12) * self._ssig1 / self._dn1
M21 = csig12 - (t * self._ssig1 - self._csig1 * J12) * ssig2 / dn2
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:
def get_next_position(self, origin_lat, origin_lng, origin_alt, dest_lat, dest_lng, dest_alt, distance):
polyline = PolylineObjectHandler.cached_polyline((self.bot.position[0], self.bot.position[1]), (dest_lat, dest_lng), google_map_api_key=self.bot.config.gmapkey)
while True:
_, (dest_lat, dest_lng) = polyline._step_dict[polyline._step_keys[polyline._last_step]]
next_lat, next_lng, _ = super(PolylineWalker, self).get_next_position(origin_lat, origin_lng, origin_alt, dest_lat, dest_lng, dest_alt, distance)
if polyline._last_step == len(polyline._step_keys) - 1:
break
else:
travelled = Geodesic.WGS84.Inverse(origin_lat, origin_lng, next_lat, next_lng)["s12"]
remaining = Geodesic.WGS84.Inverse(next_lat, next_lng, dest_lat, dest_lng)["s12"]
step_distance = Geodesic.WGS84.Inverse(origin_lat, origin_lng, dest_lat, dest_lng)["s12"]
if remaining < (self.precision + self.epsilon):
polyline._last_step += 1
distance = abs(distance - step_distance)
else:
distance = abs(distance - travelled)
if distance > (self.precision + self.epsilon):
origin_lat, origin_lng, origin_alt = dest_lat, dest_lng, dest_alt
else:
break
polyline._last_pos = (next_lat, next_lng)
next_alt = polyline.get_alt() or origin_alt
return next_lat, next_lng, next_alt + random_alt_delta()
salp2 = self._salp0; calp2 = self._calp0 * csig2 # No need to normalize
if outmask & Geodesic.DISTANCE:
s12 = self._b * ((1 + self._A1m1) * sig12 + AB1) if arcmode else s12_a12
if outmask & Geodesic.LONGITUDE:
# tan(omg2) = sin(alp0) * tan(sig2)
somg2 = self._salp0 * ssig2; comg2 = csig2 # No need to normalize
E = Math.copysign(1, self._salp0) # East or west going?
# omg12 = omg2 - omg1
omg12 = (E * (sig12
- (math.atan2( ssig2, csig2) -
math.atan2( self._ssig1, self._csig1))
+ (math.atan2(E * somg2, comg2) -
math.atan2(E * self._somg1, self._comg1)))
if outmask & Geodesic.LONG_UNROLL
else math.atan2(somg2 * self._comg1 - comg2 * self._somg1,
comg2 * self._comg1 + somg2 * self._somg1))
lam12 = omg12 + self._A3c * (
sig12 + (Geodesic._SinCosSeries(True, ssig2, csig2, self._C3a)
- self._B31))
lon12 = math.degrees(lam12)
lon2 = (self.lon1 + lon12 if outmask & Geodesic.LONG_UNROLL else
Math.AngNormalize(Math.AngNormalize(self.lon1) +
Math.AngNormalize(lon12)))
if outmask & Geodesic.LATITUDE:
lat2 = Math.atan2d(sbet2, self._f1 * cbet2)
if outmask & Geodesic.AZIMUTH:
azi2 = Math.atan2d(salp2, calp2)
(*lat1*, *lon1*), with azimuth *azi1* to be found. The default
value of *caps* is STANDARD | DISTANCE_IN. The optional parameters
*salp1* and *calp1* should not be supplied; they are part of the
private interface.
"""
from geographiclib.geodesic import Geodesic
self.a = geod.a
"""The equatorial radius in meters (readonly)"""
self.f = geod.f
"""The flattening (readonly)"""
self._b = geod._b
self._c2 = geod._c2
self._f1 = geod._f1
self.caps = (caps | Geodesic.LATITUDE | Geodesic.AZIMUTH |
Geodesic.LONG_UNROLL)
"""the capabilities (readonly)"""
# Guard against underflow in salp0
self.lat1 = Math.LatFix(lat1)
"""the latitude of the first point in degrees (readonly)"""
self.lon1 = lon1
"""the longitude of the first point in degrees (readonly)"""
if Math.isnan(salp1) or Math.isnan(calp1):
self.azi1 = Math.AngNormalize(azi1)
self.salp1, self.calp1 = Math.sincosd(Math.AngRound(azi1))
else:
self.azi1 = azi1
"""the azimuth at the first point in degrees (readonly)"""
self.salp1 = salp1
"""the sine of the azimuth at the first point (readonly)"""
for vcnt, vertex in enumerate(vertices):
v = geom_to_4326.transform(vertex.x(), vertex.y())
gline = geod.Inverse(cy, cx, v.y(), v.x())
vdist = gline['s12']
vazi = gline['azi1']
if mode == 0: # flip horizontally
vazi = -1.0 * vazi
elif mode == 1: # Flip vertically
vazi = -1.0 * (vazi + 180)
elif mode == 2: # Rotate 180
vazi += 180
elif mode == 3: # Rotate 90
vazi += 90
else:
vazi -= 90 # Rotate -90
g = geod.Direct(cy, cx, vazi, vdist, Geodesic.LATITUDE | Geodesic.LONGITUDE)
new_vertex = to_sink_crs.transform(g['lon2'], g['lat2'])
geom.moveVertex(new_vertex.x(), new_vertex.y(), vcnt)
layer.changeGeometry(feature.id(), geom)
layer.updateExtents()
iface.mapCanvas().refresh()
def Geodesic(self):
'''(INTERNAL) Get the wrapped C{Geodesic} class, provided the
U{GeographicLib}
package is installed, otherwise throw an C{ImportError}.
'''
if _Wrapped._Geodesic is None:
from geographiclib.geodesic import Geodesic as _Geodesic
class Geodesic(_Geodesic):
'''Karney U{Geodesic } wrapper.
'''
def Direct(self, lat1, lon1, azi1, s12, *outmask):
'''Return the C{Direct} result.
'''
d = _Geodesic.Direct(self, lat1, lon1, azi1, s12, *outmask)
return _Adict(d)
def Direct3(self, lat1, lon1, azi1, s12): # PYCHOK outmask
'''Return the destination lat, lon and reverse azimth
in C{degrees}.
'''
m = self.AZIMUTH | self.LATITUDE | self.LONGITUDE
d = self.Direct(lat1, lon1, azi1, s12, m)
"""Construct a PolygonArea object
:param earth: a :class:`~geographiclib.geodesic.Geodesic` object
:param polyline: if true, treat object as a polyline instead of a polygon
Initially the polygon has no vertices.
"""
from geographiclib.geodesic import Geodesic
self.earth = earth
"""The geodesic object (readonly)"""
self.polyline = polyline
"""Is this a polyline? (readonly)"""
self.area0 = 4 * math.pi * earth._c2
"""The total area of the ellipsoid in meter^2 (readonly)"""
self._mask = (Geodesic.LATITUDE | Geodesic.LONGITUDE |
Geodesic.DISTANCE |
(Geodesic.EMPTY if self.polyline else
Geodesic.AREA | Geodesic.LONG_UNROLL))
if not self.polyline: self._areasum = Accumulator()
self._perimetersum = Accumulator()
self.num = 0
"""The current number of points in the polygon (readonly)"""
self.lat1 = Math.nan
"""The current latitude in degrees (readonly)"""
self.lon1 = Math.nan
"""The current longitude in degrees (readonly)"""
self.Clear()