| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- -- Määrame skeemi keskkonnamuutujast või vaikimisi 'public'
- local schema = os.getenv("PGSCHEMA") or "public"
- -- This config example file is released into the Public Domain.
- -- Get a location for all objects with addresses. If mapped as a polygon or
- -- multipolygon, the centroid will be used.
- local addrs = osm2pgsql.define_table({
- name = 'addrs',
- schema = schema,
- proj = 3301,
- ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' },
- columns = {
- { column = 'name', type = 'text' },
- { column = 'country', type = 'text' },
- { column = 'state', type = 'text' },
- { column = 'postcode', type = 'text' },
- { column = 'city', type = 'text' },
- { column = 'place', type = 'text' },
- { column = 'street', type = 'text' },
- { column = 'housenumber', type = 'text' },
- { column = 'geom', type = 'point', projection = 3301, not_null = true }
- }
- })
- local function get_address(tags)
- local addr = {}
- local count = 0
- for _, key in ipairs({'housenumber', 'street', 'city', 'postcode', 'country', 'state', 'place'}) do
- local a = tags['addr:' .. key]
- if a then
- addr[key] = a
- count = count + 1
- end
- end
- return count > 1, addr
- end
- function osm2pgsql.process_node(object)
- local any, addr = get_address(object.tags)
- if any then
- addr.name = object.tags.name
- addr.geom = object:as_point()
- addrs:insert(addr)
- end
- end
- function osm2pgsql.process_way(object)
- if object.is_closed then
- local any, addr = get_address(object.tags)
- if any then
- addr.name = object.tags.name
- addr.geom = object:as_polygon():centroid()
- addrs:insert(addr)
- end
- end
- end
- function osm2pgsql.process_relation(object)
- if object.tags.type == 'multipolygon' then
- local any, addr = get_address(object.tags)
- if any then
- addr.name = object.tags.name
- addr.geom = object:as_multipolygon():centroid()
- addrs:insert(addr)
- end
- end
- end
|