How to stop D3.js from creating infinite areas from linear polygons

176 Views Asked by At

I'm trying to draw topojson features with D3, they are generated by TileStache from a PostGIS database. Small triangular polygons tend to simplify into "lines": the 3 points are on a straight line. If the TopoJSON goes like this the polygon is drawn as a line:

"arcs":[[[609,278],[-1,-1],[-1,-1],[2,2]]]

However if the TopoJSON goes like this:

"arcs":[[[609,278],[-2,-2],[1,1],[1,1]]]}

An infinite area with a 'line shaped' hole is drawn, messing up the map. How can I stop D3 from creating infinite areas when the feature is line-shaped?

You can see the effect of the two styles of TopoJSON here: http://research.geodan.nl/sites/vectortiling/test/faultytile.html

The are greater effect of these infinite features is visible here: http://research.geodan.nl/sites/vectortiling/

1

There are 1 best solutions below

0
On

It is indeed a bug in D3 see: https://github.com/mbostock/d3/issues/2025 I've created a basic fix by checking if the polygon has an area of zero and if so, return false at the pointInPolygon function. Jason and Mike are working on it, so I hope at some point there will be a D3 release which doesn't create infinite polygons :)