Ejemplo n.º 1
0
  @Test
  public void polygonToPolygonsIntersectionTest() throws IOException {
    // create polygons
    List<Point> firstPolygonPoints = new ArrayList<Point>();
    firstPolygonPoints.add(new PointImpl(10, 10, SpatialContext.GEO));
    firstPolygonPoints.add(new PointImpl(8, 10, SpatialContext.GEO));
    firstPolygonPoints.add(new PointImpl(8, 8, SpatialContext.GEO));
    firstPolygonPoints.add(new PointImpl(10, 8, SpatialContext.GEO));
    firstPolygonPoints.add(new PointImpl(10, 10, SpatialContext.GEO));
    Map<String, Object> firstPolygon = buildGeoJsonPolygon(firstPolygonPoints);
    List<Point> secondPolygonPoints = new ArrayList<Point>();
    secondPolygonPoints.add(new PointImpl(14, 10, SpatialContext.GEO));
    secondPolygonPoints.add(new PointImpl(12, 10, SpatialContext.GEO));
    secondPolygonPoints.add(new PointImpl(12, 8, SpatialContext.GEO));
    secondPolygonPoints.add(new PointImpl(14, 8, SpatialContext.GEO));
    secondPolygonPoints.add(new PointImpl(14, 10, SpatialContext.GEO));
    Map<String, Object> secondPolygon = buildGeoJsonPolygon(secondPolygonPoints);

    // add the vertices to graph
    graph.addVertex(T.label, DOCUMENT_TYPE, T.id, "1", "location", firstPolygon);
    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.intersercts(geoJsonPoint)).count().next();
    assertEquals(1l, intersectionCounter);
    Element location = g.V().has("location", Geo.intersercts(geoJsonPoint)).next();
    assertEquals("1", location.id().toString());
  }
 public static void verifyElementOrder(
     Iterator<? extends Element> elements, String key, Order order, int expectedCount) {
   Comparable previous = null;
   int count = 0;
   while (elements.hasNext()) {
     Element element = elements.next();
     Comparable current = element.value(key);
     if (previous != null) {
       int cmp = previous.compareTo(current);
       assertTrue(
           previous + " <> " + current + " @ " + count, order == Order.ASC ? cmp <= 0 : cmp >= 0);
     }
     previous = current;
     count++;
   }
   assertEquals(expectedCount, count);
 }