Skip to content

Commit

Permalink
apply pre-commit hoops issues
Browse files Browse the repository at this point in the history
  • Loading branch information
joshinils committed Mar 3, 2024
1 parent 655c9a4 commit 0adfa40
Show file tree
Hide file tree
Showing 9 changed files with 1,100 additions and 742 deletions.
18 changes: 9 additions & 9 deletions cycling_quality_index.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ------------------------------------------------------------------------- #
# Cycling Quality Index #
# -------------------------------------------------- #
# Script for processing OSM data to analyse the cycling quality of ways. #
# Download OSM data input from https://overpass-turbo.eu/s/1G3t, #
# save it at data/way_import.geojson and run the script. #
# #
# > version/date: 2024-03-02 #
# ------------------------------------------------------------------------- #
"""
Cycling Quality Index
--------------------------------------------------
Script for processing OSM data to analyse the cycling quality of ways.
Download OSM data input from https://overpass-turbo.eu/s/1G3t,
save it at data/way_import.geojson and run the script.
version/date: 2024-03-02
"""

import imp
import imp
Expand Down
132 changes: 72 additions & 60 deletions helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
from qgis import *
from qgis.core import *
from qgis.PyQt.QtCore import *
from qgis.core import NULL


#derive cycleway and sidewalk attributes mapped on the centerline for transferring them to separate ways
def deriveAttribute(feature, attribute_name, type, side, vartype):
"""
derive cycleway and sidewalk attributes mapped on the centerline for transferring them to separate ways
"""

attribute = NULL
attribute = feature.attribute(str(type) + ':' + str(side) + ':' + str(attribute_name))
if not attribute:
Expand All @@ -23,42 +27,46 @@ def deriveAttribute(feature, attribute_name, type, side, vartype):
attribute = float(attribute)
if vartype == 'str':
attribute = str(attribute)
except:
except TypeError:
attribute = NULL
return(attribute)

return attribute


#derive separation on the side of a specific traffic mode (e.g. foot traffic usually on the right side)
def deriveSeparation(feature, traffic_mode):
"""
derive separation on the side of a specific traffic mode (e.g. foot traffic usually on the right side)
"""

separation = NULL
separation_left = feature.attribute('separation:left')
separation_right = feature.attribute('separation:right')
traffic_mode_left = feature.attribute('traffic_mode:left')
traffic_mode_right = feature.attribute('traffic_mode:right')

#default for the right side: adjacent foot traffic
# default for the right side: adjacent foot traffic
if traffic_mode == 'foot':
if traffic_mode_left == 'foot':
separation = separation_left
if not traffic_mode_right or traffic_mode_right == 'foot':
separation = separation_right

#TODO: Wenn beidseitig gleicher traffic_mode, dann schwächere separation übergeben
# TODO: Wenn beidseitig gleicher traffic_mode, dann schwächere separation übergeben

#default for the left side: adjacent motor vehicle traffic
# default for the left side: adjacent motor vehicle traffic
if traffic_mode == 'motor_vehicle':
if traffic_mode_right in ['motor_vehicle', 'parking', 'psv']:
separation = separation_right
if not traffic_mode_left or traffic_mode_left in ['motor_vehicle', 'parking', 'psv']:
separation = separation_left

return(separation)
return separation



#interpret access tags of a feature to get the access value for a specific traffic mode
def getAccess(feature, access_key):
"""
interpret access tags of a feature to get the access value for a specific traffic mode
"""

access_dict = {
'foot': ['access'],
'vehicle': ['access'],
Expand All @@ -76,51 +84,54 @@ def getAccess(feature, access_key):
for i in range(len(access_dict[access_key])):
if not access_value and feature.fields().indexOf(access_dict[access_key][i]) != -1:
access_value = feature.attribute(access_dict[access_key][i])
return(access_value)



#return a value as a float
def getNumber(value):
if value != NULL:
try:
value = float(value)
except:
value = NULL
return(value)



#if there is a specific delimiter character in a string (like ";" or "|"), return a list of single, non-delimited values (e.g. "asphalt;paving_stones" -> ["asphalt", "paving_stones"])
def getDelimitedValues(value_string, deli_char, var_type):
delimiters = [-1]
for pos, char in enumerate(value_string):
if(char == deli_char):
delimiters.append(pos)
#Start- (oben) und Endpunkte des strings ergänzen zur einfacheren Verarbeitung
delimiters.append(len(value_string))

#einzelne Abbiegespuren in Array speichern und zurückgeben
value_array = []
for i in range(len(delimiters) - 1):
value = value_string[delimiters[i] + 1:delimiters[i + 1]]
if var_type == 'float' or var_type == 'int':
if value == '' or value == NULL:
value = 0
if var_type == 'float':
value_array.append(float(value))
if var_type == 'int':
value_array.append(int(value))
else:
value_array.append(value)
return(value_array)



#from a list of surface values, choose the weakest one
def getWeakestSurfaceValue(value_list):
#surface values in descent order
surface_value_list = ['asphalt', 'paved', 'concrete', 'chipseal', 'metal', 'paving_stones', 'compacted', 'fine_gravel', 'paving_stones', 'concrete:plates', 'bricks', 'sett', 'cobblestone', 'concrete:lanes', 'unpaved', 'wood', 'unhewn_cobblestone', 'ground', 'dirt', 'earth', 'mud', 'gravel', 'pebblestone', 'grass', 'grass_paver', 'stepping_stones', 'woodchips', 'sand', 'rock']
return access_value


def cast_to_float(value):
# return a value as a float
try:
return float(value)
except TypeError:
return None


def get_weakest_surface_value(value_list):
"""
from a list of surface values, choose the weakest one
"""

# surface values in descent order
surface_value_list = [
'asphalt',
'paved',
'concrete',
'chipseal',
'metal',
'paving_stones',
'compacted',
'fine_gravel',
'paving_stones',
'concrete:plates',
'bricks',
'sett',
'cobblestone',
'concrete:lanes',
'unpaved',
'wood',
'unhewn_cobblestone',
'ground',
'dirt',
'earth',
'mud',
'gravel',
'pebblestone',
'grass',
'grass_paver',
'stepping_stones',
'woodchips',
'sand',
'rock'
]

value = NULL
for i in range(len(value_list)):
Expand All @@ -130,13 +141,14 @@ def getWeakestSurfaceValue(value_list):
else:
if surface_value_list.index(value_list[i]) > surface_value_list.index(value):
value = value_list[i]
return(value)

return value


#add a value to a delimited string
def addDelimitedValue(var, value):
"""
add a value to a delimited string
"""
if var:
var += ';'
var += value
return(var)
return var
Loading

0 comments on commit 0adfa40

Please sign in to comment.