zele-utils/functions/network.py
2024-09-11 10:56:17 -04:00

32 lines
1.0 KiB
Python

from bs4 import BeautifulSoup
import pandas,pyproj, re
from shapely.geometry import Point
def process_nodes(data):
ELEMENT_LIST = []
elements = BeautifulSoup(data,'lxml-xml')
for element in elements.find_all("node"):
ELEMENT_LIST.append(dict(element.attrs))
return pandas.DataFrame(ELEMENT_LIST)
def process_links(data):
ELEMENT_LIST = []
elements = BeautifulSoup(data,'lxml-xml')
for element in elements.find_all("link"):
ELEMENT_LIST.append(dict(element.attrs))
return pandas.DataFrame(ELEMENT_LIST)
def process_links_attr(data):
ELEMENT_LIST = []
elements = BeautifulSoup(data,'lxml-xml')
for element in elements.find_all("link"):
ELEMENT_DICT = {}
if element.find_all("attribute"):
for attr in element.find_all("attribute"):
ELEMENT_DICT.update({attr["name"]: attr.get_text()})
else:
continue
ELEMENT_DICT["id"]=element.getattr("id")
ELEMENT_LIST.append(ELEMENT_DICT)
return pandas.DataFrame(ELEMENT_LIST)