@@ -80,7 +80,7 @@ Feature: Locators
8080 Error in 'first_intersecting': Need locator and geometry arguments
8181 """
8282
83- Scenario : Use a all_intersecting() without geometry fails
83+ Scenario : Use of all_intersecting() without geometry fails
8484 Given the OSM data
8585 """
8686 n10 v1 dV Tamenity=post_box x0.5 y0.5
@@ -231,3 +231,69 @@ Feature: Locators
231231 | node_id | region | ST_AsText (geom ) |
232232 | 10 | P1 | 15 8 |
233233
234+ Scenario : Define and use a locator with relation from db
235+ Given the 10.0 grid with origin 10.0 10.0
236+ | 10 | 11 | 12 |
237+ | 13 | 14 | 15 |
238+ And the OSM data
239+ """
240+ w29 v1 dV Tregion=P1 Nn10,n11,n14,n13,n10
241+ """
242+ And the lua style
243+ """
244+ local regions = osm2pgsql.define_way_table('osm2pgsql_test_regions', {
245+ { column = 'region', type = 'text' },
246+ { column = 'geom', type = 'polygon', projection = 4326 },
247+ })
248+
249+ function osm2pgsql.process_way(object)
250+ regions:insert({
251+ region = object.tags.region,
252+ geom = object:as_polygon(),
253+ })
254+ end
255+ """
256+ When running osm2pgsql flex
257+ Then table osm2pgsql_test_regions contains exactly
258+ | way_id | region | ST_AsText (geom ) |
259+ | 29 | P1 | (10 0 ,20 0 ,20 10 ,10 10 , 10 0 ) |
260+
261+ Given the 10.0 grid with origin 10.0 10.0
262+ | 10 | 11 | 12 |
263+ | 13 | 14 | 15 |
264+ And the OSM data
265+ """
266+ w20 v1 dV Nn10,n11,n13
267+ w21 v1 dV Nn13,n10
268+ w22 v1 dV Nn14,n15
269+ w23 v1 dV Nn12,n15
270+ r30 v1 dV Tfoo=bar Mw20@,w21@,w22@,n12@
271+ r31 v1 dV Tfoo=bar Mn12@,n15@
272+ r32 v1 dV Tfoo=bar Mw23@
273+ """
274+ And the lua style
275+ """
276+ local regions = osm2pgsql.define_locator({ name = 'regions' })
277+ regions:add_from_db('SELECT region, geom FROM osm2pgsql_test_regions')
278+
279+ local points = osm2pgsql.define_relation_table('osm2pgsql_test_rels', {
280+ { column = 'region', type = 'text' },
281+ { column = 'geom', type = 'geometry', projection = 4326 },
282+ })
283+
284+ function osm2pgsql.process_relation(object)
285+ local g = object:as_geometrycollection()
286+ local r = regions:first_intersecting(g)
287+ if r then
288+ points:insert({
289+ region = r,
290+ geom = g,
291+ })
292+ end
293+ end
294+ """
295+ When running osm2pgsql flex
296+ Then table osm2pgsql_test_rels contains exactly
297+ | relation_id | region | ST_GeometryType (geom ) |
298+ | 30 | P1 | ST_GeometryCollection |
299+
0 commit comments