Skip to content

Commit

Permalink
Fix failed merge with geometry in output tables
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Dec 13, 2024
1 parent 322c927 commit 3569a70
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.*;

/**
*
* Create SQL Tables from a stream of noise levels
*/
public class NoiseMapMaker implements NoiseMapByReceiverMaker.PropagationProcessDataFactory, NoiseMapByReceiverMaker.IComputeRaysOutFactory, ProfilerThread.Metric {
NoiseMapParameters noiseMapParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ public int getMaximumRaysOutputCount() {
Boolean sqlOutputFileCompression = true;
Boolean dropResultsTable = true;
public boolean computeLAEQOnly = false;

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

/**
* @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;
}

/**
* @param maximumRaysOutputCount if export rays, do not keep more than this number of rays per computation area (0 infinite)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

package org.noise_planet.noisemodelling.jdbc;

import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.PrecisionModel;
import org.noise_planet.noisemodelling.jdbc.utils.StringPreparedStatements;
import org.noise_planet.noisemodelling.propagation.cnossos.CnossosPath;
import org.noise_planet.noisemodelling.propagation.Attenuation;
Expand All @@ -29,7 +31,9 @@
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.*;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.dbaToW;


/**
* Process that run SQL query to feed tables
*/
public class NoiseMapWriter implements Runnable {
Logger LOGGER = LoggerFactory.getLogger(NoiseMapWriter.class);
File sqlFilePath;
Expand Down Expand Up @@ -140,6 +144,9 @@ void processStack(String tableName, ConcurrentLinkedDeque<Attenuation.SourceRece
if(!noiseMapParameters.mergeSources) {
query.append(", ?"); // ID_SOURCE
}
if(noiseMapParameters.exportReceiverPosition) {
query.append(", ?"); // THE_GEOM
}
if (!noiseMapParameters.computeLAEQOnly) {
query.append(", ?".repeat(noiseMapParameters.attenuationCnossosParametersDay.freq_lvl.size())); // freq value
query.append(", ?, ?);"); // laeq, leq
Expand All @@ -153,6 +160,7 @@ void processStack(String tableName, ConcurrentLinkedDeque<Attenuation.SourceRece
ps = new StringPreparedStatements(o, query.toString());
}
int batchSize = 0;
GeometryFactory factory = new GeometryFactory(new PrecisionModel(), srid);
while(!stack.isEmpty()) {
Attenuation.SourceReceiverAttenuation row = stack.pop();
AttenuatedPaths.queueSize.decrementAndGet();
Expand All @@ -161,7 +169,11 @@ void processStack(String tableName, ConcurrentLinkedDeque<Attenuation.SourceRece
if(!noiseMapParameters.mergeSources) {
ps.setLong(parameterIndex++, row.sourceId);
}

if(noiseMapParameters.exportReceiverPosition) {
ps.setObject(parameterIndex++, row.receiverPosition != null ?
factory.createPoint(row.receiverPosition):
factory.createPoint());
}
if (!noiseMapParameters.computeLAEQOnly){
for(int idfreq = 0; idfreq < noiseMapParameters.attenuationCnossosParametersDay.freq_lvl.size(); idfreq++) {
double value = row.value[idfreq];
Expand Down Expand Up @@ -212,6 +224,11 @@ private String forgeCreateTable(String tableName) {
} else {
sb.append(" (IDRECEIVER bigint NOT NULL");
}
if(noiseMapParameters.exportReceiverPosition) {
sb.append(", THE_GEOM GEOMETRY(POINTZ,");
sb.append(srid);
sb.append(")");
}
if (noiseMapParameters.computeLAEQOnly){
sb.append(", LAEQ REAL");
sb.append(");");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def exec(Connection connection, input) {
ldenConfig.setComputeLNight(!confSkipLnight)
ldenConfig.setComputeLDEN(!confSkipLden)
ldenConfig.setMergeSources(!confExportSourceId)
//ldenConfig.setExportReceiverPosition(true)
ldenConfig.setExportReceiverPosition(true)
ldenConfig.setlDayTable("LDAY_GEOM")
ldenConfig.setlEveningTable("LEVENING_GEOM")
ldenConfig.setlNightTable("LNIGHT_GEOM")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def exec(Connection connection, input) {
ldenConfig.setComputeLNight(!confSkipLnight)
ldenConfig.setComputeLDEN(!confSkipLden)
ldenConfig.setMergeSources(!confExportSourceId)
//ldenConfig.setExportReceiverPosition(true)
ldenConfig.setExportReceiverPosition(true)
ldenConfig.setlDayTable("LDAY_GEOM")
ldenConfig.setlEveningTable("LEVENING_GEOM")
ldenConfig.setlNightTable("LNIGHT_GEOM")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.h2gis.utilities.wrapper.ConnectionWrapper
import org.locationtech.jts.geom.Geometry
import org.noise_planet.noisemodelling.jdbc.NoiseEmissionMaker
import org.noise_planet.noisemodelling.jdbc.NoiseMapParameters
import org.noise_planet.noisemodelling.pathfinder.utils.Utils
import org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions
import org.noise_planet.noisemodelling.propagation.cnossos.AttenuationCnossosParameters
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -205,9 +205,9 @@ def exec(Connection connection, input) {

// Compute emission sound level for each road segment
def results = noiseEmissionMaker.computeLw(rs)
def lday = Utils.wToDba(results[0])
def levening = Utils.wToDba(results[1])
def lnight = Utils.wToDba(results[2])
def lday = AcousticIndicatorsFunctions.wToDba(results[0])
def levening = AcousticIndicatorsFunctions.wToDba(results[1])
def lnight = AcousticIndicatorsFunctions.wToDba(results[2])
// fill the LW_ROADS table
ps.addBatch(rs.getLong(pkIndex) as Integer, geo as Geometry,
lday[0] as Double, lday[1] as Double, lday[2] as Double,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,11 +813,6 @@ class WpsPropagationProcessDataProba extends Scene {
return [ld, le, ln, lden]
}


@Override
double[] getMaximalSourcePower(int sourceId) {
return wjSourcesD.get(sourceId)
}
}

class WpsPropagationProcessDataProbaFactory implements NoiseMapByReceiverMaker.PropagationProcessDataFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import java.sql.SQLException
class TestAcousticTools extends JdbcTestCase {
Logger LOGGER = LoggerFactory.getLogger(TestAcousticTools.class)

@Test
void testAddLeqLaeqColumns1() {

SHPRead.importTable(connection, TestAcousticTools.getResource("ROADS2.shp").getPath())
Expand All @@ -50,7 +49,6 @@ class TestAcousticTools extends JdbcTestCase {
assertEquals("This table does not contain column with this suffix : HZ", res)
}

@Test
void testAddLeqLaeqColumns2() {

SHPRead.importTable(connection, TestAcousticTools.getResource("ROADS2.shp").getPath())
Expand All @@ -67,7 +65,6 @@ class TestAcousticTools extends JdbcTestCase {
assertEquals(true, fields.contains("LEQ"))
}

/*@Test
void testCreateIsosurface() {
def sql = new Sql(connection)

Expand Down Expand Up @@ -102,10 +99,8 @@ class TestAcousticTools extends JdbcTestCase {
assertTrue(fieldValues.contains("5"));
assertTrue(fieldValues.contains("6"));
assertTrue(fieldValues.contains("7"));
}*/

}

@Test
void testUpdateZ() throws SQLException, IOException {
SHPRead.importTable(connection, TestAcousticTools.getResource("receivers.shp").getPath())
def st = new Sql(connection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory
class TestNoiseModelling extends JdbcTestCase {
Logger LOGGER = LoggerFactory.getLogger(TestNoiseModelling.class)

@Test

void testRoadEmissionFromDEN() {

SHPRead.importTable(connection, TestDatabaseManager.getResource("ROADS2.shp").getPath())
Expand All @@ -45,8 +45,6 @@ class TestNoiseModelling extends JdbcTestCase {
assertEquals("Calculation Done ! The table LW_ROADS has been created.", res)
}


/*@Test
void testRailWayEmissionFromDEN() {

def sql = new Sql(connection)
Expand Down Expand Up @@ -108,9 +106,8 @@ class TestNoiseModelling extends JdbcTestCase {
"tableToExport": "LDAY_GEOM"])

//assertEquals(70.38,receiversLvl[0]["LEQ"] as Double,4)
}*/
}

@Test
void testLdayFromTraffic() {

SHPRead.importTable(connection, TestNoiseModelling.getResource("ROADS2.shp").getPath())
Expand Down Expand Up @@ -186,7 +183,7 @@ class TestNoiseModelling extends JdbcTestCase {
assertEquals(63, leqs[7] as Double, 2.0)
}

@Test

void testLdayFromTrafficWithBuildingsZ() {

def sql = new Sql(connection)
Expand Down Expand Up @@ -270,7 +267,7 @@ class TestNoiseModelling extends JdbcTestCase {
assertEquals(63, leqs[7] as Double, 2.0)
}

@Test

void testLdenFromEmission() {

SHPRead.importTable(connection, TestNoiseModelling.getResource("ROADS2.shp").getPath())
Expand Down Expand Up @@ -300,7 +297,7 @@ class TestNoiseModelling extends JdbcTestCase {
assertTrue(res.contains("LDEN_GEOM"))
}

/*void testLdenFromEmission1khz() {
void testLdenFromEmission1khz() {

SHPRead.importTable(connection, TestNoiseModelling.getResource("ROADS2.shp").getPath())

Expand Down Expand Up @@ -337,5 +334,5 @@ class TestNoiseModelling extends JdbcTestCase {
def fields = JDBCUtilities.getColumnNames(connection, "LDAY_GEOM")

assertArrayEquals(["IDRECEIVER","THE_GEOM", "HZ1000", "LAEQ", "LEQ"].toArray(), fields.toArray())
}*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory
class TestTutorials extends JdbcTestCase {
Logger LOGGER = LoggerFactory.getLogger(TestTutorials.class)

@Test

void testTutorialPointSource() {
Sql sql = new Sql(connection)

Expand Down Expand Up @@ -88,8 +88,8 @@ class TestTutorials extends JdbcTestCase {
assertTrue(res.contains("LDAY_GEOM"))

def rowResult = sql.firstRow("SELECT MAX(LEQ), MAX(LAEQ) FROM LDAY_GEOM")
//assertEquals(72, rowResult[0] as Double, 5.0)
//assertEquals(69, rowResult[1] as Double, 5.0)
assertEquals(72, rowResult[0] as Double, 5.0)
assertEquals(69, rowResult[1] as Double, 5.0)

// Check export geojson
File testPath = new File("target/tutoPointSource.geojson")
Expand All @@ -98,14 +98,14 @@ class TestTutorials extends JdbcTestCase {
testPath.delete()
}

/*new Export_Table().exec(connection,
new Export_Table().exec(connection,
["exportPath" : "target/tutoPointSource.geojson",
"tableToExport": "LDAY_GEOM"])*/
"tableToExport": "LDAY_GEOM"])


}

/*@Test

void testTutorialPointSourceDirectivity() {
Logger logger = LoggerFactory.getLogger(TestTutorials.class)

Expand Down Expand Up @@ -149,8 +149,9 @@ class TestTutorials extends JdbcTestCase {
logger.info(new Delaunay_Grid().exec(connection, [maxArea: 60, tableBuilding: "BUILDINGS",
sourcesTableName : "POINT_SOURCE" , height: 1.6]));

//new Export_Table().exec(connection, [exportPath:"target/receivers.shp", tableToExport: "RECEIVERS"])
//new Export_Table().exec(connection, [exportPath:"target/TRIANGLES.shp", tableToExport: "TRIANGLES"])

new Export_Table().exec(connection, [exportPath:"target/receivers.shp", tableToExport: "RECEIVERS"])
new Export_Table().exec(connection, [exportPath:"target/TRIANGLES.shp", tableToExport: "TRIANGLES"])

new Noise_level_from_source().exec(connection, [tableBuilding: "BUILDINGS", tableSources:"POINT_SOURCE",
tableReceivers : "RECEIVERS",
Expand All @@ -171,5 +172,5 @@ class TestTutorials extends JdbcTestCase {



}*/
}
}

0 comments on commit 3569a70

Please sign in to comment.