Beispiel #1
0
  public void loadGeo() {

    try {
      CSVReader reader = new CSVReader(new FileReader(GEOFILE));
      String[] nextLine;
      int lineCounter = 0;
      while ((nextLine = reader.readNext()) != null) {
        // nextLine[] is an array of values from the line
        if (lineCounter > 0) {
          GeoRecord newRecord = new GeoRecord(nextLine);
          double[] key = new double[1];

          // Keep track of trps
          int tripNumber = newRecord.getTripId();
          if (tripNumber > tripCounter) tripCounter = tripNumber;
          key[0] = newRecord.getSecondsSinceMidnight();

          // Key the time range
          if (key[0] < firstTime) firstTime = key[0];
          if (key[0] > lastTime) lastTime = key[0];

          System.err.println("trying sec " + newRecord.getSecondsSinceMidnight());
          geoRecords.insert(key, newRecord);
        }
        lineCounter++;
      }
    } catch (Exception e) {
      System.err.println(e);
    }
  }
Beispiel #2
0
  /** Dumps the results as a series of KML's..one per trip */
  public void writeKMLandCSV() {

    String csv_header =
        "INDEX,DATE,TIME,SECONDS_SINCE_MIDNIGHT,TRIP_ID,DIR,SPEED,LAT,LONG,ALT,EXITS,ENTRANCES";

    try {
      CSVWriter writer = new CSVWriter(new FileWriter("bus_data.csv"), ',');

      // Write the header
      String[] entries = csv_header.split(",");
      writer.writeNext(entries);

      // Setup some style
      LineStyle lineStyle = new LineStyle();
      lineStyle.setColor("ff005555");
      lineStyle.setWidth(5.0);

      IconStyle peopleIconStyle = new IconStyle();
      // Icon peopleIcon = new Icon();
      // peopleIcon.setHref("http://maps.google.com/mapfiles/kml/man.png");
      peopleIconStyle.setIconHref("http://maps.google.com/mapfiles/kml/shapes/man.png");
      peopleIconStyle.setScale(1.50);

      IconStyle wpIconStyleNorth = new IconStyle();
      // wpIcon.setHref("http://maps.google.com/mapfiles/kml/paddle/red-stars.png");
      // wpIconStyleNorth.setIconHref("http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png");
      wpIconStyleNorth.setIconHref("http://maps.google.com/mapfiles/ms/micons/green-dot.png");
      wpIconStyleNorth.setScale(0.50);

      IconStyle wpIconStyleSouth = new IconStyle();
      // wpIcon.setHref("http://maps.google.com/mapfiles/kml/paddle/red-stars.png");
      wpIconStyleSouth.setIconHref("http://maps.google.com/mapfiles/ms/micons/yellow-dot.png");
      wpIconStyleSouth.setScale(0.50);

      Style style_lineStyle = new Style();
      style_lineStyle.setLineStyle(lineStyle);

      Style style_peopleIconStyle = new Style();
      style_peopleIconStyle.setId("peopleIcon");
      style_peopleIconStyle.setIconStyle(peopleIconStyle);

      Style style_wpIconStyleNorth = new Style();
      style_wpIconStyleNorth.setId("wpIconNorth");
      style_wpIconStyleNorth.setIconStyle(wpIconStyleNorth);

      Style style_wpIconStyleSouth = new Style();
      style_wpIconStyleSouth.setId("wpIconSouth");
      style_wpIconStyleSouth.setIconStyle(wpIconStyleSouth);

      Kml[] kml = new Kml[tripCounter];
      Document[] document = new Document[tripCounter];
      Folder[] northFolders = new Folder[tripCounter];
      Folder[] southFolders = new Folder[tripCounter];
      Folder[] peopleFolders = new Folder[tripCounter];
      // Folder[] tracksFolders = new Folder[tripCounter];

      for (int i = 0; i < tripCounter; i++) {
        kml[i] = new Kml();
        kml[i].setXmlIndent(true);
        document[i] = new Document();
        document[i].addStyleSelector(style_lineStyle);
        document[i].addStyleSelector(style_peopleIconStyle);
        document[i].addStyleSelector(style_wpIconStyleNorth);
        document[i].addStyleSelector(style_wpIconStyleSouth);
        kml[i].setFeature(document[i]);

        northFolders[i] = new Folder();
        northFolders[i].setName("North Route");

        southFolders[i] = new Folder();
        southFolders[i].setName("South Route");

        peopleFolders[i] = new Folder();
        peopleFolders[i].setName("People");

        // tracksFolders[i] = new Folder();
        // tracksFolders[i].setName("Tracks");

        document[i].addFeature(northFolders[i]);
        document[i].addFeature(southFolders[i]);
        document[i].addFeature(peopleFolders[i]);
        // document[i].addFeature(tracksFolders[i]);

      }

      double[] lowerKey = new double[1];
      double[] upperKey = new double[1];

      lowerKey[0] = firstTime;
      upperKey[0] = lastTime;

      Object[] foo = geoRecords.range(lowerKey, upperKey);
      for (int i = 0; i < foo.length; i++) {
        GeoRecord nextRecord = (GeoRecord) foo[i];
        int tripNumber = nextRecord.getTripId();
        // System.out.println(foo[i]);
        if (nextRecord.getDirection().equals("N")) {
          northFolders[tripNumber - 1].addFeature(nextRecord.toKML());
        } else {
          southFolders[tripNumber - 1].addFeature(nextRecord.toKML());
        }
        if (nextRecord.getAssociatedPeople().size() > 0) {
          peopleFolders[tripNumber - 1].addFeature(nextRecord.toKMLWithPeople());
        }

        // Write CSV entry
        String csvLine = nextRecord.toCSV();
        String[] entries2 = csvLine.split(",");
        writer.writeNext(entries2);
      }

      // Write the KML files
      for (int i = 0; i < tripCounter; i++) {
        kml[i].createKml("bus_route" + i + ".kml");
      }

      // Close the csv writer
      writer.close();

    } catch (Exception e) {
      System.err.println(e);
    }
  }