MATSIM
Links2ESRIShape.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * Links2ESRIShape.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.utils.gis.matsim2esri.network;
22 
23 import java.util.ArrayList;
24 import java.util.Collection;
25 
26 import org.apache.logging.log4j.LogManager;
27 import org.apache.logging.log4j.Logger;
28 import org.geotools.api.feature.simple.SimpleFeature;
29 import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
30 import org.matsim.api.core.v01.Scenario;
39 
50 public class Links2ESRIShape {
51 
52  private static final Logger log = LogManager.getLogger(Links2ESRIShape.class);
53 
55  private final Network network;
56  private final String filename;
57 
58 
59  public Links2ESRIShape(final Network network, final String filename, final String coordinateSystem) {
60  this(network, filename, new FeatureGeneratorBuilderImpl(network, coordinateSystem));
61  }
62 
63  public Links2ESRIShape(final Network network, final String filename, final FeatureGeneratorBuilder builder) {
64  this.network = network;
65  this.filename = filename;
66  this.featureGenerator = builder.createFeatureGenerator();
67 
68  }
69 
70  public void write() {
71  log.info("creating features...");
72  Collection<SimpleFeature> features = new ArrayList<SimpleFeature>();
73  for (Link link : NetworkUtils.getSortedLinks(this.network)) {
74  features.add(this.featureGenerator.getFeature(link));
75  }
76  log.info("writing features to shape file... " + this.filename);
77  GeoFileWriter.writeGeometries(features, this.filename);
78  log.info("done writing shape file.");
79  }
80 
81  public static void main(final String [] args) {
82  String netfile = null ;
83  String outputFileLs = null ;
84  String outputFileP = null ;
85  String defaultCRS = "DHDN_GK4";
86  boolean commonWealth = false; //to render Commonwealth networks correctly (e.g. drive on left-hand side of the road)
87  if ( args.length == 0 ) {
88  netfile = "./examples/equil/network.xml";
89 // String netfile = "./test/scenarios/berlin/network.xml.gz";
90 
91  outputFileLs = "./plans/networkLs.shp";
92  outputFileP = "./plans/networkP.shp";
93  } else if ( args.length == 3 ) {
94  netfile = args[0] ;
95  outputFileLs = args[1] ;
96  outputFileP = args[2] ;
97  } else if ( args.length == 4 ) {
98  netfile = args[0] ;
99  outputFileLs = args[1] ;
100  outputFileP = args[2] ;
101  defaultCRS = args[3] ;
102  } else if ( args.length == 5 ) {
103  netfile = args[0] ;
104  outputFileLs = args[1] ;
105  outputFileP = args[2] ;
106  defaultCRS = args[3] ;
107  commonWealth = Boolean.parseBoolean(args[4]) ;
108  } else {
109  log.error("Arguments cannot be interpreted. Aborting ...") ;
110  System.exit(-1) ;
111  }
112 
114  scenario.getConfig().global().setCoordinateSystem(defaultCRS);
115 
116  log.info("loading network from " + netfile);
117  final Network network = scenario.getNetwork();
118  new MatsimNetworkReader(scenario.getNetwork()).readFile(netfile);
119  log.info("done.");
120 
121  FeatureGeneratorBuilderImpl builder = new FeatureGeneratorBuilderImpl(network, defaultCRS);
123  builder.setWidthCoefficient(0.5);
125  new Links2ESRIShape(network,outputFileLs, builder).write();
126 
127  CoordinateReferenceSystem crs = MGC.getCRS(defaultCRS);
128  builder.setWidthCoefficient((commonWealth ? -1 : 1) * 0.003);
131  builder.setCoordinateReferenceSystem(crs);
132  new Links2ESRIShape(network,outputFileP, builder).write();
133 
134  }
135 
136 }
void setFeatureGeneratorPrototype(final Class<? extends FeatureGenerator > prototype)
Links2ESRIShape(final Network network, final String filename, final String coordinateSystem)
static void writeGeometries(final Collection< SimpleFeature > features, final String filename)
static Link [] getSortedLinks(final Network network)
void setCoordinateSystem(final String coordinateSystem)
Links2ESRIShape(final Network network, final String filename, final FeatureGeneratorBuilder builder)
void setWidthCalculatorPrototype(final Class<? extends WidthCalculator > prototype)
final GlobalConfigGroup global()
Definition: Config.java:395
static Scenario createScenario(final Config config)
static Config createConfig(final String context)
static CoordinateReferenceSystem getCRS(final String wktOrAuthorityCodeOrShorthandName)
Definition: MGC.java:169