|
| 1 | +Feature: Creating (multi)linestring features from way and relations |
| 2 | + |
| 3 | + Scenario: |
| 4 | + Given the grid |
| 5 | + | 1 | 2 | | |
| 6 | + | 4 | | 3 | |
| 7 | + | | 5 | 6 | |
| 8 | + And the OSM data |
| 9 | + """ |
| 10 | + w20 Thighway=motorway Nn1,n2,n3 |
| 11 | + w21 Thighway=motorway Nn4,n5,n6 |
| 12 | + r30 Ttype=route,route=road Mw20@ |
| 13 | + r31 Ttype=route,route=road Mw20@,w21@ |
| 14 | + """ |
| 15 | + And the lua style |
| 16 | + """ |
| 17 | + local lines = osm2pgsql.define_table({ |
| 18 | + name = 'osm2pgsql_test_lines', |
| 19 | + ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' }, |
| 20 | + columns = { |
| 21 | + { column = 'geom', type = 'geometry', projection = 4326 }, |
| 22 | + } |
| 23 | + }) |
| 24 | +
|
| 25 | + function osm2pgsql.process_way(object) |
| 26 | + if object.tags.highway == 'motorway' then |
| 27 | + lines:insert({ |
| 28 | + geom = object:as_multilinestring() |
| 29 | + }) |
| 30 | + end |
| 31 | + end |
| 32 | +
|
| 33 | + function osm2pgsql.process_relation(object) |
| 34 | + if object.tags.type == 'route' then |
| 35 | + lines:insert({ |
| 36 | + geom = object:as_multilinestring() |
| 37 | + }) |
| 38 | + end |
| 39 | + end |
| 40 | + """ |
| 41 | + When running osm2pgsql flex |
| 42 | + |
| 43 | + Then table osm2pgsql_test_lines contains exactly |
| 44 | + | osm_type | osm_id | ST_GeometryType(geom) | ST_AsText(ST_GeometryN(geom, 1)) | ST_AsText(ST_GeometryN(geom, 2)) | |
| 45 | + | W | 20 | ST_LineString | 1, 2, 3 | NULL | |
| 46 | + | W | 21 | ST_LineString | 4, 5, 6 | NULL | |
| 47 | + | R | 30 | ST_LineString | 1, 2, 3 | NULL | |
| 48 | + | R | 31 | ST_MultiLineString | 1, 2, 3 | 4, 5, 6 | |
| 49 | + |
| 50 | + Scenario: |
| 51 | + Given the grid |
| 52 | + | 1 | 2 | | | |
| 53 | + | | | 3 | 4 | |
| 54 | + And the OSM data |
| 55 | + """ |
| 56 | + w20 Thighway=motorway Nn1,n2 |
| 57 | + w21 Thighway=motorway Nn2,n3 |
| 58 | + w22 Thighway=motorway Nn3,n4 |
| 59 | + r30 Ttype=route,route=road Mw20@,w21@ |
| 60 | + r31 Ttype=route,route=road Mw20@,w22@ |
| 61 | + """ |
| 62 | + And the lua style |
| 63 | + """ |
| 64 | + local roads = osm2pgsql.define_relation_table('osm2pgsql_test_roads', { |
| 65 | + { column = 'geom', type = 'geometry', projection = 4326 }, |
| 66 | + { column = 'merged', type = 'geometry', projection = 4326 } |
| 67 | + }) |
| 68 | +
|
| 69 | + function osm2pgsql.process_relation(object) |
| 70 | + local g = object:as_multilinestring() |
| 71 | + roads:insert({ |
| 72 | + geom = g, |
| 73 | + merged = g:line_merge() |
| 74 | + }) |
| 75 | + end |
| 76 | + """ |
| 77 | + When running osm2pgsql flex |
| 78 | + |
| 79 | + Then table osm2pgsql_test_roads contains exactly |
| 80 | + | relation_id | ST_GeometryType(geom) | ST_GeometryType(merged) | ST_AsText(ST_GeometryN(merged, 1)) | ST_AsText(ST_GeometryN(merged, 2)) | |
| 81 | + | 30 | ST_MultiLineString | ST_MultiLineString | 1, 2, 3 | NULL | |
| 82 | + | 31 | ST_MultiLineString | ST_MultiLineString | 1, 2 | 3, 4 | |
| 83 | + |
0 commit comments