From 50a59379d03bb308b900c040b5ad554d35c25def Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 10 Oct 2014 11:21:12 +0100 Subject: Improve handling of building entrances --- create-data.js | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/create-data.js b/create-data.js index 1bdc294..4f224bf 100755 --- a/create-data.js +++ b/create-data.js @@ -703,31 +703,41 @@ function createBuildingParts(buildings, callback) { buildingParts.push.apply(buildingParts, buildingEntrances); - portals.forEach(function(portal) { - console.log(JSON.stringify(portal, null, 4)); + var buildingEntrancesByURI = {}; + buildingEntrances.forEach(function(entrance) { + buildingEntrancesByURI[entrance.properties.uri] = entrance; + }); + portals.forEach(function(portal) { if (portal.building in buildings) { - building = buildings[portal.building] + var building = buildings[portal.building] - portal.buildingpart = "entrance"; + if (portal.uri in buildingEntrancesByURI) { + var entrance = buildingEntrancesByURI[portal.uri]; - var portalObj = { - type: "Feature", + entrance.properties.label = portal.label; + entrance.properties.comment = portal.comment; + } else { + portal.buildingpart = "entrance"; - properties: portal - }; + var portalObj = { + type: "Feature", - if ("lat" in portal && "lon" in portal) { - portalObj.geometry = { - type: "Point", - coordinates: [ - parseFloat(portal.lon, 10), - parseFloat(portal.lat, 10) - ] + properties: portal }; - } - buildingParts.push(portalObj); + if ("lat" in portal && "lon" in portal) { + portalObj.geometry = { + type: "Point", + coordinates: [ + parseFloat(portal.lon, 10), + parseFloat(portal.lat, 10) + ] + }; + } + + buildingParts.push(portalObj); + } buildingProperties = building.properties; if (!("entrances" in buildingProperties)) { @@ -917,7 +927,7 @@ function getDoors(room, callback) { } function getBuildingEntrances(callback) { - var query = "select osm_id, ST_AsGeoJSON(ST_Transform(way, 4326), 10) as polygon from planet_osm_point where ST_Contains((select ST_Union(way) from uni_site), way) and entrance is not null"; + var query = "select osm_id, ST_AsGeoJSON(ST_Transform(way, 4326), 10) as polygon, entrance, uri from planet_osm_point where ST_Contains((select ST_Union(way) from uni_site), way) and entrance is not null"; pg.query(query, function(err, results) { if (err) { @@ -935,6 +945,11 @@ function getBuildingEntrances(callback) { buildingpart: "entrance" } }; + + if (part.uri !== null) { + feature.properties.uri = part.uri; + } + feature.geometry = JSON.parse(part.polygon); callback(null, feature); -- cgit v1.2.3