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);
}
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);
}
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);
}
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());
}
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;
}
Aggregations