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");
var turf = require('turf');
var log = require('loglevel');
log.setLevel("debug");
log.setLevel("warn");
function getRGB(osmColor) {
if (osmColor) {
......@@ -42,7 +42,7 @@ function getRGB(osmColor) {
return color.toRGB();
}
}
return "rgb(240,240,240)";
return undefined;
}
function heightToMeter(height) {
......@@ -169,14 +169,18 @@ function convert(options, onConvert) {
onRelation = false;
var way = {};
var relation = {};
bounds = groundBlock(
options.bounds,
((options && options.tile) ? options.tile : null));
blocks[blocks.length] = bounds;
xmlStream.on('opentag', function(node) {
var name = node.name,
attrs = node.attributes;
if (name === 'bounds') {
var tile = ((options && options.tile) ? options.tile : null);
bounds = groundBlock(attrs, tile);
blocks[blocks.length] = bounds;
} else if (name === 'node') {
// if (name === 'bounds') {
// var tile = ((options && options.tile) ? options.tile : null);
// bounds = groundBlock(attrs, tile);
// blocks[blocks.length] = bounds;
if (name === 'node') {
var id = +attrs.id;
var lat = attrs.lat;
var lon = attrs.lon;
......@@ -246,14 +250,17 @@ function convert(options, onConvert) {
relation.name = attrs.v;
break;
case 'building:part':
relation.isBldPart = (attrs.v === 'yes');
relation.isBld = (attrs.v === 'yes');
log.debug('relation ' + relation.id + ' is a buildingPart');
relation.isBldPart = true;
relation.isBld = true;
break;
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;
case 'type':
relation.isBld = (attrs.v === 'building');
relation.isBld = (attrs.v === 'building') ? true : relation.isBld;
break;
case 'height':
relation.osmBldPartHeight = heightToMeter(attrs.v);
......@@ -277,7 +284,7 @@ function convert(options, onConvert) {
// var roof = roofBlock(way);
// }
var geoBldPart = geoBldPartBlock(way);
if (way.isBld && !way.isBldPart) {
if (way.isBld) {
var geoBld = getGeoBuilding(geoBlds, +way.id);
geoBld.features[geoBld.features.length] = geoBldPart;
// if (roof && options.loD > 1 && options.geoJsonExtended && options.geoJsonExtended == true) {
......@@ -300,9 +307,13 @@ function convert(options, onConvert) {
// },
// if (geoBld.features[0].properties.id == "249680748") {
if (turf.inside(turf.centroid(geoBld), bounds)) {
log.debug('building ' + way.id + ' is inside bounds.');
// if (way.isBldPart || turf.inside(turf.centroid(geoBld), bounds)) {
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) {
// console.log('geoBld:', JSON.stringify(geoBld));
// }
} else {
// if (turf.inside(turf.centroid(geoBldPart), bounds)) {
geoBldParts[+way.id] = geoBldPart;
// }
if (turf.inside(turf.centroid(geoBldPart), bounds)) {
log.debug('way ' + way.id + ' is inside bounds.');
geoBldParts[+way.id] = geoBldPart;
} else {
log.debug('way ' + way.id + ' is not inside bounds.');
}
// if (roof) {
// roofs[+way.id] = roof;
// }
}
} else if (name === 'relation') {
log.debug('relation:' + JSON.stringify(relation));
// <tag k="type" v="building"/>
if (!relation.isBld) {
removeBuilding(geoBlds, +relation.id);
log.debug("relation is not a building.");
log.debug('relation ' + relation.id + ' is not a building.');
} else {
log.debug("relation is a building.");
log.debug('relation ' + relation.id + ' is a building.');
var geoBld = getGeoBuilding(geoBlds, relation.id);
if (relation.osmBldPartHeight !== undefined) {
geoBld.properties.name = relation.name;
for (var i = 0; i < geoBld.features.length; i++) {
var geoBldPart = geoBld.features[i];
if (geoBldPart.properties.height !== undefined) {
geoBldPart.properties.height = relation.osmBldPartHeight;
}
if (geoBldPart.properties.minHeight === undefined) {
geoBldPart.properties.minHeight = relation.minHeight;
}
// if (relation.osmBldPartHeight !== undefined) {
relation.osmBldPartHeight = (relation.osmBldPartHeight !== undefined) ? relation.osmBldPartHeight : 10;
geoBld.properties.name = relation.name;
for (var i = 0; i < geoBld.features.length; i++) {
var geoBldPart = geoBld.features[i];
// geoBldPart.properties.height = (relation.osmBldPartHeight !== undefined) ? relation.osmBldPartHeight : 10;
if (geoBldPart.properties.height === undefined) {
geoBldPart.properties.height = relation.osmBldPartHeight;
}
// 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;
} else if (name === 'osm') {
......
......@@ -4,19 +4,18 @@
"version": "0.0.17",
"devDependencies": {},
"dependencies": {
"body-parser": "~1.0.0",
"node-expat": "",
"chai": "",
"chai-fuzzy": "",
"loglevel": "",
"node-getopt": "",
"node-xml-compare": "",
"pkgfiles": "",
"body-parser": "~1.0.2",
"chai": "3.5.0",
"chai-fuzzy": "1.6.1",
"loglevel": "1.4.0",
"node-getopt": "0.2.3",
"node-xml-compare": "0.1.0",
"pkgfiles": "2.3.0",
"rgbcolor": "0.0.4",
"sax": "",
"three": "",
"turf": "",
"xslt": ""
"sax": "1.2.1",
"three": "0.76.1",
"turf": "2.0.2",
"xslt": "0.7.0"
},
"main": "./web_server.js",
"scripts": {
......
......@@ -46,6 +46,7 @@ opt = require('node-getopt').create([
.bindHelp() // bind option 'help' to default action
.parseSystem(); // parse command line
// log.setLevel("warn");
log.setLevel("warn");
if (opt.options.debug) {
log.setLevel("debug");
......@@ -97,6 +98,7 @@ var server = http.createServer(function(request, response) {
var args = querystring.parse(url.parse(request.url).query);
log.debug(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/tiledata/18/77196/98527" -O tile.osm
// 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) {
// tile2lat(+args.ytile, args.zoom), // top
// method: 'GET'
// };
var options = {
hostname: 'localhost',
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'
};
console.log('options:', options);
// var osmRequest = http.request(optionsOverpass, function(osmReadStream) {
var osmRequest = http.request(options, function(osmReadStream) {
log.debug('Get osm map response.')
......@@ -145,8 +152,15 @@ var server = http.createServer(function(request, response) {
geoJsonExtended: false,
zoom: args.zoom,
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;
switch (args.format) {
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