Skip to content

Instantly share code, notes, and snippets.

@nsivertsen
Last active March 14, 2017 19:17
Show Gist options
  • Save nsivertsen/5fdd92d78527bac442e81536053f1aa1 to your computer and use it in GitHub Desktop.
Save nsivertsen/5fdd92d78527bac442e81536053f1aa1 to your computer and use it in GitHub Desktop.
Berlin Street Lights
license: mit
height: 800
border: no
.DS_Store
node_modules
lights.xml

All public lights in Berlin.

Source: Geoportal Berlin / Öffentliche Beleuchtung

<!DOCTYPE html>
<meta charset="utf-8">
<style>
</style>
<body>
<canvas width="960" height="800"></canvas>
<script src="//d3js.org/d3.v4.min.js" charset="utf-8"></script>
<script src="//d3js.org/topojson.v2.min.js"></script>
<script>
var canvas = d3.select('canvas'),
context = canvas.node().getContext('2d'),
width = canvas.node().width,
height = canvas.node().height;
canvas
.attr('width', width * window.devicePixelRatio)
.attr('height', height * window.devicePixelRatio)
.style('width', width + 'px')
.style('height', height + 'px');
context.scale(window.devicePixelRatio, window.devicePixelRatio);
var radius = 0.3;
var tau = 2 * Math.PI;
context.beginPath();
context.fillStyle = 'rgb(0, 0, 0)';
context.fillRect(0, 0, width, height);
d3.json('lights.json', function(error, lights) {
if (error) return console.error(error);
context.fillStyle = 'rgba(255, 255, 0, 0.4)';
topojson.feature(lights, lights.objects.lights).features[0].geometry.coordinates.forEach(function(val, i) {
context.beginPath();
context.arc(val[0], val[1], radius, 0, tau);
context.fill();
});
});
</script>
lights.json: lights_proj.json
./node_modules/.bin/ndjson-split \
< $< \
'd.features' \
| ./node_modules/.bin/ndjson-filter \
'd.properties.STATUS === "In Betrieb"' \
| ./node_modules/.bin/ndjson-map \
'd.geometry.coordinates' \
| ./node_modules/.bin/ndjson-reduce \
'p.coordinates.push(d), p' \
'{type: "MultiPoint", coordinates: []}' \
| ./node_modules/.bin/ndjson-map \
'{type: "FeatureCollection", features: [{type: "Feature", geometry: d}]}' \
| ./node_modules/.bin/geo2topo \
lights=- \
| ./node_modules/.bin/toposimplify \
-p 1 -f \
| ./node_modules/.bin/topo2geo \
lights=- \
| ./node_modules/.bin/geo2topo \
lights=- \
| ./node_modules/.bin/topoquantize \
1e4 \
> $@
lights_proj.json: lights.xml
ogr2ogr -f GeoJSON /vsistdout/ $< \
-s_srs http://spatialreference.org/ref/epsg/25833/ \
-t_srs http://spatialreference.org/ref/epsg/4326/ \
| ./node_modules/.bin/ndjson-cat \
| ./node_modules/.bin/geoproject \
'd3.geoConicEqualArea().parallels([50, 55]).rotate([0, 0]).fitSize([960, 800], d)' \
> $@
lights.xml:
curl -o $@ 'http://fbinter.stadt-berlin.de/fb/wfs/geometry/senstadt/re_beleuchtung/?service=wfs&request=GetFeature&version=2.0.0&typeNames=fis:re_beleuchtung&outputFormat=gml2'
.PHONY : clean
clean :
-rm lights.xml \
lights.json
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment