MATSIM
KmlNetworkWriter.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * KmlNetworkWriter.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.core.network.io;
22 
23 import java.io.IOException;
24 
25 import org.apache.log4j.Logger;
31 import org.matsim.vis.kml.KMZWriter;
35 
36 import net.opengis.kml.v_2_2_0.AbstractFeatureType;
37 import net.opengis.kml.v_2_2_0.DocumentType;
38 import net.opengis.kml.v_2_2_0.FolderType;
39 import net.opengis.kml.v_2_2_0.ObjectFactory;
40 import net.opengis.kml.v_2_2_0.PlacemarkType;
41 import net.opengis.kml.v_2_2_0.StyleType;
42 
46 public final class KmlNetworkWriter implements MatsimSomeWriter {
47  // yyyyyy move network io into separate package
48 
49  private static final Logger log = Logger.getLogger(KmlNetworkWriter.class);
50 
51  private final Network network;
52 
54 
55  private final ObjectFactory kmlObjectFactory = new ObjectFactory();
56 
58 
59  public KmlNetworkWriter(final Network network, final CoordinateTransformation coordTransform, KMZWriter writer, DocumentType doc) {
60  this.network = network;
61  this.styleFactory = new MatsimKmlStyleFactory(writer, doc);
62  this.networkFeatureFactory = new NetworkFeatureFactory(coordTransform, network);
63  }
64 
66  this.styleFactory = styleFac;
67  }
68 
69  public FolderType getNetworkFolder() throws IOException {
70 
71  FolderType folder = this.kmlObjectFactory.createFolderType();
72 
73  folder.setName("MATSIM Network");
74  StyleType networkLinkStyle = this.styleFactory.createDefaultNetworkLinkStyle();
75  StyleType networkNodeStyle = this.styleFactory.createDefaultNetworkNodeStyle();
76 
77  FolderType nodeFolder = kmlObjectFactory.createFolderType();
78  nodeFolder.setName("Nodes");
79 // linkFolder.addStyle(this.networkNodeStyle);
80  for (Node n : this.network.getNodes().values()) {
81 
82  AbstractFeatureType abstractFeature = this.networkFeatureFactory.createNodeFeature(n, networkNodeStyle);
83  if (abstractFeature.getClass().equals(PlacemarkType.class)) {
84  nodeFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark((PlacemarkType) abstractFeature));
85  } else if (abstractFeature.getClass().equals(FolderType.class)) {
86  nodeFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder((FolderType) abstractFeature));
87  } else {
88  log.warn("Not yet implemented: Adding node KML features of type " + abstractFeature.getClass());
89  }
90 
91  }
92  folder.getAbstractFeatureGroup().add(kmlObjectFactory.createFolder(nodeFolder));
93 
94  FolderType linkFolder = kmlObjectFactory.createFolderType();
95  linkFolder.setName("Links");
96 // linkFolder.addStyle(this.networkLinkStyle);
97  for (Link l : this.network.getLinks().values()) {
98  AbstractFeatureType abstractFeature = this.networkFeatureFactory.createLinkFeature(l, networkLinkStyle);
99  if (abstractFeature.getClass().equals(PlacemarkType.class)) {
100  linkFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark((PlacemarkType) abstractFeature));
101  } else if (abstractFeature.getClass().equals(FolderType.class)) {
102  linkFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder((FolderType) abstractFeature));
103  } else {
104  log.warn("Not yet implemented: Adding node KML features of type " + abstractFeature.getClass());
105  }
106  }
107  folder.getAbstractFeatureGroup().add(kmlObjectFactory.createFolder(linkFolder));
108 
109  return folder;
110 
111  }
112 
113 }
final NetworkFeatureFactory networkFeatureFactory
Map< Id< Node >, ? extends Node > getNodes()
AbstractFeatureType createLinkFeature(final Link l, StyleType networkStyle)
void setNetworkKmlStyleFactory(NetworkKmlStyleFactory styleFac)
abstract StyleType createDefaultNetworkNodeStyle()
Map< Id< Link >, ? extends Link > getLinks()
AbstractFeatureType createNodeFeature(final Node n, StyleType networkStyle)
KmlNetworkWriter(final Network network, final CoordinateTransformation coordTransform, KMZWriter writer, DocumentType doc)
abstract StyleType createDefaultNetworkLinkStyle()