Search in sources :

Example 21 with CoordinatePoint

use of org.onebusaway.geospatial.model.CoordinatePoint 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 22 with CoordinatePoint

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

the class PolylineEncoder method createEncodings.

/**
 * If level < 0, then {@link EncodedPolylineBean#getLevels()} will be null.
 *
 * @param points
 * @param level
 * @return
 */
public static EncodedPolylineBean createEncodings(Iterable<CoordinatePoint> points, int level) {
    StringBuilder encodedPoints = new StringBuilder();
    StringBuilder encodedLevels = new StringBuilder();
    int plat = 0;
    int plng = 0;
    int count = 0;
    for (CoordinatePoint trackpoint : points) {
        int late5 = floor1e5(trackpoint.getLat());
        int lnge5 = floor1e5(trackpoint.getLon());
        int dlat = late5 - plat;
        int dlng = lnge5 - plng;
        plat = late5;
        plng = lnge5;
        encodedPoints.append(encodeSignedNumber(dlat)).append(encodeSignedNumber(dlng));
        if (level >= 0)
            encodedLevels.append(encodeNumber(level));
        count++;
    }
    String pointsString = encodedPoints.toString();
    String levelsString = level >= 0 ? encodedLevels.toString() : null;
    return new EncodedPolylineBean(pointsString, levelsString, count);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 23 with CoordinatePoint

use of org.onebusaway.geospatial.model.CoordinatePoint 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 24 with CoordinatePoint

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

the class DistanceAlongShapeLibrary method assignmentSanityCheck.

private void assignmentSanityCheck(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes, List<List<PointAndIndex>> possibleAssignments) throws DistanceAlongShapeException {
    int stIndex = 0;
    for (List<PointAndIndex> assignments : possibleAssignments) {
        if (assignments.isEmpty()) {
            StopTimeEntry stopTime = stopTimes.get(stIndex);
            throw new InvalidStopToShapeMappingException(stopTime.getTrip());
        }
        Min<PointAndIndex> m = new Min<PointAndIndex>();
        for (PointAndIndex pindex : assignments) m.add(pindex.distanceFromTarget, pindex);
        if (m.getMinValue() > _maxDistanceFromStopToShapePoint) {
            StopTimeEntry stopTime = stopTimes.get(stIndex);
            PointAndIndex pindex = m.getMinElement();
            CoordinatePoint point = shapePoints.getPointForIndex(pindex.index);
            throw new StopIsTooFarFromShapeException(stopTime, pindex, point);
        }
        stIndex++;
    }
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Min(org.onebusaway.collections.Min) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) XYPoint(org.onebusaway.geospatial.model.XYPoint)

Example 25 with CoordinatePoint

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

the class GtfsComputePolylineBoundaryForStopsMain method printLineString.

private void printLineString(PrintWriter out, UTMProjection proj, LineString line, boolean latFirst) {
    for (int i = 0; i < line.getNumPoints(); i++) {
        Point point = line.getPointN(i);
        XYPoint p = new XYPoint(point.getX(), point.getY());
        CoordinatePoint c = proj.reverse(p);
        if (latFirst)
            out.println(c.getLat() + " " + c.getLon());
        else
            out.println(c.getLon() + " " + c.getLat());
    }
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Point(com.vividsolutions.jts.geom.Point) XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Point(com.vividsolutions.jts.geom.Point) XYPoint(org.onebusaway.geospatial.model.XYPoint)

Aggregations

CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)57 ArrayList (java.util.ArrayList)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)12 Test (org.junit.Test)10 XYPoint (org.onebusaway.geospatial.model.XYPoint)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)9 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)7 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)7 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)6 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)6 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)5 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)4 VehicleLocationRecordBean (org.onebusaway.transit_data.model.realtime.VehicleLocationRecordBean)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 VehiclePosition (com.google.transit.realtime.GtfsRealtime.VehiclePosition)3 List (java.util.List)3 Min (org.onebusaway.collections.Min)3 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)3 Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)3