MCPcopy Create free account
hub / github.com/comaps/comaps / create_diff

Function create_diff

tools/python/stylesheet/drules_merge.py:56–83  ·  view source on GitHub ↗

Calculates difference between zoom dicts, and returns a tuple: (add_zooms_low, add_zooms_high, add_types), for missing zoom levels and missing types altogether. Zooms are separate to preserve sorting order in elements.

(zooms1, zooms2)

Source from the content-addressed store, hash-verified

54 print("{}: extra {} {}".format(typ, 'high' if high else 'low', zooms_string(scales[0], scales[1] - 1)))
55
56def create_diff(zooms1, zooms2):
57 """Calculates difference between zoom dicts, and returns a tuple:
58 (add_zooms_low, add_zooms_high, add_types), for missing zoom levels
59 and missing types altogether. Zooms are separate to preserve sorting
60 order in elements."""
61 add_elements_low = collections.defaultdict(list)
62 add_elements_high = collections.defaultdict(list)
63 seen = set(zooms2.keys())
64 for typ in zooms1:
65 if typ in zooms2:
66 seen.remove(typ)
67 add_missing_zooms(add_elements_low, typ, zooms1[typ][0], zooms2[typ][0], False)
68 add_missing_zooms(add_elements_high, typ, zooms1[typ][1], zooms2[typ][1], True)
69 else:
70 print("{}: not found in the alternative style; {}".format(typ, zooms_string(zooms1[typ][0].scale, zooms1[typ][1].scale)))
71
72 add_types = []
73 for typ in sorted(seen):
74 print("{}: missing completely; {}".format(typ, zooms_string(zooms2[typ][0].scale, zooms2[typ][1].scale)))
75 cont = drules_struct_pb2.ClassifElementProto()
76 cont.name = typ
77 for z in range(zooms2[typ][0].scale, zooms2[typ][1].scale + 1):
78 fix = copy.deepcopy(zooms2[typ][0])
79 fix.scale = z
80 cont.element.extend([fix])
81 add_types.append(cont)
82
83 return (add_elements_low, add_elements_high, add_types)
84
85def apply_diff(drules, diff):
86 """Applies diff tuple (from create_diff) to a drules set."""

Callers 1

drules_merge.pyFile · 0.85

Calls 6

add_missing_zoomsFunction · 0.85
zooms_stringFunction · 0.85
formatMethod · 0.80
ClassifElementProtoMethod · 0.80
removeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected