Skip to content

Commit

Permalink
Merge pull request #1701 from tilezen/1135-merge-water-lines
Browse files Browse the repository at this point in the history
Merge water lines
  • Loading branch information
zerebubuth authored Nov 9, 2018
2 parents 6d0facb + 7736f73 commit 0553ea5
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 0 deletions.
116 changes: 116 additions & 0 deletions integration-test/1135-water-lines-merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from . import FixtureTest


class WaterLinesMergeTest(FixtureTest):

def test_successful_merge(self):
from ModestMaps.Core import Coordinate
from shapely.geometry import LineString
from tilequeue.tile import coord_to_bounds
import dsl

z, x, y = 9, 145, 201

bounds = coord_to_bounds(Coordinate(zoom=z, column=x, row=y))
mid_x = (bounds[2] - bounds[0]) / 2.0 + bounds[0]
mid_y = (bounds[3] - bounds[1]) / 2.0 + bounds[1]
ls1 = LineString([(mid_x-0.01, mid_y-0.01), (mid_x, mid_y)])
ls2 = LineString([(mid_x, mid_y), (mid_x+0.01, mid_y+0.01)])
props = dict(waterway=u'river', name=u'foo')
self.generate_fixtures(
dsl.way(1, ls1, props),
dsl.way(2, ls2, props),
)

self.assert_n_matching_features(
z, x, y, 'water', {
'name': 'foo',
'kind': 'river',
'label_placement': type(None),
}, 1)

with self.features_in_tile_layer(z, x, y, 'water') as features:
for f in features:
if 'label_placement' in f['properties']:
continue
assert f['geometry']['type'] == 'LineString'
assert len(f['geometry']['coordinates']) == 2

def test_unsuccessful_merge_same_props(self):
from ModestMaps.Core import Coordinate
from shapely.geometry import LineString
from tilequeue.tile import coord_to_bounds
import dsl

z, x, y = 9, 145, 201

bounds = coord_to_bounds(Coordinate(zoom=z, column=x, row=y))
mid_x = (bounds[2] - bounds[0]) / 2.0 + bounds[0]
mid_y = (bounds[3] - bounds[1]) / 2.0 + bounds[1]
ls1 = LineString([
(bounds[0]+0.1, bounds[1]+0.1),
(mid_x-0.1, mid_y-0.1),
])
ls2 = LineString([
(mid_x+0.1, mid_y+0.1),
(bounds[2]-0.1, bounds[2]-0.1),
])
props = dict(waterway=u'river', name=u'foo')
self.generate_fixtures(
dsl.way(1, ls1, props),
dsl.way(2, ls2, props),
)

self.assert_n_matching_features(
z, x, y, 'water', {
'name': 'foo',
'kind': 'river',
'label_placement': type(None),
}, 1)

with self.features_in_tile_layer(z, x, y, 'water') as features:
for f in features:
if 'label_placement' in f['properties']:
continue
assert f['geometry']['type'] == 'MultiLineString'
multi_coords = f['geometry']['coordinates']
assert len(multi_coords) == 2
assert len(multi_coords[0]) == 2
assert len(multi_coords[1]) == 2

def test_unsuccessful_merge_diff_props(self):
from ModestMaps.Core import Coordinate
from shapely.geometry import LineString
from tilequeue.tile import coord_to_bounds
import dsl

z, x, y = 9, 145, 201

bounds = coord_to_bounds(Coordinate(zoom=z, column=x, row=y))
mid_x = (bounds[2] - bounds[0]) / 2.0 + bounds[0]
mid_y = (bounds[3] - bounds[1]) / 2.0 + bounds[1]
ls1 = LineString([
(bounds[0]+0.1, bounds[1]+0.1),
(mid_x-0.1, mid_y-0.1),
])
ls2 = LineString([
(mid_x+0.1, mid_y+0.1),
(bounds[2]-0.1, bounds[2]-0.1),
])
self.generate_fixtures(
dsl.way(1, ls1, dict(waterway=u'river', name=u'foo')),
dsl.way(2, ls2, dict(waterway=u'river', name=u'bar')),
)

self.assert_n_matching_features(
z, x, y, 'water', {
'kind': 'river',
'label_placement': type(None),
}, 2)

with self.features_in_tile_layer(z, x, y, 'water') as features:
for f in features:
if 'label_placement' in f['properties']:
continue
assert f['geometry']['type'] == 'LineString'
assert len(f['geometry']['coordinates']) == 2
24 changes: 24 additions & 0 deletions integration-test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,18 @@ def assert_no_matching_feature(self, z, x, y, layer, properties):
"layer %r, but was supposed to find none. For example: "
"%r" % (properties, layer, feature['properties']))

def assert_n_matching_features(self, z, x, y, layer, properties, n):
with self.ff.features_in_tile_layer(z, x, y, layer) as features:
num_features, num_matching = count_matching(
features, properties)

if num_matching != n:
self.test.fail(
"Found %d features matching properties %r in "
"layer %r, but was supposed to find %d. "
"Found %d total features." %
(num_matching, properties, layer, n, num_features))

def assert_feature_geom_type(self, z, x, y, layer, feature_id,
exp_geom_type):
with self.ff.features_in_tile_layer(z, x, y, layer) as features:
Expand Down Expand Up @@ -1295,6 +1307,9 @@ def assert_has_feature(self, z, x, y, layer, props):
def assert_no_matching_feature(self, z, x, y, layer, props):
self.assertions.assert_no_matching_feature(z, x, y, layer, props)

def assert_n_matching_features(self, z, x, y, layer, props, n):
self.assertions.assert_n_matching_features(z, x, y, layer, props, n)

def assert_feature_geom_type(self, z, x, y, layer, feature_id,
exp_geom_type):
self.assertions.assert_feature_geom_type(
Expand Down Expand Up @@ -1342,6 +1357,9 @@ def assert_has_feature(self, z, x, y, layer, props):
def assert_no_matching_feature(self, z, x, y, layer, props):
pass

def assert_n_matching_features(self, z, x, y, layer, props, n):
pass

def assert_feature_geom_type(self, z, x, y, layer, feature_id,
exp_geom_type):
pass
Expand Down Expand Up @@ -1388,6 +1406,9 @@ def assert_has_feature(self, z, x, y, layer, props):
def assert_no_matching_feature(self, z, x, y, layer, props):
self._add_tile(z, x, y)

def assert_n_matching_features(self, z, x, y, layer, props, n):
self._add_tile(z, x, y)

def assert_feature_geom_type(self, z, x, y, layer, feature_id,
exp_geom_type):
self._add_tile(z, x, y)
Expand Down Expand Up @@ -1442,6 +1463,9 @@ def assert_has_feature(self, z, x, y, layer, props):
def assert_no_matching_feature(self, z, x, y, layer, props):
self.test_instance.assert_no_matching_feature(z, x, y, layer, props)

def assert_n_matching_features(self, z, x, y, layer, props, n):
self.test_instance.assert_n_matching_features(z, x, y, layer, props, n)

def assert_feature_geom_type(self, z, x, y, layer, feature_id,
exp_geom_type):
self.test_instance.assert_feature_geom_type(
Expand Down
7 changes: 7 additions & 0 deletions queries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,13 @@ post_process:
params:
source_layer: water

# merge line water polygons
- fn: vectordatasource.transform.merge_line_features
params:
source_layer: water
start_zoom: 8
end_zoom: 15

- fn: vectordatasource.transform.generate_address_points
params:
source_layer: buildings
Expand Down

0 comments on commit 0553ea5

Please sign in to comment.