[Tile-serving] [openstreetmap/osm2pgsql] Make it easier to reproduce --hstore behavior with flex backend (#1123)
Paul Norman
notifications at github.com
Thu Apr 16 03:33:22 UTC 2020
I'm finding it difficult to reproduce the behavior of osm2pgsql with --hstore with the flex backend. This is somewhat of a question, but flex-specific questions aren't a great fit anywhere.
Suppose you want to reproduce `osm2pgsql --output pgsql --hstore --style foo.style` where `foo.style` is
```
node,way foo text linear
```
If you have an OSM object with foo=bar, baz=qux this ends up with an object written with foo=bar, tags=hstore(baz=qux).
With the pgsql backend this can be achieved for nodes with
```lua
function filter_tags_node (keyvalues, numberofkeys)
if next(keyvalues) == nil then
return 1, {}
end
-- other manipulation like deleting some tags goes here
return 0, keyvalues
end
```
The equivalent flex table declaration would be
```lua
tables.point = osm2pgsql.define_table{
name = 'planet_osm_point',
ids = { type = 'node', id_column = 'osm_id' },
columns = {
{ column = 'geom', type = 'point' },
{ column = 'foo', type = 'text' },
{ column = 'tags', type = 'hstore' }
}
}
```
My problems come when I try to write `osm2pgsql.process_node`. If I do
```lua
function osm2pgsql.process_node(object)
if next(object.tags) == nil then
return
end
tables.point:add_row(object.tags)
end
```
I end up with an unpopulated hstore column.
The only option I see here is something like
```lua
point_columns = {
{ column = 'geom', type = 'point' },
{ column = 'foo', type = 'text' },
{ column = 'tags', type = 'hstore' }
}
tables.point = osm2pgsql.define_table{
name = 'planet_osm_point',
ids = { type = 'node', id_column = 'osm_id' },
columns = point_columns
}
function osm2pgsql.process_node(object)
if next(object.tags) == nil then
return
output_cols = {}
for col in point_columns do
output_cols[cols.column] = object.tags[cols.column]
object.tags[cols.column] = nil
done
output_cols.tags = object.tags
tables.point:add_row(output_cols.tags)
end
```
Is there a better way? If this is the only way, we should add it to `compatible.lua`.
Was there too much "magic" in the old way where you would return all the tags and osm2pgsql would sort out what goes into its own column and what goes into tags?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/issues/1123
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20200415/9276f448/attachment.htm>
More information about the Tile-serving
mailing list