In [1]:
from ctypes import *

runtime_ds = CDLL("../target/release/librt_datastructure.so")

In [2]:
class C_Label(Structure):
    _fields_ = [("x", c_double),
                ("y", c_double),
                ("t", c_double),
                ("osm_id", c_long),
                ("prio", c_int),
                ("lbl_f", c_double),
                ("label", c_char_p)]
    
class C_Result(Structure):
    _fields_ = [("size", c_uint64),
                ("data", POINTER(C_Label))]
    
class Label:
    def __init__(self, l):
        self.x = l.x
        self.y = l.y
        self.t = l.t
        
        self.osm_id = l.osm_id
        self.prio = l.prio
        
        self.lbl_fac = l.lbl_f
        self.label = l.label.decode("utf-8")
        
    def to_string(self):
        return "Label #{}: '{}' at (x: {}, y:{}) with prio {}, t = {} and label factor: {}".format(self.osm_id, self.label, self.x, self.y, self.prio, self.t, self.lbl_fac)

In [3]:
# init
runtime_ds.init.argtypes = [c_char_p]
runtime_ds.init.restype = c_void_p

# is_good
runtime_ds.is_good.argtypes = [c_void_p]
runtime_ds.is_good.restype = c_bool

#get_data
runtime_ds.get_data.argtypes = [c_void_p, c_double, c_double, c_double, c_double, c_double]
runtime_ds.get_data.restype = C_Result

In [4]:
def to_c_string(s):
    return create_string_buffer(s.encode('utf-8'))

In [5]:
ds = runtime_ds.init(to_c_string("../resources/baden-wuerttemberg-latest.osm.pbf.ce"))

print("Initialisieren der Datenstuktur war erfolgreich: {}".format(runtime_ds.is_good(ds)))


Initialisieren der Datenstuktur war erfolgreich: True

In [6]:
min_t = 0
min_lon = 9.16402
max_lon = 9.24161
min_lat = 49.11342
max_lat = 49.16971


res = runtime_ds.get_data(ds, min_t, min_lon, max_lon, min_lat, max_lat)

l = list()
for i in range(res.size):
    l.append(Label(res.data[i]))

print("Found {} matching items:\n".format(res.size))
for e in l:
    print("{}".format(e.to_string()))


Found 24 matching items:

Label #26769661: 'Heilbronn' at (x: 9.218655, y:49.142291) with prio 14075, t = 3.2690108033729004 and label factor: 22.0
Label #1618716160: 'Horkheim' at (x: 9.1676575, y:49.116147700000006) with prio 9801, t = 0.5350372850345787 and label factor: 12.0
Label #1556687999: 'Frankenbach' at (x: 9.1717549, y:49.159423800000006) with prio 10022, t = 0.3950841200171466 and label factor: 12.0
Label #2626294843: 'Haselter' at (x: 9.1758971, y:49.13852180000001) with prio 8938, t = 0.19055895000850182 and label factor: 11.0
Label #2626294838: 'Gewerbegebiet\nBöckingen West' at (x: 9.1643681, y:49.1413585) with prio 8937, t = 0.12355901164664317 and label factor: 11.0
Label #2626882442: 'Schanz' at (x: 9.180747, y:49.1457661) with prio 8957, t = 0.27867669649156473 and label factor: 11.0
Label #1564935149: 'Sontheim' at (x: 9.1884022, y:49.118011200000005) with prio 9777, t = 0.2648671445641906 and label factor: 12.0
Label #2626882430: 'Alt-Böckingen' at (x: 9.189984, y:49.1328405) with prio 8950, t = 0.03408735157879569 and label factor: 11.0
Label #1547719713: 'Böckingen' at (x: 9.1932571, y:49.133695) with prio 10045, t = 0.2268601197300648 and label factor: 12.0
Label #2626882436: 'Kreuzgrund' at (x: 9.185573, y:49.1493641) with prio 8954, t = 0.100915114362865 and label factor: 11.0
Label #2626882431: 'Gewerbegebiet\nBöckingen-Nord' at (x: 9.1964612, y:49.148077) with prio 8951, t = 0.1647492593932629 and label factor: 11.0
Label #2313639502: 'Linsenbuckel' at (x: 9.2155926, y:49.113483300000006) with prio 7243, t = 0.16707254053819548 and label factor: 10.0
Label #1514149505: 'Neckargartach' at (x: 9.201474900000001, y:49.1686211) with prio 10037, t = 0.3000727774276258 and label factor: 12.0
Label #2626882433: 'Gewerbegebiet\nSontheim' at (x: 9.203675, y:49.12369270000001) with prio 8952, t = 0.17894624548932622 and label factor: 11.0
Label #2626294865: 'Technologiepark\nWohlgelegen' at (x: 9.207941100000001, y:49.1550932) with prio 8944, t = 0.1195369340393496 and label factor: 11.0
Label #2626294849: 'Industriegebiet\nKanalhafen' at (x: 9.206256, y:49.153490000000005) with prio 8940, t = 0.021875667042185534 and label factor: 11.0
Label #2626294862: 'Sachsenäcker' at (x: 9.200837700000001, y:49.161383) with prio 8943, t = 0.09341151177952946 and label factor: 11.0
Label #838060983: 'Salzwerk' at (x: 9.2121858, y:49.167078800000006) with prio 8835, t = 0.07653262506010274 and label factor: 11.0
Label #2626294846: 'Herbert-Hoover-\nSiedlung' at (x: 9.2277913, y:49.1235292) with prio 8939, t = 0.20128626765420973 and label factor: 11.0
Label #2626294833: 'Businesspark\nSchwabenhof' at (x: 9.2190774, y:49.1210606) with prio 8936, t = 0.07763821667745528 and label factor: 11.0
Label #86050684: 'Gewerbegebiet\nStuttgarter Straße' at (x: 9.2242551, y:49.1255115) with prio 8808, t = 0.031147968799445327 and label factor: 11.0
Label #2626882440: 'Rosenberg' at (x: 9.2122021, y:49.1355194) with prio 8956, t = 0.09969763433364151 and label factor: 11.0
Label #2626882434: 'Industriegebiet\nKnorrstraße' at (x: 9.2144423, y:49.1328806) with prio 8953, t = 0.04242723414608044 and label factor: 11.0
Label #2626294853: 'Industriegebiet\nNeckar' at (x: 9.2191031, y:49.1593183) with prio 8941, t = 0.09483923959839828 and label factor: 11.0

In [7]:
res.size


Out[7]:
24

In [ ]: