Search in sources :

Example 11 with Geoshape

use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.

the class GeoToWktConverterTest method testConvertGeoshapeMultiLineToWktString.

@Test
public void testConvertGeoshapeMultiLineToWktString() throws BackendException {
    GeometryFactory gf = new GeometryFactory();
    Geoshape g = HELPER.geoshape(gf.createMultiLineString(new LineString[] { gf.createLineString(new Coordinate[] { new Coordinate(10, 10), new Coordinate(20, 20) }), gf.createLineString(new Coordinate[] { new Coordinate(30, 30), new Coordinate(40, 40) }) }));
    String wkt1 = "MULTILINESTRING ((10 10, 20 20), (30 30, 40 40))";
    String actualWkt1 = GeoToWktConverter.convertToWktString(g);
    assertEquals(wkt1, actualWkt1);
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) Geoshape(org.janusgraph.core.attribute.Geoshape) LineString(com.vividsolutions.jts.geom.LineString) Test(org.junit.Test)

Example 12 with Geoshape

use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.

the class GeoToWktConverterTest method testConvertGeoshapePointToWktString.

/**
 * The GeoToWktConverter transforms the Geoshape's string value into a Well-Known Text
 * format understood by Solr.
 */
@Test
public void testConvertGeoshapePointToWktString() throws BackendException, ParseException {
    // no spaces, no negative values
    Geoshape p1 = Geoshape.point(35.4, 48.9);
    // negative longitude value
    Geoshape p2 = Geoshape.point(-35.4, 48.9);
    // negative latitude value
    Geoshape p3 = Geoshape.point(35.4, -48.9);
    String wkt1 = "POINT(48.9 35.4)";
    assertEquals(p1.getPoint().getLongitude(), Geoshape.fromWkt(wkt1).getPoint().getLongitude(), 1e-5);
    assertEquals(p1.getPoint().getLatitude(), Geoshape.fromWkt(wkt1).getPoint().getLatitude(), 1e-5);
    String wkt2 = "POINT(48.9 -35.4)";
    assertEquals(p2.getPoint().getLongitude(), Geoshape.fromWkt(wkt2).getPoint().getLongitude(), 1e-5);
    assertEquals(p2.getPoint().getLatitude(), Geoshape.fromWkt(wkt2).getPoint().getLatitude(), 1e-5);
    String wkt3 = "POINT(-48.9 35.4)";
    assertEquals(p3.getPoint().getLongitude(), Geoshape.fromWkt(wkt3).getPoint().getLongitude(), 1e-5);
    assertEquals(p3.getPoint().getLatitude(), Geoshape.fromWkt(wkt3).getPoint().getLatitude(), 1e-5);
}
Also used : Geoshape(org.janusgraph.core.attribute.Geoshape) LineString(com.vividsolutions.jts.geom.LineString) Test(org.junit.Test)

Example 13 with Geoshape

use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.

the class GeoToWktConverterTest method testConvertGeoshapeMultiPolygonToWktString.

@Test
public void testConvertGeoshapeMultiPolygonToWktString() throws BackendException {
    GeometryFactory gf = new GeometryFactory();
    Geoshape g = HELPER.geoshape(gf.createMultiPolygon(new Polygon[] { gf.createPolygon(new Coordinate[] { new Coordinate(0, 0), new Coordinate(0, 10), new Coordinate(10, 10), new Coordinate(0, 0) }), gf.createPolygon(new Coordinate[] { new Coordinate(20, 20), new Coordinate(20, 30), new Coordinate(30, 30), new Coordinate(20, 20) }) }));
    String wkt1 = "MULTIPOLYGON (((0 0, 0 10, 10 10, 0 0)), ((20 20, 20 30, 30 30, 20 20)))";
    String actualWkt1 = GeoToWktConverter.convertToWktString(g);
    assertEquals(wkt1, actualWkt1);
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Geoshape(org.janusgraph.core.attribute.Geoshape) LineString(com.vividsolutions.jts.geom.LineString) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test)

Example 14 with Geoshape

use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.

the class GeoToWktConverterTest method testConvertGeoshapeMultiPointToWktString.

@Test
public void testConvertGeoshapeMultiPointToWktString() throws BackendException {
    GeometryFactory gf = new GeometryFactory();
    Geoshape g = HELPER.geoshape(gf.createMultiPoint(new Coordinate[] { new Coordinate(10, 10), new Coordinate(20, 20) }));
    String wkt1 = "MULTIPOINT ((10 10), (20 20))";
    String actualWkt1 = GeoToWktConverter.convertToWktString(g);
    assertEquals(wkt1, actualWkt1);
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Geoshape(org.janusgraph.core.attribute.Geoshape) LineString(com.vividsolutions.jts.geom.LineString) Test(org.junit.Test)

Example 15 with Geoshape

use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.

the class GeoToWktConverterTest method testConvertGeoshapePolygonToWktString.

@Test
public void testConvertGeoshapePolygonToWktString() throws BackendException {
    GeometryFactory gf = new GeometryFactory();
    Geoshape p1 = Geoshape.polygon(Arrays.asList(new double[][] { { 35.4, 48.9 }, { 35.6, 48.9 }, { 35.6, 49.1 }, { 35.4, 49.1 }, { 35.4, 48.9 } }));
    Geoshape p2 = HELPER.geoshape(gf.createPolygon(gf.createLinearRing(new Coordinate[] { new Coordinate(10, 10), new Coordinate(20, 10), new Coordinate(20, 20), new Coordinate(10, 20), new Coordinate(10, 10) }), new LinearRing[] { gf.createLinearRing(new Coordinate[] { new Coordinate(13, 13), new Coordinate(17, 13), new Coordinate(17, 17), new Coordinate(13, 17), new Coordinate(13, 13) }) }));
    String wkt1 = "POLYGON ((35.4 48.9, 35.6 48.9, 35.6 49.1, 35.4 49.1, 35.4 48.9))";
    String actualWkt1 = GeoToWktConverter.convertToWktString(p1);
    assertEquals(wkt1, actualWkt1);
    String wkt2 = "POLYGON ((10 10, 20 10, 20 20, 10 20, 10 10), (13 13, 17 13, 17 17, 13 17, 13 13))";
    String actualWkt2 = GeoToWktConverter.convertToWktString(p2);
    assertEquals(wkt2, actualWkt2);
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Geoshape(org.janusgraph.core.attribute.Geoshape) LineString(com.vividsolutions.jts.geom.LineString) LinearRing(com.vividsolutions.jts.geom.LinearRing) Test(org.junit.Test)

Aggregations

Geoshape (org.janusgraph.core.attribute.Geoshape)19 Test (org.junit.Test)12 LineString (com.vividsolutions.jts.geom.LineString)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)4 Instant (java.time.Instant)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 UUID (java.util.UUID)2 Cmp (org.janusgraph.core.attribute.Cmp)2 Geo (org.janusgraph.core.attribute.Geo)2 Mapping (org.janusgraph.core.schema.Mapping)2 JanusGraphPredicate (org.janusgraph.graphdb.query.JanusGraphPredicate)2 And (org.janusgraph.graphdb.query.condition.And)2 Condition (org.janusgraph.graphdb.query.condition.Condition)2 Not (org.janusgraph.graphdb.query.condition.Not)2 Or (org.janusgraph.graphdb.query.condition.Or)2 PredicateCondition (org.janusgraph.graphdb.query.condition.PredicateCondition)2