PostGIS 2.2 rocks!

Posted by Littlebtc on 11 February 2016 in English (English)

Recently I had worked on a simple server that will import the bus stop data from the New Taipei City government and generate map tiles to be used in JOSM, as they seemed to change their license to be compatible. The result is now available on GitHub.


Historically it was hard to implement a feature in the Transport Map: Group near bus stops with the same name. But after a lot of research, I found it is not hard again: PostGIS 2.2 added friendly spatial clustering functions!

So the problem can be mostly solved by one line SQL command now:

INSERT INTO ntpc_stop_group (convex_hull, name)
    SELECT ST_ConvexHull(unnest(ST_ClusterWithin(ST_Buffer(location, 0.0003), 0.001))),
        name from ntpc_stops GROUP BY name;

Use ST_Buffer to generate circles centered at every stops, use ST_ClusterWithin to place them into groups, finally using unnest and ST_ConvexHull to generate the resulting polygon.

The current result looks great and I think further optimization is still possible. :)

Login to leave a comment