Ejemplo n.º 1
0
  public SpatialAveragingUtils(
      double xMin,
      double xMax,
      double yMin,
      double yMax,
      int noOfXbins,
      int noOfYbins,
      double smoothingRadius_m,
      String visBoundaryShapeFile,
      CoordinateReferenceSystem targetCRS) {
    this.xMin = xMin;
    this.xMax = xMax;
    this.yMin = yMin;
    this.yMax = yMax;
    this.noOfXbins = noOfXbins;
    this.noOfYbins = noOfYbins;

    this.smoothinRadiusSquared_m = smoothingRadius_m * smoothingRadius_m;
    this.area_in_smoothing_circle_sqkm =
        (Math.PI * smoothingRadius_m * smoothingRadius_m) / (1000. * 1000.);
    this.cellArea_sqkm =
        ((xMax - xMin) * (yMax - yMin)) / ((noOfXbins * noOfYbins) * (1000. * 1000.));
    this.featuresInVisBoundary = ShapeFileReader.getAllFeatures(visBoundaryShapeFile);
    this.targetCRS = targetCRS;
  }
Ejemplo n.º 2
0
  public Map<String, Zone> getZonesInsideBoundary(final String zonesBoundaryShapeFileName) {

    final Collection<SimpleFeature> features =
        ShapeFileReader.getAllFeatures(zonesBoundaryShapeFileName);
    if (features.size() != 1) {
      throw new RuntimeException("not exactly one feature in shape file");
    }

    final SimpleFeature feature = features.iterator().next();
    final WKTReader wktreader = new WKTReader();
    final Geometry limitingPolygon;
    try {
      limitingPolygon = wktreader.read(feature.getAttribute("the_geom").toString());
    } catch (ParseException e) {
      throw new RuntimeException(e);
    }

    final Map<String, Zone> result = new LinkedHashMap<String, Zone>();
    for (Map.Entry<String, Zone> id2zoneEntry : this.id2zone.entrySet()) {
      if (limitingPolygon.covers(id2zoneEntry.getValue().getGeometry())) {
        result.put(id2zoneEntry.getKey(), id2zoneEntry.getValue());
      }
    }
    return result;
  }
Ejemplo n.º 3
0
  public void createMapping(CoordinateTransformation coordinateTransformation) throws Exception {
    network = scenario.getNetwork();

    log.info("Loading Network ... done");
    log.info("Nodes: " + network.getNodes().size());
    log.info("Links: " + network.getLinks().size());

    /*
     * read zones shape file
     */
    zones = new HashSet<SimpleFeature>();

    for (SimpleFeature feature : ShapeFileReader.getAllFeatures(shapeFile)) {
      zones.add(feature);
    }

    zonesMap = new TreeMap<Integer, SimpleFeature>();
    for (SimpleFeature zone : zones) {
      //			int id = Integer.valueOf(zone.getID().replace("postcode4.", ""));	// Object Id
      //			int id = ((Long)zone.getAttribute(1)).intValue();	// Zone Id
      int id = ((Long) zone.getAttribute(3)).intValue(); // PostCode
      zonesMap.put(id, zone);
    }

    /*
     * print zones
     */
    log.info("Using " + zones.size() + " zones.");

    log.info("Adding connector nodes and links...");
    addConnectorLinks();
    log.info("done.");

    log.info("writing network ...");
    new NetworkWriter(network).write(networkOutFile);
    log.info(" ... done.");

    log.info("writing kmz network ...");
    ObjectFactory kmlObjectFactory = new ObjectFactory();
    KMZWriter kmzWriter = new KMZWriter(kmzOutFile);

    KmlType mainKml = kmlObjectFactory.createKmlType();
    DocumentType mainDoc = kmlObjectFactory.createDocumentType();
    mainKml.setAbstractFeatureGroup(kmlObjectFactory.createDocument(mainDoc));

    KmlNetworkWriter kmlNetworkWriter;
    kmlNetworkWriter =
        new KmlNetworkWriter(
            network, new GeotoolsTransformation("EPSG:28992", "WGS84"), kmzWriter, mainDoc);

    mainDoc
        .getAbstractFeatureGroup()
        .add(kmlObjectFactory.createFolder(kmlNetworkWriter.getNetworkFolder()));
    kmzWriter.writeMainKml(mainKml);
    kmzWriter.close();
    log.info("... done.");
  }
