SPB Git

Repository Public

ka1.lua 29.3 KB 675 lines lua

1-- =============================================================================2--                  SP BOUCHER | SOFTWARE & RESEARCH3--             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4-- =============================================================================5--6-- PROJECT METADATA7-- -----------------------------------------------------------------------------8-- Project          : KA Maps Engine9-- File             : server/pipeline/lua/ka1.lua10-- Module           : server11-- Repository       : https://git.spboucher.ai/ka-maps-engine12-- Created          : 2026-12-0113-- Last Modified    : 2026-12-0114--15-- =============================================================================16-- AUTHOR & PROFESSIONAL AFFILIATION17-- =============================================================================18--19-- Author           : Simon-Pierre Boucher20-- Position         : Professor of Finance21-- Institution      : Université du Québec en Outaouais (UQO)22-- Department       : Département des sciences administratives23-- Organization     : SP Boucher24--25-- Website          : https://spboucher.ai26-- Git              : https://git.spboucher.ai27--28-- =============================================================================29-- OFFICIAL CONTACT DIRECTORY30-- =============================================================================31--32-- General          : info@spboucher.ai33-- Professional     : contact@spboucher.ai34-- Direct           : simon@spboucher.ai35-- Research         : research@spboucher.ai36-- Development      : dev@spboucher.ai37-- Support          : support@spboucher.ai38-- Security/Admin   : admin@spboucher.ai39-- Notifications    : notifications@spboucher.ai40--41-- Preferred Contact: support@spboucher.ai42--43-- =============================================================================44-- COPYRIGHT & INTELLECTUAL PROPERTY45-- =============================================================================46--47-- Copyright (c) 202648-- Simon-Pierre Boucher49--50-- All rights reserved where applicable.51--52-- This file is governed by the applicable project license,53-- copyright notices, institutional agreements and relevant law.54--55-- Unless expressly authorized by the applicable license or56-- rights holder, copying, redistribution, sublicensing,57-- publication and commercial exploitation are not permitted.58--59-- Existing third-party rights and notices remain unaffected.60--61-- =============================================================================62-- CONFIDENTIALITY & SECURITY63-- =============================================================================64--65-- Classification   : Public66-- Distribution     : Public repository; use is governed by the project license67-- Security Contact : admin@spboucher.ai68--69-- Access to this source does not independently grant permission70-- to redistribute or disclose confidential materials.71--72-- Do not embed credentials, private keys, access tokens,73-- certificates or confidential personal information.74--75-- =============================================================================76-- LICENSE & MAINTENANCE77-- =============================================================================78--79-- License          : None specified (no license file in this repository)80-- Maintainer       : Simon-Pierre Boucher81-- Technical Contact: dev@spboucher.ai82--83-- =============================================================================84-- END OF SP BOUCHER SOURCE HEADER85-- =============================================================================8687-- KA Maps — schéma osm2pgsql (flex) aligné sur les couches `ka1` (docs/TILE_ENGINE.md).88-- Usage : KM_SCHEMA=osm_next osm2pgsql --output=flex --style ka1.lua …89-- Géométries en EPSG:3857. Les règles de zoom fines sont appliquées par les tables généralisées90-- (pipeline/sql/generalize.sql) et par km-tiler ; ici on normalise les attributs et on pose `minz`.9192local SCHEMA = os.getenv('KM_SCHEMA') or 'osm_next'93local SRID = 38579495local function tbl(name, ids, columns, indexes)96    return osm2pgsql.define_table({97        name = name, schema = SCHEMA, ids = ids, columns = columns, indexes = indexes,98    })99end100101local T = {}102103T.road = tbl('road', { type = 'way', id_column = 'osm_id' }, {104    { column = 'kind', type = 'text', not_null = true },105    { column = 'link', type = 'smallint', not_null = true },106    { column = 'struct', type = 'smallint', not_null = true },107    { column = 'name', type = 'text' },108    { column = 'name_en', type = 'text' },109    { column = 'ref', type = 'text' },110    { column = 'oneway', type = 'smallint', not_null = true },111    { column = 'layer', type = 'smallint', not_null = true },112    { column = 'minz', type = 'smallint', not_null = true },113    { column = 'geom', type = 'linestring', projection = SRID, not_null = true },114})115116T.water = tbl('water', { type = 'area', id_column = 'osm_id' }, {117    { column = 'kind', type = 'text', not_null = true },118    { column = 'name', type = 'text' },119    { column = 'name_en', type = 'text' },120    { column = 'area', type = 'real' },121    { column = 'geom', type = 'polygon', projection = SRID, not_null = true },122})123124T.waterway = tbl('waterway', { type = 'way', id_column = 'osm_id' }, {125    { column = 'kind', type = 'text', not_null = true },126    { column = 'name', type = 'text' },127    { column = 'name_en', type = 'text' },128    { column = 'tunnel', type = 'smallint', not_null = true },129    { column = 'geom', type = 'linestring', projection = SRID, not_null = true },130})131132T.landcover = tbl('landcover', { type = 'area', id_column = 'osm_id' }, {133    { column = 'kind', type = 'text', not_null = true },134    { column = 'area', type = 'real' },135    { column = 'geom', type = 'polygon', projection = SRID, not_null = true },136})137138T.landuse = tbl('landuse', { type = 'area', id_column = 'osm_id' }, {139    { column = 'kind', type = 'text', not_null = true },140    { column = 'name', type = 'text' },141    { column = 'name_en', type = 'text' },142    { column = 'area', type = 'real' },143    { column = 'geom', type = 'polygon', projection = SRID, not_null = true },144})145146T.building = tbl('building', { type = 'area', id_column = 'osm_id' }, {147    { column = 'kind', type = 'text', not_null = true },148    { column = 'h', type = 'int', not_null = true },        -- décimètres149    { column = 'mh', type = 'int', not_null = true },       -- décimètres150    { column = 'hs', type = 'smallint', not_null = true },  -- 1 mesurée, 2 étages, 3 estimée151    { column = 'levels', type = 'real' },152    { column = 'name', type = 'text' },153    { column = 'area', type = 'real' },154    { column = 'src', type = 'text', not_null = true },     -- osm | odb (empreinte ajoutée par enrich-odb.sql)155    { column = 'hsrc', type = 'text' },                     -- origine de la hauteur : osm | nrcan | nrcan_bloc156    { column = 'hy', type = 'smallint' },                   -- année du levé LiDAR157    { column = 'hl', type = 'real' },                       -- hauteur LiDAR appariée (m), pour le rapport158    { column = 'hlc', type = 'text' },                      -- classement LiDAR : mesure | bloc | rejet159    { column = 'geom', type = 'multipolygon', projection = SRID, not_null = true },160})161162T.boundary = tbl('boundary', { type = 'way', id_column = 'osm_id' }, {163    { column = 'level', type = 'smallint', not_null = true },164    { column = 'maritime', type = 'smallint', not_null = true },165    { column = 'geom', type = 'linestring', projection = SRID, not_null = true },166})167168-- Polygones administratifs complets (géocodage inverse, noms de municipalités) : pas dans les tuiles.169T.admin_area = tbl('admin_area', { type = 'relation', id_column = 'osm_id' }, {170    { column = 'level', type = 'smallint', not_null = true },171    { column = 'osm_level', type = 'smallint', not_null = true },172    { column = 'name', type = 'text' },173    { column = 'name_en', type = 'text' },174    { column = 'ref', type = 'text' },175    { column = 'geom', type = 'multipolygon', projection = SRID, not_null = true },176})177178T.place = tbl('place', { type = 'node', id_column = 'osm_id' }, {179    { column = 'kind', type = 'text', not_null = true },180    { column = 'name', type = 'text', not_null = true },181    { column = 'name_en', type = 'text' },182    { column = 'pop', type = 'int' },183    { column = 'capital', type = 'smallint' },184    { column = 'geom', type = 'point', projection = SRID, not_null = true },185})186187T.poi = tbl('poi', { type = 'any', id_column = 'osm_id', type_column = 'osm_type' }, {188    { column = 'kind', type = 'text', not_null = true },189    { column = 'name', type = 'text' },190    { column = 'name_en', type = 'text' },191    { column = 'rank', type = 'smallint', not_null = true },192    { column = 'area', type = 'real' },193    { column = 'geom', type = 'point', projection = SRID, not_null = true },194})195196T.housenum = tbl('housenum', { type = 'any', id_column = 'osm_id', type_column = 'osm_type' }, {197    { column = 'num', type = 'text', not_null = true },198    { column = 'street', type = 'text' },199    { column = 'unit', type = 'text' },200    { column = 'city', type = 'text' },201    { column = 'postcode', type = 'text' },202    { column = 'geom', type = 'point', projection = SRID, not_null = true },203})204205T.transit_line = tbl('transit_line', { type = 'way', id_column = 'osm_id' }, {206    { column = 'kind', type = 'text', not_null = true },207    { column = 'name', type = 'text' },208    { column = 'network', type = 'text' },209    { column = 'colour', type = 'text' },210    { column = 'tunnel', type = 'smallint', not_null = true },211    { column = 'geom', type = 'linestring', projection = SRID, not_null = true },212})213214T.transit_point = tbl('transit_point', { type = 'any', id_column = 'osm_id', type_column = 'osm_type' }, {215    { column = 'kind', type = 'text', not_null = true },216    { column = 'name', type = 'text' },217    { column = 'network', type = 'text' },218    { column = 'colour', type = 'text' },219    { column = 'geom', type = 'point', projection = SRID, not_null = true },220})221222-- ---------------------------------------------------------------------------------------------223224local function names(tags)225    local n = tags['name:fr'] or tags.name226    local en = tags['name:en']227    if en == n then en = nil end228    return n, en229end230231local function yes(v) return v == 'yes' or v == 'true' or v == '1' end232233local function to_int(v)234    if not v then return nil end235    local n = tonumber((v:gsub('[%s,]', '')))236    if n and n == n and n >= 0 and n < 2e9 then return math.floor(n) end237    return nil238end239240local function layer_of(tags)241    local l = tonumber(tags.layer or '')242    if not l or l ~= l then return 0 end243    l = math.floor(l)244    if l > 5 then l = 5 elseif l < -5 then l = -5 end245    return l246end247248-- Longueur en mètres : « 12 », « 12.5 m », « 40 ft », « 40' », « 12,5 ».249local function metres(v)250    if not v then return nil end251    local s = v:lower():gsub(',', '.')252    local ft, inch = s:match("^%s*(%d+%.?%d*)%s*'%s*(%d*%.?%d*)")253    if ft then254        return tonumber(ft) * 0.3048 + (tonumber(inch) or 0) * 0.0254255    end256    local num, unit = s:match('^%s*(%d+%.?%d*)%s*(%a*)')257    num = tonumber(num)258    if not num then return nil end259    if unit == 'ft' or unit == 'feet' or unit == 'foot' then return num * 0.3048 end260    if unit == '' or unit == 'm' or unit == 'metre' or unit == 'metres' or unit == 'meter' or unit == 'meters' then261        return num262    end263    return nil264end265266-- ----------------------------------------------------------------------------- routes267268local HIGHWAY = {269    motorway = { 'motorway', 0, 4 }, motorway_link = { 'motorway', 1, 9 },270    trunk = { 'trunk', 0, 5 }, trunk_link = { 'trunk', 1, 10 },271    primary = { 'primary', 0, 7 }, primary_link = { 'primary', 1, 11 },272    secondary = { 'secondary', 0, 9 }, secondary_link = { 'secondary', 1, 12 },273    tertiary = { 'tertiary', 0, 10 }, tertiary_link = { 'tertiary', 1, 12 },274    unclassified = { 'minor', 0, 12 }, residential = { 'minor', 0, 12 }, living_street = { 'minor', 0, 12 },275    road = { 'minor', 0, 12 }, busway = { 'minor', 0, 13 },276    service = { 'service', 0, 13 },277    pedestrian = { 'path', 0, 13 }, footway = { 'path', 0, 14 }, path = { 'path', 0, 13 },278    steps = { 'path', 0, 14 }, bridleway = { 'path', 0, 14 }, corridor = nil,279    cycleway = { 'cycleway', 0, 13 },280    track = { 'track', 0, 12 },281}282283local function road_struct(tags)284    if tags.tunnel and tags.tunnel ~= 'no' then return 2 end285    if tags.covered == 'yes' and tags.highway then return 2 end286    if tags.bridge and tags.bridge ~= 'no' then return 1 end287    return 0288end289290local function process_road(object)291    local tags = object.tags292    local kind, link, minz293    local hw = tags.highway294    if hw then295        local def = HIGHWAY[hw]296        if not def then return end297        if tags.area == 'yes' then return end298        kind, link, minz = def[1], def[2], def[3]299        if kind == 'service' then300            local s = tags.service301            if s == 'parking_aisle' or s == 'driveway' or s == 'drive-through' or s == 'emergency_access' then302                minz = 14303            end304        elseif kind == 'path' and tags.footway == 'sidewalk' or tags.footway == 'crossing' then305            minz = 14306        elseif kind == 'track' and tags.tracktype and tags.tracktype >= 'grade4' then307            minz = 13308        end309    elseif tags.railway == 'rail' or tags.railway == 'narrow_gauge' then310        kind, link, minz = 'rail', 0, 8311        local s = tags.service312        if s == 'yard' or s == 'siding' or s == 'spur' or s == 'crossover' then link, minz = 1, 13 end313        if tags.usage == 'industrial' or tags.usage == 'tourism' then minz = math.max(minz, 10) end314    elseif tags.route == 'ferry' then315        kind, link, minz = 'ferry', 0, 7316    else317        return318    end319    local name, name_en = names(tags)320    local ow = 0321    if yes(tags.oneway) or tags.oneway == '-1' or tags.junction == 'roundabout'322        or (hw == 'motorway' and tags.oneway ~= 'no') then323        ow = 1324    end325    local ref = tags.ref326    if ref and #ref > 24 then ref = nil end327    T.road:insert({328        kind = kind, link = link, struct = road_struct(tags), name = name, name_en = name_en, ref = ref,329        oneway = ow, layer = layer_of(tags), minz = minz, geom = object:as_linestring(),330    })331end332333-- ----------------------------------------------------------------------------- lignes d'eau334335local WATERWAY = { river = 'river', stream = 'stream', canal = 'canal', drain = 'drain', ditch = 'drain' }336337local function process_waterway(object)338    local kind = WATERWAY[object.tags.waterway]339    if not kind then return end340    local name, name_en = names(object.tags)341    local t = object.tags.tunnel342    T.waterway:insert({343        kind = kind, name = name, name_en = name_en,344        tunnel = (t and t ~= 'no') and 1 or 0, geom = object:as_linestring(),345    })346end347348-- ----------------------------------------------------------------------------- surfaces349350local function water_kind(tags)351    if tags.natural == 'water' then352        local w = tags.water353        if w == 'river' or w == 'canal' or w == 'stream' or w == 'rapids' or w == 'lock' then return 'river' end354        if w == 'reservoir' then return 'reservoir' end355        if w == 'basin' or w == 'wastewater' or w == 'reflecting_pool' then return 'basin' end356        return 'lake'357    end358    if tags.waterway == 'riverbank' or tags.waterway == 'dock' then return 'river' end359    if tags.landuse == 'reservoir' then return 'reservoir' end360    if tags.landuse == 'basin' then return 'basin' end361    return nil362end363364local LANDCOVER_NATURAL = {365    wood = 'forest', grassland = 'grass', wetland = 'wetland', bare_rock = 'rock', scree = 'rock',366    sand = 'sand', beach = 'sand', scrub = 'scrub', heath = 'scrub', glacier = 'glacier', fell = 'grass',367    tundra = 'scrub',368}369local LANDCOVER_LANDUSE = {370    forest = 'forest', grass = 'grass', meadow = 'grass', village_green = 'grass',371    farmland = 'farmland', farmyard = 'farmland', orchard = 'farmland', vineyard = 'farmland',372}373374local function landcover_kind(tags)375    return (tags.natural and LANDCOVER_NATURAL[tags.natural]) or (tags.landuse and LANDCOVER_LANDUSE[tags.landuse])376end377378local LANDUSE_LANDUSE = {379    residential = 'residential', commercial = 'commercial', retail = 'commercial', industrial = 'industrial',380    cemetery = 'cemetery', military = 'military', quarry = 'quarry', recreation_ground = 'park',381}382local LANDUSE_LEISURE = {383    park = 'park', garden = 'park', playground = 'park', dog_park = 'park', nature_reserve = 'park',384    pitch = 'pitch', track = 'pitch', golf_course = 'golf',385}386local LANDUSE_AMENITY = {387    school = 'school', kindergarten = 'school', university = 'university', college = 'university',388    hospital = 'hospital', parking = 'parking', grave_yard = 'cemetery',389}390391local function landuse_kind(tags)392    if tags.leisure and LANDUSE_LEISURE[tags.leisure] then393        if tags.leisure == 'garden' and tags.access == 'private' then return nil end394        return LANDUSE_LEISURE[tags.leisure]395    end396    if tags.amenity and LANDUSE_AMENITY[tags.amenity] then397        if tags.amenity == 'parking' and (tags.parking == 'underground' or tags.parking == 'multi-storey') then398            return nil399        end400        return LANDUSE_AMENITY[tags.amenity]401    end402    if tags.landuse and LANDUSE_LANDUSE[tags.landuse] then return LANDUSE_LANDUSE[tags.landuse] end403    if tags.aeroway == 'aerodrome' then return 'airport' end404    if tags.boundary == 'national_park' or (tags.boundary == 'protected_area' and tags.leisure == 'nature_reserve') then405        return 'park'406    end407    return nil408end409410-- ----------------------------------------------------------------------------- bâtiments411412local B_HOUSE = { house = 1, detached = 1, semidetached_house = 1, bungalow = 1, cabin = 1, terrace = 1,413    farm = 1, hut = 1, static_caravan = 1, duplex = 1, triplex = 1, allotment_house = 1, houseboat = 1 }414local B_APART = { apartments = 1, residential = 1, dormitory = 1, hotel = 1, condominium = 1, block = 1 }415local B_INDUS = { industrial = 1, warehouse = 1, manufacture = 1, hangar = 1, factory = 1, storage_tank = 1,416    silo = 1, barn = 1, farm_auxiliary = 1, greenhouse = 1, cowshed = 1, stable = 1, sty = 1 }417local B_COMM = { commercial = 1, retail = 1, office = 1, supermarket = 1, kiosk = 1, store = 1, shop = 1 }418local B_PUBLIC = { school = 1, university = 1, college = 1, hospital = 1, church = 1, cathedral = 1, chapel = 1,419    civic = 1, public = 1, government = 1, kindergarten = 1, train_station = 1, transportation = 1,420    mosque = 1, synagogue = 1, temple = 1, fire_station = 1, stadium = 1, sports_centre = 1, sports_hall = 1,421    library = 1, museum = 1 }422local B_GARAGE = { garage = 1, garages = 1, shed = 1, carport = 1, roof = 1, parking = 1, service = 1 }423424local function building_kind(b)425    if B_HOUSE[b] then return 'house' end426    if B_APART[b] then return 'apartments' end427    if B_INDUS[b] then return 'industrial' end428    if B_COMM[b] then return 'commercial' end429    if B_PUBLIC[b] then return 'public' end430    if B_GARAGE[b] then return 'garage' end431    return 'other'432end433434-- Règle `hs` de TILE_ENGINE.md, appliquée telle quelle.435local function building_height(tags, kind)436    local h = metres(tags.height) or metres(tags['building:height'])437    local levels = tonumber(tags['building:levels'] or '')438    if levels and (levels ~= levels or levels <= 0 or levels > 200) then levels = nil end439    local hs440    if h and h > 0.5 and h < 1000 then441        hs = 1442    elseif levels then443        h = levels * 3.1 + 1.0444        hs = 2445    else446        if kind == 'house' then h = 6 elseif kind == 'apartments' then h = 12447        elseif kind == 'industrial' then h = 8 else h = 7 end448        hs = 3449    end450    local mh = metres(tags.min_height)451    if not mh then452        local ml = tonumber(tags['building:min_level'] or '')453        if ml and ml == ml and ml > 0 and ml < 200 then mh = ml * 3.1 end454    end455    if not mh or mh < 0 or mh >= h then mh = 0 end456    return math.floor(h * 10 + 0.5), math.floor(mh * 10 + 0.5), hs, levels457end458459-- ----------------------------------------------------------------------------- lieux, POI, adresses460461local PLACE = { country = 'country', state = 'province', province = 'province', city = 'city', town = 'town',462    village = 'village', suburb = 'suburb', borough = 'suburb', quarter = 'neighbourhood',463    neighbourhood = 'neighbourhood', hamlet = 'hamlet' }464465local function poi_kind(tags)466    local a, s = tags.amenity, tags.shop467    if a == 'university' then return 'university', 1 end468    if a == 'college' then return 'college', 2 end469    if a == 'school' then return 'school', 3 end470    if a == 'hospital' then return 'hospital', 1 end471    if a == 'clinic' or a == 'doctors' then return 'clinic', 3 end472    if a == 'pharmacy' or s == 'chemist' then return 'pharmacy', 3 end473    if a == 'library' then return 'library', 2 end474    if s == 'supermarket' then return 'grocery', 2 end475    if s == 'grocery' or s == 'greengrocer' or s == 'convenience' then return 'grocery', 3 end476    if s == 'mall' then return 'mall', 1 end477    if tags.leisure == 'park' or tags.boundary == 'national_park' then return 'park', 2 end478    if tags.aeroway == 'aerodrome' then479        if tags.iata then return 'airport', 1 end480        return 'airport', 3481    end482    if tags.railway == 'station' or tags.railway == 'halt' then return 'station', 1 end483    return nil484end485486local function transit_point_kind(tags)487    if tags.railway == 'station' or tags.railway == 'halt' then488        local net = (tags.network or '') .. ' ' .. (tags.operator or '')489        if net:find('REM') or net:find('Réseau express métropolitain') then return 'rem' end490        if tags.station == 'subway' or tags.subway == 'yes' then return 'metro' end491        if tags.station == 'light_rail' or tags.light_rail == 'yes' then return 'rem' end492        return 'train'493    end494    if tags.amenity == 'bus_station' then return 'bus_terminal' end495    return nil496end497498local function add_points(object, point_fn, area)499    local tags = object.tags500    local pk, prank = poi_kind(tags)501    local name, name_en502    if pk and (tags.name or pk == 'pharmacy' or pk == 'grocery' or pk == 'clinic') then503        name, name_en = names(tags)504        if not (pk == 'park' and not name) then505            T.poi:insert({ kind = pk, name = name, name_en = name_en, rank = prank, area = area, geom = point_fn() })506        end507    end508    local tk = transit_point_kind(tags)509    if tk then510        name, name_en = names(tags)511        T.transit_point:insert({ kind = tk, name = name, network = tags.network, colour = tags.colour, geom = point_fn() })512    end513    local num = tags['addr:housenumber']514    if num and #num <= 16 then515        T.housenum:insert({516            num = num, street = tags['addr:street'], unit = tags['addr:unit'], city = tags['addr:city'],517            postcode = tags['addr:postcode'], geom = point_fn(),518        })519    end520end521522-- ----------------------------------------------------------------------------- relations → voies523524local way_boundary = {}   -- way id → { level, maritime }525local way_transit = {}    -- way id → { kind, name, network, colour }526527local ADMIN = { ['2'] = 2, ['4'] = 4, ['6'] = 6, ['8'] = 8, ['9'] = 10, ['10'] = 10 }528local ROUTE = { subway = 'subway', light_rail = 'light_rail', tram = 'tram', train = 'train' }529local RAIL_TRANSIT = { subway = 'subway', light_rail = 'light_rail', tram = 'tram' }530531function osm2pgsql.select_relation_members(relation)532    local t = relation.tags533    if t.type == 'boundary' and t.boundary == 'administrative' and ADMIN[t.admin_level] then534        return { ways = osm2pgsql.way_member_ids(relation) }535    end536    if t.type == 'route' and ROUTE[t.route] then537        return { ways = osm2pgsql.way_member_ids(relation) }538    end539end540541-- ----------------------------------------------------------------------------- traitement542543local function process_area(object, geom, is_relation)544    local tags = object.tags545    local did = false546547    local b = tags.building548    if b and b ~= 'no' then549        local kind = building_kind(b)550        local h, mh, hs, levels = building_height(tags, kind)551        local name = names(tags)552        T.building:insert({ kind = kind, h = h, mh = mh, hs = hs, levels = levels, name = name,553            area = geom:area(), src = 'osm', hsrc = (hs == 1) and 'osm' or nil, geom = geom })554        did = true555    end556557    local wk = water_kind(tags)558    local lc = (not wk) and landcover_kind(tags) or nil559    local lu = (not wk) and landuse_kind(tags) or nil560    if wk or lc or lu then561        local name, name_en = names(tags)562        for g in geom:geometries() do563            local a = g:area()564            if wk then565                T.water:insert({ kind = wk, name = name, name_en = name_en, area = a, geom = g })566            end567            if lc then T.landcover:insert({ kind = lc, area = a, geom = g }) end568            if lu then T.landuse:insert({ kind = lu, name = name, name_en = name_en, area = a, geom = g }) end569        end570        did = true571    end572573    if tags.amenity or tags.shop or tags.leisure or tags.aeroway or tags.railway or tags['addr:housenumber']574        or tags.boundary then575        local c576        add_points(object, function()577            if not c then578                local ok, p = pcall(function() return geom:pole_of_inaccessibility() end)579                if ok and p and not p:is_null() then c = p else c = geom:centroid() end580            end581            return c582        end, geom:area())583    end584    return did585end586587function osm2pgsql.process_node(object)588    local tags = object.tags589    local pk = tags.place and PLACE[tags.place]590    if pk and tags.name then591        local name, name_en = names(tags)592        local cap = nil593        if tags.capital == 'yes' then cap = 2 elseif tags.capital then cap = tonumber(tags.capital) end594        T.place:insert({ kind = pk, name = name, name_en = name_en, pop = to_int(tags.population), capital = cap,595            geom = object:as_point() })596    end597    if tags.amenity or tags.shop or tags.leisure or tags.aeroway or tags.railway or tags['addr:housenumber'] then598        add_points(object, function() return object:as_point() end, nil)599    end600end601602function osm2pgsql.process_way(object)603    local tags = object.tags604605    -- Limites administratives et lignes de transport : attributs hérités des relations (2e passe).606    local wb = way_boundary[object.id]607    if wb then608        local mar = wb.maritime609        if tags.maritime == 'yes' or tags.boundary_type == 'maritime' or tags.natural == 'coastline' then mar = 1 end610        T.boundary:insert({ level = wb.level, maritime = mar, geom = object:as_linestring() })611    end612    local wt = way_transit[object.id]613    local rk = tags.railway and RAIL_TRANSIT[tags.railway]614    if wt or rk then615        local kind = rk or (wt and wt.kind)616        -- Une voie ferrée ordinaire empruntée par un train de voyageurs : kind = train.617        if kind and not (wt == nil and tags.service) then618            local tn = tags.tunnel619            T.transit_line:insert({620                kind = kind, name = wt and wt.name or tags.name, network = wt and wt.network or tags.network,621                colour = wt and wt.colour or tags.colour, tunnel = (tn and tn ~= 'no') and 1 or 0,622                geom = object:as_linestring(),623            })624        end625    end626627    if tags.highway or tags.railway or tags.route == 'ferry' then process_road(object) end628    if tags.waterway then process_waterway(object) end629630    if object.is_closed and tags.area ~= 'no' then631        if tags.building or tags.natural or tags.landuse or tags.leisure or tags.amenity or tags.aeroway632            or tags.shop or tags.waterway == 'riverbank' or tags.waterway == 'dock' or tags.boundary633            or (tags['addr:housenumber'] and not tags.highway) then634            local geom = object:as_polygon():transform(SRID)635            if not geom:is_null() then process_area(object, geom, false) end636        end637    elseif tags['addr:housenumber'] and tags['addr:interpolation'] == nil then638        -- voie ouverte avec adresse : ignorée639    end640end641642function osm2pgsql.process_relation(object)643    local t = object.tags644    if t.type == 'boundary' and t.boundary == 'administrative' and ADMIN[t.admin_level] then645        local level = ADMIN[t.admin_level]646        local mar = (t.maritime == 'yes' or t.boundary_type == 'maritime') and 1 or 0647        for _, id in ipairs(osm2pgsql.way_member_ids(object)) do648            local cur = way_boundary[id]649            if not cur or level < cur.level then way_boundary[id] = { level = level, maritime = mar } end650        end651        local geom = object:as_multipolygon()652        if not geom:is_null() then653            local name, name_en = names(t)654            T.admin_area:insert({ level = level, osm_level = tonumber(t.admin_level), name = name, name_en = name_en,655                ref = t.ref or t['ref:statcan'], geom = geom })656        end657        return658    end659    if t.type == 'route' and ROUTE[t.route] then660        local info = { kind = ROUTE[t.route], name = t.ref or t.name, network = t.network, colour = t.colour }661        for _, id in ipairs(osm2pgsql.way_member_ids(object)) do662            local cur = way_transit[id]663            -- priorité : métro/REM/tram avant train ; sinon première relation rencontrée664            if not cur or (cur.kind == 'train' and info.kind ~= 'train') then way_transit[id] = info end665        end666        return667    end668    if t.type == 'multipolygon' or (t.type == 'boundary' and (t.boundary == 'national_park' or t.boundary == 'protected_area')) then669        if t.building or t.natural or t.landuse or t.leisure or t.amenity or t.aeroway or t.waterway or t.boundary then670            local geom = object:as_multipolygon():transform(SRID)671            if not geom:is_null() then process_area(object, geom, true) end672        end673    end674end675
Files main
Menu

Theme