Skip to content

Changes on TopoJSON

26. March 2013

Today I made some experiments with the TopoJSON file format and topological consistent line simplification, applying Visvalingham algorithm (like in this example). In previous posts, I have already described how to install and understand TopoJSON.

Therefore, I made a TopoJSON file that contains the borders of german states and the rivers ‘Rhine’ and ‘Oder’. As these two rivers are partially identical with german borders, they will share also ‘arcs’ within the TopoJSON file. And when they share arcs…I am able to simply detect topological ‘anchor points’…which I can use as fixed points during line simplification.

But I got this error…

        var i = -1, n = coordinates.length;
TypeError: Cannot read property 'length' of undefined


…when I tried to apply this command:

topojson \
  -o de-osm-data_river2.json \
  rhein.json \
  oder.json \

Hmmm…I’ve got no clue what causes this problem…but maybe it will help to change something in the source code.

So I’ve opened the according file…

sudo gedit /usr/local/lib/node_modules/topojson/lib/topojson/type.js

…and changed these lines…

line: function(coordinates) {
var i = -1, n = coordinates.length;
while (++i < n) this.point(coordinates[i]);

to this:

line: function(coordinates) {
if (coordinates){
var i = -1, n = coordinates.length;
while (++i < n) this.point(coordinates[i]);

That solved the problem, but you can see in the resulting visualisation what is the problem…some parts of the rivers are laying outside of the boundary of the states.json. In result, are these parts not displayed in my map.

See in the next post, how I get the river-data.

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: