Skip to content

Commit

Permalink
add back Geo support #43
Browse files Browse the repository at this point in the history
  • Loading branch information
rmagen committed May 18, 2015
1 parent f6cdc92 commit 564616e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.apache.tinkerpop.gremlin.elastic.elasticservice;

import com.spatial4j.core.shape.Shape;
import com.spatial4j.core.shape.SpatialRelation;
import com.spatial4j.core.shape.*;
import org.apache.tinkerpop.gremlin.structure.*;
import org.elasticsearch.common.Preconditions;
import org.elasticsearch.common.geo.ShapeRelation;
import org.elasticsearch.common.geo.builders.ShapeBuilder;
Expand All @@ -11,15 +11,15 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.*;

public enum Geo implements BiPredicate {

/**
* Whether the intersection between two geographic regions is non-empty
*/

INTERSECT(ShapeRelation.INTERSECTS, (geometry1, geometry2) -> {
INTERSECTS(ShapeRelation.INTERSECTS, (geometry1, geometry2) -> {
SpatialRelation relation = geometry1.relate(geometry2);
return relation == SpatialRelation.INTERSECTS || relation == SpatialRelation.CONTAINS || relation == SpatialRelation.WITHIN;
}
Expand Down Expand Up @@ -85,6 +85,11 @@ else if (o instanceof String){


}


public static <V> P<V> intersercts(final V value) { return new P(Geo.INTERSECTS, value); };
public static <V> P<V> disjoint(final V value) { return new P(Geo.DISJOINT, value); };
public static <V> P<V> within(final V value) { return new P(Geo.WITHIN, value); };
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.impl.PointImpl;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.tinkerpop.gremlin.elastic.elasticservice.ElasticService;
import org.apache.tinkerpop.gremlin.elastic.elasticservice.*;
import org.apache.tinkerpop.gremlin.elastic.structure.ElasticGraph;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.*;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand All @@ -17,6 +17,7 @@
import java.util.*;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.junit.Assert.assertEquals;

/**
* Created by Eliran on 6/3/2015.
Expand Down Expand Up @@ -66,10 +67,10 @@ public void geoPointPolygonsIntersectionTest() throws IOException {
GraphTraversalSource g = graph.traversal();

String geoJsonPoint = "{ \"type\": \"Point\",\"coordinates\": [9, 9]}";
/*long intersectionCounter = g.V().has("location", Geo.INTERSECT, geoJsonPoint).count().next();
long intersectionCounter = g.V().has("location", Geo.intersercts(geoJsonPoint)).count().next();
assertEquals(1l, intersectionCounter);
Element location = g.V().has("location", Geo.INTERSECT, geoJsonPoint).next();
assertEquals("1",location.id().toString());*/
Element location = g.V().has("location", Geo.intersercts(geoJsonPoint)).next();
assertEquals("1",location.id().toString());
}

@Test
Expand All @@ -95,13 +96,13 @@ public void polygonToPolygonsIntersectionTest() throws IOException {
graph.addVertex(T.label,DOCUMENT_TYPE,T.id,"2","location",secondPolygon);

GraphTraversalSource g = graph.traversal();
/*

String geoJsonPoint = "{ \"type\": \"Polygon\",\"coordinates\": [[[9, 10],[11, 10],[11, 8],[9, 8],[9, 10]]]}";
long intersectionCounter = g.V().has("location", Geo.INTERSECT, geoJsonPoint).count().next();
long intersectionCounter = g.V().has("location", Geo.intersercts(geoJsonPoint)).count().next();
assertEquals(1l, intersectionCounter);
Element location = g.V().has("location", Geo.INTERSECT, geoJsonPoint).next();
Element location = g.V().has("location", Geo.intersercts(geoJsonPoint)).next();
assertEquals("1",location.id().toString());
*/

}

private Map<String, Object> buildGeoJsonPolygon(List<Point> points) throws IOException {
Expand Down

0 comments on commit 564616e

Please sign in to comment.