Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_output_format(self):
bbox = self.method([Point(50, 160), Point(30, 170)],
" %(lon2)s|%(lat2)s -- %(lat1)s|%(lon1)s ")
self.assertEqual(bbox, " 170.0|50.0 -- 30.0|160.0 ")
def test_point_setitem_normalization(self):
point = Point()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
with self.assertRaises(ValueError):
point[0] = 100
self.assertEqual(1, len(w))
self.assertEqual((0, 0, 0), tuple(point))
point[0] = -80
point[1] = 200
# Please note that attribute assignments are not normalized.
# Only __setitem__ assignments are.
self.assertEqual((-80, -160, 0), tuple(point))
with self.assertRaises(ValueError):
point[1] = float("nan")
self.assertEqual(1, len(w))
self.assertEqual((-80, -160, 0), tuple(point))
def test_reverse_with_language_de(self):
"""
Here.reverse using point and language parameter to get a non-English response
"""
res = self.reverse_run(
{"query": Point(40.753898, -73.985071), "language": "de-DE"},
{}
)
self.assertIn("Vereinigte Staaten", res.address)
def test_reverse_with_include_country_code(self):
"""
Bing.reverse using point and include country-code in the response
"""
res = self.reverse_run(
{"query": Point(40.753898, -73.985071),
"include_country_code": True},
{},
)
self.assertEqual(res.raw["address"].get("countryRegionIso2", 'missing'), 'US')
def test_point_from_string(self):
# Examples are from the docstring of `Point.from_string`.
self.assertEqual(Point("41.5;-81.0"), (41.5, -81.0, 0.0))
self.assertEqual(Point("41.5,-81.0"), (41.5, -81.0, 0.0))
self.assertEqual(Point("41.5 -81.0"), (41.5, -81.0, 0.0))
self.assertEqual(Point("41.5 N -81.0 W"), (41.5, 81.0, 0.0))
self.assertEqual(Point("-41.5 S;81.0 E"), (41.5, 81.0, 0.0))
self.assertEqual(Point("23 26m 22s N 23 27m 30s E"),
(23.439444444444444, 23.458333333333332, 0.0))
self.assertEqual(Point("23 26' 22\" N 23 27' 30\" E"),
(23.439444444444444, 23.458333333333332, 0.0))
self.assertEqual(Point(u("UT: N 39\xb020' 0'' / W 74\xb035' 0''")),
(39.333333333333336, -74.58333333333333, 0.0))
def test_point_assign_coordinates(self):
point = Point(self.lat + 10, self.lon + 10, self.alt + 10)
point.latitude = self.lat
point.longitude = self.lon
point.altitude = self.alt
self.assertEqual(point[0], self.lat)
self.assertEqual(point[1], self.lon)
self.assertEqual(point[2], self.alt)
self.assertEqual(self.coords, tuple(point))
self.assertEqual(point.latitude, self.lat)
self.assertEqual(point.longitude, self.lon)
self.assertEqual(point.altitude, self.alt)
def _get_point(p):
"""
Convert to geopy Point
"""
if isinstance(p, GPoint):
return p
elif isinstance(p, list):
return GPoint(p[1], p[0])
elif isinstance(p, geojson.Point):
return GPoint(p.coordinates[1], p.coordinates[0])
elif isinstance(p, dict) and "coordinates" in p:
return GPoint(p["coordinates"][1], p["coordinates"][0])
elif isinstance(p, dict) and "geopoint" in p:
return GPoint(p["geopoint"]["y"], p["geopoint"]["x"])
else:
return GPoint(p.y, p.x)
def addDistanceToPoint(self,startPoint, distanceXinMeter, distanceYinMeter):
currentPoint = Point(startPoint.latitude, startPoint.longitude)
oldLatitude = startPoint.latitude
currentPoint.latitude += (distanceYinMeter / self.MIDLE_EARTH_RADIUS_IN_METER) * (180 / math.pi);
currentPoint.longitude += (distanceXinMeter / self.MIDLE_EARTH_RADIUS_IN_METER) * (180 / math.pi) / math.cos(oldLatitude * math.pi/180);
return currentPoint
def parse_coordinates(s):
if not s:
return None
try:
p = Point(s)
return (p.latitude, p.longitude) # pylint: disable=no-member
except Exception:
raise SpatialException(_("Invalid spatial point encountered: %s" % s))