Skip to content

Commit

Permalink
Store receiver position if required in ldenConfig (default false)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Oct 2, 2023
1 parent 87594f5 commit 8557d2c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.noise_planet.noisemodelling.jdbc;

import org.locationtech.jts.geom.Coordinate;
import org.noise_planet.noisemodelling.pathfinder.IComputeRaysOut;
import org.noise_planet.noisemodelling.pathfinder.PropagationPath;
import org.noise_planet.noisemodelling.pathfinder.utils.PowerUtils;
Expand Down Expand Up @@ -107,10 +108,10 @@ public ThreadComputeRaysOut(LDENComputeRaysOut multiThreadParent) {
return levels;
}

double[] processAndPushResult(long receiverPK, List<double[]> wjSources,List<VerticeSL> receiverAttenuationLevels, ConcurrentLinkedDeque<VerticeSL> result, boolean feedStack) {
double[] processAndPushResult(long receiverPK,Coordinate receiverCoordinate, List<double[]> wjSources,List<VerticeSL> receiverAttenuationLevels, ConcurrentLinkedDeque<VerticeSL> result, boolean feedStack) {
double[] levels = sumLevels(wjSources, receiverAttenuationLevels);
if(feedStack) {
pushInStack(result, new VerticeSL(receiverPK, -1, wToDba(levels)));
pushInStack(result, new VerticeSL(receiverPK, -1, wToDba(levels), receiverCoordinate));
}
return levels;
}
Expand Down Expand Up @@ -250,7 +251,9 @@ public void finalizeReceiver(final long receiverId) {
propagationPaths.clear();
}
long receiverPK = receiverId;
Coordinate receiverPosition = null;
if(ldenComputeRaysOut.inputData != null) {
receiverPosition = ldenComputeRaysOut.inputData.receivers.get((int)receiverId);
if(receiverId < ldenComputeRaysOut.inputData.receiversPk.size()) {
receiverPK = ldenComputeRaysOut.inputData.receiversPk.get((int)receiverId);
}
Expand Down Expand Up @@ -291,19 +294,19 @@ public void finalizeReceiver(final long receiverId) {
if (ldenConfig.computeLDay || ldenConfig.computeLDEN) {
dayLevels = sumArray(wToDba(ldenComputeRaysOut.ldenPropagationProcessData.wjSourcesD.get((int) sourceId)), entry.getValue().dayLevels);
if(ldenConfig.computeLDay) {
pushInStack(ldenComputeRaysOut.ldenData.lDayLevels, new VerticeSL(receiverPK, sourcePK, dayLevels));
pushInStack(ldenComputeRaysOut.ldenData.lDayLevels, new VerticeSL(receiverPK, sourcePK, dayLevels, receiverPosition));
}
}
if (ldenConfig.computeLEvening || ldenConfig.computeLDEN) {
eveningLevels = sumArray(wToDba(ldenComputeRaysOut.ldenPropagationProcessData.wjSourcesE.get((int) sourceId)), entry.getValue().eveningLevels);
if(ldenConfig.computeLEvening) {
pushInStack(ldenComputeRaysOut.ldenData.lEveningLevels, new VerticeSL(receiverPK, sourcePK, eveningLevels));
pushInStack(ldenComputeRaysOut.ldenData.lEveningLevels, new VerticeSL(receiverPK, sourcePK, eveningLevels, receiverPosition));
}
}
if (ldenConfig.computeLNight || ldenConfig.computeLDEN) {
nightLevels = sumArray(wToDba(ldenComputeRaysOut.ldenPropagationProcessData.wjSourcesN.get((int) sourceId)), entry.getValue().nightLevels);
if(ldenConfig.computeLNight) {
pushInStack(ldenComputeRaysOut.ldenData.lNightLevels, new VerticeSL(receiverPK, sourcePK, nightLevels));
pushInStack(ldenComputeRaysOut.ldenData.lNightLevels, new VerticeSL(receiverPK, sourcePK, nightLevels, receiverPosition));
}
}
if (ldenConfig.computeLDEN) {
Expand All @@ -313,25 +316,25 @@ public void finalizeReceiver(final long receiverId) {
4 * dbaToW(wToDba(eveningLevels[idFrequency]) + 5) +
8 * dbaToW(wToDba(nightLevels[idFrequency]) + 10)) / 24.0;
}
pushInStack(ldenComputeRaysOut.ldenData.lDenLevels, new VerticeSL(receiverPK, sourcePK, levels));
pushInStack(ldenComputeRaysOut.ldenData.lDenLevels, new VerticeSL(receiverPK, sourcePK, levels, receiverPosition));
}
}
} else {
// Merge all results
if (ldenConfig.computeLDay || ldenConfig.computeLDEN) {
dayLevels = processAndPushResult(receiverPK,
dayLevels = processAndPushResult(receiverPK, receiverPosition,
ldenComputeRaysOut.ldenPropagationProcessData.wjSourcesD,
lDENThreadRaysOut[0].receiverAttenuationLevels, ldenComputeRaysOut.ldenData.lDayLevels,
ldenConfig.computeLDay);
}
if (ldenConfig.computeLEvening || ldenConfig.computeLDEN) {
eveningLevels = processAndPushResult(receiverPK,
eveningLevels = processAndPushResult(receiverPK, receiverPosition,
ldenComputeRaysOut.ldenPropagationProcessData.wjSourcesE,
lDENThreadRaysOut[1].receiverAttenuationLevels, ldenComputeRaysOut.ldenData.lEveningLevels,
ldenConfig.computeLEvening);
}
if (ldenConfig.computeLNight || ldenConfig.computeLDEN) {
nightLevels = processAndPushResult(receiverPK,
nightLevels = processAndPushResult(receiverPK, receiverPosition,
ldenComputeRaysOut.ldenPropagationProcessData.wjSourcesN,
lDENThreadRaysOut[2].receiverAttenuationLevels, ldenComputeRaysOut.ldenData.lNightLevels,
ldenConfig.computeLNight);
Expand All @@ -343,7 +346,7 @@ public void finalizeReceiver(final long receiverId) {
4 * dbaToW(wToDba(eveningLevels[idFrequency]) + 5) +
8 * dbaToW(wToDba(nightLevels[idFrequency]) + 10)) / 24.0;
}
pushInStack(ldenComputeRaysOut.ldenData.lDenLevels, new VerticeSL(receiverPK, -1, wToDba(levels)));
pushInStack(ldenComputeRaysOut.ldenData.lDenLevels, new VerticeSL(receiverPK, -1, wToDba(levels), receiverPosition));
}
}
for (ThreadRaysOut threadRaysOut : lDENThreadRaysOut) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,30 @@ public enum ExportRaysMethods {TO_RAYS_TABLE, TO_MEMORY, NONE}
Boolean sqlOutputFileCompression = true;
Boolean dropResultsTable = true;

/**
* If true the position of the receiver (with the altitude if available) will be exported into the results tables
*/
boolean exportReceiverPosition = false;

public LDENConfig(INPUT_MODE input_mode) {
this.input_mode = input_mode;
}

/**
* @return If true the position of the receiver (with the altitude if available) will be exported into the results
* tables
*/
public boolean isExportReceiverPosition() {
return exportReceiverPosition;
}

/**
* @param exportReceiverPosition If true the position of the receiver (with the altitude if available) will be
* exported into the results tables
*/
public void setExportReceiverPosition(boolean exportReceiverPosition) {
this.exportReceiverPosition = exportReceiverPosition;
}
public PropagationProcessPathData getPropagationProcessPathData(TIME_PERIOD time_period) {
switch (time_period) {
case DAY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

import org.h2gis.utilities.GeometryTableUtilities;
import org.h2gis.utilities.JDBCUtilities;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.PrecisionModel;
import org.noise_planet.noisemodelling.emission.LineSource;
import org.noise_planet.noisemodelling.emission.directivity.DirectivitySphere;
import org.noise_planet.noisemodelling.emission.railway.cnossos.RailWayCnossosParameters;
Expand Down Expand Up @@ -334,6 +336,9 @@ void processStack(String tableName, ConcurrentLinkedDeque<ComputeRaysOutAttenuat
if(!ldenConfig.mergeSources) {
query.append(", ?"); // ID_SOURCE
}
if(ldenConfig.exportReceiverPosition) {
query.append(", ?"); // THE_GEOM
}
if (!ldenConfig.computeLAEQOnly) {
query.append(", ?".repeat(ldenConfig.propagationProcessPathDataDay.freq_lvl.size())); // freq value
query.append(", ?, ?);"); // laeq, leq
Expand All @@ -347,6 +352,7 @@ void processStack(String tableName, ConcurrentLinkedDeque<ComputeRaysOutAttenuat
ps = new StringPreparedStatements(o, query.toString());
}
int batchSize = 0;
GeometryFactory factory = new GeometryFactory(new PrecisionModel(), srid);
while(!stack.isEmpty()) {
ComputeRaysOutAttenuation.VerticeSL row = stack.pop();
ldenData.queueSize.decrementAndGet();
Expand All @@ -355,7 +361,11 @@ void processStack(String tableName, ConcurrentLinkedDeque<ComputeRaysOutAttenuat
if(!ldenConfig.mergeSources) {
ps.setLong(parameterIndex++, row.sourceId);
}

if(ldenConfig.exportReceiverPosition) {
ps.setObject(parameterIndex++, row.receiverPosition != null ?
factory.createPoint(row.receiverPosition):
factory.createPoint());
}
if (!ldenConfig.computeLAEQOnly){
for(int idfreq=0;idfreq < ldenConfig.propagationProcessPathDataDay.freq_lvl.size(); idfreq++) {
double value = row.value[idfreq];
Expand Down Expand Up @@ -401,6 +411,11 @@ private String forgeCreateTable(String tableName) {
} else {
sb.append(" (IDRECEIVER bigint NOT NULL");
}
if(ldenConfig.exportReceiverPosition) {
sb.append(", THE_GEOM GEOMETRY(POINTZ,");
sb.append(srid);
sb.append(")");
}
if (ldenConfig.computeLAEQOnly){
sb.append(", LAEQ numeric(5, 2)");
sb.append(");");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.Point;
import org.noise_planet.noisemodelling.emission.LineSource;
import org.noise_planet.noisemodelling.emission.railway.RailWayParameters;
import org.noise_planet.noisemodelling.emission.railway.cnossos.RailwayCnossos;
Expand Down Expand Up @@ -1066,6 +1067,7 @@ public void TestPointSource() throws SQLException, IOException {
ldenConfig.setComputeLNight(false);
ldenConfig.setComputeLDEN(false);
ldenConfig.setMergeSources(true); // No idsource column
ldenConfig.setExportReceiverPosition(true); // create geometry columns with receiver position

LDENPointNoiseMapFactory factory = new LDENPointNoiseMapFactory(connection, ldenConfig);

Expand Down Expand Up @@ -1134,32 +1136,15 @@ public void TestPointSource() throws SQLException, IOException {
assertEquals(4361, rs.getInt(1));
}

connection.createStatement().execute("CREATE TABLE RESULTS AS SELECT R.the_geom the_geom, R.PK pk, LVL.* FROM "+ ldenConfig.lDayTable + " LVL, RECEIVERS R WHERE LVL.IDRECEIVER = R.PK");
SHPDriverFunction shpDriver = new SHPDriverFunction();
shpDriver.exportTable(connection, "RESULTS", new File("target/Results_PtSource"+name_output+".shp"), true,new EmptyProgressVisitor());



try(ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM "+ ldenConfig.lDayTable)) {
try(ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM "+ ldenConfig.lDayTable+" ORDER BY IDRECEIVER")) {
assertTrue(rs.next());
/* double[] leqs = new double[ldenConfig.propagationProcessPathData.freq_lvl.size()];
for (int idfreq = 1; idfreq <= ldenConfig.propagationProcessPathData.freq_lvl.size(); idfreq++) {
leqs[idfreq - 1] = rs.getDouble(idfreq);
}
assertEquals(75, leqs[0], 2.0);
assertEquals(69, leqs[1], 2.0);
assertEquals(68, leqs[2], 2.0);
assertEquals(69, leqs[3], 2.0);
assertEquals(71, leqs[4], 2.0);
assertEquals(69, leqs[5], 2.0);
assertEquals(60, leqs[6], 2.0);
assertEquals(51, leqs[7], 2.0);
assertEquals(79, rs.getDouble(9), 2.0);
assertEquals(75,rs.getDouble(10), 2.0);*/
assertEquals(1, rs.getInt("IDRECEIVER"));
Object geom = rs.getObject("THE_GEOM");
assertNotNull(geom);
assertTrue(geom instanceof Point);
// We get receiver Altitude not height
assertEquals(293.27, ((Point) geom).getCoordinate().z, 0.01);
}


}

public static void exportScene(String name, ProfileBuilder builder, ComputeRaysOutAttenuation result) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ public static class VerticeSL {
public final long sourceId;
public final long receiverId;
public final double[] value;
public final Coordinate receiverPosition;

/**
*
Expand All @@ -451,6 +452,21 @@ public VerticeSL(long receiverId, long sourceId, double[] value) {
this.sourceId = sourceId;
this.receiverId = receiverId;
this.value = value;
this.receiverPosition = null;
}


/**
*
* @param receiverId Receiver identifier
* @param sourceId Source identifier
* @param value Noise level in dB
*/
public VerticeSL(long receiverId, long sourceId, double[] value, Coordinate receiverPosition) {
this.sourceId = sourceId;
this.receiverId = receiverId;
this.value = value;
this.receiverPosition = receiverPosition;
}
}

Expand Down Expand Up @@ -488,7 +504,10 @@ public double[] addPropagationPaths(long sourceId, double sourceLi, long receive
}
}
if (aGlobalMeteo != null) {
receiverAttenuationLevels.add(new VerticeSL(receiverId, sourceId, aGlobalMeteo));
receiverAttenuationLevels.add(new VerticeSL(receiverId, sourceId, aGlobalMeteo,
multiThreadParent.inputData != null ?
multiThreadParent.inputData.receivers.get((int)receiverId) :
null));
return aGlobalMeteo;
} else {
return new double[0];
Expand Down

0 comments on commit 8557d2c

Please sign in to comment.