diff --git a/.gitignore b/.gitignore index 741160e..b1a0129 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,136 @@ *.vscode/* +*.pyc + +# Byte-compiled / optimized / DLL files *__pycache__/* -*.pyc \ No newline at end of file +*.py[cod] +*$py.class + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +sources/* +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. \ No newline at end of file diff --git a/README.rst b/README.rst index 436d18c..70a934d 100644 --- a/README.rst +++ b/README.rst @@ -17,9 +17,9 @@ and applications on traffic modeling. Publication ==================================== -Lu, J., & Zhou, X.S. (2023). Virtual track networks: A hierarchical modeling framework and -open-source tools for simplified and efficient connected and automated mobility (CAM) system -design based on general modeling network specification (GMNS). Transportation Research +Lu, J., & Zhou, X.S. (2023). Virtual track networks: A hierarchical modeling framework and +open-source tools for simplified and efficient connected and automated mobility (CAM) system +design based on general modeling network specification (GMNS). Transportation Research Part C: Emerging Technologies, 153, 104223. `paper link`_ @@ -88,10 +88,35 @@ You can use the following code to get the relation id of a place of interest and # e.g. "Tempe, Arizona, United States" # e.g. "Arizona, US" # e.g. "Beijing Jiaotong University, Beijing, China" - >>> rel = og.OSM_RelationID_Finder('Arizona State University') + >>> rel_id = og.getOSMRelationID('Arizona State University') + >>> rel_id + Info: Found relation id 3444656 from web + Info: location of the place of interest: + { + "place_id": 318528634, + "licence": "Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright", + "osm_type": "relation", + "osm_id": 3444656, + "lat": "33.4213174", + "lon": "-111.93316305413154", + "class": "amenity", + "type": "university", + "place_rank": 30, + "importance": 0.5547365758311374, + "addresstype": "amenity", + "name": "Arizona State University", + "display_name": "Arizona State University, 1151, South Forest Avenue, Tempe Junction, Tempe, Maricopa County, Arizona, 85281, United States", + "boundingbox": [ + "33.4102062", + "33.4329786", + "-111.9411651", + "-111.9092447" + ] + } + 3444656 # download the corresponding osm file - >>> og.downloadOSMdata(rel.rel_id, 'asu.osm') + >>> og.downloadOSMData(rel_id, 'asu.osm') Visualization diff --git a/osm2gmns/func_lib/global_rel_id.json b/dependencies/global_rel_id.json similarity index 100% rename from osm2gmns/func_lib/global_rel_id.json rename to dependencies/global_rel_id.json diff --git a/docs/source/acknowledgement.rst b/docs/source/acknowledgement.rst index 3f730c0..704b194 100644 --- a/docs/source/acknowledgement.rst +++ b/docs/source/acknowledgement.rst @@ -7,11 +7,11 @@ Grant No. CMMI 1663657 "Collaborative Research: Real-time Management of Large Fl Self-Driving Vehicles Using Virtual CyberTracks" The second author also thanks for the early support from FHWA project titled "The Effective -Integration of Analysis, Modeling, and Simulation Tools - AMS Data hub Concept of Opeartions". +Integration of Analysis, Modeling, and Simulation Tools - AMS Data hub Concept of Operations". https://www.fhwa.dot.gov/publications/research/operations/13036/004.cfm -Many thanks for GMNS specification efforts led by Scott Smith and Ian Berg from Volpe Center, -USDOT. Their TRB poster can be found at https://github.com/zephyr-data-specs/GMNS/blob/TRB/TRBPoster_22-02127.pdf +Many thanks for GMNS specification efforts led by Scott Smith and Ian Berg from Volpe Center, +USDOT. Their TRB poster can be found at https://github.com/zephyr-data-specs/GMNS/blob/TRB/TRBPoster_22-02127.pdf This document is prepared with the help from `Entai Wang`_ and `Chongnan Li`_. diff --git a/docs/source/conf.py b/docs/source/conf.py index 87590f3..210261f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -23,11 +23,11 @@ # -- Project information ----------------------------------------------------- project = 'osm2gmns' -copyright = '2020-2022, Jiawei Lu, Xuesong (Simon) Zhou' -author = 'Jiawei Lu, Xuesong (Simon) Zhou' +copyright = '2020-, Jiawei Lu, Xiangyong Luo, Xuesong (Simon) Zhou' +author = 'Jiawei Lu, Xiangyong Luo, Xuesong (Simon) Zhou' # The full version, including alpha/beta/rc tags -release = '0.7.3' +release = '0.7.4' # -- General configuration --------------------------------------------------- diff --git a/docs/source/quick-start.rst b/docs/source/quick-start.rst index 0374b0a..01355a3 100644 --- a/docs/source/quick-start.rst +++ b/docs/source/quick-start.rst @@ -14,6 +14,47 @@ osm files to extract useful network information. As a result, the first step is Thanks to the open-source nature of OpenStreetMap, there are lots of APIs and mirror sites that we can use to download osm map data. We list several popular sites here for users to choose. +0) osm2gmns built-in class: OSM_RelationID_Finder +Get the relation id of a place of interest, eg. "Arizona State University", "Arizona, United States", "Tempe, AZ"... + +-- code-block:: python + + >>> import osm2gmns as og + # get relation id of a place of interest + # For the place of interest, e.g. Arizona State University + # e.g. "Tempe, Arizona, United States" + # e.g. "Arizona, US" + # e.g. "Beijing Jiaotong University, Beijing, China" + >>> rel_id = og.getOSMRelationID('Arizona State University') + >>> rel_id + Info: Found relation id 3444656 from web + Info: location of the place of interest: + { + "place_id": 318528634, + "licence": "Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright", + "osm_type": "relation", + "osm_id": 3444656, + "lat": "33.4213174", + "lon": "-111.93316305413154", + "class": "amenity", + "type": "university", + "place_rank": 30, + "importance": 0.5547365758311374, + "addresstype": "amenity", + "name": "Arizona State University", + "display_name": "Arizona State University, 1151, South Forest Avenue, Tempe Junction, Tempe, Maricopa County, Arizona, 85281, United States", + "boundingbox": [ + "33.4102062", + "33.4329786", + "-111.9411651", + "-111.9092447" + ] + } + 3444656 + + # download the corresponding osm file + >>> og.downloadOSMData(rel_id, 'asu.osm') + 1) OpenStreetMap Homepage @@ -180,7 +221,7 @@ Consolidate Intersections ========================= In OpenStreetMap, one large intersection is often represented by multiple nodes. This structure brings some -difficulties when performing traffic-oriented modelings. osm2gmns enables users to consolidate intersections +difficulties when performing traffic-oriented modelings. osm2gmns enables users to consolidate intersections that are originally represented by multiple nodes into a single node. Note that osm2gmns only identifies and consolidates signalized intersections. @@ -197,9 +238,9 @@ consolidates signalized intersections. Complex intersection consolidation -Users can visualize the consolidated network in `QGIS`_ or `NeXTA`_. -For complex interestions that were not successfully identified and consolidated by osm2gmns, users can manually specify -them by revising the column "intersection_id" in node.csv and utilize the commands below to do the re-consolidation. +Users can visualize the consolidated network in `QGIS`_ or `NeXTA`_. +For complex interestions that were not successfully identified and consolidated by osm2gmns, users can manually specify +them by revising the column "intersection_id" in node.csv and utilize the commands below to do the re-consolidation. Nodes assgined with the same "intersection_id" will be consolidated into a new node. .. code-block:: python diff --git a/osm2gmns/__init__.py b/osm2gmns/__init__.py index be172da..48ce719 100644 --- a/osm2gmns/__init__.py +++ b/osm2gmns/__init__.py @@ -10,13 +10,32 @@ from osm2gmns.io.downloader import downloadOSMData from osm2gmns.io.writefile import outputNetToCSV from osm2gmns.utils.util import config -from osm2gmns.func_lib.extract_relation_id import OSM_RelationID_Finder +from osm2gmns.func_lib.extract_relation_id import getOSMRelationID import osm2gmns.settings as og_settings -__version__ = '0.7.3' +__version__ = '0.7.4' print(f'osm2gmns, {__version__}') +__all__ = [ + 'getNetFromFile', + 'combineShortLinks', + 'consolidateComplexIntersections', + 'generateNodeActivityInfo', + 'generateLinkVDFInfo', + 'connectPOIWithNet', + 'show', + 'saveFig', + 'generateMovements', + 'buildMultiResolutionNets', + 'loadNetFromCSV', + 'downloadOSMData', + 'outputNetToCSV', + 'config', + 'getOSMRelationID', + 'og_settings' +] + # todo: railway allowed_use diff --git a/osm2gmns/func_lib/__init__.py b/osm2gmns/func_lib/__init__.py index f9a6100..4784171 100644 --- a/osm2gmns/func_lib/__init__.py +++ b/osm2gmns/func_lib/__init__.py @@ -6,4 +6,7 @@ ############################################################## # Please note, -# All countries, states, and cities in global_rel_id.json file are from https://github.com/dr5hn/countries-states-cities-database/tree/master \ No newline at end of file +# All countries, states, and cities in global_rel_id.json file are from https://github.com/dr5hn/countries-states-cities-database/tree/master +from .extract_relation_id import getOSMRelationID + +__all__ = ['getOSMRelationID'] \ No newline at end of file diff --git a/osm2gmns/func_lib/extract_relation_id.py b/osm2gmns/func_lib/extract_relation_id.py index ddb22f6..a5b86a3 100644 --- a/osm2gmns/func_lib/extract_relation_id.py +++ b/osm2gmns/func_lib/extract_relation_id.py @@ -14,33 +14,69 @@ from pathlib import Path -class OSM_RelationID_Finder: +class OSMRelationIDFinder: """A class to find the osm relation id of a place of interest globally Use the Nominatim API to find the relation id of a place of interest + + Args: + poi_name (str): the name of the place of interest, + e.g., "Arizona State University" + e.g., "Tempe, Arizona, USA" + e.g., "Arizona, USA" + + Example: + >>> import osm2gmns as og + >>> rel = og.OSM_RelationID_Finder("Arizona State University") + >>> rel.rel_id + Info: Found relation id 3444656 from web + Info: location of the place of interest: + { + "place_id": 318528634, + "licence": "Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright", + "osm_type": "relation", + "osm_id": 3444656, + "lat": "33.4213174", + "lon": "-111.93316305413154", + "class": "amenity", + "type": "university", + "place_rank": 30, + "importance": 0.5547365758311374, + "addresstype": "amenity", + "name": "Arizona State University", + "display_name": "Arizona State University, 1151, South Forest Avenue, Tempe Junction, Tempe, Maricopa County, Arizona, 85281, United States", + "boundingbox": [ + "33.4102062", + "33.4329786", + "-111.9411651", + "-111.9092447" + ] + } + 3444656 + + # download the corresponding osm file + >>> og.downloadOSMData(rel.rel_id, 'asu.osm') + """ - def __init__(self, poi_name: str): - """ - Args: - poi_name (str): the name of the place of interest, - e.g., "Arizona State University" - e.g., "Tempe, Arizona, USA" - e.g., "Arizona, USA" - """ - self._poi_name = poi_name - self._url_json = self._get_url_data() + def __init__(self, poi_name: str) -> None: + + self.poi_name = poi_name + self.__url_json = self.__get_url_data() # maximum number of results to show + # if parameter will applied in function rel_id_info + # if the number of results is greater than _max_show, only show the first _max_show results self._max_show = 5 + # TODO: Unable to find the relation id locally, search from the web # the default path to save/load global country, state, and city information - self._path_global_rel_id = self._path2linux(os.path.join( - Path(__file__).resolve().parent, "global_rel_id.json")) + self._path_global_rel_id = self.__path2linux(os.path.join( + Path(__file__).resolve().parent.parent.parent, "dependencies/global_rel_id.json")) - def _get_url_data(self): + def __get_url_data(self) -> dict: # prepare url base_url = 'https://nominatim.openstreetmap.org/search?' - params = {"q": self._poi_name, "format": "json"} + params = {"q": self.poi_name, "format": "json"} url = base_url + urllib.parse.urlencode(params) # get data from url using requests @@ -49,63 +85,87 @@ def _get_url_data(self): return url_json @property - def rel_id(self): + def rel_id(self) -> Union[float, None]: # Three logic to find the relation id - # 1. If relation id exist, return the relation id - # 2. If relation id does not exist, check whether url_json is empty, + # 1. Search from web, if relation id exist, return the relation id + # 2. If relation id does not exist + # check whether url_json (result from web) is empty, # if not, return relation id of the first element # 3. If url_json is empty, Search locally, return None if not found locally - for i in self._url_json: + for i in self.__url_json: if i["osm_type"] == "relation": + print(f" Info: Found relation id {i['osm_id']} from web") + print(" Info: location of the place of interest:") + print(json.dumps(i, indent=4)) return i["osm_id"] if len(self.rel_id_info) > 0: + print(" Info: Could not find relation id directly from web") + print(f" but there is a possible relation id {self.rel_id_info[0]['osm_id']} from web") + print(" or you can find more related ids: rel.rel_id_info") + print(f"Detailed info for {self.rel_id_info[0]['osm_id']}: {json.dumps(self.rel_id_info[0], indent=4)}\n") return self.rel_id_info[0]["osm_id"] - return self._find_local_rel_id() + print(" Info: Could not find relation id from web: https://nominatim.openstreetmap.org/ui/search.html \n") + return self.__find_local_rel_id() @property - def rel_id_info(self): + def rel_id_info(self) -> dict: # show detailed information of the relation id - return self._url_json if len(self._url_json) < self._max_show else self._url_json[:self._max_show] + return self.__url_json if len(self.__url_json) < self._max_show else self.__url_json[:self._max_show] # convert OS path to standard linux path - def _path2linux(self, path: Union[str, Path]) -> str: + def __path2linux(self, path: Union[str, Path]) -> str: """Convert a path to a linux path, linux path can run in windows, linux and mac""" try: return path.replace("\\", "/") except Exception: return str(path).replace("\\", "/") - def _find_local_rel_id(self) -> str: + def __find_local_rel_id(self) -> str: + # sourcery skip: extract-duplicate-method - # Step 0 load the global country, state, and city information locally + # Step 0 load the global country, state, and city information from github try: - with open(self._path_global_rel_id, "r") as f: - self._global_rel_id = json.load(f) + print(" Info: Try to load global_rel_id.json from GitHub\n") + github_url = "https://raw.githubusercontent.com/xyluo25/OSM2GMNS/master/dependencies/global_rel_id.json" + global_rel_id_dict = json.loads(requests.get(github_url).text) except Exception: - github_url = "https://raw.githubusercontent.com/xyluo25/OSM2GMNS/master/osm2gmns/func_lib/global_rel_id.json" - self._global_rel_id = json.loads(requests.get(github_url).text) + # if user can not access the internet, load the local file instead + # please make sure the file exists in the local path + # path: dependencies/global_rel_id.json + print(" Info: Can not load global_rel_id.json from GitHub") + print(f" try to load local file: {self._path_global_rel_id}.\n") + try: + with open(self._path_global_rel_id, "r") as f: + global_rel_id_dict = json.load(f) + except Exception: + print(" Error: Can not load global_rel_id.json from local file\n \ + please make sure the file exists in dependencies/global_rel_id.json \n \ + Please search from https://www.openstreetmap.org/#map=5/40.298/-102.500 \n") + return None # if we can not load dictionary, return None - if not isinstance(self._global_rel_id, dict): + if not isinstance(global_rel_id_dict, dict): + print(" Info: Could not load global_rel_id.json from GitHub.") + print(" Please search from https://www.openstreetmap.org/#map=5/40.298/-102.500 \n") return None - search_name = self._poi_name.split(",")[0].strip() - if search_name == self._poi_name: - search_name = self._poi_name.split(" ")[0].strip() + search_name = self.poi_name.split(",")[0].strip() + if search_name == self.poi_name: + search_name = self.poi_name.split(" ")[0].strip() # Step 1 Find the country start with the input characters - start_with_country = [country_name for country_name in self._global_rel_id["country"].keys( + start_with_country = [country_name for country_name in global_rel_id_dict["country"].keys( ) if country_name.lower().startswith(search_name.lower())][:self._max_show] # Step 2 Find the state start with the input characters - start_with_state = [state_name for state_name in self._global_rel_id["state"].keys( + start_with_state = [state_name for state_name in global_rel_id_dict["state"].keys( ) if state_name.lower().startswith(search_name.lower())][:self._max_show] # Step 3 Find the city start with the input characters - start_with_city = [city_name for city_name in self._global_rel_id["city"].keys( + start_with_city = [city_name for city_name in global_rel_id_dict["city"].keys( ) if city_name.lower().startswith(search_name.lower())][:self._max_show] # Step 4 Format the results @@ -113,29 +173,77 @@ def _find_local_rel_id(self) -> str: if start_with_city: formatted_str += "City:\n" for city_name in start_with_city: - formatted_str += f"""{city_name}, {self._global_rel_id["city"][city_name]["state"]}, {self._global_rel_id["city"][city_name]["country"]}, rel_id: {self._global_rel_id["city"][city_name]["osm_id"]} \n""" + formatted_str += f"""{city_name}, + {global_rel_id_dict["city"][city_name]["state"]}, + {global_rel_id_dict["city"][city_name]["country"]}, + rel_id: {global_rel_id_dict["city"][city_name]["osm_id"]} \n""" if start_with_state: formatted_str += "State:\n" for state_name in start_with_state: - formatted_str += f"""{state_name}, {self._global_rel_id["state"][state_name]["country"]}, rel_id: {self._global_rel_id["state"][state_name]["osm_id"]} \n""" + formatted_str += f"""{state_name}, + {global_rel_id_dict["state"][state_name]["country"]}, + rel_id: {global_rel_id_dict["state"][state_name]["osm_id"]} \n""" if start_with_country: formatted_str += "Country:\n" for country_name in start_with_country: - formatted_str += f"""{country_name}, rel_id: {self._global_rel_id["country"][country_name]["osm_id"]} \n""" + formatted_str += f"""{country_name}, + rel_id: {global_rel_id_dict["country"][country_name]["osm_id"]} \n""" if formatted_str: - formatted_str = f"""Info:\nWe can not search rel_id from web with place of interest: {self._poi_name} \nSearch locally with country, state and city startswith {search_name}:\n""" + formatted_str + formatted_str = f"""Info:\nWe can not search rel_id from web with place of interest: {self.poi_name} \n \ + Search locally with country, state and city startswith {search_name}:\n""" + formatted_str formatted_str += "You can replace your place of interest with local results above to get the rel_id\n" print(formatted_str) + print(" Info: Could not load global_rel_id.json locally") + print(" Please search from https://www.openstreetmap.org/#map=5/40.298/-102.500 \n") return None -if __name__ == "__main__": - - rel = OSM_RelationID_Finder("tempe, arizona, usa") - print(rel.rel_id) +def getOSMRelationID(poi_name: str) -> Union[float, None]: + """Get the relation id of a place of interest globally + + Args: + poi_name (str): the name of the place of interest, + e.g., "Arizona State University" + e.g., "Tempe, Arizona, USA" + e.g., "Arizona, USA" + + Returns: + Union[float, None]: the relation id of the place of interest, if not found, return None + + Example: + >>> import osm2gmns as og + >>> rel = og.getOSMRelationID("Arizona State University") + >>> rel + Info: Found relation id 3444656 from web + Info: location of the place of interest: + { + "place_id": 318528634, + "licence": "Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright", + "osm_type": "relation", + "osm_id": 3444656, + "lat": "33.4213174", + "lon": "-111.93316305413154", + "class": "amenity", + "type": "university", + "place_rank": 30, + "importance": 0.5547365758311374, + "addresstype": "amenity", + "name": "Arizona State University", + "display_name": "Arizona State University, 1151, South Forest Avenue, Tempe Junction, Tempe, Maricopa County, Arizona, 85281, United States", + "boundingbox": [ + "33.4102062", + "33.4329786", + "-111.9411651", + "-111.9092447" + ] + } + 3444656 + """ + rel = OSMRelationIDFinder(poi_name) + return rel.rel_id \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b141ff6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +matplotlib==3.7.2 +numpy==1.24.3 +osmium==3.7.0 +Requests==2.31.0 +Shapely==2.0.2 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7010bbd --- /dev/null +++ b/setup.py @@ -0,0 +1,17 @@ +import setuptools + +setuptools.setup( + name='osm2gmns', + version='0.7.4', + author='Jiawei Lu, Xuesong Zhou', + author_email='jiaweil9@asu.edu, xzhou74@asu.edu', + url='https://github.com/jiawlu/OSM2GMNS', + description='convert map data from OpenStreetMap to network files in GMNS format', + long_description=open('README_pypi.rst').read(), + license='GPLv3+', + packages=setuptools.find_packages(), + python_requires=">=3.6.0", + install_requires=['shapely >= 2.0.1', 'osmium >= 3.1.3', 'numpy'], + classifiers=['License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', + 'Programming Language :: Python :: 3'] +) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..ae65ced --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,8 @@ +# -*- coding:utf-8 -*- +############################################################## +# Created Date: Sunday, February 4th 2024 +# Contact Info: luoxiangyong01@gmail.com +# Author/Copyright: Mr. Xiangyong Luo +############################################################## + + diff --git a/tests/test_relation_id_finder.py b/tests/test_relation_id_finder.py new file mode 100644 index 0000000..475a137 --- /dev/null +++ b/tests/test_relation_id_finder.py @@ -0,0 +1,24 @@ +# -*- coding:utf-8 -*- +############################################################## +# Created Date: Sunday, February 4th 2024 +# Contact Info: luoxiangyong01@gmail.com +# Author/Copyright: Mr. Xiangyong Luo +############################################################## + + +from osm2gmns.func_lib.extract_relation_id import OSM_RelationID_Finder + + +def test_rel_id_web_search_exists(): + + rel_identifier = OSM_RelationID_Finder("Arizona State University") + rel_id = rel_identifier.rel_id + print(type(rel_id)) + assert isinstance(rel_id, int) + + +def test_rel_id_web_search_not_exists(): + + rel_identifier = OSM_RelationID_Finder("TTTTTTEEEEEESSSSSTTTTT") + rel_id = rel_identifier.rel_id + assert rel_id is None