diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | LICENSE | 22 | ||||
-rw-r--r-- | README.md | 7 | ||||
-rwxr-xr-x | osm_where.py | 38 | ||||
-rw-r--r-- | pyproject.toml | 27 |
5 files changed, 98 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a363e1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +cache/ +*.egg-info +build/ +*.whl @@ -0,0 +1,22 @@ +Copyright © 2022 Matěj Cepl, mcepl at cepl dot eu + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..efa3827 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +osm_where +========= + +Simple tool to get [GeoURI](https://geouri.org/) for given +relation referred by the English name. + +Currently defaults to looking at Ukraine. diff --git a/osm_where.py b/osm_where.py new file mode 100755 index 0000000..e0b7022 --- /dev/null +++ b/osm_where.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +import argparse +from OSMPythonTools.overpass import Overpass + +import logging + +logging.getLogger("OSMPythonTools").setLevel(logging.ERROR) + + +def get_URI(name, area, lang): + overpass = Overpass() + + result = overpass.query( + f'area["ISO3166-1"="{area}"][admin_level=2];relation["name:{lang}"="{name}"](area);out center;' + ) + if len(result.elements()) > 0: + bakhmut = result.elements()[0] + return bakhmut.centerLat(), bakhmut.centerLon() + else: + return None + + +def main(): + parser = argparse.ArgumentParser( + prog="osm_where", description="Get geo: URI for given locality from OSM" + ) + parser.add_argument("name") + parser.add_argument("-a", "--area", default="UA", help="ISO 3166 area code") + parser.add_argument("-l", "--lang", default="en", help="ISO 639-1 language code") + args = parser.parse_args() + + geo = get_URI(args.name, args.area, args.lang) + if geo: + print(f"geo:{geo[0]},{geo[1]}") + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7b190cb --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,27 @@ +[project] +name = "osm_where" +description = "Get geo: URI for given locality from OSM" +version = "0.1.0" +requires-python = ">=3.6" +authors = [ + { name = "Matěj Cepl", email = "mcepl@cepl.eu" } +] +license = { file="LICENSE" } +readme = "README.md" +dependencies = [ + "OSMPythonTools", +] +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering :: GIS", + "Environment :: Console", +] + +[project.scripts] +osm_where = "osm_where:main" + +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" |