예제 #1
0
  public Context() {
    graphService.putGraph(null, makeSimpleGraph()); // default graph is tiny test graph
    graphService.putGraph("portland", graph);
    ShapefileStreetGraphBuilderImpl builder = new ShapefileStreetGraphBuilderImpl();
    FeatureSourceFactory factory =
        new ShapefileFeatureSourceFactoryImpl(
            new File("src/test/resources/portland/Streets_pdx.shp"));
    builder.setFeatureSourceFactory(factory);
    ShapefileStreetSchema schema = new ShapefileStreetSchema();
    schema.setIdAttribute("LOCALID");
    schema.setNameAttribute("FULL_NAME");

    CaseBasedTraversalPermissionConverter perms =
        new CaseBasedTraversalPermissionConverter(
            "DIRECTION", StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);

    perms.addPermission("2", StreetTraversalPermission.ALL, StreetTraversalPermission.PEDESTRIAN);
    perms.addPermission("3", StreetTraversalPermission.PEDESTRIAN, StreetTraversalPermission.ALL);
    perms.addPermission("1", StreetTraversalPermission.ALL, StreetTraversalPermission.ALL);

    schema.setPermissionConverter(perms);

    // as a test, use prefixes ("NE", SE", etc) as an alert
    schema.setNoteConverter(new AttributeFeatureConverter<String>("PREFIX"));

    builder.setSchema(schema);
    builder.buildGraph(graph, new HashMap<Class<?>, Object>());
    initTransit();

    initBikeRental();
    graph.streetIndex = new StreetVertexIndexServiceImpl(graph);

    try {
      graph.save(File.createTempFile("graph", ".obj"));
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    pathService.sptService = new GenericAStar();
    pathService.graphService = graphService;
    planGenerator.pathService = pathService;
  }
  /**
   * The mapping from attribute values to permissions to use when determining a street's traversal
   * permission.
   */
  public void setPermissions(Map<String, String> permissions) {
    for (Map.Entry<String, String> entry : permissions.entrySet()) {
      String attributeValue = entry.getKey();
      String perms = entry.getValue();
      String[] tokens = perms.split(",");
      if (tokens.length != 2)
        throw new IllegalArgumentException("invalid street traversal permissions: " + perms);

      StreetTraversalPermission forward = StreetTraversalPermission.valueOf(tokens[0]);
      StreetTraversalPermission reverse = StreetTraversalPermission.valueOf(tokens[1]);
      addPermission(attributeValue, forward, reverse);
    }
  }