From 251d56c226374e884c17b2b04ef0561dfd3b18ea Mon Sep 17 00:00:00 2001 From: csrichter Date: Wed, 26 Apr 2017 22:16:30 +0200 Subject: [PATCH] added decoding of areas and roads --- .gitignore | 1 + python/tmc_classes.py | 57 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index e6d30aa..cf7c7ef 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ apps/*.py apps/*.pyc build-manlap *.bak +directory_writable \ No newline at end of file diff --git a/python/tmc_classes.py b/python/tmc_classes.py index 069c285..b276860 100644 --- a/python/tmc_classes.py +++ b/python/tmc_classes.py @@ -194,6 +194,29 @@ class tmc_event: return("invalid event, ecn:%i"%self.ecn) def __repr__(self): return "ecn:%i"%self.ecn +class tmc_area: + def __init__(self,lcn,tableobj): + self.lcn=lcn + self.tableobj=tableobj + self.lcl_obj=tableobj.lcl_obj + self.name="" + self.is_valid=False + if self.lcl_obj.lcn_allocated(lcn): + if self.lcl_obj.areas.has_key(lcn): + loc_dict=self.lcl_obj.areas[lcn] + self.ltype=loc_dict[u'CLASS']+loc_dict[u'TCD'] + try: + self.subtype=int(loc_dict[u'STCD']) + except ValueError:#should not happen, all rows have int + self.subtype=0 + print("location subtype %s is invalid in location %i"%(loc_dict[u'STCD'],lcn)) + loc_dict=self.lcl_obj.areas[lcn] + self.roadnumber=loc_dict['ROADNUMBER'] + if not loc_dict['NID']==u"": + self.name=self.lcl_obj.get_name(int(loc_dict['NID'])) + self.is_valid=True + elif self.tableobj.log or self.tableobj.debug: + print("lcn not allocated %i"%lcn) class tmc_segment: def __init__(self,lcn,tableobj): self.lcn=lcn @@ -203,18 +226,28 @@ class tmc_segment: self.roadname="" self.first_name="" self.second_name="" + self.is_valid=False if self.lcl_obj.lcn_allocated(lcn): - try: - self.loc_dict=self.lcl_obj.get_segment(lcn) - self.roadnumber=self.loc_dict['ROADNUMBER'] - if not self.loc_dict['RNID']==u"": - self.roadname=self.lcl_obj.get_name(int(self.loc_dict['RNID'])) - if not self.loc_dict['N1ID']==u"": - self.first_name=self.lcl_obj.get_name(int(self.loc_dict['N1ID'])) - if not self.loc_dict['N2ID']==u"": - self.second_name=self.lcl_obj.get_name(int(self.loc_dict['N2ID'])) - except KeyError: - print("segment '%i' not found"%lcn) + loc_dict=None + if self.lcl_obj.segments.has_key(lcn): + loc_dict=self.lcl_obj.segments[lcn] + elif self.lcl_obj.roads.has_key(lcn): + loc_dict=self.lcl_obj.roads[lcn] + if not loc_dict==None: + self.ltype=loc_dict[u'CLASS']+loc_dict[u'TCD'] + try: + self.subtype=int(loc_dict[u'STCD']) + except ValueError:#should not happen, all rows have int + self.subtype=0 + print("location subtype %s is invalid in location %i"%(loc_dict[u'STCD'],lcn)) + self.roadnumber=loc_dict['ROADNUMBER'] + if not loc_dict['RNID']==u"": + self.roadname=self.lcl_obj.get_name(int(loc_dict['RNID'])) + if not loc_dict['N1ID']==u"": + self.first_name=self.lcl_obj.get_name(int(loc_dict['N1ID'])) + if not loc_dict['N2ID']==u"": + self.second_name=self.lcl_obj.get_name(int(loc_dict['N2ID'])) + self.is_valid=True elif self.tableobj.log or self.tableobj.debug: print("lcn not allocated %i"%lcn) class tmc_location: @@ -282,7 +315,7 @@ class tmc_location: self.has_koord=False self.is_valid=True if not self.loc_dict['POL_LCD']=="":#Europe (lcn==34196) does not have an area reference - self.aref=tmc_location(int(self.loc_dict['POL_LCD']),tableobj) + self.aref=tmc_area(int(self.loc_dict['POL_LCD']),tableobj) except KeyError: print("point '%i' not found"%lcn) elif self.tableobj.log or self.tableobj.debug: