generated from matsim-scenarios/matsim-scenario-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf7467b
commit e26c8b1
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/org/matsim/run/prepare/PrepareTransitSchedule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.matsim.run.prepare; | ||
|
||
import org.geotools.api.feature.simple.SimpleFeature; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.matsim.api.core.v01.Scenario; | ||
import org.matsim.application.MATSimAppCommand; | ||
import org.matsim.application.options.ShpOptions; | ||
import org.matsim.core.config.Config; | ||
import org.matsim.core.config.ConfigUtils; | ||
import org.matsim.core.scenario.ProjectionUtils; | ||
import org.matsim.core.scenario.ScenarioUtils; | ||
import org.matsim.core.utils.geometry.geotools.MGC; | ||
import org.matsim.pt.transitSchedule.api.TransitSchedule; | ||
import org.matsim.pt.transitSchedule.api.TransitScheduleWriter; | ||
import org.matsim.pt.transitSchedule.api.TransitStopFacility; | ||
import picocli.CommandLine; | ||
|
||
import java.util.List; | ||
|
||
@CommandLine.Command( | ||
name = "prepare-transit-schedule", | ||
description = "Tag transit stops for Intermodal trips" | ||
) | ||
public class PrepareTransitSchedule implements MATSimAppCommand { | ||
@CommandLine.Mixin | ||
private ShpOptions shp = new ShpOptions(); | ||
|
||
@CommandLine.Option(names = "--input", description = "input transit schedule", required = true) | ||
private String input; | ||
|
||
@CommandLine.Option(names = "--output", description = "output path of the transit schedule", required = true) | ||
private String output; | ||
|
||
public static void main(String[] args) { | ||
new PrepareTransitSchedule().execute(args); | ||
} | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
Geometry intermodalArea = null; | ||
List<SimpleFeature> features = shp.readFeatures(); | ||
for (SimpleFeature feature : features) { | ||
if (intermodalArea == null) { | ||
intermodalArea = (Geometry) feature.getDefaultGeometry(); | ||
} else { | ||
intermodalArea = intermodalArea.union((Geometry) feature.getDefaultGeometry()); | ||
} | ||
} | ||
|
||
Config config = ConfigUtils.createConfig(); | ||
config.transit().setTransitScheduleFile(input); | ||
config.global().setCoordinateSystem("EPSG:25832"); | ||
Scenario scenario = ScenarioUtils.loadScenario(config); | ||
TransitSchedule transitSchedule = scenario.getTransitSchedule(); | ||
|
||
for (TransitStopFacility stop : transitSchedule.getFacilities().values()) { | ||
if (MGC.coord2Point(stop.getCoord()).within(intermodalArea)) { | ||
// TODO maybe add another filter (e.g. only train station, long distance bus stop...) | ||
stop.getAttributes().putAttribute("allowDrtAccessEgress", "true"); | ||
} | ||
} | ||
|
||
ProjectionUtils.putCRS(transitSchedule, "EPSG:25832"); | ||
|
||
TransitScheduleWriter writer = new TransitScheduleWriter(transitSchedule); | ||
writer.writeFile(output); | ||
|
||
return 0; | ||
} | ||
} |