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); } } }
public void addBuilding(final Building building) { this.allBuildings.add(building); if (building.isVilla()) { this.villas.add(building); } else if (building.isApartmentBuilding()) { this.apartmentBuilding2size.put(building, (double) building.getBuildingSize()); this.apartmentBuildingSizeSum += building.getBuildingSize(); } else if (building.isWorkBuilding()) { this.workBuilding2size.put(building, (double) building.getBuildingSize()); this.workBuildingSizeSum += building.getBuildingSize(); } else { Logger.getLogger(this.getClass().getName()) .warning("Undefined building type. Building not added to zone."); } }