예제 #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
 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;
 }
예제 #3
0
파일: SetZones.java 프로젝트: krlmlr/matsim
  @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++;
      }
    }
  }
예제 #4
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);
      }
    }
  }