Skip to content
Browse files

Merge land polygons.

  • Loading branch information...
1 parent 0a7cee0 commit 6cee6e25282dbb0aab6f1bf740ddb0e2765c7730 @mbostock committed Feb 25, 2013
Showing with 28 additions and 1 deletion.
  1. +1 −1 Makefile
  2. +27 −0 topomerge
View
2 Makefile
@@ -72,7 +72,7 @@ topo/ne_%_us_states_lakes.json: geo/ne_%_us_states_lakes.json
mkdir -p $(dir $@) && $(TOPOJSON) -q 1e5 --id-property=postal -p name -s 7e-7 -o $@ -- states=$<
topo/world-%.json: shp/ne_%_land.shp shp/ne_%_admin_0_countries.shp
- mkdir -p $(dir $@) && $(TOPOJSON) -q 1e5 --id-property=+iso_n3 -o $@ -- land=shp/ne_$*_land.shp countries=shp/ne_$*_admin_0_countries.shp
+ mkdir -p $(dir $@) && $(TOPOJSON) -q 1e5 --id-property=+iso_n3 -- land=shp/ne_$*_land.shp countries=shp/ne_$*_admin_0_countries.shp | ./topomerge land > $@
topo/%.json: shp/%.shp
mkdir -p $(dir $@) && $(TOPOJSON) --id-property=iso_a2 -o $@ -- $<
View
27 topomerge
@@ -0,0 +1,27 @@
+#!/usr/bin/env node
+
+var fs = require("fs")
+
+var topology = JSON.parse(fs.readFileSync("/dev/stdin")),
+ object = topology.objects[process.argv[2]],
+ splice = +process.argv[3],
+ geometryId = {},
+ args = [],
+ type;
+
+object.geometries.forEach(function(g, i) {
+ if (i === splice) return;
+ switch (type = g.type) {
+ case "MultiPolygon": case "MultiLineString": g.arcs.forEach(function(c) { args.push(c); }); break;
+ case "Polygon": case "LineString": args.push(g.arcs); break;
+ default: throw new Error("unsupported type: " + g.type); break;
+ }
+});
+
+object.type = /^Multi/.test(type) ? type : "Multi" + type;
+object.arcs = args;
+delete object.geometries;
+
+// TODO garbage collect arcs
+
+console.log(JSON.stringify(topology));

0 comments on commit 6cee6e2

Please sign in to comment.
Something went wrong with that request. Please try again.