Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
place = user.location_set.latest()
distance = getattr(settings, 'LOCATIONS_DISTANCE', 20)
queryset = Location.objects.all()
rough_distance = geopy.units.degrees(
arcminutes=geopy.units.nm(miles=distance)) * 2
queryset = queryset.filter(
latitude__range=(place.latitude - rough_distance,
place.latitude + rough_distance),
longitude__range=(place.longitude - rough_distance,
place.longitude + rough_distance)
)
# Filtering the query set with an area of rough distance all the sides
locations = []
for location in queryset:
if location.latitude and location.longitude:
exact_distance = geopy.distance.distance(
(place.latitude, place.longitude),
(location.latitude, location.longitude)
)
if exact_distance.miles <= distance:
locations.append(location)
queryset = queryset.filter(id__in=[l.id for l in locations])
context['queryset'] = queryset.exclude(user=request.user)
return render_to_response("locations/nearby_checkins.html",
context,
context_instance=RequestContext(request)
)
else:
request.user.message_set.create(
message=_("You haven't checked in any location."))
return render_to_response("locations/nearby_checkins.html",
context,
def get_closest_station(lat, lon):
closest = None
for station in Station.objects.all():
d = geopy.distance.distance((station.lat, station.lon), (lat, lon)).km
if closest is None or closest['d'] > d:
closest = {'station': station, 'd': d}
return closest['station']
def getNumberOfExtraPoints(pair, min_res):
origin = [pair[0]['lat'], pair[0]['lon']]
destination = pair[1]['lat'], pair[1]['lon']
length = distance.distance(origin, destination).kilometers
return max(int(floor(length / min_res) - 1),0)
closed_camera_icon = "https://www.iconsdb.com/icons/preview/red/security-camera-xxl.png"
open_camera_icon = "https://www.iconsdb.com/icons/preview/green/security-camera-3-xxl.png"
if results:
all_ips = []
for counter, camera in enumerate(results['matches']):
ip = camera['ip_str']
product = camera['product']
coordinates.append(camera['location']['latitude'])
coordinates.append(camera['location']['longitude'])
# make marker red
coordinates_measure = (camera['location']['latitude'], camera['location']['longitude'])
distance_compare = distance.distance(first_coordinates_measure, coordinates_measure).m
unit = "m"
if distance_compare > 1000.0:
distance_compare = distance_compare / 1000
unit = "km"
popup_text = ip + "<br>" + product + "<br>" + str(distance_compare)[0:5] + "" + unit + " from target" + "<br><a href="https://shodan.io/host/"">Lookup on Shodan</a>" + " <br> <a href="https://bgp.he.net/ip/""> Check ownership </a><br>"
#check if camera has screenshot
has_screenshot = 0
if 'opts' in camera:
has_screenshot = 1
eocoded = camera['opts']['screenshot']['data']
html = '<img src="data:image/jpeg;base64,{}" style="width:100%; height:100%;">'.format(eocoded)
popup_text = popup_text + html
if recursive:
if ip not in all_ips:
def tagger(dt: datetime, point: geopy.Point) -> Tag:
'''
Tag points with known locations (e.g. work/home/etc)
'''
for lat, lon, dist, tag in known_locations:
# TODO use something more efficient?
if geopy.distance.distance((lat, lon), point).m < dist:
return tag
else:
return None
for fence in geofences:
firstpt = fence[0]
lastpt = fence[len(fence)-1]
if firstpt != lastpt:
fence.append(firstpt)
print('Updated last point in geofence to match the first point')
# Calculate the center of the geofences for the starting location
xpt = [p['lat'] for p in fence]
ypt = [p['lon'] for p in fence]
centroid.append((sum(xpt) / len(fence), sum(ypt) / len(fence)))
# Calculate the max distance from the edge so we can set the step limit
maxdistance.append(0)
for p in fence:
dist = geopy.distance.vincenty(centroid[i], (p['lat'],p['lon'])).m
if dist > maxdistance[i]:
maxdistance[i] = dist
i=i+1
print('Generating {}m circles for {} geofence(s)...\n'. format(args.radius, len(geofences)))
start_time = time.time()
# Process each geofence separately so we can reduce overlap
endresults = []
numresults = 0
ii=0
for fence in geofences:
# dist between column centers
step_distance = args.radius/1000
step_limit = int((maxdistance[ii]/args.radius)+1) # A step is "(step_limit * step_distance) + step_distance/2". Each step basically adds a layer of 70m points to the calculation
scan_location = centroid[ii] # This is the center of each geofence
def diagonal(self):
"""Return a lenght of bounding box diagonal in meters as :class:`int`."""
return geopy.distance.distance(self.corners[0], self.corners[1]).meters
def gps_accuracy(gps, posambiguity: int) -> int:
"""Calculate the GPS accuracy based on APRS posambiguity."""
pos_a_map = {0: 0, 1: 1 / 600, 2: 1 / 60, 3: 1 / 6, 4: 1}
if posambiguity in pos_a_map:
degrees = pos_a_map[posambiguity]
gps2 = (gps[0], gps[1] + degrees)
dist_m = geopy.distance.distance(gps, gps2).m
accuracy = round(dist_m)
else:
message = f"APRS position ambiguity must be 0-4, not '{posambiguity}'."
raise ValueError(message)
return accuracy
def goto_from_coord(start, distance, bearing):
"""
distance: in kilometers
bearing: 0 degree is north, 90 is east
"""
s = geopy.Point(start[0],start[1])
d = geopy.distance.VincentyDistance(kilometers = distance)
reached = d.destination(point=s, bearing=bearing)
return [reached.latitude, reached.longitude]