diff --git a/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicators.groovy b/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicators.groovy index 6e066120f1..13a1fb755e 100644 --- a/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicators.groovy +++ b/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicators.groovy @@ -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""" diff --git a/osm/classpath.index b/osm/classpath.index new file mode 100644 index 0000000000..21477a0672 Binary files /dev/null and b/osm/classpath.index differ diff --git a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy index ab372c5387..682332af30 100644 --- a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy +++ b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy @@ -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) } /** diff --git a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorkflowAbstractTest.groovy b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorkflowAbstractTest.groovy index b989990453..372142984c 100644 --- a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorkflowAbstractTest.groovy +++ b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorkflowAbstractTest.groovy @@ -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 @@ -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()) @@ -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) @@ -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]) @@ -112,7 +119,7 @@ class WorkflowAbstractTest { vegetationTableName, roadTableName, hydrographicTableName, - null, railTableName, + imperviousTableName, railTableName, parameters, prefixName) assert rsuIndicators diff --git a/osm/src/test/resources/org/orbisgis/geoclimate/osm/ZONE_ONLY_SEA.geojson b/osm/src/test/resources/org/orbisgis/geoclimate/osm/ZONE_ONLY_SEA.geojson new file mode 100644 index 0000000000..b0bd8ab765 --- /dev/null +++ b/osm/src/test/resources/org/orbisgis/geoclimate/osm/ZONE_ONLY_SEA.geojson @@ -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]"}}]} \ No newline at end of file