本文整理汇总了Python中geopy.Point方法的典型用法代码示例。如果您正苦于以下问题:Python geopy.Point方法的具体用法?Python geopy.Point怎么用?Python geopy.Point使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geopy
的用法示例。
在下文中一共展示了geopy.Point方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getBearing
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def getBearing(start_point, end_point):
"""
Calculates the bearing between two points.
Parameters
----------
start_point: geopy.Point
end_point: geopy.Point
Returns
-------
point: int
Bearing in degrees between the start and end points.
"""
warnings.warn("The getBearing function is deprecated and "
"will be removed in version 2.0.0. "
"Use the get_bearing function instead.",
FutureWarning,
stacklevel=8
)
return get_bearing(start_point, end_point)
示例2: getCoordinates
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def getCoordinates(start_point, end_point, distance_meters):
"""
Calculates the new coordinates between two points depending
of the specified distance and the calculated bearing.
Parameters
----------
start_point: geopy.Point
end_point: geopy.Point
distance_meters: float
Returns
-------
point: geopy.Point
A new point between the start and the end points.
"""
warnings.warn("The getCoordinates function is deprecated and "
"will be removed in version 2.0.0. "
"Use the get_coordinates function instead.",
FutureWarning,
stacklevel=8
)
return get_coordinates(start_point, end_point, distance_meters)
示例3: get_coordinates
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def get_coordinates(start_point, end_point, distance_meters):
"""
Calculates the new coordinates between two points depending
of the specified distance and the calculated bearing.
Parameters
----------
start_point: geopy.Point
end_point: geopy.Point
distance_meters: float
Returns
-------
point: geopy.Point
A new point between the start and the end points.
"""
bearing = get_bearing(start_point, end_point)
distance_km = distance_meters / 1000
d = geo_dist.VincentyDistance(kilometers=distance_km)
destination = d.destination(point=start_point, bearing=bearing)
return geopy.Point(destination.latitude, destination.longitude)
示例4: getPointInTheMiddle
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def getPointInTheMiddle(start_point, end_point, time_diff, point_idx):
"""
Calculates a new point between two points depending of the
time difference between them and the point index.
Parameters
----------
start_point: DataFrame
end_point: DataFrame
time_diff: float
point_idx: int
Point index between the start and the end points
Returns
-------
point: list
A new point between the start and the end points.
"""
warnings.warn("The getPointInTheMiddle function is deprecated and "
"will be removed in version 2.0.0. "
"Use the get_point_in_the_middle function instead.",
FutureWarning,
stacklevel=8
)
return get_point_in_the_middle(start_point, end_point, time_diff, point_idx)
示例5: parse_json
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def parse_json(self, page, exactly_one=True):
if not isinstance(page, basestring):
page = util.decode_page(page)
doc = json.loads(page)
places = doc.get('Placemark', [])
if len(places) == 0:
# Got empty result. Parse out the status code and raise an error if necessary.
status = doc.get("Status", [])
status_code = status["code"]
self.check_status_code(status_code)
return None
elif exactly_one and len(places) != 1:
raise ValueError("Didn't find exactly one placemark! " \
"(Found %d.)" % len(places))
def parse_place(place):
location = place.get('address')
longitude, latitude = place['Point']['coordinates'][:2]
return (location, (latitude, longitude))
if exactly_one:
return parse_place(places[0])
else:
return [parse_place(place) for place in places]
示例6: get_bearing
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def get_bearing(start_point, end_point):
"""
Calculates the bearing between two points.
Parameters
----------
start_point: geopy.Point
end_point: geopy.Point
Returns
-------
point: int
Bearing in degrees between the start and end points.
"""
start_lat = math.radians(start_point.latitude)
start_lng = math.radians(start_point.longitude)
end_lat = math.radians(end_point.latitude)
end_lng = math.radians(end_point.longitude)
d_lng = end_lng - start_lng
if abs(d_lng) > math.pi:
if d_lng > 0.0:
d_lng = -(2.0 * math.pi - d_lng)
else:
d_lng = (2.0 * math.pi + d_lng)
tan_start = math.tan(start_lat / 2.0 + math.pi / 4.0)
tan_end = math.tan(end_lat / 2.0 + math.pi / 4.0)
d_phi = math.log(tan_end / tan_start)
bearing = (math.degrees(math.atan2(d_lng, d_phi)) + 360.0) % 360.0
return bearing
示例7: _get_next_pos
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def _get_next_pos(self, lat, lon, bearing, speed, precision):
origin = Point(lat, lon)
if speed == 0.0:
return lat, lon
if speed == float("inf"):
return self.destLat, self.destLng
else:
offset_angle = (1/self.speed)*(precision/1.74)
lat, lon, _ = VincentyDistance(kilometers=speed*1e-3).destination(origin, bearing + uniform(-offset_angle, offset_angle))
return lat, lon
示例8: get_pos
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def get_pos(self):
if self.speed > self.get_total_distance():
self._last_pos = self.destination
self._last_step = len(self._step_keys)-1
if self.get_last_pos() == self.destination:
return self.get_last_pos()
distance = self.speed
origin = Point(*self._last_pos)
((so_lat, so_lng), (sd_lat, sd_lng)) = self._step_dict[self._step_keys[self._last_step]]
bearing = self._calc_bearing(so_lat, so_lng, sd_lat, sd_lng)
while haversine.haversine(self._last_pos, (sd_lat, sd_lng))*1000 < distance:
distance -= haversine.haversine(self._last_pos, (sd_lat, sd_lng))*1000
self._last_pos = (sd_lat, sd_lng)
if self._last_step < len(self._step_keys)-1:
self._last_step += 1
((so_lat, so_lng), (sd_lat, sd_lng)) = self._step_dict[self._step_keys[self._last_step]]
bearing = self._calc_bearing(so_lat, so_lng, sd_lat, sd_lng)
origin = Point(so_lat, so_lng)
lat, lng = self._calc_next_pos(origin, distance, bearing)
if haversine.haversine(self._last_pos, (lat, lng))*1000 < distance:
distance -= haversine.haversine(self._last_pos, (lat, lng))*1000
self._last_pos = (lat, lng)
else:
return self.get_last_pos()
else:
lat, lng = self._calc_next_pos(origin, distance, bearing)
self._last_pos = (lat, lng)
return self.get_last_pos()
示例9: __init__
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def __init__(self, point_class=Point, precision=12):
self.point_class = point_class
self.precision = precision
示例10: encode
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def encode(self, *args, **kwargs):
precision = kwargs.pop('precision', self.precision)
point = Point(*args, **kwargs)
lat_min, latitude, lat_max = -90, 0, 90
long_min, longitude, long_max = -180, 0, 180
string = ''
bytes = []
odd_bit = False
for i in xrange(precision):
byte = 0
for bit in (16, 8, 4, 2, 1):
if odd_bit:
if point.latitude >= latitude:
byte |= bit
lat_min = latitude
else:
lat_max = latitude
latitude = (lat_min + lat_max) / 2.
else:
if point.longitude >= longitude:
byte |= bit
long_min = longitude
else:
long_max = longitude
longitude = (long_min + long_max) / 2.
odd_bit = not odd_bit
bytes.append(byte)
return ''.join([self.ENCODE_MAP[byte] for byte in bytes])
示例11: parse_json
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def parse_json(self, page, exactly_one=True):
if not isinstance(page, basestring):
page = util.decode_page(page)
doc = json.loads(page)
results = doc.get('ResultSet', []).get('Results', [])
if not results:
raise ValueError("No results found")
elif exactly_one and len(results) != 1:
raise ValueError("Didn't find exactly one placemark! " \
"(Found %d.)" % len(results))
def parse_result(place):
line1, line2, line3, line4 = place.get('line1'), place.get('line2'), place.get('line3'), place.get('line4')
address = util.join_filter(", ", [line1, line2, line3, line4])
city = place.get('city')
state = place.get('state')
country = place.get('country')
location = util.join_filter(", ", [address, city, country])
lat, lng = place.get('latitude'), place.get('longitude')
#if lat and lng:
# point = Point(floatlat, lng)
#else:
# point = None
return (location, (float(lat), float(lng)))
if exactly_one:
return parse_result(results[0])
else:
return [parse_result(result) for result in results]
示例12: find
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def find(self, document):
if isinstance(document, basestring):
document = ElementTree.fromstring(document)
elif not ElementTree.iselement(document):
document = ElementTree.parse(document)
point_qname = self._get_qname(self.POINT_CLASS)
lat_qname = self._get_qname(self.LATITUDE_PROPERTY)
long_qname = self._get_qname(self.LONGITUDE_PROPERTY)
alt_qname = self._get_qname(self.ALTITUDE_PROPERTY)
queue = [document]
while queue:
element = queue.pop()
if not self.point_class or element.tag == point_qname:
lat_el = element.find(lat_qname)
long_el = element.find(long_qname)
alt_el = element.find(alt_qname)
if lat_el is not None and long_el is not None:
latitude = lat_el.text
longitude = long_el.text
altitude = alt_el and alt_el.text
try:
point = Point((latitude, longitude, altitude))
except (TypeError, ValueError):
if not self.ignore_invalid:
raise
else:
yield Location(None, point)
queue.extend(reversed(element))
示例13: _get_location
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def _get_location(self, attrs):
position = attrs.pop('position')
name = attrs.pop('placename')
if position is not None:
if position or not self.ignore_invalid:
try:
point = Point(position)
except (TypeError, ValueError):
if not self.ignore_invalid:
raise
else:
return Location(name, point, attrs)
示例14: _parse_waypoint
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def _parse_waypoint(self, element):
waypoint = {}
point = Point(element.get('lat'), element.get('lon'))
示例15: get_circle_centers
# 需要导入模块: import geopy [as 别名]
# 或者: from geopy import Point [as 别名]
def get_circle_centers(b1, b2, radius):
"""
the function covers the area within the bounds with circles
:param b1: south-west bounds [lat, lng]
:param b2: north-east bounds [lat, lng]
:param radius: specified radius, adapt for high density areas
:return: list of circle centers that cover the area between lower/upper
"""
sw = Point(b1)
ne = Point(b2)
# north/east distances
dist_lat = vincenty(Point(sw[0], sw[1]), Point(ne[0], sw[1])).meters
dist_lng = vincenty(Point(sw[0], sw[1]), Point(sw[0], ne[1])).meters
circles = cover_rect_with_cicles(dist_lat, dist_lng, radius)
cords = [
VincentyDistance(meters=c[0])
.destination(
VincentyDistance(meters=c[1])
.destination(point=sw, bearing=90),
bearing=0
)[:2]
for c in circles
]
return cords