Skip to content

Commit aeec903

Browse files
committed
Add example for hstore with indexes
1 parent 4bfe6ec commit aeec903

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

flex-config/hstore.lua

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
-- This config example file is released into the Public Domain.
2+
3+
-- Use hstore column for storing all tags of nodes and ways. Adds a GIST index
4+
-- for both tables that allows queries on the geometry *and* the tags.
5+
--
6+
-- See https://www.postgresql.org/docs/current/hstore.html#HSTORE-INDEXES
7+
-- for details.
8+
--
9+
-- You need to enable the hstore extension for this to work:
10+
-- CREATE EXTENSION hstore;
11+
12+
local nodes = osm2pgsql.define_table({
13+
name ='nodes',
14+
ids = { type = 'node', id_column = 'osm_id' },
15+
columns = {
16+
{ column = 'tags', type = 'hstore' },
17+
{ column = 'geom', type = 'point' },
18+
},
19+
indexes = {
20+
{ column = { 'geom', 'tags' }, method = 'gist' },
21+
},
22+
})
23+
24+
local ways = osm2pgsql.define_table({
25+
name ='ways',
26+
ids = { type = 'way', id_column = 'osm_id' },
27+
columns = {
28+
{ column = 'tags', type = 'hstore' },
29+
{ column = 'geom', type = 'geometry' },
30+
},
31+
indexes = {
32+
{ column = { 'geom', 'tags' }, method = 'gist' },
33+
},
34+
})
35+
36+
function osm2pgsql.process_node(object)
37+
nodes:insert({
38+
tags = object.tags,
39+
geom = object:as_point(),
40+
})
41+
end
42+
43+
function osm2pgsql.process_way(object)
44+
local geom = object:as_polygon()
45+
46+
if geom:is_null() then
47+
geom = object:as_linestring()
48+
end
49+
50+
ways:insert({
51+
tags = object.tags,
52+
geom = geom,
53+
})
54+
end
55+

0 commit comments

Comments
 (0)