1

I'm using D3 to create sets of polygons and I'd like to be able to outline the sets. For instance, if you have a set of path elements, such as all the states of Mexico, Canada, and the United States, and you wanted to procedurally draw a border around the path elements that share the same attribute (such as their ccode) is there an established way to do this?

Obviously, I could overlay a national path, but what I want to do is be able to draw these borders dynamically based on different attributes on-the-fly, and I'm using the geo example because I think it's the most comprehensible.

Elijah
  • 4,609
  • 3
  • 28
  • 36

1 Answers1

0

if you can break up your paths so that each path is a border between exactly two regions then you should be able to simply iterate through your "borders list" to determine when to draw each one: i.e. draw a border that has exactly one match in your list of states-to-highlight. Borders with two matches are interior and borders with no matches do not belong to the regions you are interested in.

Superboggly
  • 5,804
  • 2
  • 24
  • 27
  • Conceptually, that's definitely a solution, and I'll take a look at implementing that. But I'm going to leave the question open in the hopes that there's a function or set of functions that do this more cleanly than breaking down what can be very complex polygons into topological faces. – Elijah Nov 19 '12 at 19:37
  • Certainly there is a lot of prep needed to implement my suggestion, but once it is done you will have a good clean and pretty fast solution. You could also determine each point's "touched states" (possibly on-the-fly) and then walk the polygons colouring those segments that meet your criteria. As for functions you want to know how to find the union of polygons. Check out some answers [here](http://stackoverflow.com/questions/2667748/union-of-complex-polygons). Beware that often real-valued polygons will not quite match up perfectly so their unions will still look like two polygons. – Superboggly Nov 19 '12 at 20:25