RGCosm - Reverse Geocode for OpenStreetmap
A Python library for offline reverse geocoding from osm(.pbf) GIS converted to sqlite3 data - based on code from rgcoms scripts
Install by:
pip install rgcoms
or from source by:
git clone https://github.com/BlackCatDevel0per/rgcosm
cd rgcoms
pip install build
python -m build
Dependencies
- osmium
CLI
See cli commands by:
python rgcosm -h
output:
usage: rgcosm [-h] [-ci CINPUT] [-co COUTPUT] [-ai ADD_INDEXES] [-db DATABASE]
[-ltln LAT_LON] [-lat LATITUDE] [-lon LONGITUDE] [-st SEARCH_TAGS]
[-mtc MIN_TAGS_COUNT] [-rd RETRIEVE_DEGREE] [-rt ROUND_TO]
rgcosm cli
optional arguments:
-h, --help show this help message and exit
-ci CINPUT, --cinput CINPUT
Path to input pbf file
-co COUTPUT, --coutput COUTPUT
Path to output db file
-ai ADD_INDEXES, --add_indexes ADD_INDEXES
Add indexes for faster search default: True
-db DATABASE, --database DATABASE
Path to db file
-ltln LAT_LON, --lat_lon LAT_LON
latitude with longitude separated by space
-lat LATITUDE, --latitude LATITUDE
latitude
-lon LONGITUDE, --longitude LONGITUDE
longitude
-st SEARCH_TAGS, --search_tags SEARCH_TAGS
tags to search, default: `addr:`
-mtc MIN_TAGS_COUNT, --min_tags_count MIN_TAGS_COUNT
Minimal tags count (for `-st/--search_tags`) to filter result,
default: 1
-rd RETRIEVE_DEGREE, --retrieve_degree RETRIEVE_DEGREE
Retrieve addresses within a +/- x degree range of the original
coordinates, default: 0.001
-rt ROUND_TO, --round_to ROUND_TO
Round degree to n decimals after dot, default: 8
First convert downloaded osm(.pbf) files from:
https://download.geofabrik.de/
Then use cli to create the database (speedupped by using db in ram & dump in to disk):
python rgcosm -ci some-place.osm.pbf -co some-place.db
The output file can be x7-13 (for maldives file ~12.74 times) times larger then the source file, for example maldives file size is 2.7 mb, and after conversion size increased to 34.4 mb (time: ~14 sec.) with added indexes and 20.1 mb without (time: ~13 sec.).
You can disable adding indexes by -ai=no or --add_indexes=no arg.
Adding indexes speedups searching time up to 70 times.
Usage
from rgcosm import get_address
db_path = 'maldives-latest.db'
coordinates = (6.5506617, 72.9530232)
addr = get_address(db_path, coordinates)
print(addr)
result:
[{'id': 9508099415, 'lat': 6.5506617, 'lon': 72.9530232, 'tags': {'addr:block_number': '26', 'generator:method': 'combustion', 'generator:output:electricity': '200 kV', 'generator:source': 'diesel', 'name': 'Vaikaradhoo Fenaka Power Plant 3', 'operator': 'Fenaka Corporation Limited Vaikaradhoo', 'power': 'generator'}}]
or with multiple coordinates:
from rgcosm import get_address
db_path = 'maldives-latest.db'
coordinates = [(6.5506617, 72.9530232), (4.172474, 73.5083067), (4.1718557, 73.5154427)]
addr = get_address(db_path, coordinates)
print(addr)
result:
[{'id': 9508099415, 'lat': 6.5506617, 'lon': 72.9530232, 'tags': {'addr:block_number': '26', 'generator:method': 'combustion', 'generator:output:electricity': '200 kV', 'generator:source': 'diesel', 'name': 'Vaikaradhoo Fenaka Power Plant 3', 'operator': 'Fenaka Corporation Limited Vaikaradhoo', 'power': 'generator'}}, {'id': 2521220337, 'lat': 4.172474, 'lon': 73.5083067, 'tags': {'addr:city': "Male'", 'addr:housename': 'Ma.Seventy Flower', 'addr:street': 'Iskandharu Magu', 'amenity': 'cafe', 'cuisine': 'coffee_shop', 'internet_access': 'yes', 'name': "Chili's Café"}}, {'id': 7987147424, 'lat': 4.1718557, 'lon': 73.5154427, 'tags': {'addr:city': "Male'", 'addr:housenumber': 'H.Hostside', 'addr:postcode': '20053', 'addr:street': 'Irudheymaa Hingun', 'clothes': 'women;wedding;men;suits;fashion;children', 'contact:facebook': 'https://m.facebook.com/Aiccet/', 'currency:EUR': 'yes', 'currency:GBP': 'yes', 'currency:USD': 'yes', 'name': 'Aiccet', 'opening_hours': '24/7', 'operator': 'Aiccet', 'payment:american_express': 'yes', 'payment:cash': 'yes', 'payment:credit_cards': 'yes', 'payment:mastercard': 'yes', 'payment:visa': 'yes', 'payment:visa_debit': 'yes', 'phone': '+960 7997323', 'shop': 'clothes'}}]
Advanced (for keep connection to db):
from rgcosm import RGeocoder
db_path = 'maldives-latest.db'
geo = RGeocoder(db_path)
coordinates = [(4.1758869, 73.5094013), (-0.6699146, 73.1228688), (5.159217, 73.1312907)]
addrs = geo.locate(coordinates, 'addr:', 1)
print(addrs)
result:
[{'id': 10300135473, 'lat': 4.1758869, 'lon': 73.5094013, 'tags': {'addr:city': "Male'", 'email': 'silverlinehotelsupplier@gmail.com', 'name': 'Silverline Hotel Supplies', 'office': 'company', 'phone': '732-9577', 'website': 'http://www.silverlineenterprise.com/'}}, {'id': 9446166886, 'lat': -0.6699146, 'lon': 73.1228688, 'tags': {'addr:city': 'Addu City', 'addr:housenumber': 'Mushkuraanaage', 'addr:postcode': '19030', 'addr:street': 'Dhandivara Maga'}}, {'id': 8439302155, 'lat': 5.159217, 'lon': 73.1312907, 'tags': {'addr:city': 'Dharavandhoo', 'addr:postcode': '06060', 'amenity': 'courthouse', 'name': 'Dharavandhoo Magistrate Court', 'opening_hours': 'Sa-Th 08:00-14:00', 'operator': 'Government of Maldives'}}]
In plans:
- db serializing with lz4 compression & etc.
- Add more formats for addresses
- Add caching results
- More speedup conversion & less memory usage
- Add some features from other similar libs
- More documentation
Metadata
Release files for rgcosm 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rgcosm-0.1.2.tar.gz | 10.9 kB | Without provenance | Details for rgcosm-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rgcosm-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for rgcosm-0.1.2-py3-none-any.whl |
Total release size: 22.8 kB
Release files / rgcosm-0.1.2.tar.gz
| Download URL | rgcosm-0.1.2.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea43f6f1730ef6857eef0ea8f83c321da7f208e1806a70b22bbb56b715d811eb
|
|
BLAKE2b-256 checksum How to use checksums |
a8cb6e1f79a09d1e80bf73e48f746ef60307cc55aadd8af4c777494c7a902543
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / rgcosm-0.1.2-py3-none-any.whl
| Download URL | rgcosm-0.1.2-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e984fee828a74c1d05dd16183b1b4da95de3f1f1a12f573a811af1fac370686
|
|
BLAKE2b-256 checksum How to use checksums |
6472a701e14f9f048082aa5e3d5f3fb340220739816427bdfc67d312d284e71b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for rgcosm 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.