Skip to content

Commit

Permalink
About Universite-Gustave-Eiffel#598 LDAY_GEOM and other final tables …
Browse files Browse the repository at this point in the history
…now contains receiver altitude derived from DEM, that was used from computation
  • Loading branch information
nicolas-f committed Oct 2, 2023
1 parent 8557d2c commit acb3a16
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,11 @@ public void setBodyBarrier(boolean bodyBarrier) {
this.bodyBarrier = bodyBarrier;
}

protected double getCellWidth() {
public double getCellWidth() {
return mainEnvelope.getWidth() / gridDim;
}

protected double getCellHeight() {
public double getCellHeight() {
return mainEnvelope.getHeight() / gridDim;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,56 +300,6 @@ static Connection openGeoserverDataStoreConnection(String dbName) {
return jdbcDataStore.getDataSource().getConnection()
}

def forgeCreateTable(Sql sql, String tableName, LDENConfig ldenConfig, String geomField, String tableReceiver, String tableResult) {
// Create a logger to display messages in the geoserver logs and in the command prompt.
Logger logger = LoggerFactory.getLogger("org.noise_planet.noisemodelling")

StringBuilder sb = new StringBuilder("create table ");
sb.append(tableName);
if (!ldenConfig.mergeSources) {
sb.append(" (IDRECEIVER bigint NOT NULL");
sb.append(", IDSOURCE bigint NOT NULL");
} else {
sb.append(" (IDRECEIVER bigint NOT NULL");
}
sb.append(", THE_GEOM geometry")
List<Integer> freqLvl = ldenConfig.getPropagationProcessPathData(LDENConfig.TIME_PERIOD.DAY).freq_lvl;
for (int idfreq = 0; idfreq < freqLvl.size(); idfreq++) {
sb.append(", HZ");
sb.append(freqLvl.get(idfreq));
sb.append(" numeric(5, 2)");
}
sb.append(", LAEQ numeric(5, 2), LEQ numeric(5, 2) ) AS SELECT PK");
if (!ldenConfig.mergeSources) {
sb.append(", IDSOURCE");
}
sb.append(", ")
sb.append(geomField)
for (int idfreq = 0; idfreq < freqLvl.size(); idfreq++) {
sb.append(", HZ");
sb.append(freqLvl.get(idfreq));
}
sb.append(", LAEQ, LEQ FROM ")
sb.append(tableReceiver)
if (!ldenConfig.mergeSources) {
// idsource can't be null so we can't left join
sb.append(" a, ")
sb.append(tableResult)
sb.append(" b WHERE a.PK = b.IDRECEIVER")
} else {
sb.append(" a LEFT JOIN ")
sb.append(tableResult)
sb.append(" b ON a.PK = b.IDRECEIVER")
}
sql.execute(sb.toString())
// apply pk
logger.info("Add primary key on " + tableName)
if (!ldenConfig.mergeSources) {
sql.execute("ALTER TABLE " + tableName + " ADD PRIMARY KEY(IDRECEIVER, IDSOURCE)")
} else {
sql.execute("ALTER TABLE " + tableName + " ADD PRIMARY KEY(IDRECEIVER)")
}
}
// run the script
def run(input) {

Expand Down Expand Up @@ -581,6 +531,26 @@ def exec(Connection connection, input) {
ldenConfig.setComputeLNight(!confSkipLnight)
ldenConfig.setComputeLDEN(!confSkipLden)
ldenConfig.setMergeSources(!confExportSourceId)
ldenConfig.setExportReceiverPosition(true)
ldenConfig.setlDayTable("LDAY_GEOM")
ldenConfig.setlEveningTable("LEVENING_GEOM")
ldenConfig.setlNightTable("LNIGHT_GEOM")
ldenConfig.setlDenTable("LDEN_GEOM")


Sql sql = new Sql(connection)
if(!confSkipLday) {
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlDayTable()))
}
if(!confSkipLevening) {
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlEveningTable()))
}
if(!confSkipLnight) {
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlNightTable()))
}
if(!confSkipLden) {
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlDenTable()))
}

int maximumRaysToExport = 5000

Expand Down Expand Up @@ -742,44 +712,20 @@ def exec(Connection connection, input) {
ldenProcessing.stop()
}

// Create a sql connection to interact with the database in SQL
Sql sql = new Sql(connection)

// Associate Geometry column to the table LDEN
StringBuilder createdTables = new StringBuilder()


if (ldenConfig.computeLDay) {
sql.execute("drop table if exists LDAY_GEOM;")
logger.info('create table LDAY_GEOM')
forgeCreateTable(sql, "LDAY_GEOM", ldenConfig, geomFieldsRcv.get(0), receivers_table_name,
ldenConfig.lDayTable)
createdTables.append(" LDAY_GEOM")
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlDayTable()))
}
if (ldenConfig.computeLEvening) {
sql.execute("drop table if exists LEVENING_GEOM;")
logger.info('create table LEVENING_GEOM')
forgeCreateTable(sql, "LEVENING_GEOM", ldenConfig, geomFieldsRcv.get(0), receivers_table_name,
ldenConfig.lEveningTable)
createdTables.append(" LEVENING_GEOM")
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlEveningTable()))
}
if (ldenConfig.computeLNight) {
sql.execute("drop table if exists LNIGHT_GEOM;")
logger.info('create table LNIGHT_GEOM')
forgeCreateTable(sql, "LNIGHT_GEOM", ldenConfig, geomFieldsRcv.get(0), receivers_table_name,
ldenConfig.lNightTable)
createdTables.append(" LNIGHT_GEOM")
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlNightTable()))
}
if (ldenConfig.computeLDEN) {
sql.execute("drop table if exists LDEN_GEOM;")
logger.info('create table LDEN_GEOM')
forgeCreateTable(sql, "LDEN_GEOM", ldenConfig, geomFieldsRcv.get(0), receivers_table_name,
ldenConfig.lDenTable)
createdTables.append(" LDEN_GEOM")
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlDenTable()))
}

