First
I should mention that I am a newbie. Just trying to get
started with GeoMesa. So hopefully what I am asking is
not trivial
I
am having trouble querying based on Geometries with
FilterFactory. I am using the NaturalEarth country
shapefile ingested into Geomesa. I am easily able to
query based on attributes such as getting back all
country features with population between two values.
I
have successfully used the bbox filter because its
interface is bbox(String propertyName, double minx,
double miny, double maxx, double maxy, String srs) which
as you can see does not contain any geometry, simply
double values for the bounding box edges.
However,
when I try to use for example dwithin instead of bbox I
get errors. Its interface is dwithin(String
propertyName, Geometry geometry, double distance, String
units) which you can see takes a Geometry as the second
parameter. This is a org.opengis.geometry geometry btw.
I
am trying to get all country features which are 1000km
from a point with latitude 48.99 and longitude -118.0
(should be Canada and United States).
My
code is as follows:
GeometryBuilder
builder = new
GeometryBuilder(DefaultGeographicCRS.WGS84);
DirectPosition
pos =
builder.getPositionFactory().createDirectPosition(new
double[]{-118.0, 48.99});
Point
pnt = builder.getPrimitiveFactory().createPoint(pos);
FilterFactory
ff = CommonFactoryFinder.getFilterFactory();
Filter
f =
ff.dwithin(CountryFeature.Attribute.the_geom.getName(),
pnt, 10000, "kilometers");
Query
q = new Query(“country”, f);
FeatureCollection
results = featureStore.getFeatures(q);
Of
course there is other code to set up CountryFeature and
the featureStore, but hopefully that code is not
necessary to figure out the issue
The
problem is that when I run this I get the following
error message:
Exception
in thread "main" java.lang.ClassCastException:
org.geotools.geometry.iso.primitive.PointImpl cannot be
cast to com.vividsolutions.jts.geom.Geometry
It
is happening on the last line of the code above. It
appears like it wants a JTS geometry, but dwithin
requires an OpenGIS geometry.
I
am successfully able to change the query to the
following and it works:
Query
q = new Query(“country”, CQL.toFilter("DWITHIN(the_geom,
POINT(-118.0 48.99), 1000.0, kilometers)"));
However
I prefer not to use the CQL format because I then need
to build strings from the values. Also, it means I
cannot take advantage of the filtering capabilities
found in the FilterFactory and FilterFactory2.
Anybody
have ideas on how to get this to work?
If
need be, I can send the rest of the code.