Ejemplo n.º 4
0
 public SpatialAveragingWriter(SpatialAveragingInputData inputData) {
   this.targetCRS = inputData.getTargetCRS();
   this.xMin = inputData.getMinX();
   this.xMax = inputData.getMaxX();
   this.yMin = inputData.getMinY();
   this.yMax = inputData.getMaxY();
   this.noOfXbins = inputData.getNoOfXbins();
   this.noOfYbins = inputData.getNoOfYbins();
   this.useVisBoundary = inputData.isUseVisBoundary();
   if (this.useVisBoundary)
     this.featuresInVisBoundary =
         ShapeFileReader.getAllFeatures(inputData.getVisBoundaryShapeFile());
 }
Ejemplo n.º 5
0
 public ZonalSystem(final String zonesShapeFileName) {
   final GeometryFactory geometryFactory = new GeometryFactory();
   final WKTReader wktReader = new WKTReader(geometryFactory);
   for (SimpleFeature ft : ShapeFileReader.getAllFeatures(zonesShapeFileName)) {
     try {
       final String zoneId = ft.getAttribute("ZONE").toString();
       final Zone zone = new Zone(zoneId);
       zone.setGeometry(wktReader.read((ft.getAttribute("the_geom")).toString()));
       this.id2zone.put(zoneId, zone);
     } catch (ParseException e) {
       throw new RuntimeException(e);
     }
   }
 }
Ejemplo n.º 6
0
  public Map<String, Geometry> readShapeFile(String filename, String attrString) {

    Map<String, Geometry> shapeMap = new HashMap<String, Geometry>();

    for (SimpleFeature ft : ShapeFileReader.getAllFeatures(filename)) {

      GeometryFactory geometryFactory = new GeometryFactory();
      WKTReader wktReader = new WKTReader(geometryFactory);
      Geometry geometry;

      try {
        geometry = wktReader.read((ft.getAttribute("the_geom")).toString());
        shapeMap.put(ft.getAttribute(attrString).toString(), geometry);

      } catch (ParseException e) {
        e.printStackTrace();
      }
    }
    return shapeMap;
  }
