use of org.opentripplanner.model.ShapePoint in project OpenTripPlanner by opentripplanner.
the class OtpTransitServiceImplTest method toString.
private static String toString(ShapePoint sp) {
int lat = (int) sp.getLat();
int lon = (int) sp.getLon();
return "#" + sp.getSequence() + " (" + lat + "," + lon + ")";
}
use of org.opentripplanner.model.ShapePoint in project OpenTripPlanner by opentripplanner.
the class ServiceLinkMapperTest method mapServiceLinks.
@Test
public void mapServiceLinks() {
JourneyPattern journeyPattern = new JourneyPattern().withId("RUT:JourneyPattern:1300");
journeyPattern.setLinksInSequence(new LinksInJourneyPattern_RelStructure().withServiceLinkInJourneyPatternOrTimingLinkInJourneyPattern(new ServiceLinkInJourneyPattern_VersionedChildStructure().withServiceLinkRef(new ServiceLinkRefStructure().withRef("RUT:ServiceLink:1"))).withServiceLinkInJourneyPatternOrTimingLinkInJourneyPattern(new ServiceLinkInJourneyPattern_VersionedChildStructure().withServiceLinkRef(new ServiceLinkRefStructure().withRef("RUT:ServiceLink:2"))));
ServiceLink serviceLink1 = createServiceLink("RUT:ServiceLink:1", 200.0, new Double[] { COORDINATES[0], COORDINATES[1], COORDINATES[2], COORDINATES[3] });
ServiceLink serviceLink2 = createServiceLink("RUT:ServiceLink:2", 100.0, new Double[] { COORDINATES[2], COORDINATES[3], COORDINATES[4], COORDINATES[5] });
HierarchicalMapById<ServiceLink> serviceLinksById = new HierarchicalMapById<>();
serviceLinksById.add(serviceLink1);
serviceLinksById.add(serviceLink2);
Quay quay1 = new Quay().withId("NSR:Quay:1");
Quay quay2 = new Quay().withId("NSR:Quay:2");
Quay quay3 = new Quay().withId("NSR:Quay:3");
HierarchicalVersionMapById<Quay> quaysById = new HierarchicalVersionMapById<>();
quaysById.add(quay1);
quaysById.add(quay2);
quaysById.add(quay3);
HierarchicalMap<String, String> quayIdByStopPointRef = new HierarchicalMap<>();
quayIdByStopPointRef.add("RUT:StopPoint:1", "NSR:Quay:1");
quayIdByStopPointRef.add("RUT:StopPoint:2", "NSR:Quay:2");
quayIdByStopPointRef.add("RUT:StopPoint:3", "NSR:Quay:3");
ServiceLinkMapper serviceLinkMapper = new ServiceLinkMapper(new FeedScopedIdFactory("RB"), new DataImportIssueStore(false));
Collection<ShapePoint> shapePoints = serviceLinkMapper.getShapePointsByJourneyPattern(journeyPattern, serviceLinksById, quayIdByStopPointRef, quaysById);
List<ShapePoint> shapePointList = shapePoints.stream().sorted(Comparator.comparing(ShapePoint::getSequence)).collect(Collectors.toList());
Assert.assertEquals(COORDINATES[0], shapePointList.get(0).getLat(), 0.0001);
Assert.assertEquals(COORDINATES[1], shapePointList.get(0).getLon(), 0.0001);
Assert.assertEquals(COORDINATES[2], shapePointList.get(1).getLat(), 0.0001);
Assert.assertEquals(COORDINATES[3], shapePointList.get(1).getLon(), 0.0001);
Assert.assertEquals(COORDINATES[2], shapePointList.get(2).getLat(), 0.0001);
Assert.assertEquals(COORDINATES[3], shapePointList.get(2).getLon(), 0.0001);
Assert.assertEquals(COORDINATES[4], shapePointList.get(3).getLat(), 0.0001);
Assert.assertEquals(COORDINATES[5], shapePointList.get(3).getLon(), 0.0001);
}
use of org.opentripplanner.model.ShapePoint in project OpenTripPlanner by opentripplanner.
the class GeometryAndBlockProcessor method getUniqueShapePointsForShapeId.
/**
* If a shape appears in more than one feed, the shape points will be loaded several
* times, and there will be duplicates in the DAO. Filter out duplicates and repeated
* coordinates because 1) they are unnecessary, and 2) they define 0-length line segments
* which cause JTS location indexed line to return a segment location of NaN,
* which we do not want.
*/
private List<ShapePoint> getUniqueShapePointsForShapeId(FeedScopedId shapeId) {
List<ShapePoint> points = transitService.getShapePointsForShapeId(shapeId);
ArrayList<ShapePoint> filtered = new ArrayList<>(points.size());
ShapePoint last = null;
for (ShapePoint sp : points) {
if (last == null || last.getSequence() != sp.getSequence()) {
if (last != null && last.getLat() == sp.getLat() && last.getLon() == sp.getLon()) {
LOG.trace("pair of identical shape points (skipping): {} {}", last, sp);
} else {
filtered.add(sp);
}
}
last = sp;
}
if (filtered.size() != points.size()) {
filtered.trimToSize();
return filtered;
} else {
return new ArrayList<>(points);
}
}
use of org.opentripplanner.model.ShapePoint in project OpenTripPlanner by opentripplanner.
the class GeometryAndBlockProcessor method getLineStringForShapeId.
private LineString getLineStringForShapeId(FeedScopedId shapeId) {
LineString geometry = geometriesByShapeId.get(shapeId);
if (geometry != null)
return geometry;
List<ShapePoint> points = getUniqueShapePointsForShapeId(shapeId);
if (points.size() < 2) {
return null;
}
Coordinate[] coordinates = new Coordinate[points.size()];
double[] distances = new double[points.size()];
boolean hasAllDistances = true;
int i = 0;
for (ShapePoint point : points) {
coordinates[i] = new Coordinate(point.getLon(), point.getLat());
distances[i] = point.getDistTraveled();
if (!point.isDistTraveledSet())
hasAllDistances = false;
i++;
}
// assume the units will match
if (!hasAllDistances) {
distances = null;
}
CoordinateSequence sequence = new PackedCoordinateSequence.Double(coordinates, 2);
geometry = geometryFactory.createLineString(sequence);
geometriesByShapeId.put(shapeId, geometry);
distancesByShapeId.put(shapeId, distances);
return geometry;
}
use of org.opentripplanner.model.ShapePoint in project OpenTripPlanner by opentripplanner.
the class GTFSToOtpTransitServiceMapper method map.
private OtpTransitServiceBuilder map(GtfsRelationalDao data) {
OtpTransitServiceBuilder builder = new OtpTransitServiceBuilder();
builder.getAgenciesById().addAll(agencyMapper.map(data.getAllAgencies()));
builder.getCalendarDates().addAll(serviceCalendarDateMapper.map(data.getAllCalendarDates()));
builder.getCalendars().addAll(serviceCalendarMapper.map(data.getAllCalendars()));
builder.getFareAttributes().addAll(fareAttributeMapper.map(data.getAllFareAttributes()));
builder.getFareRules().addAll(fareRuleMapper.map(data.getAllFareRules()));
builder.getFeedInfos().addAll(feedInfoMapper.map(data.getAllFeedInfos()));
builder.getFrequencies().addAll(frequencyMapper.map(data.getAllFrequencies()));
builder.getRoutes().addAll(routeMapper.map(data.getAllRoutes()));
for (ShapePoint shapePoint : shapePointMapper.map(data.getAllShapePoints())) {
builder.getShapePoints().put(shapePoint.getShapeId(), shapePoint);
}
mapGtfsStopsToOtpTypes(data, builder);
builder.getPathways().addAll(pathwayMapper.map(data.getAllPathways()));
builder.getStopTimesSortedByTrip().addAll(stopTimeMapper.map(data.getAllStopTimes()));
builder.getTransfers().addAll(transferMapper.map(data.getAllTransfers()));
builder.getTripsById().addAll(tripMapper.map(data.getAllTrips()));
return builder;
}
Aggregations