Search in sources :

Example 1 with AreaIndex

use of com.graphhopper.routing.util.AreaIndex in project graphhopper by graphhopper.

the class AreaIndexTest method basic.

@Test
void basic() {
    GeometryFactory geometryFactory = new GeometryFactory();
    Polygon border1 = geometryFactory.createPolygon(new Coordinate[] { new Coordinate(1, 1), new Coordinate(2, 1), new Coordinate(2, 2), new Coordinate(1, 2), new Coordinate(1, 1) });
    Polygon border2 = geometryFactory.createPolygon(new Coordinate[] { new Coordinate(5, 5), new Coordinate(6, 5), new Coordinate(6, 6), new Coordinate(5, 6), new Coordinate(5, 5) });
    Polygon border3 = geometryFactory.createPolygon(new Coordinate[] { new Coordinate(9, 9), new Coordinate(10, 9), new Coordinate(10, 10), new Coordinate(9, 10), new Coordinate(9, 9) });
    AreaIndex<CustomArea> index = new AreaIndex<>(Arrays.asList(createCustomArea("1", border1), createCustomArea("2", border2), createCustomArea("3", border3), createCustomArea("4", border2, border3)));
    testQuery(index, 0, 0);
    testQuery(index, 1.5, 1.5, "1");
    testQuery(index, 1.00001, 1.00001, "1");
    testQuery(index, 1.5, 1.00001, "1");
    testQuery(index, 1.00001, 1.5, "1");
    testQuery(index, 5.5, 5.5, "2", "4");
    testQuery(index, 9.5, 9.5, "3", "4");
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Polygon(org.locationtech.jts.geom.Polygon) CustomArea(com.graphhopper.routing.util.CustomArea) AreaIndex(com.graphhopper.routing.util.AreaIndex) Test(org.junit.jupiter.api.Test)

Example 2 with AreaIndex

use of com.graphhopper.routing.util.AreaIndex in project graphhopper by graphhopper.

the class AreaIndexTest method testPrecision.

@Test
void testPrecision() {
    // Taken from here: https://github.com/johan/world.geo.json/blob/master/countries/DEU.geo.json
    String germanPolygonJson = "[9.921906,54.983104],[9.93958,54.596642],[10.950112,54.363607],[10.939467,54.008693],[11.956252,54.196486],[12.51844,54.470371],[13.647467,54.075511],[14.119686,53.757029],[14.353315,53.248171],[14.074521,52.981263],[14.4376,52.62485],[14.685026,52.089947],[14.607098,51.745188],[15.016996,51.106674],[14.570718,51.002339],[14.307013,51.117268],[14.056228,50.926918],[13.338132,50.733234],[12.966837,50.484076],[12.240111,50.266338],[12.415191,49.969121],[12.521024,49.547415],[13.031329,49.307068],[13.595946,48.877172],[13.243357,48.416115],[12.884103,48.289146],[13.025851,47.637584],[12.932627,47.467646],[12.62076,47.672388],[12.141357,47.703083],[11.426414,47.523766],[10.544504,47.566399],[10.402084,47.302488],[9.896068,47.580197],[9.594226,47.525058],[8.522612,47.830828],[8.317301,47.61358],[7.466759,47.620582],[7.593676,48.333019],[8.099279,49.017784],[6.65823,49.201958],[6.18632,49.463803],[6.242751,49.902226],[6.043073,50.128052],[6.156658,50.803721],[5.988658,51.851616],[6.589397,51.852029],[6.84287,52.22844],[7.092053,53.144043],[6.90514,53.482162],[7.100425,53.693932],[7.936239,53.748296],[8.121706,53.527792],[8.800734,54.020786],[8.572118,54.395646],[8.526229,54.962744],[9.282049,54.830865],[9.921906,54.983104]";
    Polygon germanPolygon = parsePolygonString(germanPolygonJson);
    AreaIndex<CustomArea> index = new AreaIndex<>(Collections.singletonList(createCustomArea("germany", germanPolygon)));
    // Far from the border of Germany, in Germany
    testQuery(index, 48.777106, 9.180769, "germany");
    testQuery(index, 51.806281, 7.269380, "germany");
    testQuery(index, 50.636710, 12.514561, "germany");
    // Far from the border of Germany, not in Germany
    testQuery(index, 48.029533, 7.250122);
    testQuery(index, 51.694467, 15.209218);
    testQuery(index, 47.283669, 11.167381);
    // Close to the border of Germany, in Germany - Whereas the borders are defined by the GeoJson above and do not strictly follow the actual border
    testQuery(index, 50.017714, 12.356129, "germany");
    testQuery(index, 49.949930, 6.225853, "germany");
    testQuery(index, 47.580866, 9.707582, "germany");
    testQuery(index, 47.565101, 9.724267, "germany");
    testQuery(index, 47.557166, 9.738343, "germany");
    // Close to the border of Germany, not in Germany
    testQuery(index, 50.025342, 12.386262);
    testQuery(index, 49.932900, 6.174023);
    testQuery(index, 47.547463, 9.741948);
}
Also used : Polygon(org.locationtech.jts.geom.Polygon) CustomArea(com.graphhopper.routing.util.CustomArea) AreaIndex(com.graphhopper.routing.util.AreaIndex) Test(org.junit.jupiter.api.Test)

Example 3 with AreaIndex

use of com.graphhopper.routing.util.AreaIndex in project graphhopper by graphhopper.

the class AreaIndexTest method testHole.

@Test
public void testHole() {
    GeometryFactory gf = new GeometryFactory();
    LinearRing shell = gf.createLinearRing(new Coordinate[] { new Coordinate(1, 1), new Coordinate(7, 1), new Coordinate(7, 7), new Coordinate(1, 7), new Coordinate(1, 1) });
    LinearRing hole = gf.createLinearRing(new Coordinate[] { new Coordinate(4, 2), new Coordinate(6, 2), new Coordinate(6, 4), new Coordinate(4, 6), new Coordinate(4, 2) });
    {
        Polygon p = gf.createPolygon(shell, new LinearRing[] { hole });
        AreaIndex<CustomArea> index = new AreaIndex<>(Collections.singletonList(createCustomArea("1", p)));
        testQuery(index, 3, 5);
    }
    {
        Polygon p = gf.createPolygon(hole);
        AreaIndex<CustomArea> index = new AreaIndex<>(Collections.singletonList(createCustomArea("2", p)));
        testQuery(index, 3, 5, "2");
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) AreaIndex(com.graphhopper.routing.util.AreaIndex) Test(org.junit.jupiter.api.Test)

Example 4 with AreaIndex

use of com.graphhopper.routing.util.AreaIndex in project graphhopper by graphhopper.

the class AreaIndexTest method testOverlap.

@Test
public void testOverlap() {
    GeometryFactory gf = new GeometryFactory();
    // Let the two polygons overlap
    Polygon border1 = gf.createPolygon(new Coordinate[] { new Coordinate(1, 1), new Coordinate(2, 1), new Coordinate(2, 2), new Coordinate(1, 2), new Coordinate(1, 1) });
    Polygon border2 = gf.createPolygon(new Coordinate[] { new Coordinate(0.5, 1), new Coordinate(1.5, 1), new Coordinate(1.5, 2), new Coordinate(0.5, 2), new Coordinate(0.5, 1) });
    AreaIndex<CustomArea> index = new AreaIndex<>(Arrays.asList(createCustomArea("1", border1), createCustomArea("2", border2)));
    testQuery(index, 1.5, 1.25, "1", "2");
    testQuery(index, 1.5, 0.99, "2");
    testQuery(index, 1.5, 1.0001, "1", "2");
    testQuery(index, 1.5, 1.4999, "1", "2");
    testQuery(index, 1.5, 1.51, "1");
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Polygon(org.locationtech.jts.geom.Polygon) CustomArea(com.graphhopper.routing.util.CustomArea) AreaIndex(com.graphhopper.routing.util.AreaIndex) Test(org.junit.jupiter.api.Test)

Example 5 with AreaIndex

use of com.graphhopper.routing.util.AreaIndex in project graphhopper by graphhopper.

the class LandmarkStorageTest method testWithBorderBlocking.

@Test
public void testWithBorderBlocking() {
    RoutingAlgorithmTest.initBiGraph(graph, encoder);
    LandmarkStorage storage = new LandmarkStorage(graph, new RAMDirectory(), new LMConfig("car", new FastestWeighting(encoder)), 2);
    final SplitArea right = new SplitArea(emptyList());
    final SplitArea left = new SplitArea(emptyList());
    final AreaIndex<SplitArea> areaIndex = new AreaIndex<SplitArea>(emptyList()) {

        @Override
        public List<SplitArea> query(double lat, double lon) {
            if (lon > 0.00105) {
                return Collections.singletonList(right);
            } else {
                return Collections.singletonList(left);
            }
        }
    };
    storage.setAreaIndex(areaIndex);
    storage.setMinimumNodes(2);
    storage.createLandmarks();
    assertEquals(3, storage.getSubnetworksWithLandmarks());
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) AreaIndex(com.graphhopper.routing.util.AreaIndex) RAMDirectory(com.graphhopper.storage.RAMDirectory) RoutingAlgorithmTest(com.graphhopper.routing.RoutingAlgorithmTest) Test(org.junit.jupiter.api.Test)

Aggregations

AreaIndex (com.graphhopper.routing.util.AreaIndex)5 Test (org.junit.jupiter.api.Test)5 Polygon (org.locationtech.jts.geom.Polygon)4 CustomArea (com.graphhopper.routing.util.CustomArea)3 Coordinate (org.locationtech.jts.geom.Coordinate)3 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)3 RoutingAlgorithmTest (com.graphhopper.routing.RoutingAlgorithmTest)1 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)1 RAMDirectory (com.graphhopper.storage.RAMDirectory)1 LinearRing (org.locationtech.jts.geom.LinearRing)1