Contour Lines in Qgis

What with the GSoC project and all the other general discussion about analysis tools in QGis, I got somehow sidetracked into pondering how to do contour maps in QGis. There's the hard way: writing a bunch of C++ code to implement a contouring algorithm, then hooking that into QGis and into the GUI for raster drawing properties. Ah, no.

So quick hackery time. Take a raster data set into R, use R's contour() function to get a list of contour lines and heights, then convert that into a SpatialLinesDataFrame using functions in the "sp" package, then convert that to a shapefile of lines using functions in the "rgdal" package. Load resulting shapefile into QGis and look at the pretty contour lines. Style to taste. See attached screenshot (if it uploads ok).

It's far from perfect - when R draws contour plots it puts the labels on the contour lines in a very nice way. Fiddling with line labelling in QGis couldn't get me that effect. Eventually I might package this up as a plugin, but for now I'll just have to leave you to bash your own code together to do this!

It did get me thinking about other "transformative" plugins though - from polygons to point-centroids, from points to voronoi polygons and so forth. Maybe these can be done via GRASS, but it might interesting to implement them using Shapely...

Okay I think that qualifies as rambling enough...

AttachmentSize
contours.png68.37 KB

Reply