|
| 1 | +-- This config example file is released into the Public Domain. |
| 2 | + |
| 3 | +-- This file shows some options around index creation. |
| 4 | + |
| 5 | +local tables = {} |
| 6 | + |
| 7 | +-- When "indexes" is explicitly set to an empty Lua table, there will be no |
| 8 | +-- index on this table. (The index for the id column is still built if |
| 9 | +-- osm2pgsql needs that for updates.) |
| 10 | +tables.pois = osm2pgsql.define_table({ |
| 11 | + name = 'pois', |
| 12 | + ids = { type = 'node', id_column = 'node_id' }, |
| 13 | + columns = { |
| 14 | + { column = 'tags', type = 'jsonb' }, |
| 15 | + { column = 'geom', type = 'point', not_null = true }, |
| 16 | + }, |
| 17 | + indexes = {} |
| 18 | +}) |
| 19 | + |
| 20 | +-- The "indexes" field is not set at all, you get the default, a GIST index on |
| 21 | +-- the only (or first) geometry column. |
| 22 | +tables.ways = osm2pgsql.define_way_table('ways', { |
| 23 | + { column = 'tags', type = 'jsonb' }, |
| 24 | + { column = 'geom', type = 'linestring', not_null = true }, |
| 25 | +}) |
| 26 | + |
| 27 | +-- Setting "indexes" explicitly: Two indexes area created, one on the polygon |
| 28 | +-- geometry ("geom"), one on the center point geometry ("center"), both use |
| 29 | +-- the GIST method. |
| 30 | +tables.polygons = osm2pgsql.define_area_table('polygons', { |
| 31 | + { column = 'tags', type = 'jsonb' }, |
| 32 | + { column = 'geom', type = 'geometry', not_null = true }, |
| 33 | + { column = 'center', type = 'point', not_null = true }, |
| 34 | +}, { indexes = { |
| 35 | + { column = 'geom', method = 'gist' }, |
| 36 | + { column = 'center', method = 'gist' } |
| 37 | +}}) |
| 38 | + |
| 39 | +-- You can put an index on any column, not just geometry columns, and use any |
| 40 | +-- index method available in your PostgreSQL version. To get a list of methods |
| 41 | +-- use: "SELECT amname FROM pg_catalog.pg_am WHERE amtype = 'i';" |
| 42 | +tables.pubs = osm2pgsql.define_node_table('pubs', { |
| 43 | + { column = 'name', type = 'text' }, |
| 44 | + { column = 'geom', type = 'geometry', not_null = true }, |
| 45 | +}, { indexes = { |
| 46 | + { column = 'geom', method = 'gist' }, |
| 47 | + { column = 'name', method = 'btree' } |
| 48 | +}}) |
| 49 | + |
| 50 | +-- You can also create indexes using multiple columns by specifying an array |
| 51 | +-- as the "column". And you can add a where condition to the index. Note that |
| 52 | +-- the content of the where condition is not checked, but given "as is" to |
| 53 | +-- the database. You have to make sure it makes sense. |
| 54 | +tables.roads = osm2pgsql.define_way_table('roads', { |
| 55 | + { column = 'name', type = 'text' }, |
| 56 | + { column = 'type', type = 'text' }, |
| 57 | + { column = 'ref', type = 'text' }, |
| 58 | + { column = 'geom', type = 'linestring', not_null = true }, |
| 59 | +}, { indexes = { |
| 60 | + { column = { 'name', 'ref' }, method = 'btree' }, |
| 61 | + { column = { 'geom' }, method = 'gist', where = "type='primary'" } |
| 62 | +}}) |
| 63 | + |
| 64 | +-- Instead of on a column (or columns) you can define an index on an expression. |
| 65 | +tables.postboxes = osm2pgsql.define_node_table('postboxes', { |
| 66 | + { column = 'operator', type = 'text' }, |
| 67 | + { column = 'geom', type = 'point', not_null = true }, |
| 68 | +}, { indexes = { |
| 69 | + { expression = 'lower(operator)', method = 'btree' }, |
| 70 | +}}) |
| 71 | + |
| 72 | +-- Helper function that looks at the tags and decides if this is possibly |
| 73 | +-- an area. |
| 74 | +function has_area_tags(tags) |
| 75 | + if tags.area == 'yes' then |
| 76 | + return true |
| 77 | + end |
| 78 | + if tags.area == 'no' then |
| 79 | + return false |
| 80 | + end |
| 81 | + |
| 82 | + return tags.aeroway |
| 83 | + or tags.amenity |
| 84 | + or tags.building |
| 85 | + or tags.harbour |
| 86 | + or tags.historic |
| 87 | + or tags.landuse |
| 88 | + or tags.leisure |
| 89 | + or tags.man_made |
| 90 | + or tags.military |
| 91 | + or tags.natural |
| 92 | + or tags.office |
| 93 | + or tags.place |
| 94 | + or tags.power |
| 95 | + or tags.public_transport |
| 96 | + or tags.shop |
| 97 | + or tags.sport |
| 98 | + or tags.tourism |
| 99 | + or tags.water |
| 100 | + or tags.waterway |
| 101 | + or tags.wetland |
| 102 | + or tags['abandoned:aeroway'] |
| 103 | + or tags['abandoned:amenity'] |
| 104 | + or tags['abandoned:building'] |
| 105 | + or tags['abandoned:landuse'] |
| 106 | + or tags['abandoned:power'] |
| 107 | + or tags['area:highway'] |
| 108 | +end |
| 109 | + |
| 110 | +function osm2pgsql.process_node(object) |
| 111 | + local geom = object:as_point() |
| 112 | + |
| 113 | + tables.pois:insert({ |
| 114 | + tags = object.tags, |
| 115 | + geom = geom |
| 116 | + }) |
| 117 | + |
| 118 | + if object.tags.amenity == 'pub' then |
| 119 | + tables.pubs:insert({ |
| 120 | + name = object.tags.name, |
| 121 | + geom = geom |
| 122 | + }) |
| 123 | + elseif object.tags.amenity == 'post_box' then |
| 124 | + tables.postboxes:insert({ |
| 125 | + operator = object.tags.operator, |
| 126 | + geom = geom |
| 127 | + }) |
| 128 | + end |
| 129 | +end |
| 130 | + |
| 131 | +function osm2pgsql.process_way(object) |
| 132 | + if object.is_closed and has_area_tags(object.tags) then |
| 133 | + local geom = object:as_polygon() |
| 134 | + tables.polygons:insert({ |
| 135 | + tags = object.tags, |
| 136 | + geom = geom, |
| 137 | + center = geom:centroid() |
| 138 | + }) |
| 139 | + else |
| 140 | + tables.ways:insert({ |
| 141 | + tags = object.tags, |
| 142 | + geom = object:as_linestring() |
| 143 | + }) |
| 144 | + end |
| 145 | + |
| 146 | + if object.tags.highway then |
| 147 | + tables.roads:insert({ |
| 148 | + type = object.tags.highway, |
| 149 | + name = object.tags.name, |
| 150 | + ref = object.tags.ref, |
| 151 | + geom = object:as_linestring() |
| 152 | + }) |
| 153 | + end |
| 154 | +end |
| 155 | + |
0 commit comments