diff --git a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoV2Workflow.groovy b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoV2Workflow.groovy index fab7d26d20..f51919f791 100644 --- a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoV2Workflow.groovy +++ b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoV2Workflow.groovy @@ -127,7 +127,7 @@ Integer loadDataFromPostGIS(Object input_database_properties, Object code, Objec if (inputTables.route) { //Extract route def inputTableName = """(SELECT ID, st_setsrid(the_geom, $commune_srid) as the_geom, NATURE, LARGEUR, POS_SOL, - FRANCHISST, SENS, IMPORTANCE, CL_ADMIN FROM ${inputTables.route} WHERE + FRANCHISST, SENS, IMPORTANCE, CL_ADMIN, NB_VOIES FROM ${inputTables.route} WHERE st_setsrid(the_geom, $commune_srid) && 'SRID=$commune_srid;$geomToExtract'::GEOMETRY AND ST_INTERSECTS(st_setsrid(the_geom, $commune_srid), 'SRID=$commune_srid;$geomToExtract'::GEOMETRY) AND NATURE NOT IN ('Bac auto', 'Bac piéton', 'Escalier'))""".toString() @@ -352,7 +352,7 @@ def filterLinkedShapeFiles(def location, float distance, LinkedHashMap inputTabl debug "Loading in the H2GIS database $outputTableName" h2gis_datasource.execute("""DROP TABLE IF EXISTS $outputTableName ; CREATE TABLE $outputTableName as SELECT ID, $formatting_geom, NATURE, LARGEUR, POS_SOL, FRANCHISST, SENS, - IMPORTANCE, CL_ADMIN FROM ${inputTables.route} + IMPORTANCE, CL_ADMIN, NB_VOIES FROM ${inputTables.route} WHERE the_geom && 'SRID=$sourceSRID;$geomToExtract'::GEOMETRY AND ST_INTERSECTS(the_geom, 'SRID=$sourceSRID;$geomToExtract'::GEOMETRY) AND NATURE NOT IN ('Bac auto', 'Bac piéton', 'Escalier')""".toString()) diff --git a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoV3Workflow.groovy b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoV3Workflow.groovy index a81f54306c..18b1cf6f61 100644 --- a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoV3Workflow.groovy +++ b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoV3Workflow.groovy @@ -103,11 +103,11 @@ def filterLinkedShapeFiles(def location, float distance, LinkedHashMap inputTabl debug "Loading in the H2GIS database $outputTableName" h2gis_datasource.execute("""DROP TABLE IF EXISTS $outputTableName ; CREATE TABLE $outputTableName as SELECT ID, $formatting_geom, NATURE, LARGEUR, POS_SOL, SENS, - IMPORTANCE, CL_ADMIN, NAT_RESTR FROM ${inputTables.troncon_de_route} + IMPORTANCE, CL_ADMIN, NAT_RESTR, NB_VOIES FROM ${inputTables.troncon_de_route} WHERE the_geom && 'SRID=$sourceSRID;$geomToExtract'::GEOMETRY AND ST_INTERSECTS(the_geom, 'SRID=$sourceSRID;$geomToExtract'::GEOMETRY) AND NATURE NOT IN ('Bac ou liaison maritime', 'Escalier') - """.toString()) + """) } else { throw new Exception("The troncon_de_route table must be provided") } @@ -300,7 +300,7 @@ Integer loadDataFromPostGIS(Object input_database_properties, Object code, Objec if (inputTables.troncon_de_route) { //Extract route def inputTableName = """(SELECT ID, st_setsrid(the_geom, $commune_srid) as the_geom, NATURE, LARGEUR, POS_SOL, - FRANCHISST, SENS, IMPORTANCE, CL_ADMIN, NAT_RESTR FROM ${inputTables.troncon_de_route} + FRANCHISST, SENS, IMPORTANCE, CL_ADMIN, NAT_RESTR, NB_VOIES FROM ${inputTables.troncon_de_route} WHERE st_setsrid(the_geom, $commune_srid) && 'SRID=$commune_srid;$geomToExtract'::GEOMETRY AND ST_INTERSECTS(st_setsrid(the_geom, $commune_srid), 'SRID=$commune_srid;$geomToExtract'::GEOMETRY) AND NATURE NOT IN ('Bac ou liaison maritime', 'Escalier'))""".toString() diff --git a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/InputDataFormatting.groovy b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/InputDataFormatting.groovy index 9b8bef0955..0d4bc7b1db 100644 --- a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/InputDataFormatting.groovy +++ b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/InputDataFormatting.groovy @@ -379,7 +379,7 @@ String formatRoadLayer(JdbcDataSource datasource, String road, String zone = "") datasource.execute(""" DROP TABLE IF EXISTS $outputTableName; CREATE TABLE $outputTableName (THE_GEOM GEOMETRY, id_road serial, ID_SOURCE VARCHAR, WIDTH FLOAT, TYPE VARCHAR, CROSSING VARCHAR(30), - SURFACE VARCHAR, SIDEWALK VARCHAR, MAXSPEED INTEGER, DIRECTION INTEGER, ZINDEX INTEGER); + SURFACE VARCHAR, SIDEWALK VARCHAR, MAXSPEED INTEGER, DIRECTION INTEGER, LANES INTEGER, ZINDEX INTEGER); """) if (road) { def road_types_width = @@ -402,7 +402,7 @@ String formatRoadLayer(JdbcDataSource datasource, String road, String zone = "") "pedestrian" : 3, "service" : 3] if (datasource.hasTable(road)) { - def queryMapper = "SELECT a.ID_SOURCE, a.WIDTH, a.TYPE, a.ZINDEX, a.CROSSING, a.DIRECTION, a.RANK, a.ADMIN_SCALE" + def queryMapper = "SELECT a.ID_SOURCE, a.WIDTH, a.TYPE, a.ZINDEX, a.CROSSING, a.DIRECTION, a.RANK, a.ADMIN_SCALE, a.NB_VOIES" if (zone) { datasource.createSpatialIndex(road, "the_geom") queryMapper += ", ST_CollectionExtract(st_intersection(a.the_geom, b.the_geom), 2) as the_geom " + @@ -557,6 +557,7 @@ String formatRoadLayer(JdbcDataSource datasource, String road, String zone = "") '${qualified_sidewalk}', ${qualified_road_maxspeed}, ${road_sens}, + ${row.'nb_voies'}, ${qualified_road_zindex}) """.toString() } diff --git a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/InputDataLoading.groovy b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/InputDataLoading.groovy index 571fe889d6..eb52f067b1 100644 --- a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/InputDataLoading.groovy +++ b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/InputDataLoading.groovy @@ -85,7 +85,7 @@ def loadV2( String name = layer.getValue() if (name) { if (datasource.hasTable(name)) { - def hasRow = datasource.firstRow("select 1 as id from ${name} limit 1".toString()) + def hasRow = datasource.firstRow("select 1 as id from ${name} limit 1") if (hasRow) { tablesExist.put(layer.key, name) def currentSrid = GeometryTableUtilities.getSRID(con, TableLocation.parse(name, datasource.getDataBaseType())) @@ -133,7 +133,7 @@ def loadV2( datasource.execute("""DROP TABLE IF EXISTS $route; CREATE TABLE $route (THE_GEOM geometry(linestring, $srid), ID varchar, LARGEUR DOUBLE PRECISION, NATURE varchar, POS_SOL integer, FRANCHISST varchar, SENS varchar, - IMPORTANCE VARCHAR, CL_ADMIN VARCHAR);""".toString()) + IMPORTANCE VARCHAR, CL_ADMIN VARCHAR, NB_VOIES INTEGER);""".toString()) } String troncon_voie_ferree = tablesExist.get("troncon_voie_ferree") if (!troncon_voie_ferree) { @@ -234,16 +234,15 @@ def loadV2( datasource.execute(""" DROP TABLE IF EXISTS INPUT_ROAD; CREATE TABLE INPUT_ROAD (THE_GEOM geometry, ID_SOURCE varchar(24), WIDTH DOUBLE PRECISION, TYPE varchar, ZINDEX integer, CROSSING varchar, - DIRECTION varchar, RANK INTEGER, ADMIN_SCALE VARCHAR) + DIRECTION varchar, RANK INTEGER, ADMIN_SCALE VARCHAR, NB_VOIES INTEGER) AS SELECT ST_FORCE2D(ST_MAKEVALID(a.THE_GEOM)) as the_geom, a.ID, a.LARGEUR, a.NATURE, a.POS_SOL, a.FRANCHISST, a.SENS , CASE WHEN a.IMPORTANCE IN ('1', '2', '3', '4', '5') THEN CAST (a.IMPORTANCE AS INTEGER) ELSE NULL END , - a.CL_ADMIN + a.CL_ADMIN, A.NB_VOIES FROM $route a, ZONE_EXTENDED b WHERE a.the_geom && b.the_geom AND ST_INTERSECTS(a.the_geom, b.the_geom) and a.POS_SOL>=0; """.toString()) //5. Prepare the Rail table (from the layer "TRONCON_VOIE_FERREE") that are in the study area (ZONE) - datasource.execute(""" DROP TABLE IF EXISTS INPUT_RAIL; CREATE TABLE INPUT_RAIL (THE_GEOM geometry, ID_SOURCE varchar(24), TYPE varchar, ZINDEX integer, CROSSING varchar, WIDTH DOUBLE PRECISION) @@ -428,7 +427,7 @@ Map loadV3(JdbcDataSource datasource, datasource.execute("""DROP TABLE IF EXISTS $troncon_de_route; CREATE TABLE $troncon_de_route (THE_GEOM geometry(linestring, $srid), ID varchar, LARGEUR DOUBLE PRECISION, NATURE varchar, POS_SOL integer, FRANCHISST varchar, SENS varchar, - IMPORTANCE VARCHAR, CL_ADMIN VARCHAR, NAT_RESTR VARCHAR);""".toString()) + IMPORTANCE VARCHAR, CL_ADMIN VARCHAR, NAT_RESTR VARCHAR, NB_VOIES INTEGER);""".toString()) } String troncon_de_voie_ferree = tablesExist.get("troncon_de_voie_ferree") @@ -562,7 +561,7 @@ Map loadV3(JdbcDataSource datasource, DROP TABLE IF EXISTS INPUT_ROAD; CREATE TABLE INPUT_ROAD (THE_GEOM geometry, ID_SOURCE varchar(24), WIDTH DOUBLE PRECISION, TYPE varchar, ZINDEX integer, CROSSING varchar, DIRECTION varchar, - RANK INTEGER, ADMIN_SCALE VARCHAR) + RANK INTEGER, ADMIN_SCALE VARCHAR, NB_VOIES INTEGER) AS SELECT ST_FORCE2D(a.THE_GEOM) as the_geom, a.ID, a.LARGEUR, CASE WHEN a.NAT_RESTR = 'Piste cyclable' then a.NAT_RESTR else a.NATURE end, CASE WHEN a.POS_SOL='Gué ou radier' THEN 0 ELSE CAST(a.POS_SOL AS INT ) END AS POS_SOL, @@ -574,7 +573,7 @@ Map loadV3(JdbcDataSource datasource, WHEN a.SENS='Sens inverse' THEN 'Inverse' ELSE null END AS SENS, CASE WHEN a.IMPORTANCE IN ('1', '2', '3', '4', '5', '6') THEN CAST (a.IMPORTANCE AS INTEGER) ELSE NULL END , - a.CL_ADMIN + a.CL_ADMIN, a.NB_VOIES FROM $troncon_de_route a, ZONE_EXTENDED b WHERE a.the_geom && b.the_geom AND ST_INTERSECTS(a.the_geom, b.the_geom) and a.POS_SOL not in ('-4' , '-3' ,'-2' ,'-1'); diff --git a/bdtopo/src/test/groovy/org/orbisgis/geoclimate/bdtopo/WorkflowAbstractTest.groovy b/bdtopo/src/test/groovy/org/orbisgis/geoclimate/bdtopo/WorkflowAbstractTest.groovy index f33ce23b18..4f6aeb601e 100644 --- a/bdtopo/src/test/groovy/org/orbisgis/geoclimate/bdtopo/WorkflowAbstractTest.groovy +++ b/bdtopo/src/test/groovy/org/orbisgis/geoclimate/bdtopo/WorkflowAbstractTest.groovy @@ -143,17 +143,17 @@ abstract class WorkflowAbstractTest { assertTrue(h2gis.firstRow("""SELECT count(*) as count from ${tableNames.water} where TYPE is not null;""".toString()).count > 0) //Test vegetation - assertTrue(h2gis.firstRow("""SELECT count(*) as count from ${tableNames.vegetation} where TYPE is not null;""".toString()).count > 0) - assertTrue(h2gis.firstRow("""SELECT count(*) as count from ${tableNames.vegetation} where HEIGHT_CLASS is not null;""".toString()).count > 0) + assertTrue(h2gis.firstRow("""SELECT count(*) as count from ${tableNames.vegetation} where TYPE is not null;""").count > 0) + assertTrue(h2gis.firstRow("""SELECT count(*) as count from ${tableNames.vegetation} where HEIGHT_CLASS is not null;""").count > 0) //Test road - assertTrue(h2gis.firstRow("""SELECT count(*) as count from ${tableNames.road} where TYPE is not null;""".toString()).count > 0) - assertTrue(h2gis.firstRow("""SELECT count(*) as count from ${tableNames.road} where WIDTH is not null or WIDTH>0 ;""".toString()).count > 0) + assertTrue(h2gis.firstRow("""SELECT count(*) as count from ${tableNames.road} where TYPE is not null;""").count > 0) + assertTrue(h2gis.firstRow("""SELECT count(*) as count from ${tableNames.road} where WIDTH is not null or WIDTH>0 ;""").count > 0) //Test road_traffic - assertTrue h2gis.firstRow("select count(*) as count from ${tableNames.road_traffic} where road_type is null".toString()).count == 0 + assertTrue h2gis.firstRow("select count(*) as count from ${tableNames.road_traffic} where road_type is null").count == 0 assertEquals(h2gis.firstRow("""SELECT sum(ST_Length(the_geom)) as road_length from ${tableNames.road} where type not in ('track', 'path', 'cycleway', 'steps');""".toString()).road_length, - h2gis.firstRow("""SELECT sum(ST_Length(the_geom)) as traffic_Length from ${tableNames.road_traffic};""".toString()).traffic_Length) + h2gis.firstRow("""SELECT sum(ST_Length(the_geom)) as traffic_Length from ${tableNames.road_traffic};""").traffic_Length) //Test ground acoustic diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 854bd19899..76e13dd6f9 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,3 +10,4 @@ - Add TARGET landcover production - Force TARGET ROOF fraction to 0.75 when BUILDING fraction is greater than 0.75 - Force TARGET W indicator to the grid resolution +- Add lanes informations on abstract model plus OSM and BDTopo drivers diff --git a/osm/src/main/groovy/org/orbisgis/geoclimate/osm/InputDataFormatting.groovy b/osm/src/main/groovy/org/orbisgis/geoclimate/osm/InputDataFormatting.groovy index f707b603bd..718c48e8dd 100644 --- a/osm/src/main/groovy/org/orbisgis/geoclimate/osm/InputDataFormatting.groovy +++ b/osm/src/main/groovy/org/orbisgis/geoclimate/osm/InputDataFormatting.groovy @@ -294,7 +294,7 @@ String formatRoadLayer( datasource """ DROP TABLE IF EXISTS $outputTableName; CREATE TABLE $outputTableName (THE_GEOM GEOMETRY, id_road serial, ID_SOURCE VARCHAR, WIDTH FLOAT, TYPE VARCHAR, CROSSING VARCHAR(30), - SURFACE VARCHAR, SIDEWALK VARCHAR, MAXSPEED INTEGER, DIRECTION INTEGER, ZINDEX INTEGER); + SURFACE VARCHAR, SIDEWALK VARCHAR, MAXSPEED INTEGER, DIRECTION INTEGER, LANES INTEGER, ZINDEX INTEGER); """.toString() if (road) { //Define the mapping between the values in OSM and those used in the abstract model @@ -416,6 +416,7 @@ String formatRoadLayer( ${singleQuote(sidewalk)}, ${maxspeed_value}, ${direction}, + ${row.'lanes'}, ${zIndex}) """.toString() } diff --git a/osm/src/main/resources/org/orbisgis/geoclimate/osm/roadParams.json b/osm/src/main/resources/org/orbisgis/geoclimate/osm/roadParams.json index 884c3ad33f..57297caee3 100644 --- a/osm/src/main/resources/org/orbisgis/geoclimate/osm/roadParams.json +++ b/osm/src/main/resources/org/orbisgis/geoclimate/osm/roadParams.json @@ -40,6 +40,7 @@ "sidewalk", "layer", "maxspeed", + "lanes", "oneway", "route", "junction", diff --git a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/InputDataFormattingTest.groovy b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/InputDataFormattingTest.groovy index 4505714bb8..252f34e5fa 100644 --- a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/InputDataFormattingTest.groovy +++ b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/InputDataFormattingTest.groovy @@ -107,6 +107,7 @@ class InputDataFormattingTest { assertTrue h2GIS.firstRow("select count(*) as count from ${road} where WIDTH is null".toString()).count == 0 assertTrue h2GIS.firstRow("select count(*) as count from ${road} where WIDTH<=0".toString()).count == 0 assertTrue h2GIS.firstRow("select count(*) as count from ${road} where CROSSING IS NOT NULL".toString()).count == 7 + assertTrue h2GIS.firstRow("select count(*) as count from ${road} where LANES IS NOT NULL".toString()).count == 17 //Rails String rails = OSM.InputDataFormatting.formatRailsLayer(h2GIS, extractData.rail)