How to build TopoJSON using geodata from a Web Feature Service (WFS). For more details on how a WFS works, I recommend Using a Web Feature Service.
Data from opendata.admin.ch © GIS-ZH
| .DS_Store | |
| build | |
| node_modules |
How to build TopoJSON using geodata from a Web Feature Service (WFS). For more details on how a WFS works, I recommend Using a Web Feature Service.
Data from opendata.admin.ch © GIS-ZH
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <style> | |
| .grenze { | |
| fill: none; | |
| stroke: #cfcfcf; | |
| stroke-linejoin: round; | |
| stroke-linecap: round; | |
| } | |
| .gemeinde { | |
| fill: #f0f0f0; | |
| } | |
| .gemeinde :hover { | |
| fill: #d7d7d7; | |
| } | |
| .see { | |
| fill: #cbdbe9; | |
| stroke: #b0becb; | |
| } | |
| </style> | |
| <body> | |
| <script src="http://d3js.org/d3.v3.min.js"></script> | |
| <script src="http://d3js.org/topojson.v1.min.js"></script> | |
| <script> | |
| var width = 960, | |
| height = 960; | |
| var path = d3.geo.path() | |
| .projection(null); | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", width) | |
| .attr("height", height); | |
| d3.json("zh.json", function(error, zh) { | |
| svg.append("g") | |
| .attr("class", "gemeinde") | |
| .selectAll("path") | |
| .data(topojson.feature(zh, zh.objects.gemeinden).features) | |
| .enter().append("path") | |
| .attr("d", path); | |
| svg.append("g") | |
| .attr("class", "see") | |
| .selectAll("path") | |
| .data(topojson.feature(zh, zh.objects.seen).features) | |
| .enter().append("path") | |
| .attr("d", path); | |
| svg.append("path") | |
| .datum(topojson.mesh(zh, zh.objects.gemeinden, function(a, b) { return a !== b; })) | |
| .attr("class", "grenze") | |
| .style("stroke-width", "1px") | |
| .attr("d", path); | |
| }); | |
| d3.select(self.frameElement).style("height", height + "px"); | |
| </script> |
| .PHONY: all clean | |
| GENERATED_FILES = \ | |
| zh.json | |
| .SECONDARY: | |
| all: node_modules $(GENERATED_FILES) | |
| clean: | |
| rm -rf build $(GENERATED_FILES) | |
| node_modules: package.json | |
| npm install | |
| touch $@ | |
| build/%.gml: | |
| mkdir -p $(dir $@) | |
| curl 'http://maps.zh.ch/wfs/GemZHWFS?Service=WFS&version=1.1.0&Request=GetFeature&typeName=ms:$*' -o $@.download | |
| mv $@.download $@ | |
| build/gemeinden.json: build/gem_seen_grenzen.gml | |
| rm -f $@ | |
| ogr2ogr -f 'GeoJSON' -where 'art_code = "0" OR art_code = "1" OR art_code = "2"' $@ $< | |
| build/seen.json: build/gem_seen_grenzen.gml | |
| rm -f $@ | |
| ogr2ogr -f 'GeoJSON' -where 'art_code = "3"' $@ $< | |
| zh.json: build/gemeinden.json build/seen.json | |
| mkdir -p $(dir $@) | |
| node_modules/.bin/topojson \ | |
| -o $@ \ | |
| --width=960 \ | |
| --height=960 \ | |
| --margin=10 \ | |
| --simplify=1 \ | |
| --id-property=+bfs \ | |
| -- $^ |
| { | |
| "name": "anonymous", | |
| "version": "0.0.1", | |
| "private": true, | |
| "dependencies": { | |
| "topojson": ">=1.6.6 <2" | |
| } | |
| } |