MATSIM
LineStringBasedFeatureGenerator.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * LineStringBasedFeatureGenerator.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 org.geotools.api.feature.simple.SimpleFeature;
24 import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
25 import org.geotools.feature.simple.SimpleFeatureBuilder;
26 import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
27 import org.locationtech.jts.geom.Coordinate;
28 import org.locationtech.jts.geom.GeometryFactory;
29 import org.locationtech.jts.geom.LineString;
33 
35 
37  private SimpleFeatureBuilder builder;
38  private final CoordinateReferenceSystem crs;
39  private final GeometryFactory geofac;
40 
41 
42  public LineStringBasedFeatureGenerator(final WidthCalculator widthCalculator, final CoordinateReferenceSystem crs) {
43  this.widthCalculator = widthCalculator;
44  this.crs = crs;
45  this.geofac = new GeometryFactory();
47  }
48 
49 
50  private void initFeatureType() {
51  SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
52  typeBuilder.setName("link");
53  typeBuilder.setCRS(this.crs);
54  typeBuilder.add("the_geom", LineString.class);
55  typeBuilder.add("ID", String.class);
56  typeBuilder.add("fromID", String.class);
57  typeBuilder.add("toID", String.class);
58  typeBuilder.add("length", Double.class);
59  typeBuilder.add("freespeed", Double.class);
60  typeBuilder.add("capacity", Double.class);
61  typeBuilder.add("lanes", Double.class);
62  typeBuilder.add("visWidth", Double.class);
63  typeBuilder.add("type", String.class);
64 
65  this.builder = new SimpleFeatureBuilder(typeBuilder.buildFeatureType());
66  }
67 
68 
69  @Override
70  public SimpleFeature getFeature(final Link link) {
71  double width = this.widthCalculator.getWidth(link);
72  LineString ls = this.geofac.createLineString(new Coordinate[] {MGC.coord2Coordinate(link.getFromNode().getCoord()),
74 
75  Object [] attribs = new Object[10];
76  attribs[0] = ls;
77  attribs[1] = link.getId().toString();
78  attribs[2] = link.getFromNode().getId().toString();
79  attribs[3] = link.getToNode().getId().toString();
80  attribs[4] = link.getLength();
81  attribs[5] = link.getFreespeed();
82  attribs[6] = link.getCapacity();
83  attribs[7] = link.getNumberOfLanes();
84  attribs[8] = width;
85  attribs[9] = NetworkUtils.getType(link);
86 
87  try {
88  return this.builder.buildFeature(null, attribs);
89  } catch (IllegalArgumentException e) {
90  throw new RuntimeException(e);
91  }
92 
93  }
94 
95 }
static String getType(Node node)
LineStringBasedFeatureGenerator(final WidthCalculator widthCalculator, final CoordinateReferenceSystem crs)
static Coordinate coord2Coordinate(final Coord coord)
Definition: MGC.java:113