1

I have some cql attr > PLACEHOLDER that I want to convert to valid XML using geotools. I have heard of terms like filter functions that can somehow replace the placeholder with a function, but not totally sure the best way to go about this.

0

I wrote a blog post about this a few years ago.

    org.geotools.xml.Configuration configuration = new org.geotools.filter.v1_0.OGCConfiguration();
    org.geotools.xml.Encoder encoder = new org.geotools.xml.Encoder(
        configuration);
    encoder.setIndenting(true);

    line = "attr > PLACEHOLDER";
    try {
        Filter filter = CQL.toFilter(line);
        // System.out.println("\t" + filter);
        encoder.encode(filter, org.geotools.filter.v1_0.OGC.Filter, System.out);
    } catch (CQLException e) {
       e.printStackTrace();
    }

Obviously, in a real program, you'd want to write to a StringBuffer or something instead of stdout. If you want to use the filter at other points in the GeoTools code all you need is filter.

  • Thanks for this writeup, pretty cool stuff. Is there a possible implementation you know of regarding functions? I know this is valid in the 2.0 spec – John Lippson Feb 15 '18 at 18:08
  • Just change the configuration to version 2.0 – Ian Turton Feb 15 '18 at 18:59
  • Ideally what I'm wanting is when a function tag is hit in the XML when I'm converting from XML to CQL it will replace all the placeholders with my input parameters. – John Lippson Feb 15 '18 at 19:25

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.