Esempio n. 1
0
    def __init__(self, camera: Camera, element_tree: ElementTree):
        self.camera = camera
        self.element_tree = element_tree
        self.osm_helper = OsmHelper(element_tree)

        for element in element_tree.getroot():
            if element.tag == 'bounds':
                self.bounds = Rectangle(float(element.attrib['minlat']), float(element.attrib['minlon']),
                                        float(element.attrib['maxlat']), float(element.attrib['maxlon']))
                break
        else:
            points = [(float(element.attrib['lat']), float(element.attrib['lon']))
                      for element in element_tree.getroot() if element.tag == 'node']
            self.bounds = Rectangle(min(points, key=itemgetter(0))[0], min(points, key=itemgetter(1))[1],
                                    max(points, key=itemgetter(0))[0], max(points, key=itemgetter(1))[1])

        draw_pairs = []
        self.artists = get_artists()
        for i, artist in enumerate(self.artists):
            nulano_gui_callback(group='loading map', status=str(artist), current=i+1, maximum=len(self.artists))
            for element in element_tree.getroot():
                if artist.wants_element(element, osm_helper=self.osm_helper):
                    draw_pairs += [(element, artist)]

        nulano_gui_callback(status='initializing location filter', current=1)
        self.filter = LocationFilter(0.1, self.bounds, draw_pairs, self.osm_helper)
        self.zoom_cache = defaultdict(lambda: defaultdict(dict))
Esempio n. 2
0
def element_to_bbox(element: Element, osm_helper: OsmHelper):
    points = element_to_points(element, osm_helper)
    if len(points) == 0:
        return Rectangle(0, 0, 0, 0)
    from operator import itemgetter
    bbox = Rectangle(
        min(points, key=itemgetter(0))[0],
        min(points, key=itemgetter(1))[1],
        max(points, key=itemgetter(0))[0],
        max(points, key=itemgetter(1))[1])
    return bbox
Esempio n. 3
0
 def approx_location(self, element: Element, osm_helper: OsmHelper):
     points = osm_helper.way_coordinates(element)
     if len(points) == 0:
         return []
     from operator import itemgetter
     return [
         Rectangle(
             min(points, key=itemgetter(0))[0],
             min(points, key=itemgetter(1))[1],
             max(points, key=itemgetter(0))[0],
             max(points, key=itemgetter(1))[1])
     ]
Esempio n. 4
0
    def _select(self, element, name=None):
        self.highlight, self.selection = None, None
        self.dirty = True
        if element is None:
            return
        if not name:
            name = osm_helper.tag_dict(element).get('name')

        if element.tag == 'node':
            self.highlight = (float(element.attrib['lat']),
                              float(element.attrib['lon']))
            self.camera.center_at(*self.highlight)
            self.selection = name
        else:
            points = []
            tp = element.tag
            if element.tag == 'way':
                points = self.osm_helper.way_coordinates(element)
            elif element.tag == 'relation':
                tags = osm_helper.tag_dict(element)
                tp = '{}:{}'.format(element.tag, tags.get('type'))
                if tags.get('type') == 'multipolygon':
                    points = [
                        point for polygon in
                        self.osm_helper.multipolygon_to_polygons(element)
                        for point in polygon
                    ]
            if len(points) == 0:
                log('Don\'t know how to select element {} of type {}'.format(
                    name, tp),
                    level=1)
            else:
                rect = Rectangle(
                    min(points, key=itemgetter(0))[0],
                    min(points, key=itemgetter(1))[1],
                    max(points, key=itemgetter(0))[0],
                    max(points, key=itemgetter(1))[1])
                self.highlight = rect
                self.camera.center_at((rect.min_lat + rect.max_lat) / 2,
                                      (rect.min_lon + rect.max_lon) / 2)
                self.selection = name
        log('Selected {} at {}'.format(self.highlight, self.selection))
Esempio n. 5
0

def find_artist(arg):
    package, _, clazz = arg.rpartition('.')
    return getattr(__import__(package, globals=globals()), clazz)()


with open('testdata/input.in', 'r') as f:
    test_cases = int(f.readline())
    for i in range(test_cases):
        osm_filename = f.readline().rstrip()
        min_lat, min_lon, max_lat, max_lon = map(float, f.readline().split())
        png_filename = f.readline().rstrip()
        width, height = map(int, f.readline().split())

        cam = BoxCamera(Rectangle(min_lat, min_lon, max_lat, max_lon),
                        (width, height))
        zoom = int(f.readline())
        artists = [find_artist(arg) for arg in sys.argv[1:]]
        tree = ET.parse(osm_filename)
        helper = osm_helper.OsmHelper(tree)

        root = tree.getroot()
        to_draw = defaultdict(list)
        skipped = []  # TODO print these
        for element in root:
            for artist in artists:
                if artist.wants_element(element, helper):
                    to_draw[artist].append(element)
            else:
                skipped.append(element)
Esempio n. 6
0
import PIL.Image
import PIL.ImageDraw


print('testing', sys.argv[1:])


with open('testdata/input.in', 'r') as f:
    test_cases = int(f.readline())
    for i in range(test_cases):
        osm_filename = f.readline().rstrip()
        min_lat, min_lon, max_lat, max_lon = map(float, f.readline().split())
        png_filename = f.readline().rstrip()
        width, height = map(int, f.readline().split())
        
        cam = BoxCamera(Rectangle(min_lat, min_lon, max_lat, max_lon), (width, height))
        zoom = int(f.readline())
        artists = []
        for arg in sys.argv[1:]:
            artists += getattr(__import__(arg, globals=globals()), '_all')
        tree = ET.parse(osm_filename)
        helper = osm_helper.OsmHelper(tree)
        
        root = tree.getroot()
        to_draw = defaultdict(list)
        skipped = []  # TODO print these?
        for element in root:
            for artist in artists:
                if artist.wants_element(element, helper):
                    to_draw[artist].append(element)
            else:
Esempio n. 7
0
        return False
    for x, y in zip(a, b):
        if not are_objects_equal(x, y):
            return False
    return True

print('testing location_filter.LocationFilter')
expected_count = 0
found_count = 0
failed_to_find = 0

with open('testdata/input.in', 'r') as f:
    test_cases = int(f.readline())
    for i in range(test_cases):
        typical_query, min_lat, min_lon, max_lat, max_lon = map(float, f.readline().split())
        bounds = Rectangle(min_lat, min_lon, max_lat, max_lon)
        obj_count = int(f.readline())
        pairs = []
        for j in range(obj_count):
            rect_count = int(f.readline())
            obj = []
            for k in range(rect_count):
                min_lat, min_lon, max_lat, max_lon = map(float, f.readline().split())
                obj.append(Rectangle(min_lat, min_lon, max_lat, max_lon))
            pairs.append((obj, Dummy(j)))
        filt = LocationFilter(typical_query, bounds, pairs, None)
        
        query_count = int(f.readline())
        for j in range(query_count):
            min_lat, min_lon, max_lat, max_lon = map(float, f.readline().split())
            
Esempio n. 8
0
 def get_rect(self):
     a, b = self.px_to_gps((0, 0)), self.px_to_gps(self.dimensions)
     return Rectangle(b[0], a[1], a[0], b[1])