Browse Source

allow to skip certain tags for more then 16 tags on item - limitation of mapsforge file format

tkas 2 years ago
parent
commit
b0aa625908
1 changed files with 41 additions and 3 deletions
  1. 41 3
      tagsCopy.py

+ 41 - 3
tagsCopy.py

@@ -24,6 +24,36 @@ tagsToCopy_cycle = (
                 (('network',),('ncn','rcn','lcn',)),
              )
 
+WaysManyTags = { 
+                 '5658162'  : ('kct_yellow'),
+                 '29493918' : ('piste:grooming'),
+                 '29628610' : ('piste:grooming'),
+                 '29700212' : ('surface', 'piste:grooming'),
+                 '30897583' : ('surface', 'piste:grooming'),
+                 '30897641' : ('surface', 'piste:grooming'),
+                 '30897681' : ('surface', 'piste:grooming'),
+                 '30897684' : ('surface'),
+                 '30897700' : ('surface', 'piste:grooming'),
+                 '30897834' : ('surface', 'piste:grooming'),
+                 '37050156' : ('surface', 'mtb:scale'),
+                 '38580684' : ('surface', 'piste:grooming'),
+                 '39175696' : ('surface'),
+                 '45730916' : ('surface', 'piste:grooming'),
+                 '50754013' : ('surface', 'piste:grooming'),
+                 '57401797' : ('surface'),
+                 '96137142' : ('piste:grooming'),
+                 '123446253': ('surface', 'piste:grooming'),
+                 '162367251': ('surface', 'foot'),
+                 '172859867': ('surface', 'piste:grooming'),
+                 '172859877': ('surface', 'piste:grooming'),
+                 '183157092': ('surface'),
+                 '316101906': ('surface', 'piste:grooming'),
+                 '326973214': ('surface', 'piste:grooming'),
+                 '664882558': ('surface', 'kct_yellow'),
+               }
+
+#WaysManyTagsSkip = [ 'surface', 'piste:grooming', 'mtb:scale', 'foot' ]
+
 outFileName = 'map/mergedMap.osm'
 ################ Functions ###############
 
@@ -197,22 +227,30 @@ outFile = open(outFileName,'a')
         
 with open('ways.xml','r') as inFile:
     counter = 0
-    way_id = None
+    first_tag = 0
     for line in inFile:
         if ('<way id="' in line): # if I am in way
             outFile.write(line) # first write it to file
             way_id = (re.search(r'\d+', line)).group(0) # extract its ID
+            first_tag = 1
         elif ('<tag k="' in line):
-            if way_id is not None: # I have relation ID to check
+            tag_key = (re.search(r'<tag k="([:_\w\-\+\.\(\) ]+)"', line)).group(1) #get tag key
+            if(way_id in WaysManyTags.keys() and tag_key in WaysManyTags[way_id]):
+                  print("Way with lot of tags: "+way_id+" with tag to skip: "+tag_key)
+                  continue
+            if first_tag: # I have relation ID to check
                 for way in allRels:
                     my_id = index(way[1],way_id)
+                    if(my_id != -1 and way_id in WaysManyTags.keys() and way[0][0] in WaysManyTags[way_id]):
+                          print("Way with lot of tags: "+way_id+" with tag from relation to skip: "+way[0][0])
+                          continue
                     if (my_id != -1): # if there is some relation tag to copy to this way
                         outFile.write('<tag k="'+way[0][0]+'" v="'+way[0][1]+'"/>\n')# write it here
                 if (way_id in allRefs):
                     for a in allRefs[way_id]:
                         outFile.write('<tag k="ref" v="'+a+'"/>\n')# write it here
                     #TODO here I can remove allRefs[way_id] from dict?
-                way_id = None
+                first_tag = 0
             outFile.write(line) # and then write the tag
         else:
             outFile.write(line) # some nd or other info that has to be just copied