Commit de42ec83 authored by Clément Igonet's avatar Clément Igonet

osm2x3d - Add "factor" feature to optimize request from OSM server.

parent 755a5574
...@@ -29,7 +29,7 @@ var sax = require("sax"); ...@@ -29,7 +29,7 @@ var sax = require("sax");
var turf = require('turf'); var turf = require('turf');
var log = require('loglevel'); var log = require('loglevel');
log.setLevel("debug"); log.setLevel("warn");
function getRGB(osmColor) { function getRGB(osmColor) {
if (osmColor) { if (osmColor) {
...@@ -42,7 +42,7 @@ function getRGB(osmColor) { ...@@ -42,7 +42,7 @@ function getRGB(osmColor) {
return color.toRGB(); return color.toRGB();
} }
} }
return "rgb(240,240,240)"; return undefined;
} }
function heightToMeter(height) { function heightToMeter(height) {
...@@ -169,14 +169,18 @@ function convert(options, onConvert) { ...@@ -169,14 +169,18 @@ function convert(options, onConvert) {
onRelation = false; onRelation = false;
var way = {}; var way = {};
var relation = {}; var relation = {};
bounds = groundBlock(
options.bounds,
((options && options.tile) ? options.tile : null));
blocks[blocks.length] = bounds;
xmlStream.on('opentag', function(node) { xmlStream.on('opentag', function(node) {
var name = node.name, var name = node.name,
attrs = node.attributes; attrs = node.attributes;
if (name === 'bounds') { // if (name === 'bounds') {
var tile = ((options && options.tile) ? options.tile : null); // var tile = ((options && options.tile) ? options.tile : null);
bounds = groundBlock(attrs, tile); // bounds = groundBlock(attrs, tile);
blocks[blocks.length] = bounds; // blocks[blocks.length] = bounds;
} else if (name === 'node') { if (name === 'node') {
var id = +attrs.id; var id = +attrs.id;
var lat = attrs.lat; var lat = attrs.lat;
var lon = attrs.lon; var lon = attrs.lon;
...@@ -246,14 +250,17 @@ function convert(options, onConvert) { ...@@ -246,14 +250,17 @@ function convert(options, onConvert) {
relation.name = attrs.v; relation.name = attrs.v;
break; break;
case 'building:part': case 'building:part':
relation.isBldPart = (attrs.v === 'yes'); log.debug('relation ' + relation.id + ' is a buildingPart');
relation.isBld = (attrs.v === 'yes'); relation.isBldPart = true;
relation.isBld = true;
break; break;
case 'building': case 'building':
relation.isBld = (attrs.v === 'yes'); relation.isBld = true;
log.debug('relation ' + relation.id + ' is a building');
log.debug('relation:' + JSON.stringify(relation));
break; break;
case 'type': case 'type':
relation.isBld = (attrs.v === 'building'); relation.isBld = (attrs.v === 'building') ? true : relation.isBld;
break; break;
case 'height': case 'height':
relation.osmBldPartHeight = heightToMeter(attrs.v); relation.osmBldPartHeight = heightToMeter(attrs.v);
...@@ -277,7 +284,7 @@ function convert(options, onConvert) { ...@@ -277,7 +284,7 @@ function convert(options, onConvert) {
// var roof = roofBlock(way); // var roof = roofBlock(way);
// } // }
var geoBldPart = geoBldPartBlock(way); var geoBldPart = geoBldPartBlock(way);
if (way.isBld && !way.isBldPart) { if (way.isBld) {
var geoBld = getGeoBuilding(geoBlds, +way.id); var geoBld = getGeoBuilding(geoBlds, +way.id);
geoBld.features[geoBld.features.length] = geoBldPart; geoBld.features[geoBld.features.length] = geoBldPart;
// if (roof && options.loD > 1 && options.geoJsonExtended && options.geoJsonExtended == true) { // if (roof && options.loD > 1 && options.geoJsonExtended && options.geoJsonExtended == true) {
...@@ -300,9 +307,13 @@ function convert(options, onConvert) { ...@@ -300,9 +307,13 @@ function convert(options, onConvert) {
// }, // },
// if (geoBld.features[0].properties.id == "249680748") { // if (geoBld.features[0].properties.id == "249680748") {
if (turf.inside(turf.centroid(geoBld), bounds)) { if (turf.inside(turf.centroid(geoBld), bounds)) {
log.debug('building ' + way.id + ' is inside bounds.');
// if (way.isBldPart || turf.inside(turf.centroid(geoBld), bounds)) { // if (way.isBldPart || turf.inside(turf.centroid(geoBld), bounds)) {
blocks[blocks.length] = JSON.parse(JSON.stringify(geoBld)); blocks[blocks.length] = JSON.parse(JSON.stringify(geoBld));
// } // }
} else {
log.debug('building ' + way.id + ' is not inside bounds.');
} }
// //
// } // }
...@@ -315,38 +326,44 @@ function convert(options, onConvert) { ...@@ -315,38 +326,44 @@ function convert(options, onConvert) {
// console.log('geoBld:', JSON.stringify(geoBld)); // console.log('geoBld:', JSON.stringify(geoBld));
// } // }
} else { } else {
// if (turf.inside(turf.centroid(geoBldPart), bounds)) { if (turf.inside(turf.centroid(geoBldPart), bounds)) {
log.debug('way ' + way.id + ' is inside bounds.');
geoBldParts[+way.id] = geoBldPart; geoBldParts[+way.id] = geoBldPart;
} else {
// } log.debug('way ' + way.id + ' is not inside bounds.');
}
// if (roof) { // if (roof) {
// roofs[+way.id] = roof; // roofs[+way.id] = roof;
// } // }
} }
} else if (name === 'relation') { } else if (name === 'relation') {
log.debug('relation:' + JSON.stringify(relation));
// <tag k="type" v="building"/> // <tag k="type" v="building"/>
if (!relation.isBld) { if (!relation.isBld) {
removeBuilding(geoBlds, +relation.id); removeBuilding(geoBlds, +relation.id);
log.debug("relation is not a building."); log.debug('relation ' + relation.id + ' is not a building.');
} else { } else {
log.debug("relation is a building."); log.debug('relation ' + relation.id + ' is a building.');
var geoBld = getGeoBuilding(geoBlds, relation.id); var geoBld = getGeoBuilding(geoBlds, relation.id);
if (relation.osmBldPartHeight !== undefined) { // if (relation.osmBldPartHeight !== undefined) {
geoBld.properties.name = relation.name; relation.osmBldPartHeight = (relation.osmBldPartHeight !== undefined) ? relation.osmBldPartHeight : 10;
for (var i = 0; i < geoBld.features.length; i++) { geoBld.properties.name = relation.name;
var geoBldPart = geoBld.features[i]; for (var i = 0; i < geoBld.features.length; i++) {
if (geoBldPart.properties.height !== undefined) { var geoBldPart = geoBld.features[i];
geoBldPart.properties.height = relation.osmBldPartHeight; // geoBldPart.properties.height = (relation.osmBldPartHeight !== undefined) ? relation.osmBldPartHeight : 10;
} if (geoBldPart.properties.height === undefined) {
if (geoBldPart.properties.minHeight === undefined) { geoBldPart.properties.height = relation.osmBldPartHeight;
geoBldPart.properties.minHeight = relation.minHeight; }
} // geoBldPart.properties.minHeight = (relation.minHeight !== undefined) ? relation.minHeight : 0;
if (geoBldPart.properties.minHeight === undefined) {
geoBldPart.properties.minHeight = relation.minHeight;
} }
} }
if (turf.inside(turf.centroid(geoBld), bounds)) { // }
blocks[blocks.length] = JSON.parse(JSON.stringify(geoBld)); // if (turf.inside(turf.centroid(geoBld), bounds)) {
} blocks[blocks.length] = JSON.parse(JSON.stringify(geoBld));
// }
log.debug('Add block:' + JSON.stringify(geoBld));
} }
onRelation = false; onRelation = false;
} else if (name === 'osm') { } else if (name === 'osm') {
......
...@@ -4,19 +4,18 @@ ...@@ -4,19 +4,18 @@
"version": "0.0.17", "version": "0.0.17",
"devDependencies": {}, "devDependencies": {},
"dependencies": { "dependencies": {
"body-parser": "~1.0.0", "body-parser": "~1.0.2",
"node-expat": "", "chai": "3.5.0",
"chai": "", "chai-fuzzy": "1.6.1",
"chai-fuzzy": "", "loglevel": "1.4.0",
"loglevel": "", "node-getopt": "0.2.3",
"node-getopt": "", "node-xml-compare": "0.1.0",
"node-xml-compare": "", "pkgfiles": "2.3.0",
"pkgfiles": "",
"rgbcolor": "0.0.4", "rgbcolor": "0.0.4",
"sax": "", "sax": "1.2.1",
"three": "", "three": "0.76.1",
"turf": "", "turf": "2.0.2",
"xslt": "" "xslt": "0.7.0"
}, },
"main": "./web_server.js", "main": "./web_server.js",
"scripts": { "scripts": {
......
...@@ -46,6 +46,7 @@ opt = require('node-getopt').create([ ...@@ -46,6 +46,7 @@ opt = require('node-getopt').create([
.bindHelp() // bind option 'help' to default action .bindHelp() // bind option 'help' to default action
.parseSystem(); // parse command line .parseSystem(); // parse command line
// log.setLevel("warn");
log.setLevel("warn"); log.setLevel("warn");
if (opt.options.debug) { if (opt.options.debug) {
log.setLevel("debug"); log.setLevel("debug");
...@@ -97,6 +98,7 @@ var server = http.createServer(function(request, response) { ...@@ -97,6 +98,7 @@ var server = http.createServer(function(request, response) {
var args = querystring.parse(url.parse(request.url).query); var args = querystring.parse(url.parse(request.url).query);
log.debug(args); log.debug(args);
if ('format' in args && 'zoom' in args && 'xtile' in args && 'ytile' in args) { if ('format' in args && 'zoom' in args && 'xtile' in args && 'ytile' in args) {
var factor = ('factor' in args) ? args.factor : 0;
// wget "http://www.openstreetmap.org/api/0.6/map?bbox=-73.9874267578125,40.74725696280421,-73.98605346679688,40.74829735476796" -O result.osm // wget "http://www.openstreetmap.org/api/0.6/map?bbox=-73.9874267578125,40.74725696280421,-73.98605346679688,40.74829735476796" -O result.osm
// wget "http://www.openstreetmap.org/api/0.6/tiledata/18/77196/98527" -O tile.osm // wget "http://www.openstreetmap.org/api/0.6/tiledata/18/77196/98527" -O tile.osm
// wget "http://www.openearthview.net/osm2x3d.php?zoom=18&xtile=77196&ytile=98527" -O ESB18_old.x3d // wget "http://www.openearthview.net/osm2x3d.php?zoom=18&xtile=77196&ytile=98527" -O ESB18_old.x3d
...@@ -124,12 +126,17 @@ var server = http.createServer(function(request, response) { ...@@ -124,12 +126,17 @@ var server = http.createServer(function(request, response) {
// tile2lat(+args.ytile, args.zoom), // top // tile2lat(+args.ytile, args.zoom), // top
// method: 'GET' // method: 'GET'
// }; // };
var options = { var options = {
hostname: 'localhost', hostname: 'localhost',
port: 8082, port: 8082,
path: "/osmCache/osmXml?tile=" + args.zoom + "," + args.xtile + "," + args.ytile, path: "/osmCache/osmXml?tile=" +
(args.zoom - factor) + "," +
Math.floor(args.xtile / (Math.pow(2, factor))) + "," +
Math.floor(args.ytile / (Math.pow(2, factor))),
method: 'GET' method: 'GET'
}; };
console.log('options:', options);
// var osmRequest = http.request(optionsOverpass, function(osmReadStream) { // var osmRequest = http.request(optionsOverpass, function(osmReadStream) {
var osmRequest = http.request(options, function(osmReadStream) { var osmRequest = http.request(options, function(osmReadStream) {
log.debug('Get osm map response.') log.debug('Get osm map response.')
...@@ -145,8 +152,15 @@ var server = http.createServer(function(request, response) { ...@@ -145,8 +152,15 @@ var server = http.createServer(function(request, response) {
geoJsonExtended: false, geoJsonExtended: false,
zoom: args.zoom, zoom: args.zoom,
xtile: args.xtile, xtile: args.xtile,
ytile: args.ytile ytile: args.ytile,
bounds: {
minlon: tile2long(+args.xtile, +args.zoom),
maxlon: tile2long(+args.xtile + 1, +args.zoom),
minlat: tile2lat(+args.ytile, +args.zoom),
maxlat: tile2lat(+args.ytile + 1, +args.zoom)
}
} }
// console.log('myOptions:', JSON.stringify(myOptions));
var myWriteStream; var myWriteStream;
switch (args.format) { switch (args.format) {
case "osm": case "osm":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment