use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class SphericalGeometryLibraryTest method testGetCenterOfBounds.
@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);
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class UTMProjectionTest method assertUTMPoint.
private void assertUTMPoint(double lat, double lon, double x, double y) {
CoordinatePoint point = new CoordinatePoint(lat, lon);
int zone = UTMLibrary.getUTMZoneForLongitude(lon);
UTMProjection projection = new UTMProjection(zone);
XYPoint p = projection.forward(point);
assertEquals(x, p.getX(), 0.01);
assertEquals(y, p.getY(), 0.01);
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class PolylineEncoder method decode.
public static List<CoordinatePoint> decode(String pointString) {
double lat = 0;
double lon = 0;
int strIndex = 0;
List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
while (strIndex < pointString.length()) {
int[] rLat = decodeSignedNumberWithIndex(pointString, strIndex);
lat = lat + rLat[0] * 1e-5;
strIndex = rLat[1];
int[] rLon = decodeSignedNumberWithIndex(pointString, strIndex);
lon = lon + rLon[0] * 1e-5;
strIndex = rLon[1];
points.add(new CoordinatePoint(lat, lon));
}
return points;
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class StopTimeEntriesFactory method ensureStopTimesHaveShapeDistanceTraveledSet.
/**
* We have to make sure shape distance traveled is set, even if we don't have
* shape information
*
* @param stopTimes
* @param shapePoints potentially null
*/
private void ensureStopTimesHaveShapeDistanceTraveledSet(List<StopTimeEntryImpl> stopTimes, ShapePoints shapePoints) {
boolean distanceTraveledSet = false;
// Do we have shape information?
if (shapePoints != null) {
try {
PointAndIndex[] stopTimePoints = _distanceAlongShapeLibrary.getDistancesAlongShape(shapePoints, stopTimes);
for (int i = 0; i < stopTimePoints.length; i++) {
PointAndIndex pindex = stopTimePoints[i];
StopTimeEntryImpl stopTime = stopTimes.get(i);
stopTime.setShapePointIndex(pindex.index);
stopTime.setShapeDistTraveled(pindex.distanceAlongShape);
}
distanceTraveledSet = true;
} catch (StopIsTooFarFromShapeException ex) {
StopTimeEntry stopTime = ex.getStopTime();
TripEntry trip = stopTime.getTrip();
StopEntry stop = stopTime.getStop();
AgencyAndId shapeId = trip.getShapeId();
CoordinatePoint point = ex.getPoint();
PointAndIndex pindex = ex.getPointAndIndex();
_log.warn("Stop is too far from shape: trip=" + trip.getId() + " stop=" + stop.getId() + " stopLat=" + stop.getStopLat() + " stopLon=" + stop.getStopLon() + " shapeId=" + shapeId + " shapePoint=" + point + " index=" + pindex.index + " distance=" + pindex.distanceFromTarget);
} catch (DistanceAlongShapeException ex) {
_invalidStopToShapeMappingExceptionCount++;
} catch (IllegalArgumentException iae) {
_log.warn("Stop has illegal coordinates along shapes=" + shapePoints);
}
}
if (!distanceTraveledSet) {
// Make do without
double d = 0;
StopTimeEntryImpl prev = null;
for (StopTimeEntryImpl stopTime : stopTimes) {
if (prev != null) {
CoordinatePoint from = prev.getStop().getStopLocation();
CoordinatePoint to = stopTime.getStop().getStopLocation();
d += SphericalGeometryLibrary.distance(from, to);
}
stopTime.setShapeDistTraveled(d);
prev = stopTime;
}
}
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class ProjectedPointFactory method reverse.
public static ProjectedPoint reverse(double x, double y, int srid) {
UTMProjection projection = new UTMProjection(srid);
XYPoint p = new XYPoint(x, y);
CoordinatePoint latlon = projection.reverse(p);
return new ProjectedPoint(latlon.getLat(), latlon.getLon(), x, y, srid);
}
Aggregations