MATSIM
MatsimCountsReader.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * MatsimCountsReader.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.counts;
22 
23 import java.util.Stack;
24 
25 import org.apache.logging.log4j.LogManager;
26 import org.apache.logging.log4j.Logger;
27 import org.geotools.referencing.operation.transform.IdentityTransform;
34 import org.xml.sax.Attributes;
35 
42 public class MatsimCountsReader extends MatsimXmlParser {
43 
44  private final static Logger log = LogManager.getLogger(MatsimCountsReader.class);
45  private final static String COUNTS_V1 = "counts_v1.xsd";
46  private final static String COUNTS_V2 = "counts_v2.xsd";
47  private final Counts counts;
48  private final String inputCRS;
49  private final String targetCRS;
50  private MatsimXmlParser delegate = null;
51  private final Class<? extends Identifiable<?>> idClass;
52 
53 
59  public MatsimCountsReader(final Counts counts) {
60  this( null, null, counts, Link.class );
61  }
62 
71  String inputCRS, String targetCRS, final Counts counts ) {
72  this( inputCRS, targetCRS, counts, Link.class );
73  }
74 
84  String inputCRS, String targetCRS, final Counts counts,
85  Class<? extends Identifiable<?>> idClass) {
86  super(ValidationType.XSD_ONLY);
87  this.inputCRS = inputCRS;
88  this.targetCRS = targetCRS;
89  this.counts = counts;
90  this.idClass = idClass;
91  }
92 
93  @Override
94  public void startTag(final String name, final Attributes atts, final Stack<String> context) {
95  this.delegate.startTag(name, atts, context);
96  }
97 
98  @Override
99  public void endTag(final String name, final String content, final Stack<String> context) {
100  this.delegate.endTag(name, content, context);
101  }
102 
103  @Override
104  protected void setDoctype(final String doctype) {
105  super.setDoctype(doctype);
106  // Currently the only counts-type is v1
107  if (COUNTS_V1.equals(doctype)) {
108  CoordinateTransformation coordinateTransformation = new IdentityTransformation();
109  if (inputCRS != null && targetCRS != null) {
110  coordinateTransformation = TransformationFactory.getCoordinateTransformation(inputCRS, targetCRS );
111  }
112  this.delegate = new CountsReaderMatsimV1( coordinateTransformation, this.counts);
113  log.info("using counts_v1-reader.");
114  } else if (COUNTS_V2.equals(doctype)) {
115  this.delegate = new CountsReaderMatsimV2( inputCRS, targetCRS, this.counts, idClass);
116  log.info("using counts_v2-reader.");
117 
118  } else {
119  throw new IllegalArgumentException("Doctype \"" + doctype + "\" not known.");
120  }
121  }
122 
123 }
MatsimCountsReader(String inputCRS, String targetCRS, final Counts counts)
final Class<? extends Identifiable<?> > idClass
void endTag(final String name, final String content, final Stack< String > context)
void startTag(final String name, final Attributes atts, final Stack< String > context)
abstract void startTag(String name, Attributes atts, Stack< String > context)
static CoordinateTransformation getCoordinateTransformation(final String fromSystem, final String toSystem)
MatsimCountsReader(String inputCRS, String targetCRS, final Counts counts, Class<? extends Identifiable<?>> idClass)
abstract void endTag(String name, String content, Stack< String > context)