2

I have a Java Swing application which loads a line shapefile and draws a map. I'm using a filter and a rule to filter out the lines in the shapefile where the attribute "traffic" is greater than 500. Each line has a different "traffic" value and this works perfectly ("traffic" means the maximum allowable traffic volume of the road). I can make a separate style for this filtered lines.

    Rule rule = sb.createRule(textSymbolizer);
    rule.setFilter(sb.getFilterFactory().greater(
            sb.getFilterFactory().property("traffic"), 
            sb.getFilterFactory().literal(500.0)));
    FeatureTypeStyle fts = sb.createFeatureTypeStyle("Feature",rule);

Now I want to do the following logic

if("traffic" property value > current_traffic_value){
    // style this line uniquely
}

The "current_traffic_value" is a integer value stored in a database for each line. So I want to check each line against a variable value. Can I achieve this using SLD methods? What would be the optimum method to achieve this?

  • I just found a quick method to accomplish this by using 'EnvFunction'. I first set a unique value 'EnvFunction.setGlobalValue(unique_str, variable_value);'. Then, I'd create a function as ' Function fn = ff.function("env", ff.property(unique_str), ff.literal(0));'. This fn can be easily used in 'rule.setfilter()'. I'm sure there are much better and clean ways to achieve this. The drawback here is that I have to set global value for each line. – tybandara Apr 16 '16 at 18:57
0

If I understand what you want then it should be a simple filter like:

Rule rule = sb.createRule(textSymbolizer);
rule.setFilter(sb.getFilterFactory().greater(
        sb.getFilterFactory().property("traffic"), 
        sb.getFilterFactory().property("current_trafic")));
FeatureTypeStyle fts = sb.createFeatureTypeStyle("Feature",rule);
  • I'm sorry if I wasn't clear enough. Actually this is slightly different to what I need. I would need to get the "traffic" property (shapefile attribute) and test it against a value "current_traffic" which is stored in a database. For example, there is a database where the current_traffic for each line is stored. And there is a "traffic" attribute in the shapefile attribute. I want to test these two values. Thanks in advance. – tybandara Apr 18 '16 at 8:54
  • The best plan would be to put all the data in the database and create a view with the join. – Ian Turton Apr 18 '16 at 8:59
  • Just for testing purposes I used 'EnvFunction'. For the next update I'd plan to put all data in a database. Then I believe I'd need to check and test both values and draw the line in the unique way manually on a line feature. Is that what you meant by "create a view with the join"? – tybandara Apr 18 '16 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.