return False
return True
-def filter_far_from(nmea, miles, lat, lon):
+def filter_close_to(nmea, lat, lon, miles=1.0):
+ '''
+ Returns true if position is closer than miles from (lat, lon)
+ '''
+ return dist3_xyz(latlon_to_xyz_deg(lat, lon), latlon_to_xyz_ais(nmea.latitude, nmea.longitude)) <= miles
+
+
+def filter_far_from(nmea, lat, lon, miles=1.0):
'''
Returns true if position is farther than miles from (lat, lon)
'''
action='store', type='str', dest='area_file', metavar="FILE.KML",
help="only process a specific area as defined in a kml polygon file.")
parser.add_option('--filter-farfrom',
- action='store', dest='far_from', nargs=3, metavar='MILES LAT LONG',
+ action='store', dest='far_from', nargs=3, metavar='LAT LONG MILES',
help="only show ships farther than MILES miles from LAT,LONG")
+ parser.add_option('--filter-closeto',
+ action='store', dest='close_to', nargs=3, metavar='LAT LONG MILES',
+ help="only show ships closer than MILES miles from LAT,LONG")
parser.add_option('--filter-destination',
action='store', type='str', dest='filter_destination', metavar="DESTINATION",
area = load_area_from_kml_polygon(options.area_file)
filters.append(lambda nmea: filter_area(nmea, area))
+ if options.close_to:
+ try:
+ lat = clean_latitude(unicode(options.close_to[0], 'utf-8'))
+ lon = clean_longitude(unicode(options.close_to[1], 'utf-8'))
+ except LatLonFormatError as err:
+ print >> sys.stderr, err.args
+ sys.exit(1)
+ miles = float(options.close_to[2])
+ filters.append(lambda nmea: filter_close_to(nmea, lat, lon, miles))
+
if options.far_from:
- miles = float(options.far_from[0])
try:
- lat = clean_latitude(unicode(options.far_from[1], 'utf-8'))
- lon = clean_longitude(unicode(options.far_from[2], 'utf-8'))
+ lat = clean_latitude(unicode(options.far_from[0], 'utf-8'))
+ lon = clean_longitude(unicode(options.far_from[1], 'utf-8'))
except LatLonFormatError as err:
print >> sys.stderr, err.args
sys.exit(1)
- filters.append(lambda nmea: filter_far_from(nmea, miles, lat, lon))
+ miles = float(options.far_from[2])
+ filters.append(lambda nmea: filter_far_from(nmea, lat, lon, miles))
if options.type_list:
def filter_type(nmea):