diff --git a/osm/src/main/groovy/org/orbisgis/geoclimate/osm/WorkflowOSM.groovy b/osm/src/main/groovy/org/orbisgis/geoclimate/osm/WorkflowOSM.groovy index 4223aa2b25..60fe0fcf95 100644 --- a/osm/src/main/groovy/org/orbisgis/geoclimate/osm/WorkflowOSM.groovy +++ b/osm/src/main/groovy/org/orbisgis/geoclimate/osm/WorkflowOSM.groovy @@ -232,6 +232,9 @@ Map workflow(def input) { error "The all parameter must be a boolean value" return null } + + def osm_date= inputParameters.get("date") + def osm_size_area = inputParameters.get("area") if (!osm_size_area) { @@ -241,7 +244,6 @@ Map workflow(def input) { error "The area of the bounding box to be extracted from OSM must be greater than 0 kmĀ²" return null } - def overpass_timeout = inputParameters.get("timeout") if (!overpass_timeout) { overpass_timeout = 900 @@ -360,7 +362,7 @@ Map workflow(def input) { def logTableZones = postfix("log_zones") Map osmprocessing = osm_processing(h2gis_datasource, processing_parameters, locations.findAll { it }, file_outputFolder, outputFileTables, outputDatasource, outputTables, outputSRID, downloadAllOSMData, deleteOutputData, deleteOSMFile, logTableZones, osm_size_area, - overpass_timeout, overpass_maxsize) + overpass_timeout, overpass_maxsize, osm_date) if (!osmprocessing) { h2gis_datasource.save(logTableZones,"${file_outputFolder.getAbsolutePath() + File.separator}logzones.geojson", true) return null @@ -401,7 +403,7 @@ Map osm_processing(JdbcDataSource h2gis_datasource, def processing_parameters, d def outputSRID, def downloadAllOSMData, def deleteOutputData, def deleteOSMFile, def logTableZones, def bbox_size, - def overpass_timeout, def overpass_maxsize) { + def overpass_timeout, def overpass_maxsize,def overpass_date) { //Store the zone identifier and the names of the tables def outputTableNamesResult = [:] //Create the table to log on the processed zone @@ -421,7 +423,7 @@ Map osm_processing(JdbcDataSource h2gis_datasource, def processing_parameters, d error "Cannot find any geometry to define the zone to extract the OSM data" return } - def srid = h2gis_datasource.getSpatialTable(zone).srid + def srid = h2gis_datasource.getSrid(zone) def reproject = false if (outputSRID) { if (outputSRID != srid) { @@ -432,7 +434,11 @@ Map osm_processing(JdbcDataSource h2gis_datasource, def processing_parameters, d } //Prepare OSM extraction //TODO set key values ? - def query = "[timeout:$overpass_timeout][maxsize:$overpass_maxsize]" + OSMTools.Utilities.buildOSMQuery(zones.envelope, null, OSMElement.NODE, OSMElement.WAY, OSMElement.RELATION) + def osm_date="" + if(overpass_date){ + osm_date = "[date:\"$overpass_date\"]" + } + def query = "[timeout:$overpass_timeout][maxsize:$overpass_maxsize]$osm_date" + OSMTools.Utilities.buildOSMQuery(zones.envelope, null, OSMElement.NODE, OSMElement.WAY, OSMElement.RELATION) if (downloadAllOSMData) { //Create a custom OSM query to download all requiered data. It will take more time and resources @@ -441,7 +447,7 @@ Map osm_processing(JdbcDataSource h2gis_datasource, def processing_parameters, d "leisure", "highway", "natural", "landuse", "landcover", "vegetation", "waterway", "area", "aeroway", "area:aeroway", "tourism", "sport"] - query = "[timeout:$overpass_timeout][maxsize:$overpass_maxsize]" + OSMTools.Utilities.buildOSMQueryWithAllData(zones.envelope, keysValues, OSMElement.NODE, OSMElement.WAY, OSMElement.RELATION) + query = "[timeout:$overpass_timeout][maxsize:$overpass_maxsize]$osm_date" + OSMTools.Utilities.buildOSMQueryWithAllData(zones.envelope, keysValues, OSMElement.NODE, OSMElement.WAY, OSMElement.RELATION) } def extract = OSMTools.Loader.extract(query) 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 324e9be2ac..38d0130766 100644 --- a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy +++ b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy @@ -663,6 +663,7 @@ class WorflowOSMTest extends WorkflowAbstractTest { "input" : [ "locations": [location],//["Pont-de-Veyle"],//[nominatim["bbox"]],//["Lorient"], "area": 2800, + //"date":"2017-12-31T19:20:00Z", /*"timeout":182, "maxsize": 536870918, "endpoint":"https://lz4.overpass-api.de/api"*/], @@ -809,6 +810,66 @@ class WorflowOSMTest extends WorkflowAbstractTest { assertTrue h2gis.firstRow("select count(*) as count from $building where HEIGHT_WALL>0 and HEIGHT_ROOF>0").count > 0 } + @Test + void testEstimateBuildingWithAllInputHeightFromPoint() { + String directory = folder.absolutePath + File.separator + "test_building_height" + File dirFile = new File(directory) + dirFile.delete() + dirFile.mkdir() + def osm_parmeters = [ + "geoclimatedb": [ + "folder": dirFile.absolutePath, + "name" : "geoclimate_chain_db", + "delete": false + ], + "input" : [ + "locations": [[43.726898,7.298452,100]]], + "output" : [ + "folder": ["path" : directory, + "tables": ["building", "zone"]]], + "parameters" : + [ + rsu_indicators: ["indicatorUse" : ["LCZ"]] + ] + ] + Map process = OSM.WorkflowOSM.workflow(osm_parmeters) + def tableNames = process.values() + def building = tableNames.building[0] + H2GIS h2gis = H2GIS.open("${directory + File.separator}geoclimate_chain_db;AUTO_SERVER=TRUE") + assertTrue h2gis.firstRow("select count(*) as count from $building where HEIGHT_WALL>0 and HEIGHT_ROOF>0").count > 0 + } + + @Disabled //Because it takes some time to build the OSM query + @Test + void testEstimateBuildingWithAllInputHeightDate() { + String directory = folder.absolutePath + File.separator + "test_building_height" + File dirFile = new File(directory) + dirFile.delete() + dirFile.mkdir() + def osm_parmeters = [ + "geoclimatedb": [ + "folder": dirFile.absolutePath, + "name" : "geoclimate_chain_db", + "delete": false + ], + "input" : [ + "locations": [[43.726898,7.298452,43.727677,7.299632]], + "date":"2015-12-31T19:20:00Z"], + "output" : [ + "folder": ["path" : directory, + "tables": ["building", "zone"]]], + "parameters" : + ["distance" : 0, + rsu_indicators: ["indicatorUse" : ["LCZ"]] + ] + ] + Map process = OSM.WorkflowOSM.workflow(osm_parmeters) + def tableNames = process.values() + def building = tableNames.building[0] + H2GIS h2gis = H2GIS.open("${directory + File.separator}geoclimate_chain_db;AUTO_SERVER=TRUE") + assertTrue h2gis.firstRow("select count(*) as count from $building where HEIGHT_WALL>0 and HEIGHT_ROOF>0").count > 0 + } + @Test void testOneSeaLCZ() { String directory = folder.absolutePath + File.separator + "test_sea_lcz" diff --git a/osmtools/src/main/groovy/org/orbisgis/geoclimate/osmtools/utils/Utilities.groovy b/osmtools/src/main/groovy/org/orbisgis/geoclimate/osmtools/utils/Utilities.groovy index 6b11f1d42c..6ed59a2ffb 100644 --- a/osmtools/src/main/groovy/org/orbisgis/geoclimate/osmtools/utils/Utilities.groovy +++ b/osmtools/src/main/groovy/org/orbisgis/geoclimate/osmtools/utils/Utilities.groovy @@ -638,7 +638,8 @@ Geometry geometryFromNominatim(def bbox) { * * @author Erwan Bocher (CNRS LAB-STICC) * - * @param bbox 4 values to define a bbox + * @param bbox 4 values to define a bbox or 3 values to define a point (lat/long) + * with a distance around it, expressed in meters * @return a JTS polygon */ Geometry geometryFromValues(def bbox) { @@ -651,6 +652,9 @@ Geometry geometryFromValues(def bbox) { if (bbox.size() == 4) { return buildGeometry([bbox[1], bbox[0], bbox[3], bbox[2]]); } + else if (bbox.size()==3){ + return getAreaFromPoint(bbox[1], bbox[0], bbox[2]) + } }