File: use_nodecache.py

package info (click to toggle)
pyosmium 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,600 kB
  • sloc: python: 4,493; cpp: 2,616; makefile: 21
file content (32 lines) | stat: -rw-r--r-- 735 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Iterate over all ways (and ways only) using node cache to obtain geometries
"""
import osmium
import sys


class WayHandler:

    def __init__(self, idx):
        self.idx = idx

    def way(self, w):
        locations = []
        for n in w.nodes:
            locations.append(idx.get(n.ref))  # note that cache is used here
        print(w.id, len(w.nodes), locations)


if len(sys.argv) != 3:
    print("Usage: python use_nodecache.py <osm file> <node cache>")
    exit()

reader = osmium.io.Reader(sys.argv[1], osmium.osm.osm_entity_bits.WAY)

idx = osmium.index.create_map("sparse_file_array," + sys.argv[2])
lh = osmium.NodeLocationsForWays(idx)
lh.ignore_errors()

osmium.apply(reader, lh, WayHandler(idx))

reader.close()