QGIS and Rules Based Rendering |
| Posted by Administrator (mikee) on 12th September, 2011 |
QGIS development continues apace and the latest feature is Rules Based Rendering. This uses SQL like rules to render features in the appropriate manner. The trouble is it's very difficult to get any information how to make this work.
A day of research on the web was what it took to get any information as to how to make this work with a pre-existing layer using some pre-defined rendering rules.
Not sure about you but I hate re-inventing the wheel. I figure that somewhere "out there" there is a set of rules (styles) for rendering such things as roads, areas etc. They are tough to find however, and it did take me an entire day do do it. Then I had to fix what I had found with a little bash-fu to suit my needs. What were my needs? Nothing complicated, I just wanted some predefined roads/paths/railway symbols. Not too difficult I thought but it seems very hard to find out how to do it all and get the data required.
So I eventually found some rules files. However I had no idea as to what it was in my shape file that triggered the rules, nobobody seemed to think I needed to know so no one was telling. I eventually read the manual, even though it contained very little of relevance. It seems I needed an extra text field named "tags" with appropriate content. Looking at the rules it seemed odd that I needed values such as "highway"="path". Note the quotes. It's already a text field why do I need even more quotes? There may a standard somewhere but I failed to turn anything up. Since they seemed unneccesary I fixed the rules file to get rid of them. Having added the tags field I needed to fill it in and what better way than a lookup/dropdown list derived from the rules file itself. To these ends I ran the commands shown below.
Bash commands:
Remove bogus quotes from rules.
sed 's/"//g' points_rules_v29_corrected.qml > points_rules.qml
Create a csv lookup table.
grep "filter=\"tags like" highway_rules.qml | awk -F\' '{print $2}' | sed 's/%//g' | awk -F= '{print $0, ",",$1, $2}' > lines.csv
I'll make the relevant file available as soon as I'm done fixing/testing. I could be wrong about the quotes. So let me know if I am. Obviously I forgot (and cannot re-find) where I got the style files from.
Files can be found here.
So basically if you create a layer with attribues , name & tags (others are optional), then use the approprate .csv file as a source for the tags then you're good to go. Of course it would be great if (UK) OS made all of this easier. The mileage of residents of other countries may vary. :)
Last changed: 14th September, 2011 at 1:45 PM
BackComments
| None Found |
Add Comment