Exemplo n.º 1
0
  public void addBuildings(final String buildingShapeFileName) {

    final GeometryFactory geometryFactory = new GeometryFactory();
    final WKTReader wktReader = new WKTReader(geometryFactory);

    final ShapeFileReader shapeFileReader = new ShapeFileReader();
    shapeFileReader.readFileAndInitialize(buildingShapeFileName);
    final Collection<SimpleFeature> features = shapeFileReader.getFeatureSet();

    for (SimpleFeature ft : features) {

      try {
        final Geometry geometry = wktReader.read((ft.getAttribute("the_geom")).toString());
        final String buildingType = ft.getAttribute("ANDAMAL_1T").toString();
        final int buildingSize = Integer.valueOf(ft.getAttribute("AREA").toString());
        final Building building = new Building(geometry, buildingSize);
        building.setBuildingType(buildingType);

        for (Zone zone : this.id2zone.values()) {
          if (zone.getGeometry() != null && zone.getGeometry().intersects(geometry)) {
            zone.addBuilding(building);
            break;
          }
        }

      } catch (ParseException e) {
        throw new RuntimeException(e);
      }
    }
  }
  /** @param args */
  public static void main(String[] args) {
    // TODO Auto-generated method stub

    String networkPath = args[0];
    String newNetworkPath = args[1];
    String shapeFilePath = args[2];

    // String shapeFile = "C:/Work/Roadpricing Scenarios/SiouxFalls/Network/SiouxFalls_nodes.shp";

    Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());

    new NetworkReaderMatsimV1(scenario).parse(networkPath);
    Network network = scenario.getNetwork();
    Map<Id<Node>, ? extends Node> nodes = network.getNodes();

    Double x = 0.0;
    Double y = 0.0;

    System.out.println(shapeFilePath);
    ShapeFileReader shapeFileReader = new ShapeFileReader();
    Collection<SimpleFeature> fts = shapeFileReader.readFileAndInitialize(shapeFilePath);
    log.info("Shape file contains " + fts.size() + " features!");

    for (SimpleFeature ft : fts) {
      Geometry geo = (Geometry) ft.getDefaultGeometry();
      Coordinate[] coordinates = geo.getCoordinates();
      Collection<Property> properties = ft.getProperties("Id");

      System.out.println(
          "Feature: "
              + ft.getID()
              + ","
              + ft.getIdentifier().toString()
              + ","
              + ft.getName().toString());

      for (int i = 0; i < coordinates.length; i++) {
        System.out.print(coordinates[i].x + "," + coordinates[i].y + "   ");
        x = coordinates[i].x;
        y = coordinates[i].y;
      }

      for (Property p : properties) {
        System.out.println("Value: " + p.getValue().toString());
        Node node = nodes.get(Id.create(p.getValue().toString(), Node.class));
        node.getCoord().setXY(x, y);
        System.out.println("Name: " + p.getName().toString());
        System.out.println("Descriptor: " + p.getDescriptor().toString());
      }
      System.out.println();
      System.out.println();

      NetworkWriter writer = new NetworkWriter(network);
      writer.write(newNetworkPath);
    }
  }
  public void readShapeFile(String shapeFileString) {
    ShapeFileReader shapeFileReader = new ShapeFileReader();
    shapeFileReader.readFileAndInitialize(shapeFileString);

    ArrayList<Geometry> geometries = new ArrayList<Geometry>();
    for (SimpleFeature ft : shapeFileReader.getFeatureSet()) {
      Geometry geo = (Geometry) ft.getDefaultGeometry();
      // System.out.println(ft.getFeatureType());
      geometries.add(geo);
    }

    Coordinate[] coords = geometries.get(0).getCoordinates();
    coords[coords.length - 1] = coords[0];

    GeometryFactory geofac = new GeometryFactory();

    LinearRing shell = geofac.createLinearRing(coords);
    areaPolygon = geofac.createPolygon(shell, null);
  }
Exemplo n.º 4
0
 // Main
 public static void main(String[] args)
     throws SQLException, NoConnectionException, IOException, InstantiationException,
         IllegalAccessException, ClassNotFoundException {
   Map<Id<ActivityFacility>, Double> maximums = new HashMap<Id<ActivityFacility>, Double>();
   Map<Id<ActivityFacility>, Polygon> masterAreas = new HashMap<Id<ActivityFacility>, Polygon>();
   ShapeFileReader shapeFileReader = new ShapeFileReader();
   Collection<SimpleFeature> features = shapeFileReader.readFileAndInitialize(POLYGONS_FILE);
   for (SimpleFeature feature : features)
     masterAreas.put(
         Id.create((Integer) feature.getAttribute(1), ActivityFacility.class),
         (Polygon) ((MultiPolygon) feature.getDefaultGeometry()).getGeometryN(0));
   DataBaseAdmin dataBaseRealState =
       new DataBaseAdmin(new File("./data/facilities/DataBaseRealState.properties"));
   ResultSet buildingsR =
       dataBaseRealState.executeQuery("SELECT type, longitude, latitude FROM building_directory");
   CoordinateTransformation coordinateTransformation =
       TransformationFactory.getCoordinateTransformation(
           TransformationFactory.WGS84, TransformationFactory.WGS84_TM);
   GeometryFactory factory = new GeometryFactory();
   while (buildingsR.next()) {
     Coord buildingCoord =
         coordinateTransformation.transform(
             new Coord(buildingsR.getDouble(2), buildingsR.getDouble(3)));
     Point p = factory.createPoint(new Coordinate(buildingCoord.getX(), buildingCoord.getY()));
     for (Entry<Id<ActivityFacility>, Polygon> polygon : masterAreas.entrySet())
       if (p.within(polygon.getValue())) {
         Double maximum = maximums.get(polygon.getKey());
         if (maximum == null) maximum = 0.0;
         maximum += getMaximum(buildingsR.getString(1), null);
         maximums.put(polygon.getKey(), maximum);
       }
   }
   dataBaseRealState.close();
   DataBaseAdmin dataBaseAux =
       new DataBaseAdmin(new File("./data/facilities/DataBaseAuxiliar.properties"));
   for (Entry<Id<ActivityFacility>, Double> maximum : maximums.entrySet())
     dataBaseAux.executeUpdate("INSERT INTO buildings VALUES");
   dataBaseAux.close();
 }
