Skip to content

Commit

Permalink
Fix issue 840 (workflow stops when only the zone is only sea
Browse files Browse the repository at this point in the history
  • Loading branch information
j3r3m1 committed Sep 21, 2023
1 parent 3d501fd commit 4afdf7c
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,18 @@ String smallestCommunGeometry(JdbcDataSource datasource, String zone, String id_
MAX(BUILDING) AS BUILDING, MAX(RAIL) AS RAIL, ${id_zone} FROM $allInfoTableName GROUP BY ${ID_COLUMN_NAME}, ${id_zone};
DROP TABLE IF EXISTS ${tablesToMerge.keySet().join(' , ')}, ${allInfoTableName}, ${tmpTablesToDrop.join(",")}""".toString()
}
else{
datasource """DROP TABLE IF EXISTS $outputTableName;
CREATE TABLE $outputTableName(AREA DOUBLE,
LOW_VEGETATION INTEGER,
HIGH_VEGETATION INTEGER,
WATER INTEGER,
IMPERVIOUS INTEGER,
ROAD INTEGER,
BUILDING INTEGER,
RAIL INTEGER,
${id_zone} INTEGER)"""
}

} else {
error """Cannot compute the smallest geometries"""
Expand Down
Binary file added osm/classpath.index
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,103 @@ class WorflowOSMTest extends WorkflowAbstractTest {
datasource.load(urlZone, zone, true)
//Run tests
geoIndicatorsCalc(dirFile.absolutePath, datasource, zone, buildingTableName, roadTableName,
null, vegetationTableName, hydrographicTableName, saveResults, svfSimplified, indicatorUse, prefixName)
railTableName, vegetationTableName, hydrographicTableName, null, "",
saveResults, svfSimplified, indicatorUse, prefixName)
}

@Test
void osmGeoIndicatorsFromTestFilesWhenOnlySea() {

String urlZone = new File(getClass().getResource("ZONE_ONLY_SEA.geojson").toURI()).absolutePath

//TODO enable it for debug purpose
boolean saveResults = false
String directory = folder.absolutePath + File.separator + "osm_processchain_geoindicators_onlysea"
def prefixName = ""
def indicatorUse = ["UTRF", "LCZ", "TEB"]
def svfSimplified = true

File dirFile = new File(directory)
dirFile.delete()
dirFile.mkdir()

H2GIS datasource = H2GIS.open(dirFile.absolutePath + File.separator + "osm_chain_db;AUTO_SERVER=TRUE")

String zone = "zone"
String buildingTableName = "buildings"
String roadTableName = "road"
String railTableName = "rails"
String vegetationTableName = "veget"
String hydrographicTableName = "hydro"
String urbanTableName = "urban"
String sealandTableName = "sealand"
String imperviousTableName = "impervious"


datasource.load(urlZone, zone, true)
datasource """DROP TABLE IF EXISTS $buildingTableName;
CREATE TABLE $buildingTableName(THE_GEOM GEOMETRY,
ID_BUILD INTEGER,
ID_SOURCE VARCHAR,
HEIGHT_WALL DOUBLE,
HEIGHT_ROOF DOUBLE,
NB_LEV INTEGER,
TYPE VARCHAR,
MAIN_USE VARCHAR,
ZINDEX INTEGER,
ROOF_SHAPE VARCHAR)"""
datasource """DROP TABLE IF EXISTS $roadTableName;
CREATE TABLE $roadTableName(THE_GEOM GEOMETRY,
ID_ROAD INTEGER,
ID_SOURCE VARCHAR,
WIDTH DOUBLE,
TYPE VARCHAR,
CROSSING VARCHAR,
SURFACE VARCHAR,
SIDE_WALK VARCHAR,
MAXSPEED INTEGER,
DIRECTION INTEGER,
ZINDEX INTEGER)"""
datasource """DROP TABLE IF EXISTS $railTableName;
CREATE TABLE $railTableName(THE_GEOM GEOMETRY,
ID_RAIL INTEGER,
ID_SOURCE VARCHAR,
WIDTH DOUBLE,
TYPE VARCHAR,
CROSSING VARCHAR,
USAGE VARCHAR,
ZINDEX INTEGER)"""
datasource """DROP TABLE IF EXISTS $vegetationTableName;
CREATE TABLE $vegetationTableName(THE_GEOM GEOMETRY,
ID INTEGER,
ID_SOURCE VARCHAR,
HEIGHT_CLASS VARCHAR,
ZINDEX INTEGER)"""
datasource """DROP TABLE IF EXISTS $hydrographicTableName;
CREATE TABLE $hydrographicTableName(THE_GEOM GEOMETRY,
ID INTEGER,
ID_SOURCE VARCHAR,
TYPE VARCHAR,
ZINDEX INTEGER)"""
datasource """DROP TABLE IF EXISTS $urbanTableName;
CREATE TABLE $urbanTableName(THE_GEOM GEOMETRY,
ID_URBAN INTEGER,
ID_SOURCE VARCHAR,
TYPE VARCHAR,
MAIN_USE VARCHAR)"""
datasource """DROP TABLE IF EXISTS $sealandTableName;
CREATE TABLE $sealandTableName(THE_GEOM GEOMETRY,
ID INTEGER,
TYPE VARCHAR)"""
datasource """DROP TABLE IF EXISTS $imperviousTableName;
CREATE TABLE $imperviousTableName(THE_GEOM GEOMETRY,
ID_IMPERVIOUS INTEGER,
TYPE VARCHAR)"""

//Run tests
geoIndicatorsCalc(dirFile.absolutePath, datasource, zone, buildingTableName, roadTableName,
railTableName, vegetationTableName, hydrographicTableName, imperviousTableName, sealandTableName,
saveResults, svfSimplified, indicatorUse, prefixName, true)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ class WorkflowAbstractTest {
*/
void geoIndicatorsCalc(String directory, def datasource, String zone, String buildingTableName,
String roadTableName, String railTableName, String vegetationTableName,
String hydrographicTableName, boolean saveResults, boolean svfSimplified = false, def indicatorUse,
String prefixName = "") {
String hydrographicTableName, String imperviousTableName = null, String sealandmaskTableName = "",
boolean saveResults, boolean svfSimplified = false, def indicatorUse,
String prefixName = "", boolean onlySea = false) {
//Create spatial units and relations : building, block, rsu
Map spatialUnits = Geoindicators.WorkflowGeoIndicators.createUnitsOfAnalysis(datasource, zone, buildingTableName,
roadTableName, railTableName, vegetationTableName,
hydrographicTableName, "", "", 10000,
hydrographicTableName, sealandmaskTableName, "", 10000,
2500, 0.01, indicatorUse, prefixName)

String relationBuildings = spatialUnits.building
Expand All @@ -58,13 +59,15 @@ class WorkflowAbstractTest {

if (saveResults) {
logger.debug("Saving spatial units")
Geoindicators.DataUtils.saveTablesAsFiles(datasource, spatialUnits.values(),
Geoindicators.DataUtils.saveTablesAsFiles(datasource, new ArrayList(spatialUnits.values()),
true, directory)
}

def maxBlocks = datasource.firstRow("select max(id_block) as max from ${relationBuildings}".toString())
def countBlocks = datasource.firstRow("select count(*) as count from ${relationBlocks}".toString())
assertEquals(countBlocks.count, maxBlocks.max)
if (!onlySea){
assertEquals(countBlocks.count, maxBlocks.max)
}


def maxRSUBlocks = datasource.firstRow("select count(distinct id_block) as max from ${relationBuildings} where id_rsu is not null".toString())
Expand All @@ -76,7 +79,9 @@ class WorkflowAbstractTest {
roadTableName, indicatorUse,
prefixName)
assert buildingIndicators
assertTrue(datasource.getSpatialTable(buildingIndicators).srid > 0)
if (!onlySea){
assertTrue(datasource.getSpatialTable(buildingIndicators).srid > 0)
}
if (saveResults) {
logger.debug("Saving building indicators")
datasource.getSpatialTable(buildingIndicators).save(directory + File.separator + "${buildingIndicators}.geojson", true)
Expand All @@ -102,7 +107,9 @@ class WorkflowAbstractTest {
def countRelationBlocks = datasource.firstRow("select count(*) as count from ${relationBlocks}".toString())
def countBlocksIndicators = datasource.firstRow("select count(*) as count from ${blockIndicators}".toString())
assertEquals(countRelationBlocks.count, countBlocksIndicators.count)
assertTrue(datasource.getSpatialTable(blockIndicators).srid > 0)
if (!onlySea){
assertTrue(datasource.getSpatialTable(blockIndicators).srid > 0)
}
}

Map parameters = Geoindicators.WorkflowGeoIndicators.getParameters(["indicatorUse": indicatorUse, "svfSimplified": svfSimplified])
Expand All @@ -112,7 +119,7 @@ class WorkflowAbstractTest {
vegetationTableName,
roadTableName,
hydrographicTableName,
null, railTableName,
imperviousTableName, railTableName,
parameters,
prefixName)
assert rsuIndicators
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"FeatureCollection","crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::32633"}},"features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[668159.840844761,3652725.8675869787],[667779.2423065485,3674902.6933475523],[686424.2826395712,3675241.3737045107],[686847.2227853552,3653063.5042925826],[668159.840844761,3652725.8675869787]]]},"properties":{"ID_ZONE":"[33, 16.8, 33.2, 17]"}}]}

0 comments on commit 4afdf7c

Please sign in to comment.