-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatiment.lua
54 lines (50 loc) · 1.98 KB
/
batiment.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local var_srid = 3948
local var_schema = 'osm_import'
local batiment = osm2pgsql.define_area_table('batiment', {
-- Define an autoincrementing id column, QGIS likes a unique id on the table
{ column = 'id', sql_type = 'serial', create_only = true },
{ column = 'geom', type = 'polygon', not_null = true },
{ column = 'building', sql_type = 'text' },
{ column = 'amenity', sql_type = 'text' },
{ column = 'office', sql_type = 'text' },
{ column = 'tourism', sql_type = 'text' },
{ column = 'leisure', sql_type = 'text' },
{ column = 'tags', type = 'jsonb' },
}, { indexes = {
-- So we get an index on the id column
{ column = 'id', method = 'btree', unique = true },
-- If we define any indexes we don't get the default index on the geometry
-- column, so we add it here.
{ column = 'geom', method = 'gist' }
}})
function osm2pgsql.process_way(object)
if object.is_closed and object.tags.building then
batiment:insert({
tags = object.tags,
geom = object:as_polygon(),
building = object.tags.building,
amenity = object.tags.amenity,
office = object.tags.office,
tourism = object.tags.tourism,
leisure = object.tags.leisure
})
end
end
function osm2pgsql.process_relation(object)
if object.tags.type == 'multipolygon' and object.tags.building then
-- A partir de la relation, nous obtenons des multipolygones...
local mp = object:as_multipolygon()
-- ...et les divisons en polygones que nous insérons dans la table
for geom in mp:geometries() do
batiment:insert({
tags = object.tags,
geom = geom,
building = object.tags.building,
amenity = object.tags.amenity,
office = object.tags.office,
tourism = object.tags.tourism,
leisure = object.tags.leisure
})
end
end
end