org.opentripplanner.gtfs.mapping.LocationMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.gtfs.mapping;
import org.opentripplanner.common.geometry.GeometryUtils;
import org.opentripplanner.common.geometry.UnsupportedGeometryException;
import org.opentripplanner.model.FlexStopLocation;
import org.opentripplanner.util.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import static org.opentripplanner.gtfs.mapping.AgencyAndIdMapper.mapAgencyAndId;
/** Responsible for mapping GTFS Location into the OTP model. */
public class LocationMapper {
private static Logger LOG = LoggerFactory.getLogger(LocationMapper.class);
private Map mappedLocations = new HashMap<>();
Collection map(Collection allLocations) {
return MapUtils.mapToList(allLocations, this::map);
}
/** Map from GTFS to OTP model, {@code null} safe. */
FlexStopLocation map(org.onebusaway.gtfs.model.Location orginal) {
return orginal == null ? null : mappedLocations.computeIfAbsent(orginal, this::doMap);
}
private FlexStopLocation doMap(org.onebusaway.gtfs.model.Location gtfsLocation) {
FlexStopLocation otpLocation = new FlexStopLocation(mapAgencyAndId(gtfsLocation.getId()));
otpLocation.setName(gtfsLocation.getName());
otpLocation.setUrl(gtfsLocation.getUrl());
otpLocation.setDescription(gtfsLocation.getDescription());
otpLocation.setZoneId(gtfsLocation.getZoneId());
try {
otpLocation.setGeometry(GeometryUtils.convertGeoJsonToJtsGeometry(gtfsLocation.getGeometry()));
}
catch (UnsupportedGeometryException e) {
LOG.warn("Unsupported geometry type for " + gtfsLocation.getId());
}
return otpLocation;
}
}