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
Showing
7 changed files
with
168 additions
and
1 deletion.
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
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
58 changes: 58 additions & 0 deletions
58
src/main/java/org/opentripplanner/graph_builder/module/OutOfAreaModule.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,58 @@ | ||
/* This program is free software: you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public License | ||
as published by the Free Software Foundation, either version 3 of | ||
the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
package org.opentripplanner.graph_builder.module; | ||
|
||
import com.conveyal.geojson.GeoJsonModule; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.vividsolutions.jts.geom.Geometry; | ||
import org.opentripplanner.graph_builder.services.GraphBuilderModule; | ||
import org.opentripplanner.routing.graph.Graph; | ||
import org.opentripplanner.routing.services.notes.OutOfAreaNotesService; | ||
|
||
import java.io.File;; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
public class OutOfAreaModule implements GraphBuilderModule { | ||
|
||
private File geojsonFile; | ||
|
||
private String startMessage, endMessage; | ||
|
||
public OutOfAreaModule(File geojsonFile, String startMessage, String endMessage) { | ||
this.geojsonFile = geojsonFile; | ||
this.startMessage = startMessage; | ||
this.endMessage = endMessage; | ||
} | ||
|
||
@Override | ||
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) { | ||
Geometry area; | ||
try { | ||
area = new ObjectMapper().registerModule(new GeoJsonModule()) | ||
.readValue(geojsonFile, Geometry.class); | ||
} catch(IOException e) { | ||
e.printStackTrace(); | ||
return; | ||
} | ||
OutOfAreaNotesService svc = new OutOfAreaNotesService(); | ||
svc.setArea(area); | ||
svc.setStartLocationMessage(startMessage); | ||
svc.setEndLocationMessage(endMessage); | ||
graph.outOfAreaNotesService = svc; | ||
} | ||
|
||
@Override | ||
public void checkInputs() { | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
src/main/java/org/opentripplanner/routing/services/notes/OutOfAreaNotesService.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,59 @@ | ||
/* This program is free software: you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public License | ||
as published by the Free Software Foundation, either version 3 of | ||
the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
package org.opentripplanner.routing.services.notes; | ||
|
||
import com.vividsolutions.jts.geom.Geometry; | ||
import com.vividsolutions.jts.geom.Point; | ||
import org.opentripplanner.common.geometry.GeometryUtils; | ||
import org.opentripplanner.routing.alertpatch.Alert; | ||
import org.opentripplanner.routing.core.RoutingRequest; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
public class OutOfAreaNotesService implements Serializable { | ||
|
||
private static final long serialVersionUID = 1; | ||
|
||
private Geometry area; | ||
|
||
private String startLocationMessage; | ||
|
||
private String endLocationMessage; | ||
|
||
public void setArea(Geometry area) { | ||
this.area = area; | ||
} | ||
|
||
public void setStartLocationMessage(String startLocationMessage) { | ||
this.startLocationMessage = startLocationMessage; | ||
} | ||
|
||
public void setEndLocationMessage(String endLocationMessage) { | ||
this.endLocationMessage = endLocationMessage; | ||
} | ||
|
||
public Collection<Alert> getAlerts(RoutingRequest request) { | ||
Point fromPoint = GeometryUtils.getGeometryFactory().createPoint(request.rctx.fromVertex.getCoordinate()); | ||
Point toPoint = GeometryUtils.getGeometryFactory().createPoint(request.rctx.toVertex.getCoordinate()); | ||
Collection<Alert> alerts = new ArrayList<>(); | ||
if (!area.contains(fromPoint)) { | ||
alerts.add(Alert.createSimpleAlerts(startLocationMessage)); | ||
} | ||
if (!area.contains(toPoint)) { | ||
alerts.add(Alert.createSimpleAlerts(endLocationMessage)); | ||
} | ||
return alerts; | ||
} | ||
} |
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