Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
an OSM way element
Returns
-------
dict
"""
path = {}
path['osmid'] = element['id']
# remove any consecutive duplicate elements in the list of nodes
grouped_list = groupby(element['nodes'])
path['nodes'] = [group[0] for group in grouped_list]
if 'tags' in element:
for useful_tag in settings.useful_tags_path:
if useful_tag in element['tags']:
path[useful_tag] = element['tags'][useful_tag]
return path
level : int
one of the logger.level constants
name : string
name of the logger
filename : string
name of the log file
Returns
-------
logger.logger
"""
if level is None:
level = settings.log_level
if name is None:
name = settings.log_name
if filename is None:
filename = settings.log_filename
logger = lg.getLogger(name)
# if a logger with this name is not already set up
if not getattr(logger, 'handler_set', None):
# get today's date and construct a log filename
todays_date = dt.datetime.today().strftime('%Y_%m_%d')
log_filename = os.path.join(settings.logs_folder, '{}_{}.log'.format(filename, todays_date))
# if the logs folder does not already exist, create it
if not os.path.exists(settings.logs_folder):
os.makedirs(settings.logs_folder)
Parameters
----------
gdf : GeoDataFrame
the gdf to be saved
filename : string
what to call the shapefile (file extensions are added automatically)
folder : string
where to save the shapefile, if none, then default folder
Returns
-------
None
"""
if folder is None:
folder = settings.data_folder
if filename is None:
filename = make_shp_filename(gdf.gdf_name)
# give the save folder a filename subfolder to make the full path to the
# files
folder_path = os.path.join(folder, filename)
# make everything but geometry column a string
for col in [c for c in gdf.columns if not c == 'geometry']:
gdf[col] = gdf[col].fillna('').map(make_str)
# if the save folder does not already exist, create it with a filename
# subfolder
if not os.path.exists(folder_path):
os.makedirs(folder_path)
name of the log file
Returns
-------
None
"""
if level is None:
level = settings.log_level
if name is None:
name = settings.log_name
if filename is None:
filename = settings.log_filename
# if logging to file is turned on
if settings.log_file:
# get the current logger (or create a new one, if none), then log
# message at requested level
logger = get_logger(level=level, name=name, filename=filename)
if level == lg.DEBUG:
logger.debug(message)
elif level == lg.INFO:
logger.info(message)
elif level == lg.WARNING:
logger.warning(message)
elif level == lg.ERROR:
logger.error(message)
# if logging to console is turned on, convert message to ascii and print to
# the console
if settings.log_console:
# capture current stdout, then switch it to the console, print the
name = settings.log_name
if filename is None:
filename = settings.log_filename
logger = lg.getLogger(name)
# if a logger with this name is not already set up
if not getattr(logger, 'handler_set', None):
# get today's date and construct a log filename
todays_date = dt.datetime.today().strftime('%Y_%m_%d')
log_filename = os.path.join(settings.logs_folder, '{}_{}.log'.format(filename, todays_date))
# if the logs folder does not already exist, create it
if not os.path.exists(settings.logs_folder):
os.makedirs(settings.logs_folder)
# create file handler and log formatter and set them up
handler = lg.FileHandler(log_filename, encoding='utf-8')
formatter = lg.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(level)
logger.handler_set = True
return logger
message : string
the content of the message to log
level : int
one of the logger.level constants
name : string
name of the logger
filename : string
name of the log file
Returns
-------
None
"""
if level is None:
level = settings.log_level
if name is None:
name = settings.log_name
if filename is None:
filename = settings.log_filename
# if logging to file is turned on
if settings.log_file:
# get the current logger (or create a new one, if none), then log
# message at requested level
logger = get_logger(level=level, name=name, filename=filename)
if level == lg.DEBUG:
logger.debug(message)
elif level == lg.INFO:
logger.info(message)
elif level == lg.WARNING:
logger.warning(message)
log_level=settings.log_level,
log_name=settings.log_name,
log_filename=settings.log_filename,
useful_tags_node=settings.useful_tags_node,
useful_tags_path=settings.useful_tags_path,
osm_xml_node_attrs=settings.osm_xml_node_attrs,
osm_xml_node_tags=settings.osm_xml_node_tags,
osm_xml_way_attrs=settings.osm_xml_way_attrs,
osm_xml_way_tags=settings.osm_xml_way_tags,
default_access=settings.default_access,
default_crs=settings.default_crs,
default_user_agent=settings.default_user_agent,
default_referer=settings.default_referer,
default_accept_language=settings.default_accept_language,
nominatim_endpoint=settings.nominatim_endpoint,
nominatim_key=settings.nominatim_key,
overpass_endpoint=settings.overpass_endpoint):
"""
Configure osmnx by setting the default global vars to desired values.
Parameters
---------
data_folder : string
where to save and load data files
logs_folder : string
where to write the log files
imgs_folder : string
where to save figures
cache_folder : string
where to save the http response cache
use_cache : bool
if True, use a local cache to save/retrieve http responses instead of
def config(data_folder=settings.data_folder,
logs_folder=settings.logs_folder,
imgs_folder=settings.imgs_folder,
cache_folder=settings.cache_folder,
use_cache=settings.use_cache,
log_file=settings.log_file,
log_console=settings.log_console,
log_level=settings.log_level,
log_name=settings.log_name,
log_filename=settings.log_filename,
useful_tags_node=settings.useful_tags_node,
useful_tags_path=settings.useful_tags_path,
osm_xml_node_attrs=settings.osm_xml_node_attrs,
osm_xml_node_tags=settings.osm_xml_node_tags,
osm_xml_way_attrs=settings.osm_xml_way_attrs,
osm_xml_way_tags=settings.osm_xml_way_tags,
default_access=settings.default_access,