Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix #947

save_the_island_found_by_prune_floating_islands_to_a_csv_file
  • Loading branch information...
commit 2dbc0a60a71209c4d620e6c6b1cb060d230fda4f 1 parent 162a60b
@benmoovit benmoovit authored
View
1  opentripplanner-graph-builder/samples/graph-config.xml
@@ -35,6 +35,7 @@
<bean id="floatingIslands" class="org.opentripplanner.graph_builder.impl.PruneFloatingIslands">
<property name="maxIslandSize" value="5"/>
+ <property name="islandLogFile" value="c:\isolatedTest"/>
</bean>
<bean id="transitStreetLink" class="org.opentripplanner.graph_builder.impl.TransitToStreetNetworkGraphBuilderImpl" />
View
26 ...tripplanner-graph-builder/src/main/java/org/opentripplanner/graph_builder/impl/PruneFloatingIslands.java
@@ -13,6 +13,7 @@
package org.opentripplanner.graph_builder.impl;
+import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -20,16 +21,25 @@
import lombok.Getter;
import lombok.Setter;
+import org.apache.log4j.*;
+import org.apache.log4j.Logger;
import org.opentripplanner.common.StreetUtils;
import org.opentripplanner.graph_builder.services.GraphBuilder;
import org.opentripplanner.routing.graph.Graph;
+import org.slf4j.*;
public class PruneFloatingIslands implements GraphBuilder {
+ private static org.slf4j.Logger _log = LoggerFactory.getLogger(PruneFloatingIslands.class);
+
@Getter
@Setter
private int maxIslandSize = 40;
+ @Getter
+ @Setter
+ private String islandLogFile = "";
+
public List<String> provides() {
return Collections.emptyList();
}
@@ -40,7 +50,7 @@
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
- StreetUtils.pruneFloatingIslands(graph, maxIslandSize);
+ StreetUtils.pruneFloatingIslands(graph, maxIslandSize, createLogger());
}
@Override
@@ -48,4 +58,18 @@ public void checkInputs() {
//no inputs
}
+ private String createLogger() {
+ if (islandLogFile.isEmpty()) return null;
+ try{
+ PatternLayout layout = new PatternLayout("%m\n");
+ FileAppender appender = new RollingFileAppender(layout, islandLogFile, false);
+ Logger.getLogger("islands").addAppender(appender);
+ }catch (IOException ioe){
+ _log.warn("could not create file appender for " + islandLogFile + " duo to: " + ioe.getMessage());
+ return null;
+ }
+ return "islands";
+
+ }
+
}
View
18 opentripplanner-graph-builder/src/main/resources/log4j.properties
@@ -13,16 +13,22 @@
# the License.
-log4j.rootLogger = INFO, stdout
+log4j.rootLogger=INFO, stdout
-log4j.appender.stdout = org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.Threshold = DEBUG
-log4j.appender.stdout.Target = System.out
-log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern = %d{ISO8601} %-5p [%F:%L] : %m%n
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Threshold=DEBUG
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p [%F:%L] : %m%n
log4j.category.org.opentripplanner.graph_builder=DEBUG
log4j.category.org.opentripplanner.routing=DEBUG
+#This category is use to save the island of the graph by using PruneFloatingIslands model
+log4j.category.islands=DEBUG
+log4j.additivity.islands=false
+
+log4j.category.pointsInIsland=DEBUG
+log4j.additivity.pointsInIsland=false
View
41 opentripplanner-routing/src/main/java/org/opentripplanner/common/StreetUtils.java
@@ -21,6 +21,10 @@
import java.util.Map;
import java.util.Queue;
+import com.vividsolutions.jts.algorithm.ConvexHull;
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
import org.opentripplanner.gbannotation.GraphConnectivity;
import org.opentripplanner.routing.core.RoutingRequest;
import org.opentripplanner.routing.core.State;
@@ -33,15 +37,24 @@
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.graph.Vertex;
import org.opentripplanner.routing.vertextype.StreetVertex;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StreetUtils {
private static Logger _log = LoggerFactory.getLogger(StreetUtils.class);
+ //private static Logger _islandLog = LoggerFactory.getLogger("islands");
+ private static int islandCounter = 0;
- public static void pruneFloatingIslands(Graph graph, int maxIslandSize) {
+ public static void pruneFloatingIslands(Graph graph, int maxIslandSize, String islandLogName) {
_log.debug("pruning");
+
+ Logger islandLog = null;
+ if(islandLogName != null){
+ islandLog = LoggerFactory.getLogger(islandLogName);
+ islandLog.info(String.format("%s\t%s\t%s","id","size","wkt"));
+ }
Map<Vertex, HashSet<Vertex>> subgraphs = new HashMap<Vertex, HashSet<Vertex>>();
Map<Vertex, ArrayList<Vertex>> neighborsForVertex = new HashMap<Vertex, ArrayList<Vertex>>();
@@ -98,9 +111,12 @@ public static void pruneFloatingIslands(Graph graph, int maxIslandSize) {
}
islands.add(subgraph);
}
- _log.debug(islands.size() + " sub graphs found");
+ _log.info(islands.size() + " sub graphs found");
/* remove all tiny subgraphs */
for (HashSet<Vertex> island : islands) {
+ if (islandLog != null) {
+ WriteNodesInSubGraph(island, islandLog);
+ }
if (island.size() < maxIslandSize) {
_log.warn(graph.addBuilderAnnotation(new GraphConnectivity(island.iterator().next(), island.size())));
depedestrianizeOrRemove(graph, island);
@@ -151,4 +167,25 @@ private static void depedestrianizeOrRemove(Graph graph, Collection<Vertex> vert
}
return subgraph;
}
+
+ private static void WriteNodesInSubGraph(HashSet<Vertex> subgraph, Logger islandLog){
+
+ Coordinate[] subGraphCoor = new Coordinate[subgraph.size()];
+ int i = 0;
+ for(Vertex v:subgraph){
+
+ subGraphCoor[i] = v.getCoordinate();
+ i++;
+ }
+ i++;
+ ConvexHull convexHull = new ConvexHull(subGraphCoor, new GeometryFactory());
+ Geometry convexHullGeom = convexHull.getConvexHull();
+ if(convexHullGeom.getGeometryType().equalsIgnoreCase("LINESTRING")){
+ convexHullGeom = convexHullGeom.buffer(0.0001,5);
+ }
+ islandLog.info(String.format("%d\t%d\t%s",
+ islandCounter,subgraph.size(),convexHullGeom));
+ islandCounter++;
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.