var set1 = d3.set([
48111, 48421, 48195, 48357, 48295, 48205, 48341, 48233, 48393, 48211,
48359, 48375, 48065, 48179, 48483, 48485, 48077, 48337, 48237, 48009,
48503, 48023, 48269, 48125, 48107, 48303, 48219, 48079, 48501, 48445,
48305, 48169,
48117, 48381, 48011, 48129, 48087, 48369, 48069, 48437, 48045, 48191,
48075, 48017, 48279, 48189, 48153, 48345, 48101, 48155, 48197, 48487
]);
var region1 = {type: "FeatureCollection", features: counties.filter(function(d) {return set1.has(d.id); })};
countiesG.append("path")
.datum(region1)
.attr("class", "region")
.attr("d", path);
countiesG.append("path")
.datum(topojson.merge(us, us.objects.counties.geometries.filter(function(d) {return set1.has(d.id); })))
.attr("class", "region-boundary")
.attr("d", path);
You can wrap your merged geometries into a GeoJSON object and save that however you want, e.g.
let feature = topojson.merge(us, us.objects.counties.geometries.filter(function(d) {return set1.has(d.id); }))
let features = {
type: 'FeatureCollection',
features: [
{type: 'Feature', geometry: feature, properties: {}}
]
}
copy(JSON.stringify(feature, null, 2)) // only tested/working in Chrome dev tools
Result for just the feature
above (from the Bostock example you linked): https://gist.github.com/miketahani/c31291432e1d958b27a16e7b92944852
You may want to look into node + D3 to automate this process so you’re not copy/pasting JSON for every merged geometry.
--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
var region1 = {type: "FeatureCollection", features: counties.filter(function(d) {return set1.has(d.id); })};
var region2 = {type: "FeatureCollection", features: counties.filter(function(d) {return set2.has(d.id); })};