Search in sources :

Example 1 with UTMProjection

use of org.onebusaway.geospatial.services.UTMProjection in project onebusaway-application-modules by camsys.

the class ShapePointsLibraryTest method test04.

@Test
public void test04() {
    ShapePointsFactory factory = new ShapePointsFactory();
    factory.addPoint(47.66851509562011, -122.29019398384474);
    factory.addPoint(47.66486634286269, -122.29014033966445);
    factory.addPoint(47.66486634286269, -122.29560131721877);
    ShapePoints shapePoints = factory.create();
    UTMProjection projection = UTMLibrary.getProjectionForPoint(shapePoints.getLatForIndex(0), shapePoints.getLonForIndex(0));
    ShapePointsLibrary spl = new ShapePointsLibrary();
    List<XYPoint> projectedShapePoints = spl.getProjectedShapePoints(shapePoints, projection);
    XYPoint stopPoint = projection.forward(new CoordinatePoint(47.664922340500475, -122.29066873484038));
    double[] distanceAlongShape = { 0.0, 405.7, 814.0 };
    List<PointAndIndex> assignments = spl.computePotentialAssignments(projectedShapePoints, distanceAlongShape, stopPoint, 0, 3);
    assertEquals(2, assignments.size());
    PointAndIndex assignment = assignments.get(0);
    assertEquals(398.9, assignment.distanceAlongShape, 0.1);
    assertEquals(39.6, assignment.distanceFromTarget, 0.1);
    assignment = assignments.get(1);
    assertEquals(445.4, assignment.distanceAlongShape, 0.1);
    assertEquals(6.2, assignment.distanceFromTarget, 0.1);
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) UTMProjection(org.onebusaway.geospatial.services.UTMProjection) Test(org.junit.Test)

Example 2 with UTMProjection

use of org.onebusaway.geospatial.services.UTMProjection 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)

Example 3 with UTMProjection

use of org.onebusaway.geospatial.services.UTMProjection in project onebusaway-application-modules by camsys.

the class GtfsComputePolylineBoundaryForStopsMain method handleOutputAsOSMPolygon.

private void handleOutputAsOSMPolygon(PrintWriter out, StopToPolygonEntityHandler handler) throws IOException {
    Geometry geometry = handler.getGeometry();
    UTMProjection proj = handler.getProjection();
    out.println("polygon");
    AtomicInteger index = new AtomicInteger();
    printGeometry(out, geometry, proj, index, false);
    out.println("END");
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UTMProjection(org.onebusaway.geospatial.services.UTMProjection)

Example 4 with UTMProjection

use of org.onebusaway.geospatial.services.UTMProjection in project onebusaway-application-modules by camsys.

the class ProjectedShapePointServiceImpl method getProjectedShapePoints.

@Cacheable
@Override
public T2<List<XYPoint>, double[]> getProjectedShapePoints(List<AgencyAndId> shapeIds, int utmZoneId) {
    ShapePoints shapePoints = _shapePointService.getShapePointsForShapeIds(shapeIds);
    if (shapePoints == null || shapePoints.isEmpty())
        return null;
    UTMProjection projection = new UTMProjection(utmZoneId);
    List<XYPoint> projected = _shapePointsLibrary.getProjectedShapePoints(shapePoints, projection);
    return Tuples.tuple(projected, shapePoints.getDistTraveled());
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) XYPoint(org.onebusaway.geospatial.model.XYPoint) UTMProjection(org.onebusaway.geospatial.services.UTMProjection) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 5 with UTMProjection

use of org.onebusaway.geospatial.services.UTMProjection in project onebusaway-application-modules by camsys.

the class ProjectedPointFactory method forward.

public static ProjectedPoint forward(CoordinatePoint latlon, int zone) {
    UTMProjection projection = new UTMProjection(zone);
    XYPoint point = projection.forward(latlon);
    return new ProjectedPoint(latlon.getLat(), latlon.getLon(), point.getX(), point.getY(), zone);
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) UTMProjection(org.onebusaway.geospatial.services.UTMProjection) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint)

Aggregations

UTMProjection (org.onebusaway.geospatial.services.UTMProjection)7 XYPoint (org.onebusaway.geospatial.model.XYPoint)5 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ProjectedPoint (org.onebusaway.transit_data_federation.model.ProjectedPoint)2 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1 Cacheable (org.onebusaway.container.cache.Cacheable)1 PointAndIndex (org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex)1 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)1 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)1