Home » Java » How can I query for geolocation with geojson format using arangodb java driver?-Exceptionshub

How can I query for geolocation with geojson format using arangodb java driver?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Is it possible to query for geolocation in ArangoDB using the java driver when using geojson format for location? (https://geojson.org/)

I created my document class like this, also adding a Geometry class within, which maps to the geojson format mentioned above.

@Document("MyDocuments")
public class MyDocument {
    @Id
    private String _id;
    private String someData;
    @GeoIndexed
    private Geometry geometry;

    //getters and setters ...
}


public interface MyRepository extends ArangoRepository<MyDocument, String> {
    GeoPage<MyDocument> findByLocationNear(Point location, Pageable pageable);
}

When invoking:

findByLocationNear(new Point(12.511312, 44.318221), new PageRequest(0, 5));

I get the following error:

Invocation of init method failed; nested exception is
org.springframework.data.mapping.PropertyReferenceException: No
property location found for type MyDocuments!

changing the class member name from geometry to location would result in the following error at runtime:

Error encountered while trying to get information about asset with ID:
c6d162823b19b11b4c38b521cde12add9366633a Message: Response: 404,
Error: 1203 – AQL: collection or view not found: geometry (while
parsing)

However when using an AQL query I manage to get the desired result

LET areaLiteral = GEO_POLYGON(...)

FOR doc IN MyDocuments
FILTER GEO_CONTAINS(areaLiteral, doc.geometry)
LIMIT 5 RETURN doc

I tried the example from the documentation here:

https://github.com/arangodb/spring-data-demo#geospatial-queries

However this does not use the geojson format, only a list of coordinates.

Is there any possibility of achieving the same thing with geojson format?

How to&Answers: