Search in sources :

Example 6 with GtfsBundle

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle in project onebusaway-application-modules by camsys.

the class GtfsFullValidationTask method getGtfsBundles.

protected GtfsBundles getGtfsBundles(ApplicationContext context) {
    GtfsBundles bundles = (GtfsBundles) context.getBean("gtfs-bundles");
    if (bundles != null)
        return bundles;
    GtfsBundle bundle = (GtfsBundle) context.getBean("gtfs-bundle");
    if (bundle != null) {
        bundles = new GtfsBundles();
        bundles.getBundles().add(bundle);
        return bundles;
    }
    throw new IllegalStateException("must define either \"gtfs-bundles\" or \"gtfs-bundle\" in config");
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)

Example 7 with GtfsBundle

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle in project onebusaway-application-modules by camsys.

the class HastusTranslateTask method updateGtfsBundle.

private void updateGtfsBundle(BundleRequestResponse requestResponse, String zipFilename, HastusData hd) {
    GtfsBundles bundles = getGtfsBundles(_applicationContext);
    GtfsBundle bundle = new GtfsBundle();
    bundle.setDefaultAgencyId(hd.getAgencyId());
    bundle.setPath(new File(zipFilename));
    bundles.getBundles().add(bundle);
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles) File(java.io.File)

Example 8 with GtfsBundle

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle in project onebusaway-application-modules by camsys.

the class MultiAgencyModTask method run.

@Override
public void run() {
    try {
        _log.info("GtfsModTask Starting");
        GtfsBundles gtfsBundles = getGtfsBundles(_applicationContext);
        for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
            String agencyId = parseAgencyDir(gtfsBundle.getPath().getPath());
            // _log.info("no modUrl found for agency " + agencyId + " and bundle " + gtfsBundle.getPath());
            String oldFilename = gtfsBundle.getPath().getPath();
            String newFilename = runModifications(gtfsBundle, agencyId, getEmptyModUrl(), null);
            logger.changelog("Transformed " + oldFilename + " to " + newFilename + " to add multi-agency support");
        }
    } catch (Throwable ex) {
        _log.error("error modifying gtfs:", ex);
    } finally {
        _log.info("GtfsModTask Exiting");
    }
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)

Example 9 with GtfsBundle

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle in project onebusaway-application-modules by camsys.

the class GtfsComputePolylineBoundaryForStopsMain method run.

public void run(String[] args) throws IOException {
    try {
        Parser parser = new GnuParser();
        Options options = new Options();
        buildOptions(options);
        CommandLine commandLine = parser.parse(options, args);
        String[] remainingArgs = commandLine.getArgs();
        if (remainingArgs.length < 2) {
            printUsage();
            System.exit(-1);
        }
        List<GtfsBundle> bundles = getGtfsBundlesFromCommandLine(remainingArgs);
        EFormat format = getFormat(commandLine);
        StopToPolygonEntityHandler handler = new StopToPolygonEntityHandler(2500);
        for (GtfsBundle bundle : bundles) {
            System.err.println(bundle.getPath());
            GtfsReader reader = new GtfsReader();
            reader.addEntityHandler(handler);
            reader.setInputLocation(bundle.getPath());
            if (bundle.getDefaultAgencyId() != null)
                reader.setDefaultAgencyId(bundle.getDefaultAgencyId());
            reader.readEntities(Stop.class);
        }
        PrintWriter out = getOutputAsPrinter(remainingArgs[remainingArgs.length - 1]);
        switch(format) {
            case OSM:
                handleOutputAsOSMPolygon(out, handler);
                break;
            case TEXT:
                handleOutputAsText(out, handler);
                break;
        }
        out.close();
    } catch (ParseException ex) {
        System.err.println(ex.getLocalizedMessage());
        printUsage();
        System.exit(-1);
    }
    System.exit(0);
}
Also used : Options(org.apache.commons.cli.Options) GnuParser(org.apache.commons.cli.GnuParser) LineString(com.vividsolutions.jts.geom.LineString) GnuParser(org.apache.commons.cli.GnuParser) Parser(org.apache.commons.cli.Parser) CommandLine(org.apache.commons.cli.CommandLine) GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) ParseException(org.apache.commons.cli.ParseException) PrintWriter(java.io.PrintWriter)

Example 10 with GtfsBundle

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle in project onebusaway-application-modules by camsys.

the class GtfsStopReplacementVerificationMain method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
    if (args.length == 0) {
        System.err.println("usage: stop-consolidation-file gtfs_path [gtfs_path:defaultAgencyId data-sources.xml ...]");
        System.exit(-1);
    }
    EntityHandlerImpl handler = new EntityHandlerImpl();
    List<String> paths = new ArrayList<String>();
    for (int i = 1; i < args.length; i++) {
        paths.add(args[i]);
    }
    List<GtfsBundle> bundles = UtilityLibrary.getGtfsBundlesForArguments(paths);
    for (GtfsBundle bundle : bundles) {
        GtfsReader reader = new GtfsReader();
        reader.setDefaultAgencyId(bundle.getDefaultAgencyId());
        reader.setInputLocation(bundle.getPath());
        for (Map.Entry<String, String> entry : bundle.getAgencyIdMappings().entrySet()) reader.addAgencyIdMapping(entry.getKey(), entry.getValue());
        reader.getEntityClasses().retainAll(Arrays.asList(Agency.class, Stop.class));
        reader.addEntityHandler(handler);
        reader.run();
    }
    Set<AgencyAndId> ids = handler.getIds();
    InputStream in = IOLibrary.getPathAsInputStream(args[0]);
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    String line = null;
    while ((line = reader.readLine()) != null) {
        if (line.startsWith("#") || line.startsWith("{{{") || line.startsWith("}}}") || line.length() == 0)
            continue;
        String[] tokens = line.split("\\s+");
        AgencyAndId id = AgencyAndIdLibrary.convertFromString(tokens[0]);
        if (!ids.contains(id))
            System.out.println(id + " <- " + line);
    }
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) InputStreamReader(java.io.InputStreamReader) Stop(org.onebusaway.gtfs.model.Stop) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) BufferedReader(java.io.BufferedReader) Map(java.util.Map)

Aggregations

GtfsBundle (org.onebusaway.transit_data_federation.bundle.model.GtfsBundle)19 GtfsBundles (org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)13 ArrayList (java.util.ArrayList)7 File (java.io.File)6 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)4 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Properties (java.util.Properties)2 ZipFile (java.util.zip.ZipFile)2 CommandLine (org.apache.commons.cli.CommandLine)2 GnuParser (org.apache.commons.cli.GnuParser)2 Options (org.apache.commons.cli.Options)2 ParseException (org.apache.commons.cli.ParseException)2 Parser (org.apache.commons.cli.Parser)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 LineString (com.vividsolutions.jts.geom.LineString)1 BufferedReader (java.io.BufferedReader)1