Exemplo n.º 5
0
  public static void main(String[] args) throws Exception {

    String baseDir = "../../../shared-svn/projects/cottbus/data/scenarios/cottbus_scenario/";
    String networkFile = baseDir + "network_wgs84_utm33n.xml.gz";
    boolean useLanduse = true;
    String populationOutputDirectory = baseDir + "cb_spn_gemeinde_nachfrage_landuse_ohneTagebau/";

    //		String shapesOutputDirectory = populationOutputDirectory + "shapes_all_modes/";
    String shapesOutputDirectory = populationOutputDirectory + "shapes/";

    //		String populationOutputFile = populationOutputDirectory +
    // "commuter_population_wgs84_utm33n.xml.gz";
    String populationOutputFile =
        populationOutputDirectory + "commuter_population_wgs84_utm33n_car_only.xml.gz";
    OutputDirectoryLogging.initLoggingWithOutputDirectory(populationOutputDirectory);

    File shapes = new File(shapesOutputDirectory);
    if (!shapes.exists()) {
      shapes.mkdir();
    }

    Config config1 = ConfigUtils.createConfig();
    config1.network().setInputFile(networkFile);
    Scenario sc = ScenarioUtils.loadScenario(config1);

    CommuterDataReader cdr = new CommuterDataReader();
    cdr.addFilterRange(12071000);
    cdr.addFilter("12052000"); // 12052000 == cottbus stadt
    cdr.readFile(
        "../../../shared-svn/studies/countries/de/pendler_nach_gemeinden/brandenburg_einpendler.csv");
    //		cdr.getCommuterRelations().add(new CommuterDataElement("12052000", "12052000", 1000));

    String gemeindenBrandenburgShapeFile =
        "../../../shared-svn/studies/countries/de/brandenburg_gemeinde_kreisgrenzen/gemeinden/dlm_gemeinden.shp";
    ShapeFileReader gemeindenReader = new ShapeFileReader();
    Collection<SimpleFeature> gemeindenFeatures =
        gemeindenReader.readFileAndInitialize(gemeindenBrandenburgShapeFile);

    CommuterDemandWriter cdw =
        new CommuterDemandWriter(
            gemeindenFeatures,
            gemeindenReader.getCoordinateSystem(),
            cdr.getCommuterRelations(),
            MGC.getCRS(TransformationFactory.WGS84_UTM33N));
    // landuse
    if (useLanduse) {
      DgLanduseReader landuseReader = new DgLanduseReader();
      Tuple<Collection<SimpleFeature>, CoordinateReferenceSystem> homeLanduse =
          landuseReader.readLanduseDataHome();
      Tuple<Collection<SimpleFeature>, CoordinateReferenceSystem> workLanduse =
          landuseReader.readLanduseDataWork();
      cdw.addLanduse("home", homeLanduse);
      cdw.addLanduse("work", workLanduse);
    }
    //
    //		cdw.setScalefactor(1.0); // all modes
    cdw.setScalefactor(0.55); // car mode share
    //		cdw.setScalefactor(0.1); //testing

    cdw.computeDemand(sc);
    PopulationWriter populationWriter = new PopulationWriter(sc.getPopulation(), sc.getNetwork());
    populationWriter.write(populationOutputFile);
    log.info("population written to " + populationOutputFile);

    // write some test output
    Config config = ConfigUtils.createConfig();
    config.network().setInputFile(networkFile);
    config.plans().setInputFile(populationOutputFile);
    Scenario baseScenario = ScenarioUtils.loadScenario(config);

    String shapeFilename = shapesOutputDirectory + "commuter_population_home.shp";
    new DgPopulation2ShapeWriter(
            baseScenario.getPopulation(), MGC.getCRS(TransformationFactory.WGS84_UTM33N))
        .write("home", shapeFilename, MGC.getCRS(TransformationFactory.WGS84_UTM33N));
    shapeFilename = shapesOutputDirectory + "commuter_population_work.shp";
    new DgPopulation2ShapeWriter(
            baseScenario.getPopulation(), MGC.getCRS(TransformationFactory.WGS84_UTM33N))
        .write("work", shapeFilename, MGC.getCRS(TransformationFactory.WGS84_UTM33N));

    log.info("done!");
    OutputDirectoryLogging.closeOutputDirLogging();
  }