How to use the osmium._osmium.InvalidLocationError function in osmium

To help you get started, we’ve selected a few osmium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adamfranco / curvature / curvature / collector.py View on Github external
def way(self, way):
        # callback method for ways
        if 'highway' in way.tags and (not self.roads or way.tags['highway'] in self.roads):
            # ignore single-point ways
            if len(way.nodes) < 2:
                self.log('\nSkipping single-point way: id: {}, tags: {}, nodes: {}\n'.format(way.id, way.tags, way.nodes))
                return

            new_way = {'id': way.id, 'tags': {}, 'refs': [], 'coords': []}
            for tag in way.tags:
                new_way['tags'][tag.k] = tag.v
            for node in way.nodes:
                try:
                    new_way['refs'].append(node.ref)
                    new_way['coords'].append((node.lat, node.lon))
                except InvalidLocationError as e:
                    self.log('\nSkipping node: {} (x={}, y={}) because of error: {}\n'.format(node.ref, node.x, node.y, e))

            # Add our ways to a route collection if we can match them either
            # by route-number or alternatively, by name. These route-collections
            # will later be joined into longer segments so that curvature
            # calculations can extend over multiple way-segments that might be
            # split due to bridges, local names, speed limits, or other metadata
            # changes.
            if 'ref' in new_way['tags']:
                routes = new_way['tags']['ref'].split(';')
                for route in routes:
                    if route not in self.routes:
                        self.routes[route] = {  'join_type': 'ref',
                                                'join_data': route,
                                                'ways': []}
                    self.routes[route]['ways'].append(new_way)

osmium

Python bindings for libosmium, the data processing library for OSM data

BSD-2-Clause
Latest version published 1 month ago

Package Health Score

75 / 100
Full package analysis