/** * Constructs a point from its latitude and longitude information * @param latitude * @param longitude * @return */ public static final Geoshape point(final double latitude, final double longitude) { return point((float)latitude,(float)longitude); }
public static Multimap<String, Object> getRandomDocument() { final StringBuilder s = new StringBuilder(); for (int i = 0; i < 3; i++) s.append(RandomGenerator.randomString(5, 8)).append(" "); Multimap values = HashMultimap.create(); values.put(TEXT, s.toString()); values.put(NAME, s.toString()); values.put(TIME, Math.abs(random.nextLong())); values.put(WEIGHT, random.nextDouble()); values.put(LOCATION, Geoshape.point(random.nextDouble() * 180 - 90, random.nextDouble() * 360 - 180)); return values; }
double[] arr = new double[len]; for (int i=0;i<len;i++) arr[i]=((Number)Array.get(value,i)).doubleValue(); if (len==2) shape= point(arr[0],arr[1]); else if (len==3) shape= circle(arr[0],arr[1],arr[2]); else if (len==4) shape= box(arr[0],arr[1],arr[2],arr[3]);
return point(parsedCoordinates[1], parsedCoordinates[0]); } else if ("Circle".equals(type)) { Number radius = (Number) geometry.get("radius");
private void storeTest(String... stores) throws Exception { Multimap<String, Object> doc1 = getDocument("Hello world", 1001, 5.2, Geoshape.point(48.0, 0.0), Arrays.asList("1", "2", "3"), Sets.newHashSet("1", "2"), Instant.ofEpochSecond(1)); Multimap<String, Object> doc2 = getDocument("Tomorrow is the world", 1010, 8.5, Geoshape.point(49.0, 1.0), Arrays.asList("4", "5", "6"), Sets.newHashSet("4", "5"), Instant.ofEpochSecond(2)); Multimap<String, Object> doc3 = getDocument("Hello Bob, are you there?", -500, 10.1, Geoshape.point(47.0, 10.0), Arrays.asList("7", "8", "9"), Sets.newHashSet("7", "8"), Instant.ofEpochSecond(3)); add(store, "doc4", getDocument("I'ts all a big Bob", -100, 11.2, Geoshape.point(48.0, 8.0), Arrays.asList("10", "11", "12"), Sets.newHashSet("10", "11"), Instant.ofEpochSecond(4)), true); remove(store, "doc2", doc2, true); remove(store, "doc3", ImmutableMultimap.of(WEIGHT, (Object) 10.1), false);
private void testIndexing(Cardinality cardinality) { if (supportsCollections()) { PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make(); PropertyKey intProperty = mgmt.makePropertyKey("age").dataType(Integer.class).cardinality(cardinality).make(); PropertyKey longProperty = mgmt.makePropertyKey("long").dataType(Long.class).cardinality(cardinality).make(); PropertyKey uuidProperty = mgmt.makePropertyKey("uuid").dataType(UUID.class).cardinality(cardinality).make(); PropertyKey geoProperty = mgmt.makePropertyKey("geo").dataType(Geoshape.class).cardinality(cardinality).make(); mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).addKey(intProperty).addKey(longProperty).addKey(uuidProperty).addKey(geoProperty).buildMixedIndex(INDEX); finishSchema(); testCollection(cardinality, "name", "Totoro", "Hiro"); testCollection(cardinality, "age", 1, 2); testCollection(cardinality, "long", 1L, 2L); testCollection(cardinality, "uuid", UUID.randomUUID(), UUID.randomUUID()); testCollection(cardinality, "geo", Geoshape.point(1.0, 1.0), Geoshape.point(2.0, 2.0)); } else { try { PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make(); //This should throw an exception mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX); Assert.fail("Should have thrown an exception"); } catch (TitanException e) { } } }
v.property(VertexProperty.Cardinality.single, "time", i); offset = (i % 2 == 0 ? 1 : -1) * (i * 50.0 / numV); v.property(VertexProperty.Cardinality.single, "location", Geoshape.point(0.0 + offset, 0.0 + offset)); e.property("category", i % numCategories); e.property("group", i % numGroups); e.property("location", Geoshape.point(0.0 + offset, 0.0 + offset)); distance = Geoshape.point(0.0, 0.0).getPoint().distance(Geoshape.point(offset, offset).getPoint()) + 20; assertCount(i + 1, tx.query().has("location", Geo.WITHIN, Geoshape.circle(0.0, 0.0, distance)).vertices()); assertCount(i + 1, tx.query().has("location", Geo.WITHIN, Geoshape.circle(0.0, 0.0, distance)).edges()); distance = Geoshape.point(0.0, 0.0).getPoint().distance(Geoshape.point(offset, offset).getPoint()) + 20; assertCount(5, tx.query().has("location", Geo.INTERSECT, Geoshape.circle(0.0, 0.0, distance)).has("text", Text.CONTAINS, words[0]).vertices()); distance = Geoshape.point(0.0, 0.0).getPoint().distance(Geoshape.point(offset, offset).getPoint()) + 20; assertCount(i + 1, tx.query().has("location", Geo.WITHIN, Geoshape.circle(0.0, 0.0, distance)).vertices()); assertCount(i + 1, tx.query().has("location", Geo.WITHIN, Geoshape.circle(0.0, 0.0, distance)).edges()); distance = Geoshape.point(0.0, 0.0).getPoint().distance(Geoshape.point(offset, offset).getPoint()) + 20; assertCount(5, tx.query().has("location", Geo.INTERSECT, Geoshape.circle(0.0, 0.0, distance)).has("text", Text.CONTAINS, words[0]).vertices()); distance = Geoshape.point(0.0, 0.0).getPoint().distance(Geoshape.point(offset, offset).getPoint()) + 20; assertCount(i + 1, tx.query().has("location", Geo.WITHIN, Geoshape.circle(0.0, 0.0, distance)).vertices()); assertCount(i + 1, tx.query().has("location", Geo.WITHIN, Geoshape.circle(0.0, 0.0, distance)).edges()); distance = Geoshape.point(0.0, 0.0).getPoint().distance(Geoshape.point(offset, offset).getPoint()) + 20; assertCount(5, tx.query().has("location", Geo.INTERSECT, Geoshape.circle(0.0, 0.0, distance)).has("text", Text.CONTAINS, words[0]).vertices());
/** * Constructs a point from its latitude and longitude information * @param latitude * @param longitude * @return */ public static final Geoshape point(final double latitude, final double longitude) { return point((float)latitude,(float)longitude); }
/** * Constructs a point from its latitude and longitude information * @param latitude * @param longitude * @return */ public static final Geoshape point(final double latitude, final double longitude) { return point((float)latitude,(float)longitude); }
double latitude = Double.parseDouble(nextLine[2]); double longitude = Double.parseDouble(nextLine[3]); vertex.addProperty(PROP_RESTAURANT_PLACE, Geoshape.point(latitude, longitude));
public static Map<String, Object> getRandomDocument() { final StringBuilder s = new StringBuilder(); for (int i = 0; i < 3; i++) s.append(RandomGenerator.randomString(5, 8)).append(" "); return new HashMap<String, Object>() {{ put(TEXT, s.toString()); put(NAME, s.toString()); put(TIME, Math.abs(random.nextLong())); put(WEIGHT, random.nextDouble()); put(LOCATION, Geoshape.point(random.nextDouble() * 180 - 90, random.nextDouble() * 360 - 180)); }}; }
public static Map<String, Object> getRandomDocument() { final StringBuilder s = new StringBuilder(); for (int i = 0; i < 3; i++) s.append(RandomGenerator.randomString(5, 8)).append(" "); return new HashMap<String, Object>() {{ put(TEXT, s.toString()); put(NAME, s.toString()); put(TIME, Math.abs(random.nextLong())); put(WEIGHT, random.nextDouble()); put(LOCATION, Geoshape.point(random.nextDouble() * 180 - 90, random.nextDouble() * 360 - 180)); }}; }
double[] arr = new double[len]; for (int i=0;i<len;i++) arr[i]=((Number)Array.get(value,i)).doubleValue(); if (len==2) shape= point(arr[0],arr[1]); else if (len==3) shape= circle(arr[0],arr[1],arr[2]); else if (len==4) shape= box(arr[0],arr[1],arr[2],arr[3]);
double[] arr = new double[len]; for (int i=0;i<len;i++) arr[i]=((Number)Array.get(value,i)).doubleValue(); if (len==2) shape= point(arr[0],arr[1]); else if (len==3) shape= circle(arr[0],arr[1],arr[2]); else if (len==4) shape= box(arr[0],arr[1],arr[2],arr[3]);
return point(parsedCoordinates[1], parsedCoordinates[0]); } else if ("Circle".equals(type)) { Number radius = (Number) geometry.get("radius");
private void storeTest(String... stores) throws Exception { Map<String, Object> doc1 = getDocument("Hello world", 1001, 5.2, Geoshape.point(48.0, 0.0)); Map<String, Object> doc2 = getDocument("Tomorrow is the world", 1010, 8.5, Geoshape.point(49.0, 1.0)); Map<String, Object> doc3 = getDocument("Hello Bob, are you there?", -500, 10.1, Geoshape.point(47.0, 10.0)); add(store, "doc4", getDocument("I'ts all a big Bob", -100, 11.2, Geoshape.point(48.0, 8.0)), true); remove(store, "doc2", doc2, true); remove(store, "doc3", ImmutableMap.of(WEIGHT, (Object) 10.1), false);
private void storeTest(String... stores) throws Exception { Map<String, Object> doc1 = getDocument("Hello world", 1001, 5.2, Geoshape.point(48.0, 0.0)); Map<String, Object> doc2 = getDocument("Tomorrow is the world", 1010, 8.5, Geoshape.point(49.0, 1.0)); Map<String, Object> doc3 = getDocument("Hello Bob, are you there?", -500, 10.1, Geoshape.point(47.0, 10.0)); add(store, "doc4", getDocument("I'ts all a big Bob", -100, 11.2, Geoshape.point(48.0, 8.0)), true); remove(store, "doc2", doc2, true); remove(store, "doc3", ImmutableMap.of(WEIGHT, (Object) 10.1), false);
ElementHelper.setProperties(hercules.addEdge("battled", nemean), "time", 1, "place", Geoshape.point(38.1f, 23.7f)); ElementHelper.setProperties(hercules.addEdge("battled", hydra), "time", 2, "place", Geoshape.point(37.7f, 23.9f)); ElementHelper.setProperties(hercules.addEdge("battled", cerberus), "time", 12, "place", Geoshape.point(39f, 22f));