Skip to content

Commit

Permalink
insert primary key in cut profile for wall and buildings
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Dec 10, 2024
1 parent d25636c commit 3e4a506
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.Building;
import org.noise_planet.noisemodelling.pathfinder.path.Scene;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.ProfileBuilder;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.Wall;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.WallAbsorption;
import org.noise_planet.noisemodelling.propagation.cnossos.AttenuationCnossosParameters;
import org.slf4j.Logger;
Expand Down Expand Up @@ -388,11 +389,15 @@ protected void fetchCellSoilAreas(Connection connection, Envelope fetchEnvelope,
* @throws SQLException if an SQL exception occurs while fetching the buildings data.
*/
void fetchCellBuildings(Connection connection, Envelope fetchEnvelope, ProfileBuilder builder) throws SQLException {
ArrayList<Building> buildings = new ArrayList<>();
fetchCellBuildings(connection, fetchEnvelope, buildings);
List<Building> buildings = new LinkedList<>();
List<Wall> walls = new LinkedList<>();
fetchCellBuildings(connection, fetchEnvelope, buildings, walls);
for(Building building : buildings) {
builder.addBuilding(building);
}
for (Wall wall : walls) {
builder.addWall(wall);
}
}

/**
Expand All @@ -402,7 +407,7 @@ void fetchCellBuildings(Connection connection, Envelope fetchEnvelope, ProfileBu
* @param buildings the list to which the fetched buildings will be added.
* @throws SQLException if an SQL exception occurs while fetching the building data.
*/
void fetchCellBuildings(Connection connection, Envelope fetchEnvelope, List<Building> buildings) throws SQLException {
void fetchCellBuildings(Connection connection, Envelope fetchEnvelope, List<Building> buildings, List<Wall> walls) throws SQLException {
Geometry envGeo = geometryFactory.toGeometry(fetchEnvelope);
boolean fetchAlpha = JDBCUtilities.hasField(connection, buildingsTableName, alphaFieldName);
String additionalQuery = "";
Expand Down Expand Up @@ -447,7 +452,7 @@ void fetchCellBuildings(Connection connection, Envelope fetchEnvelope, List<Buil
WKTWriter wktWriter = new WKTWriter(3);
logger.error(String.format("Error with input buildings geometry\n%s\n%s",wktWriter.write(building),wktWriter.write(envGeo)), ex);
}
if(intersectedGeometry instanceof Polygon || intersectedGeometry instanceof MultiPolygon) {
if(intersectedGeometry instanceof Polygon || intersectedGeometry instanceof MultiPolygon || intersectedGeometry instanceof LineString) {
if(fetchAlpha && Double.compare(rs.getDouble(alphaFieldName), oldAlpha) != 0 ) {
// Compute building absorption value
alphaList.clear();
Expand All @@ -457,9 +462,9 @@ void fetchCellBuildings(Connection connection, Envelope fetchEnvelope, List<Buil
}
}

int pk = -1;
long pk = -1;
if(columnIndex != 0) {
pk = rs.getInt(columnIndex);
pk = rs.getLong(columnIndex);
}
for(int i=0; i<intersectedGeometry.getNumGeometries(); i++) {
Geometry geometry = intersectedGeometry.getGeometryN(i);
Expand All @@ -468,6 +473,16 @@ void fetchCellBuildings(Connection connection, Envelope fetchEnvelope, List<Buil
heightField.isEmpty() ? Double.MAX_VALUE : rs.getDouble(heightField),
alphaList, pk, iszBuildings());
buildings.add(poly);
} else if (geometry instanceof LineString) {
// decompose linestring into segments
LineString lineString = (LineString) geometry;
Coordinate[] coordinates = lineString.getCoordinates();
for(int vertex=0; vertex < coordinates.length - 1; vertex++) {
Wall wall = new Wall(new LineSegment(coordinates[vertex], coordinates[vertex+1]),
-1, ProfileBuilder.IntersectionType.WALL);
wall.setPrimaryKey(pk);
walls.add(wall);
}
}
}
}
Expand Down
Loading

0 comments on commit 3e4a506

Please sign in to comment.