Geospatial query - point in polygon - not working

geo
geoindex
query

#1

I have been following the steps on the page http://www.aerospike.com/docs/guide/geospatial.html.

So I have an index:

CREATE INDEX my_geo_index ON test.demoset (geobin) GEO2DSPHERE

I inserted data with Java. This is an example:

aql> select geobin from test.demoset where PK = 5

+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| geobin                                                                                                                                                                                                      |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "{"type":"Polygon","coordinates":[[[-0.151416025313,51.51273574101],[-0.151416025313,51.51722724101],[-0.144198435331,51.51722724101],[-0.144198435331,51.51273574101],[-0.151416025313,51.51273574101]]]}" |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 secs)

However, when I attempt to query in aql I get no results:

SELECT * from test.demoset WHERE geobin CONTAINS CAST('{"type": "Point", "coordinates": [-0.149223, 51.514275]}' AS GEOJSON)

0 rows in set (0.001 secs)

That point is within the polygon in the select above.

Similarly when I query with the Java API, using the geoContains filter, I get no results.

Please let me know what I’m doing wrong!


#2

I found the issue, it was with loading the polygon data to the db. I had been doing this:

Bin bin = new Bin(binName, geoJsonString);

I should have been doing this:

Bin bin = Bin.asGeoJSON(binName, geoJsonString);

Query now works:

aql> SELECT * from test.demoset WHERE geobin CONTAINS CAST('{"type": "Point", "coordinates": [-0.813697, 51.814155]}' AS GEOJSON)
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| geobin                                                                                                                                                                                               |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GeoJSON('{"type":"Polygon","coordinates":[[[-0.817,51.8136],[-0.817,51.8176],[-0.809,51.8176],[-0.809,51.8136],[-0.817,51.8136]]]}')                                                                 |
| GeoJSON('{"type": "Polygon", "coordinates": [[[-0.820279639334,51.8111015],[-0.820279639334,51.8200845],[-0.805748360666,51.8200845],[-0.805748360666,51.8111015],[-0.820279639334,51.8111015]]]}')  |
| GeoJSON('{"type":"Polygon","coordinates":[[[-0.820279639334,51.8111015],[-0.820279639334,51.8200845],[-0.805748360666,51.8200845],[-0.805748360666,51.8111015],[-0.820279639334,51.8111015]]]}')     |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.000 secs)