All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.gtfs.mapping.LocationMapper Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
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;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy