Skip to content

Instantly share code, notes, and snippets.

@jstcki
Last active August 29, 2015 13:58
Show Gist options
  • Save jstcki/10258270 to your computer and use it in GitHub Desktop.
Save jstcki/10258270 to your computer and use it in GitHub Desktop.
WFS to TopoJSON
.DS_Store
build
node_modules
<!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"
}
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment