Exemplo n.º 1
0
  public static void convertMATSimNetworkToKmz(
      String matsimNetworkFileName, String outputKmzFileName) throws IOException {
    Network network = readNetwork(matsimNetworkFileName);

    ObjectFactory kmlObjectFactory = new ObjectFactory();
    KMZWriter kmzWriter = new KMZWriter(outputKmzFileName);

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

    // KmlNetworkWriter kmlNetworkWriter = new KmlNetworkWriter(network, new
    // AtlantisToWGS84(), kmzWriter, mainDoc);
    KmlNetworkWriter kmlNetworkWriter =
        new KmlNetworkWriter(network, new CH1903LV03toWGS84(), kmzWriter, mainDoc);
    // KmlNetworkWriter kmlNetworkWriter = new
    // KmlNetworkWriter(network,TransformationFactory.getCoordinateTransformation(TransformationFactory.WGS84_UTM35S,
    // TransformationFactory.WGS84), kmzWriter, mainDoc);

    mainDoc
        .getAbstractFeatureGroup()
        .add(kmlObjectFactory.createFolder(kmlNetworkWriter.getNetworkFolder()));

    kmzWriter.writeMainKml(mainKml);
    kmzWriter.close();
  }
  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.");
  }