Contour Perfectionism


The current contour generation process queries a database for all the contours in a certain area. It then drops any very short contours as these are likely to be artefacts that aren’t useful, and draws tick marks to show slope direction. To make sure the ticks appear on shorter contours, the frequency of tick marks is increased for shorter lines.

Because the contours are generated in a block-by-block fashion, the above process can produce undesirable behaviour at the edges of these blocks – short segments missing and extra ticks – in both cases due to a single contour being made up of multiple segments from multiple blocks:

Contour issues

This problem would go away if each contour could be stitched back together as a single contiguous line. Easier said than done!

To achieve this in PostGIS database world, each query result has to be first broken down into individual line segments, then all combined into a single MultiLineString. ST_LineMerge will then join together adjacent lines, before the result is again broken down into separate, but hopefully complete, contour lines:

SELECT h.way as way, ST_Length(h.way) as length FROM ( SELECT (ST_Dump(ST_LineMerge(ST_collect(g.way)))).geom as way FROM ( SELECT (ST_Dump(ST_Intersection(way, !bbox!))).geom as way FROM lidar3 WHERE (height*2)::integer % (10* &contourSeparation; )::integer != 0 AND (height*2)::integer % (2* &contourSeparation; )::integer = 0 AND ST_Intersects(way,!bbox!) ) as g ) as h
Issues fixed

Much better!


Leave a Reply

Your email address will not be published. Required fields are marked *