def use_site(self, site, mapwin): """Given a starting site, center the map on it and show the map. """ if len(site) > 3 and site[3]: collection = self.find_collection(site[3]) else: collection = self.find_collection(self.default_collection) if not collection: return False mapwin.collection = collection # site[1] and site[2] are the long and lat in deg.minutes # print(site[0], site[1], site[2]) mapwin.center_lon = MapUtils.deg_min2dec_deg(site[1]) mapwin.center_lat = MapUtils.deg_min2dec_deg(site[2]) mapwin.pin_lon = mapwin.center_lon mapwin.pin_lat = mapwin.center_lat # print("Center in decimal degrees:", centerLon, centerLat) if (self.Debug): print(site[0] + ":", \ MapUtils.dec_deg2deg_min_str(mapwin.center_lon), \ MapUtils.dec_deg2deg_min_str(mapwin.center_lat)) if len(site) > 4 and collection.zoom_to: collection.zoom_to(site[4]) mapwin.draw_map() return True
def use_site(self, site, mapwin): collection = self.find_collection(site[3]) if not collection: return False mapwin.collection = collection # site[1] and site[2] are the long and lat in deg.minutes # print site[0], site[1], site[2] mapwin.center_lon = MapUtils.deg_min2dec_deg(site[1]) mapwin.center_lat = MapUtils.deg_min2dec_deg(site[2]) mapwin.pin_lon = mapwin.center_lon mapwin.pin_lat = mapwin.center_lat # print "Center in decimal degrees:", centerLon, centerLat if (self.Debug): print site[0] + ":", \ MapUtils.dec_deg2deg_min_str(mapwin.center_lon), \ MapUtils.dec_deg2deg_min_str(mapwin.center_lat) if len(site) > 4 and collection.zoom_to: collection.zoom_to(site[4]) mapwin.draw_map() return True
def use_site(self, site, mapwin): collection = self.find_collection(site[3]) if not collection: return False mapwin.collection = collection # site[1] and site[2] are the long and lat in deg.minutes # print site[0], site[1], site[2] mapwin.center_lon = MapUtils.deg_min2dec_deg(site[1]) mapwin.center_lat = MapUtils.deg_min2dec_deg(site[2]) mapwin.pin_lon = mapwin.center_lon mapwin.pin_lat = mapwin.center_lat # print "Center in decimal degrees:", centerLon, centerLat if (self.Debug): print site[0] + ":", \ MapUtils.dec_deg2deg_min_str(mapwin.center_lon), \ MapUtils.dec_deg2deg_min_str(mapwin.center_lat) if len(site) > 4 and collection.zoom_to: collection.zoom_to(site[4]) mapwin.draw_map() return True
def parse_args(self, mapwin, args): """Parse runtime arguments.""" args = args[1:] while len(args) > 0: if args[0][0] == '-' and not args[0][1].isdigit(): if args[0] == "-v" or args[0] == "--version": print self.get_version() sys.exit(0) elif args[0] == "-h" or args[0] == "--help": self.Usage() # Next clause is impossible because of the prev isdigit check: # if args[0] == "-15": # series = 15 elif args[0] == "-p": self.print_sites() elif args[0] == "-c": # Specify a collection: if len(args) < 2: print "-c must specify collection" self.Usage() mapwin.collection = self.find_collection(args[1]) if mapwin.collection is None: self.error_out("Can't find a map collection called " + args[1]) # Start initially at top left, but subsequent args # may change this: mapwin.center_lon, mapwin.center_lat = \ mapwin.collection.get_top_left() if (self.Debug): print "Collection", mapwin.collection.name, print "Starting at", \ MapUtils.dec_deg2deg_min_str(mapwin.center_lon), \ ", ", \ MapUtils.dec_deg2deg_min_str(mapwin.center_lat) args = args[1:] elif args[0] == "-d": self.Debug = True elif args[0] == "-r": self.reload_tiles = time.time() elif args[0] == "-t" and len(args) > 1: if mapwin.trackpoints is None: mapwin.trackpoints = TrackPoints() # Is it a known track? for tr in self.KnownTracks: if args[1] == tr[0]: if self.Debug: print "Reading known track", tr[0], tr[1] args[1] = tr[1] break try: mapwin.trackpoints.read_track_file(args[1]) except IOError: print "Can't read track file", args[1] args = args[1:] else: self.error_out("Unknown flag " + args[0]) # Done processing this flag args = args[1:] continue # args[0] doesn't start with '-'. Is it a track file? if args[0].endswith(".gpx") \ or args[0].endswith(".kml") \ or args[0].endswith(".kmz") \ or args[0].endswith("json"): try: if mapwin.trackpoints: mapwin.trackpoints.read_track_file(args[0]) else: trackpoints = TrackPoints() trackpoints.read_track_file(args[0]) mapwin.trackpoints = trackpoints except IOError: print "Can't read track file", args[0] except xml.parsers.expat.ExpatError: print "Can't read %s: syntax error." % args[0] if args[0].lower().endswith(".kml") or \ args[0].lower().endswith(".kmz"): print """ Is this a KML made with ArcGIS? It may have an illegal xsi:schemaLocation. If so, try changing xsi:schemaLocation to just schemaLocation.""" args = args[1:] continue # Try to match a known site: for site in self.KnownSites: if args[0] == site[0]: if not self.use_site(site, mapwin): continue break if mapwin.collection and mapwin.center_lon and mapwin.center_lat: args = args[1:] continue # Doesn't match a known site. Maybe the args are coordinates? try: if len(args) >= 2 and \ len(args[0]) > 1 and args[0][1].isdigit() and \ len(args[1]) > 1 and args[1][1].isdigit(): mapwin.center_lon = MapUtils.deg_min2dec_deg(float(args[0])) mapwin.center_lat = MapUtils.deg_min2dec_deg(float(args[2])) mapwin.collection = self.find_collection(args[3]) args = args[2:] continue print "Can't make sense of argument:", args[0] self.Usage() except ValueError: print "Couldn't parse coordinates" self.Usage() # If we get here, we still have an argument but it doesn't # match anything we know: flag, collection, site or coordinate. print "Problem parsing arguments. Remaining args:", args self.Usage() # Now we've parsed all the arguments. # If we didn't get a collection, use the default, if any: if not mapwin.collection and self.default_collection: mapwin.collection = self.find_collection(self.default_collection) # If we have a collection and a track but no center point, # center it on the trackpoints, and set scale appropriately: if mapwin.trackpoints is not None and mapwin.collection is not None \ and not (mapwin.center_lat and mapwin.center_lon): minlon, minlat, maxlon, maxlat = mapwin.trackpoints.get_bounds() mapwin.center_lon = (maxlon + minlon) / 2 mapwin.center_lat = (maxlat + minlat) / 2 mapwin.collection.zoom_to_bounds(minlon, minlat, maxlon, maxlat) if self.reload_tiles and 'set_reload_tiles' in dir(mapwin.collection): mapwin.collection.set_reload_tiles(self.reload_tiles) elif self.reload_tiles: print "Collection can't re-download tiles" # By now, we hope we have the mapwin positioned with a collection # and starting coordinates: if mapwin.collection and mapwin.center_lon and mapwin.center_lat: return # Didn't match any known run mode: # start in GUI mode choosing a location: if not mapwin.selection_window(): sys.exit(0)
def parse_args(self, mapwin, args): """Parse runtime arguments.""" args = args[1:] while len(args) > 0: if args[0][0] == '-' and not args[0][1].isdigit(): if args[0] == "-v" or args[0] == "--version": print self.get_version() sys.exit(0) elif args[0] == "-h" or args[0] == "--help": self.Usage() # Next clause is impossible because of the prev isdigit check: # if args[0] == "-15": # series = 15 elif args[0] == "-p": self.print_sites() elif args[0] == "-c": # Specify a collection: if len(args) < 2: print "-c must specify collection" self.Usage() mapwin.collection = self.find_collection(args[1]) if mapwin.collection is None: self.error_out("Can't find a map collection called " + args[1]) # Start initially at top left, but subsequent args # may change this: mapwin.center_lon, mapwin.center_lat = \ mapwin.collection.get_top_left() if (self.Debug): print "Collection", mapwin.collection.name, print "Starting at", \ MapUtils.dec_deg2deg_min_str(mapwin.center_lon), \ ", ", \ MapUtils.dec_deg2deg_min_str(mapwin.center_lat) args = args[1:] elif args[0] == "-d": self.Debug = True print "Debugging on" elif args[0] == "-r": self.reload_tiles = time.time() elif args[0] == "-t" and len(args) > 1: if mapwin.trackpoints is None: mapwin.trackpoints = TrackPoints() # Is it a known track? for tr in self.KnownTracks: if args[1] == tr[0]: if self.Debug: print "Reading known track", tr[0], tr[1] args[1] = tr[1] break try: mapwin.trackpoints.read_track_file(args[1]) except IOError: print "Can't read track file", args[1] args = args[1:] else: self.error_out("Unknown flag " + args[0]) # Done processing this flag args = args[1:] continue # args[0] doesn't start with '-'. Is it a track file? if args[0].endswith(".gpx") \ or args[0].endswith(".kml") \ or args[0].endswith(".kmz") \ or args[0].endswith("json"): try: if mapwin.trackpoints: mapwin.trackpoints.read_track_file(args[0]) else: trackpoints = TrackPoints() trackpoints.read_track_file(args[0]) mapwin.trackpoints = trackpoints except IOError: print "Can't read track file", args[0] except xml.parsers.expat.ExpatError: print "Can't read %s: syntax error." % args[0] if args[0].lower().endswith(".kml") or \ args[0].lower().endswith(".kmz"): print """ Is this a KML made with ArcGIS? It may have an illegal xsi:schemaLocation. If so, try changing xsi:schemaLocation to just schemaLocation.""" args = args[1:] continue # Try to match a known site: for site in self.KnownSites: if args[0] == site[0]: if not self.use_site(site, mapwin): continue break if mapwin.collection and mapwin.center_lon and mapwin.center_lat: args = args[1:] continue # Doesn't match a known site. Maybe the args are coordinates? try: if len(args) >= 2 and \ len(args[0]) > 1 and args[0][1].isdigit() and \ len(args[1]) > 1 and args[1][1].isdigit(): mapwin.center_lon = MapUtils.deg_min2dec_deg(float( args[0])) mapwin.center_lat = MapUtils.deg_min2dec_deg(float( args[2])) mapwin.collection = self.find_collection(args[3]) args = args[2:] continue print "Can't make sense of argument:", args[0] args = args[1:] continue except ValueError: print "Couldn't parse coordinates" self.Usage() # If we get here, we still have an argument but it doesn't # match anything we know: flag, collection, site or coordinate. print "Problem parsing arguments. Remaining args:", args self.Usage() # Now we've parsed all the arguments. # If we didn't get a collection, use the default, if any: if not mapwin.collection and self.default_collection: mapwin.collection = self.find_collection(self.default_collection) mapwin.collection.Debug = self.Debug # If we have a collection and a track but no center point, # center it on the trackpoints, and set scale appropriately: if mapwin.trackpoints is not None and mapwin.collection is not None \ and not (mapwin.center_lat and mapwin.center_lon): minlon, minlat, maxlon, maxlat = mapwin.trackpoints.get_bounds() mapwin.center_lon = (maxlon + minlon) / 2 mapwin.center_lat = (maxlat + minlat) / 2 mapwin.collection.zoom_to_bounds(minlon, minlat, maxlon, maxlat) if self.reload_tiles and 'set_reload_tiles' in dir(mapwin.collection): mapwin.collection.set_reload_tiles(self.reload_tiles) elif self.reload_tiles: print "Collection can't re-download tiles" # By now, we hope we have the mapwin positioned with a collection # and starting coordinates: if mapwin.collection and mapwin.center_lon and mapwin.center_lat: return # Didn't match any known run mode: # start in GUI mode choosing a location: if not mapwin.selection_window(): sys.exit(0)