Пример #1
0
  public void refine() throws Exception {
    ArrayList<GPSPoint> arr = GPSPointExtractor.extractFromFile(in);
    ArrayList<GPSPoint> arrResult = new ArrayList<>();
    StringBuilder sb = new StringBuilder();
    GPSPoint pre = null;
    for (GPSPoint cur : arr) {
      // loai bo 0.0,0.0
      if (cur.getLat() == 0.0 || cur.getLng() == 0.0) {
        continue;
      }

      String str = "0002," + cur.getTime() + "," + cur.getLng() + "," + cur.getLat() + "\n";
      // cat tia theo thoi gian
      if (pre == null) {
        pre = cur;
        arrResult.add(cur);

        // write to file out
        MyFile.writeToFile(out, str);
        continue;
      }

      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Date curDate = dateFormat.parse(cur.getTime());
      Date preDate = dateFormat.parse(pre.getTime());

      if (curDate.getTime() - preDate.getTime() > 1000 * 50) {
        arrResult.add(cur);
        pre = cur;

        // write to file out
        MyFile.writeToFile(out, str);
      }
    }

    System.out.println("total size: " + arrResult.size());
  }
Пример #2
0
  /**
   * the result has construct: |folder[name of input] *|file[centroids] // list centroid
   * |folder[lists] *|file[sp1] //list point of sp1 **|file[sp2]
   *
   * @param spArray
   */
  @Override
  public void writeOutFile(ArrayList<StayPoint> spArray, String path, int disThres, int timeThresh)
      throws Exception {
    String folderName = MyFile.getFileName(path) + "_" + disThres + "_" + timeThresh;
    MyFile.createFolder("output");
    MyFile.createFolder("output/" + folderName);
    folderName = "output/" + folderName;
    String fileName = folderName + "/centroids.txt";
    String s = "name,date time,longitude,latitude\n";

    // write to centroid file
    MyFile.writeToFile(fileName, s);
    for (int i = 0; i < spArray.size(); i++) {
      StayPoint sp = spArray.get(i);
      s =
          i
              + ","
              + sp.getStartTime()
              + ","
              + sp.getAvgCoordinate().getLng()
              + ","
              + sp.getAvgCoordinate().getLat()
              + "\n";
      MyFile.writeToFile(fileName, s);
    }

    // write to list
    folderName += "/lists";
    MyFile.createFolder(folderName);
    for (int i = 0; i < spArray.size(); i++) {
      StayPoint sp = spArray.get(i);
      fileName = folderName + "/" + i + ".txt";

      s = "name,date time,longitude,latitude\n";
      MyFile.writeToFile(fileName, s);
      for (GPSPoint p : sp.getArr()) {
        s = i + "," + p.getTime() + "," + p.getLng() + "," + p.getLat() + "\n";
        MyFile.writeToFile(fileName, s);
      }
    }
  }