Examples of CoordinateBounds


Examples of org.onebusaway.geospatial.model.CoordinateBounds

    assertEquals(5, bounds.getMaxLon(), 0);
  }

  @Test
  public void testAddBounds() {
    CoordinateBounds bounds = new CoordinateBounds();
    bounds.addBounds(new CoordinateBounds(1,2,3,4));
    assertEquals(1, bounds.getMinLat(), 0);
    assertEquals(2, bounds.getMinLon(), 0);
    assertEquals(3, bounds.getMaxLat(), 0);
    assertEquals(4, bounds.getMaxLon(), 0);
    bounds.addBounds(new CoordinateBounds(0,3,2,5));
    assertEquals(0, bounds.getMinLat(), 0);
    assertEquals(2, bounds.getMinLon(), 0);
    assertEquals(3, bounds.getMaxLat(), 0);
    assertEquals(5, bounds.getMaxLon(), 0);
  }
View Full Code Here

Examples of org.onebusaway.geospatial.model.CoordinateBounds

  }

  @Test
  public void testBoundsLatAndLon() {

    CoordinateBounds bounds = SphericalGeometryLibrary.bounds(
        47.97527158291236, -122.3527193069458, 400, 200);

    double d1 = SphericalGeometryLibrary.distance(bounds.getMaxLat(),
        bounds.getMaxLon(), bounds.getMinLat(), bounds.getMaxLon());
    assertEquals(800, d1, 0.01);

    double d2 = SphericalGeometryLibrary.distance(bounds.getMaxLat(),
        bounds.getMinLon(), bounds.getMinLat(), bounds.getMinLon());
    assertEquals(800, d2, 0.01);

    double d3 = SphericalGeometryLibrary.distance(bounds.getMinLat(),
        bounds.getMaxLon(), bounds.getMinLat(), bounds.getMinLon());
    assertEquals(400, d3, 0.1);

    double d4 = SphericalGeometryLibrary.distance(bounds.getMaxLat(),
        bounds.getMaxLon(), bounds.getMaxLat(), bounds.getMinLon());
    assertEquals(400, d4, 0.1);
  }
View Full Code Here

Examples of org.onebusaway.geospatial.model.CoordinateBounds

    assertEquals(5, bounds.getMaxLon(), 0);
  }

  @Test
  public void testContains() {
    CoordinateBounds bounds = new CoordinateBounds(1,2,3,4);
    assertTrue(bounds.contains(1, 2));
    assertTrue(bounds.contains(3, 4));
    assertTrue(bounds.contains(2, 3));
    assertFalse(bounds.contains(0, 3));
    assertFalse(bounds.contains(2, 0));
  }
View Full Code Here

Examples of org.onebusaway.geospatial.model.CoordinateBounds

    assertFalse(bounds.contains(2, 0));
  }

  @Test
  public void testIntersects() {
    CoordinateBounds bounds = new CoordinateBounds(1,2,3,4);
    assertTrue(bounds.intersects(new CoordinateBounds(1,2,3,4)));
    assertTrue(bounds.intersects(new CoordinateBounds(0,0,2,3)));
    assertTrue(bounds.intersects(new CoordinateBounds(0,0,1,2)));
    assertFalse(bounds.intersects(new CoordinateBounds(0,0,1,1)));
  }
View Full Code Here

Examples of org.onebusaway.geospatial.model.CoordinateBounds

    assertEquals(400, d4, 0.1);
  }

  @Test
  public void testGetCenterOfBounds() {
    CoordinateBounds b = new CoordinateBounds(-1.0, -2.0, 4.0, 3.6);
    CoordinatePoint p = SphericalGeometryLibrary.getCenterOfBounds(b);
    assertEquals(1.5, p.getLat(), 0.0);
    assertEquals(0.8, p.getLon(), 0.0);
  }
View Full Code Here

Examples of org.onebusaway.geospatial.model.CoordinateBounds

    String[] tokens = _text.trim().split("\\s+");

    if (tokens.length == 0)
      return INPUT;

    CoordinateBounds serviceArea = _serviceAreaService.getServiceArea();

    if (serviceArea == null) {
      pushNextAction("stop-by-number", "text", _text);
      return "query-default-search-location";
    }
View Full Code Here