Ejemplo n.º 7
0
  public Map<String, Geometry> readShapeFile(String filename, String attrString) {
    // attrString: Für Brandenburg: Nr
    // für OSM: osm_id

    Map<String, Geometry> shapeMap = new HashMap<String, Geometry>();

    for (SimpleFeature ft : ShapeFileReader.getAllFeatures(filename)) {

      GeometryFactory geometryFactory = new GeometryFactory();
      WKTReader wktReader = new WKTReader(geometryFactory);
      Geometry geometry;

      try {
        geometry = wktReader.read((ft.getAttribute("the_geom")).toString());
        shapeMap.put(ft.getAttribute(attrString).toString(), geometry);

      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return shapeMap;
  }
Ejemplo n.º 8
0
  public static void main(String[] args) {
    try {
      if (args.length > 0) {
        String file = args[0];
        Map<String, String> parameterMap = new XMLParameterParser().parseFile(file);
        String value;

        value = parameterMap.remove("basePath");
        if (value != null) basePath = value;

        value = parameterMap.remove("networkFile");
        if (value != null) networkFile = value;

        value = parameterMap.remove("zonalAttributesFile");
        if (value != null) zonalAttributesFile = value;

        value = parameterMap.remove("separator");
        if (value != null) separator = value;

        value = parameterMap.remove("zonalSHPFile");
        if (value != null) zonalSHPFile = value;

        value = parameterMap.remove("facilitiesFile");
        if (value != null) facilitiesFile = value;

        value = parameterMap.remove("facilitiesAttributesFile");
        if (value != null) facilitiesAttributesFile = value;

        value = parameterMap.remove("f2lFile");
        if (value != null) f2lFile = value;

        value = parameterMap.remove("facilitiesPerZone");
        if (value != null) facilitiesPerZone = Integer.parseInt(value);

        value = parameterMap.remove("validLinkTypes");
        if (value != null) validLinkTypes = CollectionUtils.stringToSet(value);

        for (String key : parameterMap.keySet())
          log.warn("Found parameter " + key + " which is not handled!");
      } else {
        log.error("No input config file was given. Therefore cannot proceed. Aborting!");
        return;
      }

      log.info("loading network ...");
      Config config = ConfigUtils.createConfig();
      config.network().setInputFile(basePath + networkFile);
      Scenario scenario = ScenarioUtils.loadScenario(config);
      log.info("done.\n");

      log.info("loading zonal attributes ...");
      boolean skipHeader = true;
      Map<Integer, Emme2Zone> zonalAttributes =
          new Emme2ZonesFileParser(basePath + zonalAttributesFile, separator).readFile(skipHeader);
      log.info("done.\n");

      log.info("loading zonal shp file ...");
      // use a TreeMap to be deterministic
      Map<Integer, SimpleFeature> zonalShapes = new TreeMap<Integer, SimpleFeature>();
      for (SimpleFeature feature : ShapeFileReader.getAllFeatures(basePath + zonalSHPFile)) {
        zonalShapes.put((Integer) feature.getAttribute(3), feature);
      }
      log.info("done.\n");

      log.info("identify nodes outside the model area ...");
      Set<Id<Node>> externalNodes = getExternalNodes(scenario, zonalShapes);
      log.info("\tfound " + externalNodes.size() + " nodes outside the mapped area");
      log.info("done.\n");

      /*
       * We have to create tta activities BEFORE filtering the network. They might also start
       * and end at highways. We do not know their real start and end positions. The coordinate
       * we know might only be the place where the agents enter the modeled area, which will
       * probably be by using a highway.
       */
      log.info("creating external facilities for tta activities ...");
      createExternalFacilities(scenario, externalNodes);
      log.info("done.\n");

      /*
       * Before creating the internal facilities, we can perform the links filtering.
       */
      log.info("removing links from network where no facilities should be attached to ...");
      List<Id<Link>> linksToRemove = new ArrayList<Id<Link>>();
      for (Link link : scenario.getNetwork().getLinks().values()) {
        String type = ((LinkImpl) link).getType();
        if (!validLinkTypes.contains(type)) linksToRemove.add(link.getId());
      }
      log.info("\tfound " + linksToRemove.size() + " links which do not match the criteria");
      for (Id<Link> linkId : linksToRemove)
        ((NetworkImpl) scenario.getNetwork()).removeLink(linkId);
      log.info(
          "\tprocessed network contains "
              + scenario.getNetwork().getLinks().size()
              + " valid links");
      log.info("done.\n");

      log.info("creating internal facilities ...");
      createInternalFacilities(scenario, zonalAttributes, zonalShapes);
      log.info("done.\n");

      log.info("writing facilities to links mapping to a file ...");
      createAndWriteF2LMapping(scenario);
      log.info("done.\n");

      log.info(
          "writing "
              + scenario.getActivityFacilities().getFacilities().size()
              + " facilities to a file ...");
      FacilitiesWriter facilitiesWriter = new FacilitiesWriter(scenario.getActivityFacilities());
      facilitiesWriter.write(basePath + facilitiesFile);
      new ObjectAttributesXmlWriter(scenario.getActivityFacilities().getFacilityAttributes())
          .writeFile(basePath + facilitiesAttributesFile);
      log.info("done.\n");
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }