Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lanes column on road layer #1019

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 " +
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -416,6 +416,7 @@ String formatRoadLayer(
${singleQuote(sidewalk)},
${maxspeed_value},
${direction},
${row.'lanes'},
${zIndex})
""".toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"sidewalk",
"layer",
"maxspeed",
"lanes",
"oneway",
"route",
"junction",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading