Commit b1ed39dd authored by Rick Gruber-Riemer's avatar Rick Gruber-Riemer

Various small improvements:

* __slots__ in osmparser to save memory and get speed
* Python v3 super()
* use builtin TRue / False on len(sequence)
parent 35164bee
......@@ -291,7 +291,7 @@ def _is_static_object_nearby(b: Building, X, static_tree) -> bool: # X is ndarr
nearby = list(set(nearby))
d = static_tree.data
if len(nearby):
if nearby:
if parameters.OVERLAP_CHECK_INSIDE:
inside = False
for i in nearby:
......
......@@ -164,7 +164,7 @@ def _process_osm_relation(rel_nodes_dict: Dict[int, osmparser.Node], rel_ways_di
if a_building is not None:
my_buildings.append(a_building)
if len(outer_ways) > 0:
if outer_ways:
# build all_outer_refs
list_outer_refs = [way.refs for way in outer_ways[1:]]
# get some order :
......@@ -413,7 +413,7 @@ def process(coords_transform: coordinates.Transformation, fg_elev: utilities.FGE
cmin, cmax = parameters.get_extent_global()
logging.info("min/max " + str(cmin) + " " + str(cmax))
if len(the_buildings) == 0:
if not the_buildings:
logging.info("No buildings found in OSM data. Stopping further processing.")
return
......@@ -440,7 +440,7 @@ def process(coords_transform: coordinates.Transformation, fg_elev: utilities.FGE
handled_clusters.append(clusters_building_mesh_rough)
# check for buildings on airport runways etc.
if len(blocked_areas) > 0:
if blocked_areas:
the_buildings = building_lib.overlap_check_blocked_areas(the_buildings, blocked_areas)
if parameters.OVERLAP_CHECK:
......@@ -473,7 +473,7 @@ def process(coords_transform: coordinates.Transformation, fg_elev: utilities.FGE
# - TODO: analyze surrounding: similar shaped buildings nearby? will get same texture
# - set building type, roof type etc
if len(the_buildings) == 0:
if not the_buildings:
logging.info("No buildings after overlap check etc. Stopping further processing.")
return
......
......@@ -28,7 +28,7 @@ def process(copy_fg_data: bool, scenery_type: str) -> None:
if os.path.isdir(sub_dir_path + os.sep + level_two_dir):
level_two_dirs.append(sub_dir_path + os.sep + level_two_dir)
if len(level_two_dirs) == 0:
if not level_two_dirs:
logging.info("ERROR: The scenery path does not seem to have necessary sub-directories in %s", scenery_path)
else:
data_dir = util.assert_trailing_slash(parameters.PATH_TO_OSM2CITY_DATA)
......
......@@ -46,11 +46,11 @@ Overview of Programs
``osm2city`` contains the following programs to generate scenery objects based on OSM data:
* ``buildings.py``: generates buildings. See also the related `Wiki osm2city article <http://wiki.flightgear.org/Osm2city.py>`_.
* ``pylons.py``: generates pylons and cables between them for power lines, aerial ways, railway overhead lines as well as street-lamps. See also the related `Wiki osm2pylon article <http://wiki.flightgear.org/Osm2pylons.py>`_.
* ``roads.py``: generates different types of roads. See also the related `Wiki roads article <http://wiki.flightgear.org/Osm2roads.py>`_.
* ``piers.py``: generates piers and boats. See also the related `Wiki piers article <http://wiki.flightgear.org/OsmPiers.py>`_.
* ``platforms.py``: generates (railway) platforms. See also the related `Wiki platforms article <http://wiki.flightgear.org/OsmPlatforms.py>`_.
* ``buildings.py``: generates buildings.
* ``pylons.py``: generates pylons and cables between them for power lines, aerial ways, railway overhead lines as well as street-lamps.
* ``roads.py``: generates different types of roads.
* ``piers.py``: generates piers and boats.
* ``platforms.py``: generates (railway) platforms.
Calling one of these programs only with command line option ``--help`` or ``-h`` will present all available parameters. E.g.
......
......@@ -25,7 +25,7 @@ def for_edges_in_bfs_call(func, args, G, node0_set, visited_set):
if func(n0, n1, args):
node0_set.add(n1)
visited_set.add(n1)
if len(node0_set) == 0:
if not node0_set:
break
......@@ -106,7 +106,7 @@ class Graph(nx.Graph):
return self.node[the_ref]['obj']
def add_node(self, the_ref, obj):
super(Graph, self).add_node(the_ref, obj=obj)
super().add_node(the_ref, obj=obj)
def add_edge(self, way):
ref0 = way.refs[0]
......@@ -117,7 +117,7 @@ class Graph(nx.Graph):
except KeyError:
#assert(the_ref1 == the_way.refs[0] and the_ref2 == the_way.refs[-1] )
junction0 = Junction(way, is_first=True) # IS_FIRST
super(Graph, self).add_node(ref0, obj=junction0)
super().add_node(ref0, obj=junction0)
try:
junction1 = self.junction(ref1)
......@@ -125,9 +125,9 @@ class Graph(nx.Graph):
except KeyError:
#assert(the_ref1 == the_way.refs[0] and the_ref2 == the_way.refs[-1] )
junction1 = Junction(way, is_first=False)
super(Graph, self).add_node(ref1, obj=junction1)
super().add_node(ref1, obj=junction1)
super(Graph, self).add_edge(ref0, ref1, obj=way)
super().add_edge(ref0, ref1, obj=way)
way.junction0 = junction0
way.junction1 = junction1
......
......@@ -49,7 +49,7 @@ class DeckShapePoly(object):
class LinearBridge(linear.LinearObject):
def __init__(self, transform, fg_elev: FGElev, osm_id, tags, refs, nodes_dict, width=9,
tex=textures.road.EMBANKMENT_2, AGL=0.5):
super(LinearBridge, self).__init__(transform, osm_id, tags, refs, nodes_dict, width, tex, AGL)
super().__init__(transform, osm_id, tags, refs, nodes_dict, width, tex, AGL)
# -- prepare elevation spline
# probe elev at n_probes locations
n_probes = max(int(self.center.length / 5.), 3)
......@@ -269,7 +269,6 @@ class LinearBridge(linear.LinearObject):
obj.face(face[::-1])
# pillars
#if len(self.refs) > 2:
z -= elev_offset
for i in range(1, n_nodes-1):
z0 = fg_elev.probe_elev(self.center.coords[i]) - elev_offset - 1.
......
......@@ -78,7 +78,7 @@ def _process_osm_piers(nodes_dict, ways_dict, my_coord_transformator) -> List[Pi
def _write_piers(stg_manager, replacement_prefix, clusters, coords_transform: coordinates.Transformation,
stats: utilities.Stats):
for cl in clusters:
if len(cl.objects) > 0:
if cl.objects:
center_tile = Vec2d(coords_transform.toGlobal(cl.center))
ac_file_name = "%spiers%02i%02i.ac" % (replacement_prefix, cl.grid_index.ix, cl.grid_index.iy)
ac = ac3d.File(stats=stats)
......@@ -325,7 +325,7 @@ def process(coords_transform: coordinates.Transformation, fg_elev: utilities.FGE
piers = _process_osm_piers(osm_nodes_dict, osm_ways_dict, coords_transform)
logging.info("ways: %i", len(piers))
if len(piers) == 0:
if not piers:
logging.info("No piers found -> aborting")
return
......
......@@ -67,7 +67,7 @@ def _process_osm_platform(nodes_dict, ways_dict, my_coord_transformator) -> List
def _write(fg_elev: utilities.FGElev, stg_manager, replacement_prefix, clusters,
coords_transform: coordinates.Transformation, stats: utilities.Stats):
for cl in clusters:
if len(cl.objects) > 0:
if cl.objects:
center_tile = Vec2d(coords_transform.toGlobal(cl.center))
ac_file_name = "%splatforms%02i%02i.ac" % (replacement_prefix, cl.grid_index.ix, cl.grid_index.iy)
ac = ac3d.File(stats=stats)
......@@ -216,7 +216,7 @@ def process(coords_transform: coordinates.Transformation, fg_elev: utilities.FGE
platforms = _process_osm_platform(osm_nodes_dict, osm_ways_dict, coords_transform)
logging.info("ways: %i", len(platforms))
if len(platforms) == 0:
if not platforms:
logging.info("No platforms found -> aborting")
return
......
......@@ -222,7 +222,7 @@ def _dump_all_provides_across_textures(texture_list: List[Texture]) -> None:
for texture in texture_list:
for feature in texture.provides:
parts = feature.split(":")
if len(parts) > 0:
if parts:
provided_features_level_one.add(parts[0])
if len(parts) > 1:
provided_features_level_two.add(parts[1])
......
......@@ -311,7 +311,7 @@ class SharedPylon(object):
class StorageTank(SharedPylon):
def __init__(self, osm_id: int, lon: float, lat: float, tags: Dict[str, str], radius: float,
elevation: float) -> None:
super(StorageTank, self).__init__()
super().__init__()
self.osm_id = osm_id
self.lon = lon
self.lat = lat
......@@ -363,7 +363,7 @@ class StorageTank(SharedPylon):
class WindTurbine(SharedPylon):
def __init__(self, osm_id: int, lon: float, lat: float, generator_output: float, tags: Dict[str, str]) -> None:
super(WindTurbine, self).__init__()
super().__init__()
self.osm_id = osm_id
self.lon = lon
self.lat = lat
......@@ -554,7 +554,7 @@ class Pylon(SharedPylon):
TYPE_AERIALWAY_STATION = 22 # OSM-key = "aerialway", value = "station"
def __init__(self, osm_id):
super(Pylon, self).__init__()
super().__init__()
self.osm_id = osm_id
self.height = 0.0 # parsed as float
self.structure = None
......@@ -592,7 +592,7 @@ class LineWithoutCables(object):
def get_center_coordinates(self):
"""Returns the lon/lat coordinates of the line"""
if len(self.shared_pylons) == 0: # FIXME
if not self.shared_pylons: # FIXME
return 0, 0
else: # FIXME: needs to be calculated more properly with shapely
if len(self.shared_pylons) == 1:
......@@ -604,7 +604,7 @@ class LineWithoutCables(object):
class StreetlampWay(LineWithoutCables):
def __init__(self, osm_id, highway):
super(StreetlampWay, self).__init__(osm_id)
super().__init__(osm_id)
self.highway = highway
@staticmethod
......@@ -662,7 +662,7 @@ class StreetlampWay(LineWithoutCables):
class Line(LineWithoutCables):
def __init__(self, osm_id):
super(Line, self).__init__(osm_id)
super().__init__(osm_id)
self.way_segments = []
self.length = 0.0 # the total length of all segments
self.original_osm_way = None
......@@ -797,7 +797,7 @@ class WayLine(Line): # The name "Line" is also used in e.g. SymPy
TYPE_AERIALWAY_GOODS = 25 # OSM-key = "aerialway", value = "goods"
def __init__(self, osm_id):
super(WayLine, self).__init__(osm_id)
super().__init__(osm_id)
self.type_ = 0 # cf. class constants TYPE_*
self.voltage = 0 # from osm-tag "voltage"
self.cables = 0 # from osm-tag "cables"
......@@ -918,7 +918,7 @@ class RailMast(SharedPylon):
TYPE_STOP_MAST = 20
def __init__(self, type_, point_on_line, mast_point, direction_type):
super(RailMast, self).__init__()
super().__init__()
self.type_ = type_
self.point_on_line = point_on_line
self.x = mast_point.x
......@@ -941,7 +941,7 @@ class RailLine(Line):
MAST_BUFFER = 3.0
def __init__(self, osm_id):
super(RailLine, self).__init__(osm_id)
super().__init__(osm_id)
self.type_ = 0
self.nodes = [] # RailNodes
self.linear = None # The LineaString of the line
......@@ -1072,7 +1072,7 @@ def process_osm_rail_overhead(nodes_dict, ways_dict, fg_elev: utilities.FGElev,
for way_key, way in ways_dict.items():
if "railway" in way.tags:
split_ways = osmparser.split_way_at_boundary(nodes_dict, way, clipping_border)
if len(split_ways) > 0:
if split_ways:
railway_candidates.extend(split_ways)
for way in railway_candidates:
......@@ -1178,7 +1178,7 @@ def process_highways_for_streetlamps(my_highways, landuse_buffers) -> List[Stree
if is_within:
my_streetlamps[my_highway.osm_id] = StreetlampWay(my_highway.osm_id, my_highway)
else:
if len(intersections) > 0:
if intersections:
index = 10000000000
for intersection in intersections:
if isinstance(intersection, shg.MultiLineString):
......@@ -1283,7 +1283,7 @@ def process_osm_power_aerialway(nodes_dict, ways_dict, fg_elev: utilities.FGElev
way_lines.append(my_line)
else:
split_ways = osmparser.split_way_at_boundary(nodes_dict, way, clipping_border)
if len(split_ways) == 0:
if not split_ways:
continue
else:
for split_way in split_ways:
......@@ -1588,7 +1588,7 @@ class LinearOSMFeature(object):
class Highway(LinearOSMFeature):
def __init__(self, osm_id):
super(Highway, self).__init__(osm_id)
super().__init__(osm_id)
self.is_roundabout = False
def get_width(self):
......
......@@ -399,7 +399,7 @@ class Roads(object):
list_of_parts.append(current_part_refs)
node_refs_in_water.append(ref)
if len(node_refs_in_water) == 0: # all on land - just continue
if not node_refs_in_water: # all on land - just continue
continue
elif len(node_refs_in_water) == 1 and len(way.refs) > 2: # only 1 point
if way.refs[0] is not node_refs_in_water[0] and way.refs[-1] is not node_refs_in_water[0]:
......@@ -437,7 +437,7 @@ class Roads(object):
def _check_blocked_areas(self, blocked_areas: List[shg.Polygon]) -> None:
"""Makes sure that there are no ways, which go across a blocked area (e.g. airport runway).
Ways are clipped over into two ways if intersecting."""
if len(blocked_areas) == 0:
if not blocked_areas:
return
new_ways = list()
for way in self.ways_list:
......@@ -707,17 +707,10 @@ class Roads(object):
# testing
if 1:
pref_an = -999
# print the_ref, " : ",
for way, is_first in ways_list:
an = angle_from(way, is_first)
# print " (%i)" % way.osm_id, is_first,
# pr_angle(an)
assert(an > pref_an)
pref_an = an
# if len(ways_list) > 3: bla
#if the_ref == 290863179: bla
our_node = np.array(ways_list[0][0].center.coords[-1 + ways_list[0][1]])
for i, (way_a, is_first_a) in enumerate(ways_list):
......@@ -808,7 +801,7 @@ class Roads(object):
if clusters:
for i, cl in enumerate(clusters):
if len(cl.objects):
if cl.objects:
cluster_color = col[random.randint(0, len(col)-1)]
c = np.array([[cl.min.x, cl.min.y],
[cl.max.x, cl.min.y],
......@@ -1003,7 +996,7 @@ def process_osm_ways(nodes_dict: Dict[int, osmparser.Node], ways_dict: Dict[int,
continue
split_ways = osmparser.split_way_at_boundary(nodes_dict, way, clipping_border)
if len(split_ways) > 0:
if split_ways:
my_ways.extend(split_ways)
return my_ways
......@@ -1135,7 +1128,7 @@ def process(coords_transform: coordinates.Transformation, fg_elev: utilities.FGE
logging.info("Number of ways before basic processing: %i", len(osm_ways_dict))
filtered_osm_ways_list = process_osm_ways(osm_nodes_dict, osm_ways_dict)
logging.info("Number of ways after basic processing: %i", len(filtered_osm_ways_list))
if len(filtered_osm_ways_list) == 0:
if not filtered_osm_ways_list:
logging.info("No roads and railways found -> aborting")
return
......
......@@ -30,7 +30,7 @@ def flat(ac_object: ac.Object, b, roof_mgr: RoofManager, stats: Stats) -> None:
b.roof_requires.append("compat:roof-flat")
b.roof_texture = roof_mgr.find_matching_roof(b.roof_requires, b.longest_edge_len, stats)
if len(b.polygon.interiors):
if b.polygon.interiors:
outer_closest = copy.copy(b.outer_nodes_closest)
i = b.nnodes_outer
inner_ring = 0
......@@ -212,7 +212,7 @@ def separate_skillion(ac_object: ac.Object, b):
ac_object.node(-x[1], b.ground_elev + b.height - b.roof_height + b.roof_height_X[i], -x[0])
i += 1
if len(b.polygon.interiors):
if b.polygon.interiors:
print(" len(b.polygon.interiors)")
outer_closest = copy.copy(b.outer_nodes_closest)
print(("outer_closest = copy.copy(b.outer_nodes_closest)", outer_closest))
......
......@@ -19,7 +19,7 @@ class Region(object):
class Atlas(Region):
def __init__(self, x, y, width, height, name):
super(Atlas, self).__init__(x, y, width, height)
super().__init__(x, y, width, height)
self.regions = [Region(x, y, width, height)]
self._textures = [] # Type atlas.Texture
self.min_width = 1
......
......@@ -247,12 +247,12 @@ class RoofManager(object):
def _screen_exclude_texture_by_name(self, texture: Texture) -> bool:
if isinstance(self, FacadeManager):
if len(parameters.TEXTURES_FACADES_NAME_EXCLUDE) > 0:
if parameters.TEXTURES_FACADES_NAME_EXCLUDE:
for a_facade_path in parameters.TEXTURES_FACADES_NAME_EXCLUDE:
if texture.filename.rfind(a_facade_path) >= 0:
return False
else:
if len(parameters.TEXTURES_ROOFS_NAME_EXCLUDE) > 0:
if parameters.TEXTURES_ROOFS_NAME_EXCLUDE:
for a_roof_path in parameters.TEXTURES_ROOFS_NAME_EXCLUDE:
if texture.filename.rfind(a_roof_path) >= 0:
return False
......@@ -260,12 +260,12 @@ class RoofManager(object):
def _screen_exclude_texture_by_provides(self, provided_feature: str) -> bool:
if isinstance(self, FacadeManager):
if len(parameters.TEXTURES_FACADES_PROVIDE_EXCLUDE) > 0:
if parameters.TEXTURES_FACADES_PROVIDE_EXCLUDE:
for a_feature in parameters.TEXTURES_FACADES_PROVIDE_EXCLUDE:
if screen_texture_tags_for_colour_spelling(a_feature) == provided_feature:
return False
else:
if len(parameters.TEXTURES_ROOFS_PROVIDE_EXCLUDE) > 0:
if parameters.TEXTURES_ROOFS_PROVIDE_EXCLUDE:
for a_feature in parameters.TEXTURES_ROOFS_PROVIDE_EXCLUDE:
if screen_texture_tags_for_colour_spelling(a_feature) == provided_feature:
return False
......@@ -273,7 +273,7 @@ class RoofManager(object):
def _screen_exclude_texture_by_region(self, texture: Texture) -> bool:
if isinstance(self, FacadeManager):
if len(parameters.TEXTURES_REGIONS_EXPLICIT) > 0:
if parameters.TEXTURES_REGIONS_EXPLICIT:
for feature in texture.provides:
for region in parameters.TEXTURES_REGIONS_EXPLICIT:
if len(feature) > 7 and feature[7:] == region: # [:7] because "region:gb" in texture.provides
......@@ -283,14 +283,14 @@ class RoofManager(object):
def find_matching_roof(self, requires: List[str], max_dimension: float, stats: Stats):
candidates = self.find_candidates(requires, list())
if len(candidates) == 0:
if not candidates:
logging.debug("WARNING: No matching texture found for " + str(requires))
# Break down requirements to find something that matches
for simple_req in requires:
candidates = self.find_candidates([simple_req], list())
if len(candidates) > 0:
if candidates:
break
if len(candidates) == 0:
if not candidates:
# Now we're really desperate - just find something!
candidates = self.find_candidates(['compat:roof-large'], list())
if "compat:roof-flat" not in requires:
......@@ -303,13 +303,13 @@ class RoofManager(object):
if not candidate.v_can_repeat and candidate.v_size_meters < max_dimension:
continue
max_dim_candidates.append(candidate)
if len(max_dim_candidates) > 0:
if max_dim_candidates:
the_texture = max_dim_candidates[random.randint(0, len(max_dim_candidates)-1)]
else:
# now we do not care about colour, material etc. Just pick a
fallback_candidates = self.find_candidates(['compat:roof-large'], list())
final_candidates = list()
if len(fallback_candidates) == 0:
if not fallback_candidates:
logging.error("Large roof required, but no roof texture providing 'compat:roof-large' found.")
exit(1)
for candidate in fallback_candidates:
......@@ -318,7 +318,7 @@ class RoofManager(object):
if not candidate.v_can_repeat and candidate.v_size_meters < max_dimension:
continue
final_candidates.append(candidate)
if len(final_candidates) > 0:
if final_candidates:
the_texture = final_candidates[random.randint(0, len(final_candidates) - 1)]
else: # give up and live with some visual residuals instead of excluding the building
the_texture = fallback_candidates[random.randint(0, len(fallback_candidates) - 1)]
......@@ -418,16 +418,16 @@ class FacadeManager(RoofManager):
if 'roof:colour' in tags:
exclusions.append("%s:%s" % ('roof:colour', tags['roof:colour']))
candidates = self.find_facade_candidates(requires, exclusions, height, width)
if len(candidates) == 0:
if not candidates:
# Break down requirements to something that matches
for simple_req in requires:
candidates = self.find_facade_candidates([simple_req], exclusions, height, width)
if len(candidates) > 0:
if candidates:
break
if len(candidates) == 0:
if not candidates:
# Now we're really desperate - just find something!
candidates = self.find_facade_candidates(['compat:roof-flat'], exclusions, height, width)
if len(candidates) == 0:
if not candidates:
logging.debug("WARNING: no matching facade texture for %1.f m x %1.1f m <%s>", height, width, str(requires))
return None
ranked_list = _rank_candidates(candidates, tags)
......
......@@ -149,7 +149,7 @@ class Object(object):
class Label(Object):
def __init__(self):
super(Label, self).__init__('label', texture='tex/ascii.png')
super().__init__('label', texture='tex/ascii.png')
self.char_w = 1.
self.char_h = 1.
......
......@@ -102,7 +102,7 @@ def _read_apt_dat_gz_file(file_name: str, min_lon: float, min_lat: float,
my_airport = None
for line in f:
parts = line.split()
if len(parts) == 0:
if not parts:
continue
if parts[0] in ['1', '16', '17', '99']:
if (my_airport is not None) and (my_airport.within_boundary(min_lon, min_lat, max_lon, max_lat)):
......
......@@ -31,6 +31,8 @@ def get_next_pseudo_osm_id() -> int:
class OSMElement(object):
__slots__ = ('osm_id', 'tags')
def __init__(self, osm_id: int) -> None:
self.osm_id = osm_id
self.tags = {}
......@@ -43,6 +45,8 @@ class OSMElement(object):
class Node(OSMElement):
__slots__ = ('lat', 'lon')
def __init__(self, osm_id: int, lat: float, lon: float) -> None:
OSMElement.__init__(self, osm_id)
self.lat = lat # float value
......@@ -50,6 +54,8 @@ class Node(OSMElement):
class Way(OSMElement):
__slots__ = ('refs', 'pseudo_osm_id', 'was_split_at_end')
def __init__(self, osm_id: int) -> None:
OSMElement.__init__(self, osm_id)
self.refs = []
......@@ -63,6 +69,8 @@ class Way(OSMElement):
class Member(object):
__slots__ = ('ref', 'type_', 'role')
def __init__(self, ref: int, type_: str, role: str) -> None:
self.ref = ref
self.type_ = type_
......@@ -70,6 +78,8 @@ class Member(object):
class Relation(OSMElement):
__slots__ = ('members')
def __init__(self, osm_id: int):
OSMElement.__init__(self, osm_id)
self.members = []
......@@ -203,7 +213,7 @@ class OSMContentHandlerOld(xml.sax.ContentHandler):
elements. A better way is to have the input file processed by e.g. Osmosis first.
"""
def __init__(self, valid_node_keys, valid_way_keys, req_way_keys, valid_relation_keys, req_relation_keys):
super(OSMContentHandlerOld, self).__init__()
super().__init__()
self.valid_way_keys = valid_way_keys
self.valid_relation_keys = valid_relation_keys
self._handler = OSMContentHandler(valid_node_keys)
......@@ -232,7 +242,7 @@ class OSMContentHandlerOld(xml.sax.ContentHandler):
all_tags = current_way.tags
current_way.tags = {}
for key in list(all_tags.keys()):
if len(self.valid_way_keys) > 0:
if self.valid_way_keys:
if key in self.valid_way_keys:
current_way.add_tag(key, all_tags[key])
else:
......@@ -243,7 +253,7 @@ class OSMContentHandlerOld(xml.sax.ContentHandler):
all_tags = current_relation.tags
current_relation.tags = {}
for key in list(all_tags.keys()):
if len(self.valid_way_keys) > 0:
if self.valid_way_keys:
if key in self.valid_way_keys:
current_relation.add_tag(key, all_tags[key])
else:
......@@ -355,10 +365,10 @@ def parse_hstore_tags(tags_string: str, osm_id: int) -> Dict[str, str]:
"""Parses the content of a string representation of a PostGIS hstore content for tags.
Returns a dict of key value pairs as string."""
tags_dict = dict()
if len(tags_string.strip()) > 0: # else we return the empty dict as is
if tags_string.strip(): # else we return the empty dict as is
elements = tags_string.strip().split('", "')
for element in elements:
if len(element.strip()) > 0:
if element.strip():
sub_elements = element.strip().split("=>")
if len(sub_elements) == 2 and len(sub_elements[0].strip()) > 1 and len(sub_elements[1].strip()) > 1:
key = sub_elements[0].strip().strip('"')
......@@ -623,8 +633,8 @@ def construct_tags_query(req_tag_keys: List[str], req_tag_key_values: List[str],
tags_query += "'" + key + "'"
tags_query += "]"
if len(req_tag_key_values) > 0:
if len(tags_query) > 0:
if req_tag_key_values:
if tags_query:
tags_query += " AND "
if len(req_tag_key_values) == 1:
tags_query += table_alias + ".tags @> '" + req_tag_key_values[0] + "'"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment