Package org.onebusaway.gtfs.serialization

Examples of org.onebusaway.gtfs.serialization.GtfsReader


        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
   
    GtfsReader reader = new GtfsReader();
      GtfsDaoImpl store = new GtfsDaoImpl();
     
      Long agencyCount = new Long(0);
     
      try {
       
        File gtfsFile = new File(Play.configuration.getProperty("application.publicGtfsDataDirectory"), snapshotMerge.snapshot.getFilename());
       
        reader.setInputLocation(gtfsFile);
          reader.setEntityStore(store);
          reader.run();
           
          Logger.info("GtfsImporter: listing agencies...");
         
        for (org.onebusaway.gtfs.model.Agency gtfsAgency : reader.getAgencies()) {
          
          GtfsAgency agency = new GtfsAgency(gtfsAgency);
          agency.snapshot = snapshotMerge.snapshot;
          agency.save();
     
View Full Code Here


        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
   
    GtfsReader reader = new GtfsReader();
      GtfsDaoImpl store = new GtfsDaoImpl();
     
      Long agencyCount = new Long(0);
      Long routeCount = new Long(0);
      Long stopCount = new Long(0);
      Long stopTimeCount = new Long(0);
      Long tripCount = new Long(0);
      Long shapePointCount = new Long(0);
      Long serviceCalendarCount = new Long(0);
      Long serviceCalendarDateCount = new Long(0);
      Long shapeCount = new Long(0);
     
      try {
       
        File gtfsFile = new File(Play.configuration.getProperty("application.publicDataDirectory"), snapshotMerge.snapshot.getFilename());
       
        reader.setInputLocation(gtfsFile);
          reader.setEntityStore(store);
          reader.run();
           
          Logger.info("GtfsImporter: importing agencies...");
       
          GtfsSnapshotMergeTask agencyTask = new GtfsSnapshotMergeTask(snapshotMerge);
          agencyTask.startTask();
       
         
          List<Agency> agencies = Agency.findAll();
         
          for (Agency agency : agencies)
          {
            agencyIdMap.put(agency.gtfsAgencyId, new BigInteger(agency.id.toString()));
          }
         
          BigInteger primaryAgencyId = null;
         
         
         
        for (org.onebusaway.gtfs.model.Agency gtfsAgency : reader.getAgencies()) {
         
          if(!agencyIdMap.containsKey(gtfsAgency.getId()))
          {
            Agency agency = new Agency(gtfsAgency);
            agency.save();
View Full Code Here

    public static GtfsContext readGtfs(File path, String defaultAgencyId) throws IOException {

        GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();

        GtfsReader reader = new GtfsReader();
        reader.setInputLocation(path);
        reader.setEntityStore(dao);

        if (defaultAgencyId != null)
            reader.setDefaultAgencyId(defaultAgencyId);

        reader.run();

        CalendarService calendarService = createCalendarService(dao);

        return new GtfsContextImpl(dao, calendarService);
    }
View Full Code Here

        StoreImpl store = new StoreImpl(dao);
        store.open();
        LOG.info("reading {}", gtfsBundle.toString());

        GtfsReader reader = new GtfsReader();
        reader.setInputSource(gtfsBundle.getCsvInputSource());
        reader.setEntityStore(store);
        reader.setInternStrings(true);

        if (LOG.isDebugEnabled())
            reader.addEntityHandler(counter);

        if (gtfsBundle.getDefaultBikesAllowed())
            reader.addEntityHandler(new EntityBikeability(true));

        for (Class<?> entityClass : reader.getEntityClasses()) {
            LOG.info("reading entities: " + entityClass.getName());
            reader.readEntities(entityClass);
            store.flush();
            // NOTE that agencies are first in the list and read before all other entity types, so it is effective to
            // set the agencyId here. Each feed ("bundle") is loaded by a separate reader, so there is no risk of
            // agency mappings accumulating.
            if (entityClass == Agency.class) {
                String defaultAgencyId = null;
                for (Agency agency : reader.getAgencies()) {
                    String agencyId = agency.getId();
                    LOG.info("This Agency has the ID {}", agencyId);
                    // Somehow, when the agency's id field is missing, OBA replaces it with the agency's name.
                    // TODO Figure out how and why this is happening.
                    if (agencyId == null || agencyIdsSeen.contains(agencyId)) {
                        // Loop in case generated name is already in use.
                        String generatedAgencyId = null;
                        while (generatedAgencyId == null || agencyIdsSeen.contains(generatedAgencyId)) {
                            generatedAgencyId = "F" + nextAgencyId;
                            nextAgencyId++;
                        }
                        LOG.warn("The agency ID '{}' was already seen, or I think it's bad. Replacing with '{}'.", agencyId, generatedAgencyId);
                        reader.addAgencyIdMapping(agencyId, generatedAgencyId); // NULL key should work
                        agency.setId(generatedAgencyId);
                        agencyId = generatedAgencyId;
                    }
                    if (agencyId != null) agencyIdsSeen.add(agencyId);
                    if (defaultAgencyId == null) defaultAgencyId = agencyId;
                }
                reader.setDefaultAgencyId(defaultAgencyId); // not sure this is a good idea, setting it to the first-of-many IDs.
            }
        }

        for (ShapePoint shapePoint : store.getAllEntitiesForType(ShapePoint.class)) {
            shapePoint.getShapeId().setAgencyId(reader.getDefaultAgencyId());
        }
        for (Route route : store.getAllEntitiesForType(Route.class)) {
            route.getId().setAgencyId(reader.getDefaultAgencyId());
        }
        for (Stop stop : store.getAllEntitiesForType(Stop.class)) {
            stop.getId().setAgencyId(reader.getDefaultAgencyId());
        }
        for (Trip trip : store.getAllEntitiesForType(Trip.class)) {
            trip.getId().setAgencyId(reader.getDefaultAgencyId());
        }
        for (ServiceCalendar serviceCalendar : store.getAllEntitiesForType(ServiceCalendar.class)) {
            serviceCalendar.getServiceId().setAgencyId(reader.getDefaultAgencyId());
        }
        for (ServiceCalendarDate serviceCalendarDate : store.getAllEntitiesForType(ServiceCalendarDate.class)) {
            serviceCalendarDate.getServiceId().setAgencyId(reader.getDefaultAgencyId());
        }
        for (FareAttribute fareAttribute : store.getAllEntitiesForType(FareAttribute.class)) {
            fareAttribute.getId().setAgencyId(reader.getDefaultAgencyId());
        }
        for (Pathway pathway : store.getAllEntitiesForType(Pathway.class)) {
            pathway.getId().setAgencyId(reader.getDefaultAgencyId());
        }

        store.close();

    }
View Full Code Here

    for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {

      System.out.println("gtfs=" + gtfsBundle.getPath());

      GtfsReader reader = new GtfsReader();
      reader.setEntitySchemaFactory(factory);
      reader.setInputLocation(gtfsBundle.getPath());

      if (gtfsBundle.getDefaultAgencyId() != null)
        reader.setDefaultAgencyId(gtfsBundle.getDefaultAgencyId());

      for (Map.Entry<String, String> entry : gtfsBundle.getAgencyIdMappings().entrySet())
        reader.addAgencyIdMapping(entry.getKey(), entry.getValue());

      multiReader.addGtfsReader(reader);
    }

    multiReader.run();
View Full Code Here

    double lat2 = Double.parseDouble(args[3]);
    double lon2 = Double.parseDouble(args[4]);

    CoordinateBounds bounds = new CoordinateBounds(lat1, lon1, lat2, lon2);

    GtfsReader reader = new GtfsReader();
    reader.setDefaultAgencyId("1");
    reader.getEntityClasses().retainAll(Arrays.asList(Stop.class));
    reader.setInputLocation(new File(args[0]));
    reader.addEntityHandler(new EntityHandlerImpl(bounds));
    reader.run();
  }
View Full Code Here

      System.exit(-1);
    }

    Geometry points = readPoints(args[1]);
   
    GtfsReader reader = new GtfsReader();
    reader.setDefaultAgencyId("1");
    reader.getEntityClasses().retainAll(Arrays.asList(Stop.class));
    reader.setInputLocation(new File(args[0]));
    reader.addEntityHandler(new EntityHandlerImpl(points));
    reader.run();
  }
View Full Code Here

      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) {
View Full Code Here

    _readers.add(reader);
  }

  public void addGtfsReaderFromInputLocation(File inputLocation)
      throws IOException {
    GtfsReader reader = new GtfsReader();
    reader.setInputLocation(inputLocation);
    addGtfsReader(reader);
  }
View Full Code Here

  }

  private static Collection<Stop> readStopsFromGtfsPath(String path,
      String defaultAgencyId) throws IOException {

    GtfsReader reader = new GtfsReader();
    reader.setInputLocation(new File(path));

    if (defaultAgencyId != null)
      reader.setDefaultAgencyId(defaultAgencyId);

    reader.readEntities(Agency.class);
    reader.readEntities(Stop.class);
    return reader.getEntityStore().getAllEntitiesForType(Stop.class);
  }
View Full Code Here

TOP

Related Classes of org.onebusaway.gtfs.serialization.GtfsReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.