|
def generate_address_points(ctx): |
|
""" |
|
Generates address points from building polygons where there is an |
|
addr:housenumber tag on the building. Removes those tags from the |
|
building. |
|
""" |
|
|
|
feature_layers = ctx.feature_layers |
|
zoom = ctx.nominal_zoom |
|
source_layer = ctx.params.get('source_layer') |
|
assert source_layer, 'generate_address_points: missing source_layer' |
|
start_zoom = ctx.params.get('start_zoom', 0) |
|
|
|
if zoom < start_zoom: |
|
return None |
|
|
|
layer = _find_layer(feature_layers, source_layer) |
|
if layer is None: |
|
return None |
|
|
|
new_features = [] |
|
for feature in layer['features']: |
|
shape, properties, fid = feature |
|
|
|
# We only want to create address points for polygonal |
|
# buildings with address tags. |
|
if shape.geom_type not in ('Polygon', 'MultiPolygon'): |
|
continue |
|
|
|
addr_housenumber = properties.get('addr_housenumber') |
|
|
|
# consider it an address if the name of the building |
|
# is just a number. |
|
name = properties.get('name') |
|
if name is not None and digits_pattern.match(name): |
|
if addr_housenumber is None: |
|
addr_housenumber = properties.pop('name') |
|
|
|
# and also suppress the name if it's the same as |
|
# the address. |
|
elif name == addr_housenumber: |
|
properties.pop('name') |
|
|
|
# if there's no address, then keep the feature as-is, |
|
# no modifications. |
|
if addr_housenumber is None: |
|
continue |
|
|
|
label_point = shape.representative_point() |
|
|
|
# we're only interested in a very few properties for |
|
# address points. |
|
label_properties = dict( |
|
addr_housenumber=addr_housenumber, |
|
kind='address') |
|
|
|
source = properties.get('source') |
|
if source is not None: |
|
label_properties['source'] = source |
|
|
|
addr_street = properties.get('addr_street') |
|
if addr_street is not None: |
|
label_properties['addr_street'] = addr_street |
|
|
|
oid = properties.get('id') |
|
if oid is not None: |
|
label_properties['id'] = oid |
|
|
|
label_feature = label_point, label_properties, fid |
|
|
|
new_features.append(label_feature) |
|
|
|
layer['features'].extend(new_features) |
|
return layer |
Occasionally the
addresspoints exported in the buildings layer are missingmin_zoomprops.Besides the vanilla address nodes in OSM, Tilezen harvests address points in queries.yaml off ways as well via this transform.py logic:
vector-datasource/vectordatasource/transform.py
Lines 2505 to 2578 in 2eb4486
We need to also set
min_zoom=17in that section, like: