Package: rgcosm
RGCosm - Reverse Geocode for OpenStreetmapA Python library for offline reverse geocoding from osm(.pbf) GIS converted to sqlite3 data - based on code fromrgcoms scriptsInstall by:pipinstallrgcomsor from source by:gitclonehttps://github.com/BlackCatDevel0per/rgcosmcdrgcoms
pipinstallbuild
python-mbuildDependenciesosmiumCLISee cli commands by:pythonrgcosm-houtput:usage:rgcosm[-h][-ciCINPUT][-coCOUTPUT][-aiADD_INDEXES][-dbDATABASE][-ltlnLAT_LON][-latLATITUDE][-lonLONGITUDE][-stSEARCH_TAGS][-mtcMIN_TAGS_COUNT][-rdRETRIEVE_DEGREE][-rtROUND_TO]rgcosmcli

optionalarguments:-h,--helpshowthishelpmessageandexit-ciCINPUT,--cinputCINPUTPathtoinputpbffile-coCOUTPUT,--coutputCOUTPUTPathtooutputdbfile-aiADD_INDEXES,--add_indexesADD_INDEXESAddindexesforfastersearchdefault:True-dbDATABASE,--databaseDATABASEPathtodbfile-ltlnLAT_LON,--lat_lonLAT_LONlatitudewithlongitudeseparatedbyspace-latLATITUDE,--latitudeLATITUDElatitude-lonLONGITUDE,--longitudeLONGITUDElongitude-stSEARCH_TAGS,--search_tagsSEARCH_TAGStagstosearch,default:`addr:`-mtcMIN_TAGS_COUNT,--min_tags_countMIN_TAGS_COUNTMinimaltagscount(for`-st/--search_tags`)tofilterresult,default:1-rdRETRIEVE_DEGREE,--retrieve_degreeRETRIEVE_DEGREERetrieveaddresseswithina+/-xdegreerangeoftheoriginalcoordinates,default:0.001-rtROUND_TO,--round_toROUND_TORounddegreetondecimalsafterdot,default:8First 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):pythonrgcosm-cisome-place.osm.pbf-cosome-place.dbThe output file can be x7-13 (for maldives file ~12.74 times) times larger then the source file, for examplemaldivesfile 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=noor--add_indexes=noarg.Adding indexes speedups searching time up to 70 times.Usagefromrgcosmimportget_addressdb_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:fromrgcosmimportget_addressdb_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):fromrgcosmimportRGeocoderdb_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 addressesAdd caching resultsMore speedup conversion & less memory usageAdd some features from other similar libsMore documentation