How is geograpy3 determining locations from text? #61
-
I have an example text string that I'm running as follows:
The result is: When I expected just the countries as named in the text (e.g. Egypt, Russia, India and Uzbekistan). Why is this happening? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There might be places in the US, Australia and Moldova that are named "Egypt", "Russia", "India" or "Uzbekistan". select * from city_labels where label in ("Russia") will return
You might want to be more specific and use the locator interface instead and explicitly look for the country information. The get_place_context is outdated and doesn't have this capability. OSMPythonTools.nominatim is also an excellent option. from geograpy.locator import LocationContext
from OSMPythonTools.nominatim import Nominatim
import os
import logging
class LocationLookup:
def __init__(self):
'''
Constructor
'''
cacheRootDir="cache"
cacheDir=f"{cacheRootDir}/.nominatim"
if not os.path.exists(cacheDir):
os.makedirs(cacheDir)
self.nominatim = Nominatim(cacheDir=cacheDir)
logging.getLogger('OSMPythonTools').setLevel(logging.ERROR)
def lookupNominatim(self,locationText:str):
location=None
nresult=self.nominatim.query(locationText,params={"extratags":"1"})
nlod=nresult._json
if len(nlod)>0:
nrecord=nlod[0]
if "extratags" in nrecord:
extratags=nrecord["extratags"]
if "wikidata" in extratags:
wikidataID=extratags["wikidata"]
location=self.getCityByWikiDataId(wikidataID)
return location |
Beta Was this translation helpful? Give feedback.
There might be places in the US, Australia and Moldova that are named "Egypt", "Russia", "India" or "Uzbekistan".
E.g.
will return
You might want to be more specific and use the locator interface instead and explicitly look for the country information. The get_place_context is outdated and doesn't have this capability.
OSMPythonTools.nominatim is also an excellent option.
see https://github.com/WolfgangFahl/ConferenceCor…