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."); }
public void writeFile() { String outputFile = this.outputDirectory + "/" + this.kmzFileName; ObjectFactory LocalkmlObjectFactory = new ObjectFactory(); // create main file and document DocumentType mainDoc = LocalkmlObjectFactory.createDocumentType(); mainDoc.setId("mainDoc"); mainDoc.setOpen(Boolean.TRUE); KmlType mainKml = LocalkmlObjectFactory.createKmlType(); mainKml.setAbstractFeatureGroup(LocalkmlObjectFactory.createDocument(mainDoc)); // create a folder FolderType mainFolder = LocalkmlObjectFactory.createFolderType(); mainFolder.setId("actsFolder"); mainFolder.setName("Matsim Data"); mainFolder.setOpen(Boolean.TRUE); mainDoc.getAbstractFeatureGroup().add(LocalkmlObjectFactory.createFolder(mainFolder)); // create the writer KMZWriter writer = new KMZWriter(outputFile); this.styleFactory = new MyKmlStyleFactory(writer, mainDoc); this.networkFeatureFactory = new MyFeatureFactory(this.coordinateTransform); try { // add the MATSim logo to the kml ScreenOverlayType logo = MatsimKMLLogo.writeMatsimKMLLogo(writer); mainFolder.getAbstractFeatureGroup().add(LocalkmlObjectFactory.createScreenOverlay(logo)); // add the person's activity links to the kml if (this.writeActivities) { createActivityLinks(); Collection<FolderType> activityFolderCollection = getActivities(); for (FolderType activityFolder : activityFolderCollection) { if (activityFolder != null) { activityFolder.setVisibility(Boolean.FALSE); mainFolder .getAbstractFeatureGroup() .add(LocalkmlObjectFactory.createFolder(activityFolder)); } } } // add the person's activity links to the kml if (this.writeActivityLinks) { createActivityLinks(); FolderType activityLinksFolder = getActivityLinksFolder(this.createActivityLinks(), "Activity Links of Person "); if (activityLinksFolder != null) { activityLinksFolder.setVisibility(Boolean.FALSE); mainFolder .getAbstractFeatureGroup() .add(LocalkmlObjectFactory.createFolder(activityLinksFolder)); } } } catch (IOException e) { log.error("Cannot create kmz or logo.", e); } writer.writeMainKml(mainKml); writer.close(); log.info("... finished"); }