示例#1
0
  public static void main(String args[]) throws IOException {
    String in = "/Users/jillenberger/work/matrix2014/data/matrices/tomtom.de.txt";
    String out = "/Users/jillenberger/work/matrix2014/data/matrices/tomtom.de.100KM.txt";
    String zoneFile = "/Users/jillenberger/work/matrix2014/data/zones/nuts3.psm.gk3.geojson";
    String idKey = "NO";

    NumericMatrix m = NumericMatrixIO.read(in);
    ZoneCollection zones = ZoneGeoJsonIO.readFromGeoJSON(zoneFile, idKey);
    DistanceCalculator dCalc = CartesianDistanceCalculator.getInstance();
    double threshold = 100000;

    Set<String> keys = m.keys();
    for (String i : keys) {
      Zone z_i = zones.get(i);
      for (String j : keys) {
        Zone z_j = zones.get(j);

        double d = dCalc.distance(z_i.getGeometry().getCentroid(), z_j.getGeometry().getCentroid());
        if (d < threshold) {
          m.set(i, j, null);
        }
      }
    }

    NumericMatrixIO.write(m, out);
  }
示例#2
0
  /**
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
    ZoneCollection zones = new ZoneCollection();
    String data =
        new String(
            Files.readAllBytes(Paths.get("/home/johannes/gsv/gis/nuts/de.nuts3.gk3.geojson")));
    zones.addAll(ZoneGeoJsonIO.parseFeatureCollection(data));
    data = null;
    zones.setPrimaryKey("gsvId");

    Map<String, Set<Zone>> aggZones = new HashMap<>();
    for (Zone zone : zones.getZones()) {
      String code = zone.getAttribute("nuts2_code");
      Set<Zone> set = aggZones.get(code);
      if (set == null) {
        set = new HashSet<>();
        aggZones.put(code, set);
      }
      set.add(zone);
    }

    Set<Zone> newZones = new HashSet<>();

    for (Entry<String, Set<Zone>> entry : aggZones.entrySet()) {
      Set<Zone> set = entry.getValue();
      Geometry refGeo = null;
      for (Zone zone : set) {
        if (refGeo != null) {

          Geometry geo2 = zone.getGeometry();

          refGeo = refGeo.union(geo2);
        } else {
          refGeo = zone.getGeometry();
        }
      }

      Zone zone = new Zone(refGeo);
      zone.setAttribute("nuts2_code", entry.getKey());
      newZones.add(zone);
    }

    data = ZoneGeoJsonIO.toJson(newZones);
    Files.write(
        Paths.get("/home/johannes/gsv/gis/nuts/de.nuts2.gk3.geojson"),
        data.getBytes(),
        StandardOpenOption.CREATE);
  }
示例#3
0
 private static TObjectDoubleHashMap<String> calcDensity(String file, ZoneCollection zones)
     throws IOException {
   TObjectDoubleHashMap<String> inhabs = new TObjectDoubleHashMap<>();
   BufferedReader reader = new BufferedReader(new FileReader(file));
   String line = reader.readLine();
   while ((line = reader.readLine()) != null) {
     String tokens[] = line.split("\t");
     String id = tokens[0];
     double pop = Double.parseDouble(tokens[1]);
     Zone zone = zones.get(id);
     if (zone != null) {
       double rho = pop / zone.getGeometry().getArea() * 1000 * 1000;
       inhabs.put(id, rho);
     }
   }
   reader.close();
   return inhabs;
 }
示例#4
0
  @Override
  public void apply(Episode plan) {
    for (Segment act : plan.getActivities()) {
      String id = act.getAttribute(CommonKeys.ACTIVITY_FACILITY);
      ActivityFacility facility =
          facilities.getFacilities().get(Id.create(id, ActivityFacility.class));

      Coordinate c = new Coordinate(facility.getCoord().getX(), facility.getCoord().getY());
      CRSUtils.transformCoordinate(c, transform);

      Zone zone = zones.get(c);

      if (zone != null) {
        act.setAttribute(ZONE_KEY, zone.getAttribute(idKey));
      } else {
        notfound++;
      }
    }
  }
示例#5
0
  private void initMappings(ZoneCollection zones, String zoneIdKey) {
    node2Zone = new ConcurrentHashMap<>();
    zone2Node = new ConcurrentHashMap<>();

    for (Node node : network.getNodes().values()) {
      Coordinate c = new Coordinate(node.getCoord().getX(), node.getCoord().getY());
      Zone zone = zones.get(c);
      if (zone != null) {
        String id = zone.getAttribute(zoneIdKey);
        node2Zone.put(node.getId(), id);

        Collection<Node> nodes = zone2Node.get(id);
        if (nodes == null) {
          nodes = new HashSet<>();
          zone2Node.put(id, nodes);
        }
        nodes.add(node);
      }
    }
  }
示例#6
0
  public NumericMatrix generate(
      Network network, ZoneCollection zones, String zoneIdKey, int nThreads) {
    this.network = network;

    logger.info("Initializing node mappings...");
    initMappings(zones, zoneIdKey);

    logger.info("Calculation travel times...");
    ExecutorService executor = Executors.newFixedThreadPool(nThreads);
    Set<Future<Worker>> futures = new HashSet<>();

    for (Zone zone : zones.getZones()) {
      Worker worker = new Worker(zone.getAttribute(zoneIdKey));
      futures.add(executor.submit(worker, worker));
    }

    ProgressLogger.init(futures.size(), 1, 10);

    HashMatrix<String, CellData> sumMatrix = new HashMatrix<>();
    int errors = 0;

    for (Future<Worker> future : futures) {
      try {
        Worker worker = future.get();
        HashMatrix<String, CellData> m = worker.getMatrix();
        Set<String> keys = m.keys();

        for (String i : keys) {
          for (String j : keys) {

            CellData cData = m.get(i, j);
            if (cData != null) {

              CellData cDataSum = sumMatrix.get(i, j);
              if (cDataSum == null) {
                cDataSum = new CellData();
                sumMatrix.set(i, j, cDataSum);
              }

              cDataSum.count += cData.count;
              cDataSum.ttSum += cData.ttSum;
            }
          }
        }

        errors += worker.getErrors();

        ProgressLogger.step();
      } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
      }
    }

    ProgressLogger.terminate();

    if (errors > 0) {
      logger.info(String.format("%s errors occured.", errors));
    }

    logger.info("Collection results...");

    NumericMatrix ttMatrix = new NumericMatrix();
    Set<String> keys = sumMatrix.keys();
    for (String i : keys) {
      for (String j : keys) {
        CellData cData = sumMatrix.get(i, j);
        double avr = cData.ttSum / cData.count;
        ttMatrix.set(i, j, avr);
      }
    }

    return ttMatrix;
  }