Geo Mapping. How to index/query a non-point geo property?
dmitryzezix@...
Hello, guys! I've tried to query complex geoshape, but got empty response. What am I doing wrong?
My query: transaction = client.submit(
Index creation: transaction = client.submit(
Vertex creation: transaction = client.submit(
Schema looks like this: [ '------------------------------------------------------------------------------------------------\n' 'Vertex Label Name | Partitioned | Static |\n' '---------------------------------------------------------------------------------------------------\n' 'place | false | false |\n' 'location | false | false |\n' '---------------------------------------------------------------------------------------------------\n' 'Edge Label Name | Directed | Unidirected | Multiplicity |\n' '---------------------------------------------------------------------------------------------------\n' '---------------------------------------------------------------------------------------------------\n' 'Property Key Name | Cardinality | Data Type |\n' '---------------------------------------------------------------------------------------------------\n' 'location | SINGLE | class org.janusgraph.core.attribute.Geoshape |\n' 'place | SINGLE | class org.janusgraph.core.attribute.Geoshape |\n' '---------------------------------------------------------------------------------------------------\n' 'Graph Index (Vertex) | Type | Unique | Backing | Key: Status |\n' '---------------------------------------------------------------------------------------------------\n' 'byLocation | Mixed | false | search | location: ENABLED |\n' '---------------------------------------------------------------------------------------------------\n' 'Graph Index (Edge) | Type | Unique | Backing | Key: Status |\n' '---------------------------------------------------------------------------------------------------\n' '---------------------------------------------------------------------------------------------------\n' 'Relation Index (VCI) | Type | Direction | Sort Key | Order | Status |\n' '---------------------------------------------------------------------------------------------------\n'] My Vertexes:
V: [{<T.id: 1>: 4096, <T.label: 4>: 'place', 'location': {'@type': 'janusgraph:Geoshape', '@value': {'geometry': {'type': 'LineString', 'coordinates': [[42.546782, 1.699474], [42.546422, 1.699865], [42.545915, 1.700278], [42.545598, 1.700634], [42.545173, 1.701465], [42.544649, 1.703692], [42.544446, 1.705885], [42.544222, 1.708992], [42.544067, 1.711593], [42.543972, 1.71567], [42.543751, 1.722193], [42.543764, 1.723969], [42.543877, 1.725626], [42.544064, 1.726973], [42.544383, 1.728158], [42.544966, 1.729793], [42.545616, 1.73112], [42.546221, 1.732211], [42.54678, 1.733105]]}}}}, {<T.id: 1>: 4136, <T.label: 4>: 'location', 'place': {'@type': 'janusgraph:Geoshape', '@value': {'geometry': {'type': 'LineString', 'coordinates': [[42.546782, 1.699474], [42.546422, 1.699865], [42.545915, 1.700278], [42.545598, 1.700634], [42.545173, 1.701465], [42.544649, 1.703692], [42.544446, 1.705885], [42.544222, 1.708992], [42.544067, 1.711593], [42.543972, 1.71567], [42.543751, 1.722193], [42.543764, 1.723969], [42.543877, 1.725626], [42.544064, 1.726973], [42.544383, 1.728158], [42.544966, 1.729793], [42.545616, 1.73112], [42.546221, 1.732211], [42.54678, 1.733105]]}}}}]
Recources used:
https://docs.janusgraph.org/index-backend/text-search/#geo-mapping |
|
hadoopmarc@...
Hi Dmitry,
toggle quoted message
Show quoted text
It is not clear to me whether you have problems to get any geo predicate working or that your specific example is the issue. Can you first confirm that the following works for you (on a clean janusgraph-full-0.6.1): $ bin/janusgraph.sh start $ bin/gremlin.sh graph = JanusGraphFactory.open('conf/janusgraph-cql-es.properties') mgmt = graph.openManagement() location = mgmt.makePropertyKey('location').dataType(Geoshape.class).cardinality(Cardinality.SINGLE).make() mgmt.buildIndex('byLocation', Vertex.class).addKey(location, Mapping.PREFIX_TREE.asParameter()).buildMixedIndex('search') mgmt.commit() mgmt = graph.openManagement() mgmt.printSchema() mgmt.close() g = graph.traversal() g.addV().property('location', Geoshape.point(52, 1)) g.V().has("location", geoWithin(Geoshape.circle(51.9, 1.1, 20.0))) Note that you may have erred on the radius units: these seem to be in kilometers (not miles, I hope, did not do the calculation...). Best wishes, Marc On Wed, Mar 30, 2022 at 03:57 PM, <dmitryzezix@...> wrote: g.V().has("location", geoWithin(Geoshape.circle({lat}, {lon}, {radius}))) |
|
dmitryzezix@...
Hi, Marc! This works. But I need to query complex geoshape, not point. I am able to query complex geoshape only if there is no index created. And after the index for property "location" created - complex geoshapes are no longer available to query. |
|
Hi Dmitry,
Here you go again: g.addV().property('location', Geoshape.line([[52, 0] as double[], [52, 2] as double[]])) g.V().elementMap() 21:09:39 WARN org.janusgraph.graphdb.transaction.StandardJanusGraphTx - Query requires iterating over all vertices [()]. For better performance, use indexes ==>[id:4240,label:vertex,location:LINESTRING (52 0, 52 2)] gremlin> g.V().has("location", geoWithin(Geoshape.circle(1, 52, 200.0))).elementMap() ==>[id:4240,label:vertex,location:LINESTRING (52 0, 52 2)] gremlin> g.V().has("location", geoContains(Geoshape.point(1, 52))) ==>v[4240] As you see, the coordinate order conventions are really warped. This may have led you believe things do not work. I had to find this out too ... Still do not not know which coordinate is latitude and which one longitude :-) If you want, you can make an issue of it, because the coordinate order for the geoWithin predicate is different for Geoshape.point and Geoshape.circle! Best wishes, Marc |
|
dmitryzezix@...
Hi Marc, The same works for me as well. But it stops when the index is added. You can query only indexed points. Indexed shapes are not retrievable. Please, try to add index and query everything again. Best wishes, Dmytro |
|
hadoopmarc@...
Hi Dmytro,
Can you please present an easily reproducible scenario, preferably using the default "bin/janusgraph.sh start", like I showed, with gremlin console output and starting with an empty db/cassandra and db/es directories. From your description it is not clear what exactly happened. And to be sure, when you first added nodes and then defined the mixed index, you also made sure that the graph was reindexed. Regards, Marc |
|
dmitryzezix@...
Hi Marc, I confirm, that this works: g.V().has("location", geoContains(Geoshape.point({lat}, {lon}))).elementMap()
g.V().has("location", geoIntersect(Geoshape.circle({lat}, {lon}, {radius}))).elementMap() My mistake. I misunderstood the GeoPredicates and also the coordinate order conventions were confusing. I've managed to make my code work! Thanks for your help |
|