0

Original Java:

FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Filter idFilter = ff.id(ff.featureId("100"));

Clojure:

(let [^FilterFactory2 ff (CommonFactoryFinder/getFilterFactory2)
      ^Filter id-filter (.id ff (.featureId ff "100"))]
  (do something...))

When I run this I get IllegalArgumentException No matching method found: id for class org.geotools.filter.FilterFactoryImpl clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)

I know that means it is unable to find a method id for ff. I searched the docs and there is an Id property. I reviewed the Clojure Java Interop docs and it says the dot notation (.id ff) should work for accessing Java properties. I am unsure how to change my code to get the proper result. I am good with Clojure but know very little about Java.

Re var length Java args: To my understanding this question is not related to variable length Java arguments as the main fn ff.id(ff.featureId("100")); takes only one argument (ff.featureId("100")) which evaluates to a String.

Sam Estep
  • 12,974
  • 2
  • 37
  • 75
kittyminky
  • 478
  • 6
  • 27
  • @SamEstep what makes you say this involves variable length args? The fn `ff.id(ff.featureId("100"))` takes only one arg `ff.featureId("100")` which evaluates to a `String`. The issue I am having is with retrieving the `id` property from `ff`. – kittyminky Sep 09 '16 at 02:48
  • 2
    No, `ff.featureId("100")` evaluates to a [`FeatureId`](http://docs.geotools.org/stable/javadocs/org/opengis/filter/identity/FeatureId.html). Meanwhile, [`id`](http://docs.geotools.org/stable/javadocs/org/geotools/filter/FilterFactoryImpl.html#id(org.opengis.filter.identity.FeatureId...)) is a [varargs method](https://en.wikipedia.org/wiki/Java_syntax#Varargs), so from Clojure, you must pass it an array, as stated in the answer to the linked question. – Sam Estep Sep 09 '16 at 02:57
  • I was confused by the FeatureId docs that say `"Features are identified as strings."` Additionally the Id doc(http://docs.geotools.org/stable/javadocs/org/opengis/filter/Id.html) is confusing to someone unfamiliar with Java and does not show anywhere that it is a varargs method. Regardless, even after changing the argument to an array I still get the same error. If I reformat it like the example in that link to `(ff/id (to-array '(.featureId ff identifier)))` I get `CompilerException java.lang.RuntimeException: No such namespace: ff` – kittyminky Sep 09 '16 at 03:14
  • 2
    The [`Id`](http://docs.geotools.org/stable/javadocs/org/opengis/filter/Id.html) class is not a varargs method; however, the [`FilterFactoryImpl#id`](http://docs.geotools.org/stable/javadocs/org/geotools/filter/FilterFactoryImpl.html#id(org.opengis.filter.identity.FeatureId...)) method, which you are trying to call, *is* a varargs method. You need to call it like this: `(.id ff (into-array [(.featureId ff "100")]))` – Sam Estep Sep 09 '16 at 03:26
  • I was incorrectly using an alternative syntax suggested in the link you provided, thank you for your help and the explanation. – kittyminky Sep 09 '16 at 03:38

0 Answers0