Skip to content

Commit

Permalink
This PR introduces two new options to process OSM data
Browse files Browse the repository at this point in the history
- date : to query the osm db from a specific date expressed in ISO 8601
- location with 3 values to specify a point in lat/lon plus a distance
  • Loading branch information
ebocher committed Jan 17, 2024
1 parent 23b290f commit 987ab52
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
18 changes: 12 additions & 6 deletions osm/src/main/groovy/org/orbisgis/geoclimate/osm/WorkflowOSM.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"*/],
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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])
}
}


Expand Down

0 comments on commit 987ab52

Please sign in to comment.