Example #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);
      }
    }
  }
Example #2
0
 public ZonalSystem(final String zonesShapeFileName) {
   final GeometryFactory geometryFactory = new GeometryFactory();
   final WKTReader wktReader = new WKTReader(geometryFactory);
   for (SimpleFeature ft : ShapeFileReader.getAllFeatures(zonesShapeFileName)) {
     try {
       final String zoneId = ft.getAttribute("ZONE").toString();
       final Zone zone = new Zone(zoneId);
       zone.setGeometry(wktReader.read((ft.getAttribute("the_geom")).toString()));
       this.id2zone.put(zoneId, zone);
     } catch (ParseException e) {
       throw new RuntimeException(e);
     }
   }
 }