示例#1
0
  private void makeLinks() {

    PolylineFeatureFactory pl =
        new PolylineFeatureFactory.Builder()
            .setName("Link")
            .setCrs(MGC.getCRS("EPSG:32632"))
            .addAttribute("nr_veh", Integer.class)
            .addAttribute("flow", Double.class)
            .addAttribute("angle", Double.class)
            .create();
    Collection<SimpleFeature> features = new ArrayList<SimpleFeature>();
    for (LinkInfo li : this.lis) {
      Link l = li.getLink();
      Coordinate[] coords =
          new Coordinate[] {
            MGC.coord2Coordinate(l.getFromNode().getCoord()),
            MGC.coord2Coordinate(l.getToNode().getCoord())
          };
      SimpleFeature ft =
          pl.createPolyline(
              coords,
              new Object[] {li.getVeh().size(), li.getFlow(), li.getAngle()},
              li.getLink().getId().toString());
      features.add(ft);
    }
    ShapeFileWriter.writeGeometries(features, this.debugDir + "/links.shp");
  }
示例#2
0
 public SimpleFeature getFeature(final Link link) {
   return this.factory.createPolyline(
       new Coordinate[] {
         MGC.coord2Coordinate(link.getFromNode().getCoord()),
         MGC.coord2Coordinate(link.getToNode().getCoord())
       },
       new Object[] {link.getId().toString(), linkDeltas.get(link.getId()).delta},
       null);
 }
示例#3
0
  public void convertTransitSchedule(String file) {

    Config config = ConfigUtils.createConfig();
    config.scenario().setUseTransit(true);
    config.scenario().setUseVehicles(true);
    Scenario scenario = ScenarioUtils.createScenario(config);

    TransitScheduleReader ts = new TransitScheduleReader(scenario);
    ts.readFile(file);

    PointFeatureFactory.Builder builder = new PointFeatureFactory.Builder();
    builder.setName("nodes");
    builder.addAttribute("id", String.class);
    PointFeatureFactory factory = builder.create();

    List<SimpleFeature> features = new ArrayList<SimpleFeature>();

    for (TransitStopFacility stop : scenario.getTransitSchedule().getFacilities().values()) {
      features.add(factory.createPoint(MGC.coord2Coordinate(stop.getCoord())));
    }

    ShapeFileWriter.writeGeometries(
        features,
        "C:/Users/Daniel/Documents/work/shared-svn/studies/countries/cl/Kai_und_Daniel/Visualisierungen/stops.shp");
  }
示例#4
0
  public void convertNet2Shape(Network net, String crs, String outputFile) {

    SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
    typeBuilder.setCRS(MGC.getCRS(crs));
    typeBuilder.setName("link feature");
    typeBuilder.add("Line String", LineString.class);
    typeBuilder.add("id", String.class);
    typeBuilder.add("length", Double.class);
    typeBuilder.add("freespeed", Double.class);
    typeBuilder.add("capacity", Double.class);
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(typeBuilder.buildFeatureType());

    List<SimpleFeature> features = new ArrayList<SimpleFeature>();

    for (Link link : net.getLinks().values()) {

      Coord from = link.getFromNode().getCoord();
      Coord to = link.getToNode().getCoord();

      SimpleFeature feature =
          builder.buildFeature(
              link.getId().toString(),
              new Object[] {
                new GeometryFactory()
                    .createLineString(
                        new Coordinate[] {MGC.coord2Coordinate(from), MGC.coord2Coordinate(to)}),
                link.getId().toString(),
                link.getLength(),
                link.getFreespeed(),
                link.getCapacity()
              });
      features.add(feature);
    }

    ShapeFileWriter.writeGeometries(features, outputFile);
  }
  public GeoPosition getNetworkCenter() {
    if (this.networkCenter != null) {
      return this.networkCenter;
    }
    Envelope e = new Envelope();
    for (Node node : this.sc.getNetwork().getNodes().values()) {

      // ignore end nodes
      if (node.getId().toString().contains("en")) continue;

      e.expandToInclude(MGC.coord2Coordinate(node.getCoord()));
    }
    Coord centerC = new CoordImpl((e.getMaxX() + e.getMinX()) / 2, (e.getMaxY() + e.getMinY()) / 2);
    CoordinateTransformation ct2 =
        new GeotoolsTransformation(this.sc.getConfig().global().getCoordinateSystem(), "EPSG:4326");
    centerC = ct2.transform(centerC);
    this.networkCenter = new GeoPosition(centerC.getY(), centerC.getX());

    return this.networkCenter;
  }