21 package org.matsim.utils.gis.matsim2esri.plans;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.List;
28 import org.geotools.api.feature.simple.SimpleFeature;
29 import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
30 import org.geotools.feature.simple.SimpleFeatureBuilder;
31 import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
32 import org.locationtech.jts.geom.Coordinate;
33 import org.locationtech.jts.geom.GeometryFactory;
34 import org.locationtech.jts.geom.LineString;
35 import org.locationtech.jts.geom.Point;
67 private final CoordinateReferenceSystem
crs;
78 private final GeometryFactory
geofac;
86 this.geofac =
new GeometryFactory();
91 this.outputSample = sample;
113 if (this.writeActs) {
116 if (this.writeLegs) {
119 }
catch (IOException e) {
125 this.outputSamplePlans =
new ArrayList<Plan>();
128 this.outputSamplePlans.add(pers.getSelectedPlan());
134 String outputFile = this.outputDir +
"/acts.shp";
135 ArrayList<SimpleFeature> fts =
new ArrayList<SimpleFeature>();
136 for (
Plan plan : this.outputSamplePlans) {
137 String
id = plan.getPerson().getId().toString();
140 Activity act = (Activity) pe;
150 String outputFile = this.outputDir +
"/legs.shp";
151 ArrayList<SimpleFeature> fts =
new ArrayList<SimpleFeature>();
152 for (
Plan plan : this.outputSamplePlans) {
153 String
id = plan.getPerson().getId().toString();
155 if (pe instanceof
Leg) {
172 String linkId = act.
getLinkId().toString();
181 return this.actBuilder.buildFeature(null,
new Object [] {
MGC.
coord2Point(c), id, type, linkId, startTime, endTime});
182 }
catch (IllegalArgumentException e) {
199 Coordinate [] coords =
new Coordinate[linkIds.size() + 1];
200 for (
int i = 0; i < linkIds.size(); i++) {
201 Link link = this.network.
getLinks().get(linkIds.get(i));
205 Coordinate cc =
new Coordinate(c.
getX()+rx,c.
getY()+ry);
209 Link link = this.network.
getLinks().get(linkIds.get(linkIds.size() - 1));
213 Coordinate cc =
new Coordinate(c.
getX()+rx,c.
getY()+ry);
214 coords[linkIds.size()] = cc;
216 LineString ls = this.geofac.createLineString(coords);
219 return this.legBuilder.buildFeature(null,
new Object [] {ls,id,mode,depTime,travTime,dist});
220 }
catch (IllegalArgumentException e) {
229 SimpleFeatureTypeBuilder actBuilder =
new SimpleFeatureTypeBuilder();
230 actBuilder.setName(
"activity");
231 actBuilder.setCRS(this.crs);
232 actBuilder.add(
"the_geom", Point.class);
233 actBuilder.add(
"PERS_ID", String.class);
234 actBuilder.add(
"TYPE", String.class);
235 actBuilder.add(
"LINK_ID", String.class);
236 actBuilder.add(
"START_TIME", Double.class);
237 actBuilder.add(
"END_TIME", Double.class);
239 SimpleFeatureTypeBuilder legBuilder =
new SimpleFeatureTypeBuilder();
240 legBuilder.setName(
"leg");
241 legBuilder.setCRS(this.crs);
242 legBuilder.add(
"the_geom", LineString.class);
243 legBuilder.add(
"PERS_ID", String.class);
244 legBuilder.add(
"MODE", String.class);
245 legBuilder.add(
"DEP_TIME", Double.class);
246 legBuilder.add(
"TRAV_TIME", Double.class);
247 legBuilder.add(
"DIST", Double.class);
249 this.actBuilder =
new SimpleFeatureBuilder(actBuilder.buildFeatureType());
250 this.legBuilder =
new SimpleFeatureBuilder(legBuilder.buildFeatureType());
253 public static void main(
final String [] args) {
255 final String populationFilename =
"./examples/equil/plans100.xml";
256 final String networkFilename =
"./examples/equil/network.xml";
260 final String outputDir =
"./plans/";
261 new File(outputDir).mkdir();
267 CoordinateReferenceSystem crs =
MGC.
getCRS(
"DHDN_GK4");
OptionalTime getEndTime()
static Random getRandom()
ArrayList< Plan > outputSamplePlans
final Population getPopulation()
OptionalTime getStartTime()
SimpleFeature getLegFeature(final Leg leg, final String id)
static void main(final String [] args)
OptionalTime getDepartureTime()
SelectedPlans2ESRIShape(final Population population, final Network network, final CoordinateReferenceSystem crs, final String outputDir)
void setLegBlurFactor(final double legBlurFactor)
final GeometryFactory geofac
static void writeGeometries(final Collection< SimpleFeature > features, final String filename)
void setWriteActs(final boolean writeActs)
SimpleFeature getActFeature(final String id, final Activity act)
final CoordinateReferenceSystem crs
static SortedMap< Id< Person >, Person > getSortedPersons(final Population population)
void setOutputSample(final double sample)
Map< Id< Link >, ? extends Link > getLinks()
OptionalTime getTravelTime()
final Network getNetwork()
static double calcDistanceExcludingStartEndLink(final NetworkRoute route, final Network network)
SimpleFeatureBuilder actBuilder
final void readFile(final String filename)
void setActBlurFactor(final double actBlurFactor)
static Scenario createScenario(final Config config)
SimpleFeatureBuilder legBuilder
void setWriteLegs(final boolean writeLegs)
static Config createConfig(final String context)
final Population population