Skip to content

Commit

Permalink
Add support for multi-level kind:xx fallback in disputed borders.
Browse files Browse the repository at this point in the history
zerebubuth committed May 15, 2019
1 parent b7807ee commit 74b4b7f
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions integration-test/1810-alternate-viewpoints.py
Original file line number Diff line number Diff line change
@@ -156,9 +156,18 @@ def test_claim(self):

self.assert_has_feature(
z, x, y, 'boundaries', {
# generally unrecognised
'kind': 'unrecognized_country',
# but BB & CC both claim this as a border
'kind:bb': 'country',
'kind:cc': 'country',
# AA disputes that this border exists. NOTE: the kind:aa is
# added to the output even though it duplicates the kind. this
# is to help with multi-level fallback. see
# https://github.com/tilezen/vector-datasource/pull/1895#discussion_r283912502
'kind:aa': 'unrecognized_country',
# DD recognizes BB's claim, so should see this as a country.
# TODO: support for recognized_by
# 'kind:dd': 'country',
})

21 changes: 20 additions & 1 deletion vectordatasource/transform.py
Original file line number Diff line number Diff line change
@@ -9009,6 +9009,18 @@ def cut(self, shape, props, fid):
updated_features = []

for mask_shape, disputants in self.masks:
# we don't want to override a kind:xx if it has already been set
# (e.g: by a claim), so we filter out disputant viewpoints where
# a kind override has already been set.
#
# this is necessary for dealing with the case where a border is
# both claimed and disputed in the same viewpoint.
non_claim_disputants = []
for disputant in disputants:
key = 'kind:' + disputant
if key not in props:
non_claim_disputants.append(disputant)

if shape.intersects(mask_shape):
cut_shape = shape.intersection(mask_shape)
cut_shape = _filter_geom_types(cut_shape, _LINE_DIMENSION)
@@ -9018,7 +9030,7 @@ def cut(self, shape, props, fid):

if not cut_shape.is_empty:
new_props = props.copy()
for disputant in disputants:
for disputant in non_claim_disputants:
new_props['kind:' + disputant] = 'unrecognized_country'
updated_features.append((cut_shape, new_props, None))

@@ -9085,6 +9097,13 @@ def apply_disputed_boundary_viewpoints(ctx):
elif kind in _BOUNDARY_KINDS:
boundaries.append((shape, props, fid))

# we want to apply disputes to already generally-unrecognised borders
# too, as this allows for multi-level fallback from one viewpoint
# possibly through several others before reaching the default.
elif (kind.startswith('unrecognized_') and
kind[len('unrecognized_'):] in _BOUNDARY_KINDS):
boundaries.append((shape, props, fid))

else:
# pass through this feature - we just ignore it.
new_features.append((shape, props, fid))

0 comments on commit 74b4b7f

Please sign in to comment.