Exemplo n.º 1
0
    def _calculate_tile_centres(self):
        centers = []

        # [out:csv(::lat,::lon)][timeout:25];node["public_transport"="platform"]({{bbox}});out;
        self.api = OverpassApi()
        data = self.api.get(self.tile.bbox,
                            self.tags,
                            nodes=True,
                            ways=False,
                            relations=False,
                            responseformat='csv(::lat,::lon)')
        data = list(map(lambda cc: Node(float(cc[0]), float(cc[1])), data[1:]))
        print(data)

        return data
Exemplo n.º 2
0
class OsmObjectWalker(Walker):
    def __init__(self,
                 tile,
                 tags,
                 square_image_length=50,
                 zoom_level=19,
                 step_width=0.66):
        super(OsmObjectWalker, self).__init__(tile, square_image_length,
                                              zoom_level, step_width)
        self.tags = tags

    def get_tiles(self):
        nodes = self._calculate_tile_centres()
        squared_tiles = self._get_squared_tiles(nodes)
        return squared_tiles

    def _calculate_tile_centres(self):
        centers = []

        # [out:csv(::lat,::lon)][timeout:25];node["public_transport"="platform"]({{bbox}});out;
        self.api = OverpassApi()
        data = self.api.get(self.tile.bbox,
                            self.tags,
                            nodes=True,
                            ways=False,
                            relations=False,
                            responseformat='csv(::lat,::lon)')
        data = list(map(lambda cc: Node(float(cc[0]), float(cc[1])), data[1:]))
        print(data)

        return data
Exemplo n.º 3
0
class StreetLoader:
    street_categories = [
        #        'road',
        #        'trunk',
        'primary',
        'secondary',
        'tertiary',
        'unclassified',
        'residential',
        'service',
        'trunk_link',
        'primary_link',
        'secondary_link',
        'tertiary_link',
        'pedestrian'
    ]

    def __init__(self, categories=None):
        self.api = OverpassApi()
        self._add([] if categories is None else categories)
        self.tags = self._generate_tags()

    def load_data(self, bbox):
        data = self.api.get(bbox,
                            self.tags,
                            nodes=True,
                            ways=True,
                            relations=False)
        return self._generate_street(data)

    def _add(self, categories):
        for category in categories:
            self.street_categories.append(category)

    def _generate_tags(self):
        tags = []
        for category in self.street_categories:
            tags.append(Tag(key='highway', value=category))
        return tags

    @staticmethod
    def _generate_street(data):
        streets = []
        for feature in data['features']:
            coordinates = feature['geometry']['coordinates']
            nodes = []
            for coordinate in coordinates:
                try:
                    lat, lon = coordinate[1], coordinate[0]
                except TypeError:
                    logger.exception()
                    logger.warn("feature was: {}, coordinate was: {}".format(
                        feature, coordinate))
                else:
                    nodes.append(Node(lat, lon))

            streets.append(Street(nodes))
        return streets
class StreetLoader:
    street_categories = [
        'road',
        'trunk',
        'primary',
        'secondary',
        'tertiary',
        'unclassified',
        'residential',
        'service',
        'trunk_link',
        'primary_link',
        'secondary_link',
        'tertiary_link',
        'pedestrian']

    def __init__(self, categories=None):
        self.api = OverpassApi()
        self._add([] if categories is None else categories)
        self.tags = self._generate_tags()

    def load_data(self, bbox):
        data = self.api.get(bbox, self.tags)
        return self._generate_street(data)

    def _add(self, categories):
        for category in categories:
            self.street_categories.append(category)

    def _generate_tags(self):
        tags = []
        for category in self.street_categories:
            tags.append(Tag(key='highway', value=category))
        return tags

    @staticmethod
    def _generate_street(data):
        streets = []
        for feature in data['features']:
            coordinates = feature['geometry']['coordinates']
            nodes = []
            for coordinate in coordinates:
                try:
                    lat, lon = coordinate[1], coordinate[0]
                except TypeError:
                    logger.exception()
                    logger.warn("feature was: {}, coordinate was: {}".format(feature, coordinate))
                else:
                    nodes.append(Node(lat, lon))

            streets.append(Street(nodes))
        return streets
Exemplo n.º 5
0
class NodeLoader:
    def __init__(self):
        self.api = OverpassApi()

    def load_data(self, bbox, tag):
        data = self.api.get(bbox, [tag])
        return self._generate_nodes(data)

    def _generate_nodes(self, data):
        nodes = []
        for feature in data['features']:
            all_nodes = self._feature_to_nodes(feature)
            nodes.append(self._get_centre(all_nodes))
        return nodes

    @staticmethod
    def _feature_to_nodes(feature):
        nodes = []
        coordinates = feature['geometry']['coordinates']
        if isinstance(coordinates, tuple):
            nodes.append(Node(coordinates[1], coordinates[0], 0))
        else:
            for coordinate in coordinates:
                nodes.append(Node(coordinate[1], coordinate[0], 0))
        return nodes

    @staticmethod
    def _get_centre(nodes):
        sum_lat = 0
        sum_lon = 0
        for node in nodes:
            sum_lat += node.latitude
            sum_lon += node.longitude
        length = len(nodes)
        centre_latitude = sum_lat / length
        centre_longitude = sum_lon / length
        return Node(centre_latitude, centre_longitude, 0)
Exemplo n.º 6
0
class StreetLoader:
    street_categories = [
        'road', 'trunk', 'primary', 'secondary', 'tertiary', 'unclassified',
        'residential', 'service', 'trunk_link', 'primary_link',
        'secondary_link', 'tertiary_link', 'pedestrian'
    ]

    def __init__(self, categories=None):
        self.api = OverpassApi()
        self._add([] if categories is None else categories)
        self.tags = self._generate_tags()

    def load_data(self, bbox):
        data = self.api.get(bbox, self.tags)
        return self._generate_street(data)

    def _add(self, categories):
        for category in categories:
            self.street_categories.append(category)

    def _generate_tags(self):
        tags = []
        for category in self.street_categories:
            tags.append(Tag(key='highway', value=category))
        return tags

    @staticmethod
    def _generate_street(data):
        streets = []
        for feature in data['features']:
            coordinates = feature['geometry']['coordinates']
            nodes = []
            for coordinate in coordinates:
                nodes.append(Node(coordinate[1], coordinate[0]))
            streets.append(Street(nodes))
        return streets
Exemplo n.º 7
0
 def __init__(self, categories=None):
     self.api = OverpassApi()
     self._add([] if categories is None else categories)
     self.tags = self._generate_tags()
Exemplo n.º 8
0
 def __init__(self):
     self.api = OverpassApi()
 def __init__(self, categories=None):
     self.api = OverpassApi()
     self._add([] if categories is None else categories)
     self.tags = self._generate_tags()