Пример #1
0
  public static void main(final String[] args) {
    final String pathToCSV = args[0];
    final String activityType = args[1];
    final String pathToOutputFacilities = args[2];

    final boolean publicFacilities = true;

    final ActivityFacilitiesFactoryImpl factory = new ActivityFacilitiesFactoryImpl();
    final ActivityFacilities facilities = FacilitiesUtils.createActivityFacilities();
    int idNumber = 0;

    CSVReader reader = new CSVReader(pathToCSV);
    reader.skipLine(); // skip header
    String[] newLine = reader.readLine(); // first line
    while (newLine != null) {

      // EMPFTE;METER_X;METER_Y;NOGA_CD_2008_6;KATEGORIE;NOGA_TAG;CAPACITY;OPEN_FROM;OPEN_TO;METER_X_GERUNDET;METER_Y_GERUNDET
      double xCoord = Double.parseDouble(newLine[1]);
      double yCoord = Double.parseDouble(newLine[2]);
      String desc = newLine[4] + " (" + newLine[5] + ")";
      double capacity = Double.parseDouble(newLine[6]);
      double openFrom = Double.parseDouble(newLine[7]);
      double openTill = Double.parseDouble(newLine[8]);

      // new facility
      ActivityFacilityImpl newFacility =
          (ActivityFacilityImpl)
              factory.createActivityFacility(
                  Id.create(String.format("%06d", ++idNumber), ActivityFacility.class),
                  new Coord(xCoord, yCoord));
      if (!publicFacilities) {
        newFacility.setDesc(desc);
      }
      // new activity
      ActivityOption newActivity = factory.createActivityOption(activityType);
      newActivity.setCapacity(capacity);
      newActivity.addOpeningTime(new OpeningTimeImpl(openFrom, openTill));
      newFacility.addActivityOption(newActivity);
      // add new facility and activity
      facilities.addActivityFacility(newFacility);

      newLine = reader.readLine(); // next line
    }

    // Write facilities
    FacilitiesWriter facilitiesWriter = new FacilitiesWriter(facilities);
    facilitiesWriter.write(pathToOutputFacilities);
    testFacilities(pathToOutputFacilities);
  }
  @Override
  public void readFacilities(ActivityFacilitiesImpl facilities) {
    log.fatal("does not work; see javadoc of class.  Aborting ..." + this);
    System.exit(-1);

    // (these are simply defined as those entities that have x/y coordinates in urbansim)
    try {
      BufferedReader reader =
          IOUtils.getBufferedReader(Matsim4Urbansim.PATH_TO_OPUS_MATSIM + "tmp/gridcells.tab");

      String header = reader.readLine();
      Map<String, Integer> idxFromKey = Utils.createIdxFromKey(header, null);

      String line = reader.readLine();
      while (line != null) {

        String[] parts = line.split("[\t]+");

        int idx_id = idxFromKey.get("grid_id:i4");
        Id<ActivityFacility> id = Id.create(parts[idx_id], ActivityFacility.class);

        int idx_x = idxFromKey.get("relative_x:i4");
        int idx_y = idxFromKey.get("relative_y:i4");
        Coord coord = new Coord(Double.parseDouble(parts[idx_x]), Double.parseDouble(parts[idx_y]));

        ActivityFacilityImpl facility = facilities.createAndAddFacility(id, coord);
        facility.setDesc("urbansim location");

        line = reader.readLine();
      }

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }