Skip to content

Instantly share code, notes, and snippets.

@nrenner
Last active December 26, 2019 23:17
Show Gist options
  • Save nrenner/cdb6e84562a9c183a310 to your computer and use it in GitHub Desktop.
Save nrenner/cdb6e84562a9c183a310 to your computer and use it in GitHub Desktop.
OSM PBF + osmtogeojson test
<!DOCTYPE html>
<html>
<head>
<title>OSM PBF to GeoJSON example (osm-read + osmtogeojson)</title>
<meta charset="utf-8"/>
</head>
<body>
<pre id="log" style="max-height: 480px; overflow-y: auto;"></pre>
<script src="http://nrenner.github.io/osmtogeojson/pbftogeojson.js"></script>
<script>
(function() {
function get(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(evt) {
callback(this.response);
};
xhr.send();
}
function convert(pbf) {
osmtogeojson(pbf, null, function(err, geojson) {
document.getElementById('log').textContent = JSON.stringify(geojson, null, 2);
});
}
get('http://norbertrenner.de/share/testdata.osm.pbf', convert);
})();
</script>
</body>
</html>
var osmtogeojson = require('osmtogeojson');
var parseOsmPbf = require('./node_modules/osmtogeojson/parse_osmpbf.js');
parseOsmPbf('testdata.osm.pbf', function(err, data) {
var geojson = osmtogeojson(data);
console.log(JSON.stringify(geojson, null, 2));
});
{
"main": "index.js",
"dependencies": {
"osmtogeojson": "nrenner/osmtogeojson#gh-pages"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment