21 package org.matsim.utils.gis.matsim2esri.network;
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.Polygon;
35 private static final double PI_HALF = Math.PI / 2.0;
36 private static final double TWO_PI = 2.0 * Math.PI;
39 private final CoordinateReferenceSystem
crs;
40 private final GeometryFactory
geofac;
47 this.geofac =
new GeometryFactory();
52 SimpleFeatureTypeBuilder typeBuilder =
new SimpleFeatureTypeBuilder();
53 typeBuilder.setName(
"link");
54 typeBuilder.setCRS(this.crs);
55 typeBuilder.add(
"the_geom", Polygon.class);
56 typeBuilder.add(
"ID", String.class);
57 typeBuilder.add(
"fromID", String.class);
58 typeBuilder.add(
"toID", String.class);
59 typeBuilder.add(
"length", Double.class);
60 typeBuilder.add(
"freespeed", Double.class);
61 typeBuilder.add(
"capacity", Double.class);
62 typeBuilder.add(
"lanes", Double.class);
63 typeBuilder.add(
"visWidth", Double.class);
65 this.builder =
new SimpleFeatureBuilder(typeBuilder.buildFeatureType());
70 double width = this.widthCalculator.
getWidth(link);
73 Polygon p = this.geofac.createPolygon(this.geofac.createLinearRing(coords), null);
74 Object [] attribs =
new Object[9];
76 attribs[1] = link.
getId().toString();
86 return this.builder.buildFeature(null, attribs);
87 }
catch (IllegalArgumentException e) {
95 double length = from.distance(to);
97 final double dx = -from.x + to.x;
98 final double dy = -from.y + to.y;
102 theta = Math.atan(dy/dx);
104 theta = Math.PI + Math.atan(dy/dx);
112 if (theta < 0.0) theta +=
TWO_PI;
113 double sinTheta = Math.sin(theta);
114 double cosTheta = Math.cos(theta);
115 double xfrom2 = from.x + sinTheta * width;
116 double yfrom2 = from.y - cosTheta * width;
117 double xto2 = from.x + cosTheta * length + sinTheta * width;
118 double yto2 = from.y + sinTheta * length - cosTheta * width;
119 Coordinate from2 =
new Coordinate(xfrom2,yfrom2);
120 Coordinate to2 =
new Coordinate(xto2,yto2);
122 return new Coordinate[] {from, to, to2, from2, from};
SimpleFeature getFeature(final Link link)
final WidthCalculator widthCalculator
SimpleFeatureBuilder builder
PolygonFeatureGenerator(final WidthCalculator widthCalculator, final CoordinateReferenceSystem crs)
static Coordinate [] createPolygonCoordsForLink(final Link link, double width)
static final double PI_HALF
final CoordinateReferenceSystem crs
double getNumberOfLanes()
double getWidth(Link link)
static final double TWO_PI
final GeometryFactory geofac