resultString = "Calculation Done ! " + createdTables.toString() + " table(s) have been created."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,58 +322,6 @@ def run(input) {
}
}

def forgeCreateTable(Sql sql, String tableName, LDENConfig ldenConfig, String geomField, String tableReceiver, String tableResult) {
// Create a logger to display messages in the geoserver logs and in the command prompt.
Logger logger = LoggerFactory.getLogger("org.noise_planet.noisemodelling")

StringBuilder sb = new StringBuilder("create table ");
sb.append(tableName);
if (!ldenConfig.mergeSources) {
sb.append(" (IDRECEIVER bigint NOT NULL");
sb.append(", IDSOURCE bigint NOT NULL");
} else {
sb.append(" (IDRECEIVER bigint NOT NULL");
}
sb.append(", THE_GEOM geometry")
PropagationProcessPathData pathData = ldenConfig.getPropagationProcessPathData(LDENConfig.TIME_PERIOD.DAY);
for (int idfreq = 0; idfreq < pathData.freq_lvl.size(); idfreq++) {
sb.append(", HZ");
sb.append(pathData.freq_lvl.get(idfreq));
sb.append(" numeric(5, 2)");
}
sb.append(", LAEQ numeric(5, 2), LEQ numeric(5, 2) ) AS SELECT PK");
if (!ldenConfig.mergeSources) {
sb.append(", IDSOURCE");
}
sb.append(", ")
sb.append(geomField)
for (int idfreq = 0; idfreq < pathData.freq_lvl.size(); idfreq++) {
sb.append(", HZ");
sb.append(pathData.freq_lvl.get(idfreq));
}
sb.append(", LAEQ, LEQ FROM ")
sb.append(tableReceiver)
if (!ldenConfig.mergeSources) {
// idsource can't be null so we can't left join
sb.append(" a, ")
sb.append(tableResult)
sb.append(" b WHERE a.PK = b.IDRECEIVER")
} else {
sb.append(" a LEFT JOIN ")
sb.append(tableResult)
sb.append(" b ON a.PK = b.IDRECEIVER")
}
sql.execute(sb.toString())
// apply pk
logger.info("Add primary key on " + tableName)
if (!ldenConfig.mergeSources) {
sql.execute("ALTER TABLE " + tableName + " ADD PRIMARY KEY(IDRECEIVER, IDSOURCE)")
} else {
sql.execute("ALTER TABLE " + tableName + " ADD PRIMARY KEY(IDRECEIVER)")
}
}


static void exportScene(String name, ProfileBuilder builder, ComputeRaysOutAttenuation result, int crs) throws IOException {
try {
FileOutputStream outData = new FileOutputStream(name);
Expand Down Expand Up @@ -574,6 +522,25 @@ def exec(Connection connection, input) {
ldenConfig.setComputeLNight(!confSkipLnight)
ldenConfig.setComputeLDEN(!confSkipLden)
ldenConfig.setMergeSources(!confExportSourceId)
ldenConfig.setExportReceiverPosition(true)
ldenConfig.setlDayTable("LDAY_GEOM")
ldenConfig.setlEveningTable("LEVENING_GEOM")
ldenConfig.setlNightTable("LNIGHT_GEOM")
ldenConfig.setlDenTable("LDEN_GEOM")

if(!confSkipLday) {
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlDayTable()))
}
if(!confSkipLevening) {
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlEveningTable()))
}
if(!confSkipLnight) {
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlNightTable()))
}
if(!confSkipLden) {
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlDenTable()))
}


int maximumRaysToExport = 5000

Expand Down Expand Up @@ -728,36 +695,16 @@ def exec(Connection connection, input) {
StringBuilder createdTables = new StringBuilder()

if (ldenConfig.computeLDay) {
sql.execute("drop table if exists LDAY_GEOM;")
logger.info('create table LDAY_GEOM')
forgeCreateTable(sql, "LDAY_GEOM", ldenConfig, geomFieldsRcv.get(0), receivers_table_name,
ldenConfig.lDayTable)
createdTables.append(" LDAY_GEOM")
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlDayTable()))
}
if (ldenConfig.computeLEvening) {
sql.execute("drop table if exists LEVENING_GEOM;")
logger.info('create table LEVENING_GEOM')
forgeCreateTable(sql, "LEVENING_GEOM", ldenConfig, geomFieldsRcv.get(0), receivers_table_name,
ldenConfig.lEveningTable)
createdTables.append(" LEVENING_GEOM")
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlEveningTable()))
}
if (ldenConfig.computeLNight) {
sql.execute("drop table if exists LNIGHT_GEOM;")
logger.info('create table LNIGHT_GEOM')
forgeCreateTable(sql, "LNIGHT_GEOM", ldenConfig, geomFieldsRcv.get(0), receivers_table_name,
ldenConfig.lNightTable)
createdTables.append(" LNIGHT_GEOM")
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlNightTable()))
}
if (ldenConfig.computeLDEN) {
sql.execute("drop table if exists LDEN_GEOM;")
logger.info('create table LDEN_GEOM')
forgeCreateTable(sql, "LDEN_GEOM", ldenConfig, geomFieldsRcv.get(0), receivers_table_name,
ldenConfig.lDenTable)
createdTables.append(" LDEN_GEOM")
sql.execute("drop table if exists " + TableLocation.parse(ldenConfig.getlDenTable()))
}

resultString = "Calculation Done ! " + createdTables.toString() + " table(s) have been created."
Expand Down

0 comments on commit acb3a16

Please sign in to comment.