Search in sources :

Example 6 with XYPoint

use of org.onebusaway.geospatial.model.XYPoint in project onebusaway-application-modules by camsys.

the class DefaultProjectionTest method assertPoint.

private void assertPoint(double lat, double lon, double x, double y) {
    CoordinatePoint point = new CoordinatePoint(lat, lon);
    XYPoint p = _projection.forward(point);
    assertEquals(x, p.getX(), 0.01);
    assertEquals(y, p.getY(), 0.01);
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 7 with XYPoint

use of org.onebusaway.geospatial.model.XYPoint in project onebusaway-application-modules by camsys.

the class UTMProjectionTest method testMultiProjection.

@Test
public void testMultiProjection() {
    assertUTMPoint(47.65458077, -122.30502529, 552186.99, 5278143.40);
    assertUTMPoint(47.66933, -122.289114, 553366.76, 5279793.45);
    List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
    points.add(new CoordinatePoint(47.65458077, -122.30502529));
    points.add(new CoordinatePoint(47.66933, -122.289114));
    List<XYPoint> results = new ArrayList<XYPoint>();
    UTMProjection projection = new UTMProjection(10);
    projection.forward(points, results, 2);
    XYPoint p0 = results.get(0);
    XYPoint p1 = results.get(1);
    assertEquals(552186.99, p0.getX(), 0.01);
    assertEquals(5278143.40, p0.getY(), 0.01);
    assertEquals(553366.76, p1.getX(), 0.01);
    assertEquals(5279793.45, p1.getY(), 0.01);
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with XYPoint

use of org.onebusaway.geospatial.model.XYPoint in project onebusaway-application-modules by camsys.

the class SphericalGeometryLibrary method getOrientation.

/**
 * If Wikipedia is to be trusted, then:
 *
 * http://en.wikipedia.org/wiki/Spherical_law_of_cosines
 *
 * claims that the standard ordinary planar law of cosines is a reasonable
 * approximation for the more-complex spherical law of cosines when the
 * central angles of the spherical triangle are small.
 *
 * @param latFrom
 * @param lonFrom
 * @param latTo
 * @param lonTo
 * @return the orientation angle in degrees, 0º is East, 90º is North, 180º is
 *         West, and 270º is South
 */
public static double getOrientation(double latFrom, double lonFrom, double latTo, double lonTo) {
    double d = distance(latFrom, lonFrom, latTo, lonTo);
    CoordinateBounds bounds = bounds(latFrom, lonFrom, d);
    XYPoint origin = new XYPoint(lonFrom, latFrom);
    XYPoint axis = new XYPoint(bounds.getMaxLon(), latFrom);
    XYPoint target = new XYPoint(lonTo, latTo);
    double angle = GeometryLibrary.getAngle(origin, axis, target);
    if (latTo < latFrom)
        angle = 2 * Math.PI - angle;
    return Math.toDegrees(angle);
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 9 with XYPoint

use of org.onebusaway.geospatial.model.XYPoint in project onebusaway-application-modules by camsys.

the class SphericalGeometryLibrary method projectPointToSegmentAppropximate.

/**
 * Note that this is an approximate method at best that will perform
 * increasingly worse as the distance between the points increases.
 *
 * @param point
 * @param segmentStart
 * @param segmentEnd
 * @return
 */
public static CoordinatePoint projectPointToSegmentAppropximate(CoordinatePoint point, CoordinatePoint segmentStart, CoordinatePoint segmentEnd) {
    XYPoint pPoint = new XYPoint(point.getLon(), point.getLat());
    XYPoint pSegmentStart = new XYPoint(segmentStart.getLon(), segmentStart.getLat());
    XYPoint pSegmentEnd = new XYPoint(segmentEnd.getLon(), segmentEnd.getLat());
    XYPoint pResult = GeometryLibrary.projectPointToSegment(pPoint, pSegmentStart, pSegmentEnd);
    return new CoordinatePoint(pResult.getY(), pResult.getX());
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 10 with XYPoint

use of org.onebusaway.geospatial.model.XYPoint in project onebusaway-application-modules by camsys.

the class DistanceAlongShapeLibrary method getDistancesAlongShape.

public PointAndIndex[] getDistancesAlongShape(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes) throws DistanceAlongShapeException {
    PointAndIndex[] stopTimePoints = new PointAndIndex[stopTimes.size()];
    UTMProjection projection = UTMLibrary.getProjectionForPoint(shapePoints.getLats()[0], shapePoints.getLons()[0]);
    List<XYPoint> projectedShapePoints = _shapePointsLibrary.getProjectedShapePoints(shapePoints, projection);
    double[] shapePointsDistTraveled = shapePoints.getDistTraveled();
    List<List<PointAndIndex>> possibleAssignments = computePotentialAssignments(projection, projectedShapePoints, shapePointsDistTraveled, stopTimes);
    pruneUnnecessaryAssignments(possibleAssignments);
    assignmentSanityCheck(shapePoints, stopTimes, possibleAssignments);
    double maxDistanceTraveled = shapePointsDistTraveled[shapePointsDistTraveled.length - 1];
    List<PointAndIndex> bestAssignment = computeBestAssignment(shapePoints, stopTimes, possibleAssignments, projection, projectedShapePoints);
    double last = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < stopTimePoints.length; i++) {
        PointAndIndex pindex = bestAssignment.get(i);
        if (pindex.distanceAlongShape > maxDistanceTraveled) {
            int index = projectedShapePoints.size() - 1;
            XYPoint point = projectedShapePoints.get(index);
            StopEntryImpl stop = stopTimes.get(i).getStop();
            XYPoint stopPoint = projection.forward(stop.getStopLocation());
            double d = stopPoint.getDistance(point);
            pindex = new PointAndIndex(point, index, d, maxDistanceTraveled);
        }
        if (last > pindex.distanceAlongShape) {
            constructError(shapePoints, stopTimes, possibleAssignments, projection);
        }
        last = pindex.distanceAlongShape;
        stopTimePoints[i] = pindex;
    }
    return stopTimePoints;
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) UTMProjection(org.onebusaway.geospatial.services.UTMProjection) ArrayList(java.util.ArrayList) List(java.util.List) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) XYPoint(org.onebusaway.geospatial.model.XYPoint) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Aggregations

XYPoint (org.onebusaway.geospatial.model.XYPoint)22 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)15 ArrayList (java.util.ArrayList)10 PointAndIndex (org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex)6 Test (org.junit.Test)5 UTMProjection (org.onebusaway.geospatial.services.UTMProjection)5 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)4 List (java.util.List)3 Min (org.onebusaway.collections.Min)3 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)3 ProjectedPoint (org.onebusaway.transit_data_federation.model.ProjectedPoint)3 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)2 Point (com.vividsolutions.jts.geom.Point)1 Cacheable (org.onebusaway.container.cache.Cacheable)1 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)1 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)1 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)1