Пример #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;
  }