Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [geomesa-users] Querying Using Geometries

Hi Nathan,

Thanks for the update! 

Shout if we can help out with anything else.

Cheers,

Jim

On 11/10/2015 12:18 PM, Nathan Mercer wrote:

Hey Jim,

 

My mistake. Although I was still using a FilterFactory rather than a FilterFactory2 because I was being silly and doing this:

FilterFactory ff = CommonFactoryFinder.getFilterFactory2();

 

After fixing this to actually make ff a FilterFactory2, the code in the link you sent me works. It appears that the ff.property and ff.literal are converted to _expression_ objects which are compatible with FilterFactory2 implementation of dwithin.

 

Thank you very much!

 

Nathan

 

From: geomesa-users-bounces@xxxxxxxxxxxxxxxx [mailto:geomesa-users-bounces@xxxxxxxxxxxxxxxx] On Behalf Of Nathan Mercer
Sent: Monday, November 9, 2015 3:05 PM
To: Geomesa User discussions <geomesa-users@xxxxxxxxxxxxxxxx>
Subject: Re: [geomesa-users] Querying Using Geometries

 

Thanks Jim,

 

But unfortunately this does not work.

 

The problem is that dwithin takes in a org.opengis.geometry object, and using the code you describe, it would be a com.vividsolutions.jts.geom.Point object and it does not work.

 

In the example link you sent, it appears that they are using the FilterFactory2 version of dwithin and they are passing in a ff.property and ff.literal rather than a String and a Geometry. Unfortunately this does not work for me. The interface to dwithin must have changed since the example code was written.

 

Thanks for your help. It appears that I may be stuck using the CQL string version for now.

 

Nathan

 

From: geomesa-users-bounces@xxxxxxxxxxxxxxxx [mailto:geomesa-users-bounces@xxxxxxxxxxxxxxxx] On Behalf Of James Hughes
Sent: Friday, November 6, 2015 7:03 PM
To: Geomesa User discussions <geomesa-users@xxxxxxxxxxxxxxxx>
Subject: Re: [geomesa-users] Querying Using Geometries

 

Hi Nathan,

 

Good news, I think this should be pretty quick to fix.  GeoTools uses JTS for most computational geometry and also has some additional geometry interfaces  The exception is due to a mismatch in instances of classes. 

 

The quickest fix would be to change this line:

 

Point pnt = builder.getPrimitiveFactory().createPoint(pos);

to

Point pnt = JTS.toGeometry(pos);

 

I think that should straighten things out.  For some examples of GeoMesa with dwithin (and other filters), check out:

 

 

Cheers,

 

Jim

 

JTS.toGeometry call: 

https://github.com/geotools/geotools/blob/11.x/modules/library/api/src/main/java/org/geotools/geometry/jts/JTS.java#L899


----- Original Message -----

From:

"Geomesa User discussions" <geomesa-users@xxxxxxxxxxxxxxxx>

 

To:

"geomesa-users@xxxxxxxxxxxxxxxx" <geomesa-users@xxxxxxxxxxxxxxxx>

Cc:

 

Sent:

Fri, 6 Nov 2015 15:59:05 -0700

Subject:

[geomesa-users] Querying Using Geometries

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.


  ­­  


  ­­  


  ­­  

_______________________________________________
geomesa-users mailing list
geomesa-users@xxxxxxxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
http://www.locationtech.org/mailman/listinfo/geomesa-users


Back to the top