Examples of org.onebusaway.geospatial.model.CoordinateBounds

  private Map<CoordinateBounds, List<AgencyAndId>> buildShapeSpatialIndex() {

    Map<CoordinatePoint, Set<AgencyAndId>> shapeIdsByGridCellCorner = new FactoryMap<CoordinatePoint, Set<AgencyAndId>>(
        new HashSet<AgencyAndId>());

    CoordinateBounds fullBounds = new CoordinateBounds();
    for (StopEntry stop : _transitGraphDao.getAllStops())
      fullBounds.addPoint(stop.getStopLat(), stop.getStopLon());

    if (fullBounds.isEmpty()) {
      return Collections.emptyMap();
    }

    double centerLat = (fullBounds.getMinLat() + fullBounds.getMaxLat()) / 2;
    double centerLon = (fullBounds.getMinLon() + fullBounds.getMaxLon()) / 2;
    CoordinateBounds gridCellExample = SphericalGeometryLibrary.bounds(
        centerLat, centerLon, _gridSize / 2);

    double latStep = gridCellExample.getMaxLat() - gridCellExample.getMinLat();
    double lonStep = gridCellExample.getMaxLon() - gridCellExample.getMinLon();

    _log.info("generating shape point geospatial index...");

    Set<AgencyAndId> allShapeIds = getAllShapeIds();

    for (AgencyAndId shapeId : allShapeIds) {

      ShapePoints shapePoints = _shapePointHelper.getShapePointsForShapeId(shapeId);

      for (int i = 0; i < shapePoints.getSize(); i++) {

        double lat = shapePoints.getLatForIndex(i);
        double lon = shapePoints.getLonForIndex(i);

        addGridCellForShapePoint(shapeIdsByGridCellCorner, lat, lon, latStep,
            lonStep, shapeId);

        /**
         * If there is a particularly long stretch between shape points, we want
         * to fill in grid cells in-between
         */
        if (i > 0) {
          double prevLat = shapePoints.getLatForIndex(i - 1);
          double prevLon = shapePoints.getLonForIndex(i - 1);
          double totalDistance = SphericalGeometryLibrary.distance(prevLat,
              prevLon, lat, lon);
          for (double d = _gridSize; d < totalDistance; d += _gridSize) {
            double r = d / totalDistance;
            double latPart = (lat - prevLat) * r + prevLat;
            double lonPart = (lon - prevLon) * r + prevLon;
            addGridCellForShapePoint(shapeIdsByGridCellCorner, latPart,
                lonPart, latStep, lonStep, shapeId);
          }
        }
      }
    }

    _log.info("block shape geospatial nodes: "
        + shapeIdsByGridCellCorner.size());

    Map<CoordinateBounds, List<AgencyAndId>> shapeIdsByGridCell = new HashMap<CoordinateBounds, List<AgencyAndId>>();

    for (Map.Entry<CoordinatePoint, Set<AgencyAndId>> entry : shapeIdsByGridCellCorner.entrySet()) {
      CoordinatePoint p = entry.getKey();
      CoordinateBounds bounds = new CoordinateBounds(p.getLat(), p.getLon(),
          p.getLat() + latStep, p.getLon() + lonStep);

      List<AgencyAndId> shapeIds = new ArrayList<AgencyAndId>(entry.getValue());
      shapeIdsByGridCell.put(bounds, shapeIds);
    }
View Full Code Here

Examples of org.onebusaway.geospatial.model.CoordinateBounds

      addFieldError("maxCount", "must be greater than zero");

    if (hasErrors())
      return setValidationErrorsResponse();

    CoordinateBounds bounds = getSearchBounds();

    SearchQueryBean routesQuery = new SearchQueryBean();

    if (_query != null)
      routesQuery.setQuery(_query);
View Full Code Here

Examples of org.onebusaway.geospatial.model.CoordinateBounds

  @Test
  public void test01() {

    GridFactory factory = new GridFactory(0.1,0.1);

    CoordinateBounds bounds = new CoordinateBounds(5.05, 4.05, 5.15, 4.15);
    factory.addBounds(bounds);

    List<CoordinateBounds> grid = factory.getGrid();

    assertEquals(4, grid.size());

    Collections.sort(grid, BOUNDS_COMPARATOR);

    checkBounds(grid.get(0), new CoordinateBounds(5.0, 4.0, 5.1, 4.1), DELTA);
    checkBounds(grid.get(1), new CoordinateBounds(5.0, 4.1, 5.1, 4.2), DELTA);
    checkBounds(grid.get(2), new CoordinateBounds(5.1, 4.0, 5.2, 4.1), DELTA);
    checkBounds(grid.get(3), new CoordinateBounds(5.1, 4.1, 5.2, 4.2), DELTA);

    List<EncodedPolygonBean> boundary = factory.getBoundary();
    assertEquals(1, boundary.size());

    EncodedPolygonBean polygon = boundary.get(0);
    assertTrue(polygon.getInnerRings().isEmpty());

    List<CoordinatePoint> points = PolylineEncoder.decode(polygon.getOuterRing());
    points = shiftPoints(points);

    assertEquals(8, points.size());

    assertEqualsPoints(new CoordinatePoint(5.0, 4.0), points.get(0), DELTA);
    assertEqualsPoints(new CoordinatePoint(5.1, 4.0), points.get(1), DELTA);
    assertEqualsPoints(new CoordinatePoint(5.2, 4.0), points.get(2), DELTA);
    assertEqualsPoints(new CoordinatePoint(5.2, 4.1), points.get(3), DELTA);
    assertEqualsPoints(new CoordinatePoint(5.2, 4.2), points.get(4), DELTA);
    assertEqualsPoints(new CoordinatePoint(5.1, 4.2), points.get(5), DELTA);
    assertEqualsPoints(new CoordinatePoint(5.0, 4.2), points.get(6), DELTA);
    assertEqualsPoints(new CoordinatePoint(5.0, 4.1), points.get(7), DELTA);

    factory.addBounds(new CoordinateBounds(5.15, 4.05, 5.26, 4.19));

    grid = factory.getGrid();

    assertEquals(6, grid.size());

    Collections.sort(grid, BOUNDS_COMPARATOR);

    checkBounds(grid.get(0), new CoordinateBounds(5.0, 4.0, 5.1, 4.1), DELTA);
    checkBounds(grid.get(1), new CoordinateBounds(5.0, 4.1, 5.1, 4.2), DELTA);
    checkBounds(grid.get(2), new CoordinateBounds(5.1, 4.0, 5.2, 4.1), DELTA);
    checkBounds(grid.get(3), new CoordinateBounds(5.1, 4.1, 5.2, 4.2), DELTA);
    checkBounds(grid.get(4), new CoordinateBounds(5.2, 4.0, 5.3, 4.1), DELTA);
    checkBounds(grid.get(5), new CoordinateBounds(5.2, 4.1, 5.3, 4.2), DELTA);

    boundary = factory.getBoundary();
    assertEquals(1, boundary.size());

    polygon = boundary.get(0);
View Full Code Here

Examples of org.onebusaway.geospatial.model.CoordinateBounds

  @Test
  public void test02() {

    GridFactory factory = new GridFactory(1,1);

    CoordinateBounds bounds = new CoordinateBounds(1.5, 2.5, 2.5, 3.5);
    factory.addBounds(bounds);

    List<CoordinateBounds> grid = factory.getGrid();

    assertEquals(4, grid.size());

    Collections.sort(grid, BOUNDS_COMPARATOR);

    checkBounds(grid.get(0), new CoordinateBounds(1.0, 2.0, 2.0, 3.0), DELTA);
    checkBounds(grid.get(1), new CoordinateBounds(1.0, 3.0, 2.0, 4.0), DELTA);
    checkBounds(grid.get(2), new CoordinateBounds(2.0, 2.0, 3.0, 3.0), DELTA);
    checkBounds(grid.get(3), new CoordinateBounds(2.0, 3.0, 3.0, 4.0), DELTA);

    List<EncodedPolygonBean> boundary = factory.getBoundary();
    assertEquals(1, boundary.size());

    EncodedPolygonBean polygon = boundary.get(0);
    assertTrue(polygon.getInnerRings().isEmpty());

    List<CoordinatePoint> points = PolylineEncoder.decode(polygon.getOuterRing());
    points = shiftPoints(points);

    assertEquals(8, points.size());

    assertEqualsPoints(new CoordinatePoint(1.0, 2.0), points.get(0), DELTA);
    assertEqualsPoints(new CoordinatePoint(2.0, 2.0), points.get(1), DELTA);
    assertEqualsPoints(new CoordinatePoint(3.0, 2.0), points.get(2), DELTA);
    assertEqualsPoints(new CoordinatePoint(3.0, 3.0), points.get(3), DELTA);
    assertEqualsPoints(new CoordinatePoint(3.0, 4.0), points.get(4), DELTA);
    assertEqualsPoints(new CoordinatePoint(2.0, 4.0), points.get(5), DELTA);
    assertEqualsPoints(new CoordinatePoint(1.0, 4.0), points.get(6), DELTA);
    assertEqualsPoints(new CoordinatePoint(1.0, 3.0), points.get(7), DELTA);

    factory.addBounds(new CoordinateBounds(5.5, 4.5, 5.6, 4.6));

    grid = factory.getGrid();

    assertEquals(5, grid.size());

    Collections.sort(grid, BOUNDS_COMPARATOR);

    checkBounds(grid.get(0), new CoordinateBounds(1.0, 2.0, 2.0, 3.0), DELTA);
    checkBounds(grid.get(1), new CoordinateBounds(1.0, 3.0, 2.0, 4.0), DELTA);
    checkBounds(grid.get(2), new CoordinateBounds(2.0, 2.0, 3.0, 3.0), DELTA);
    checkBounds(grid.get(3), new CoordinateBounds(2.0, 3.0, 3.0, 4.0), DELTA);
    checkBounds(grid.get(4), new CoordinateBounds(5.0, 4.0, 6.0, 5.0), DELTA);

    boundary = factory.getBoundary();

    assertEquals(2, boundary.size());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.