-
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #886 from sickelap/more_geocode_providers
more geocode providers, not used yet
- Loading branch information
Showing
31 changed files
with
9,276 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from constance import config as settings | ||
|
||
from .parsers.mapbox import parse as parse_mapbox | ||
from .parsers.nominatim import parse as parse_nominatim | ||
from .parsers.opencage import parse as parse_opencage | ||
from .parsers.photon import parse as parse_photon | ||
from .parsers.tomtom import parse as parse_tomtom | ||
|
||
config = { | ||
"mapbox": { | ||
"geocode_args": {"api_key": settings.MAP_API_KEY}, | ||
"parser": parse_mapbox, | ||
}, | ||
"maptiler": { | ||
"geocode_args": {"api_key": settings.MAP_API_KEY}, | ||
"parser": parse_mapbox, | ||
}, | ||
"tomtom": { | ||
"geocode_args": {"api_key": settings.MAP_API_KEY}, | ||
"parser": parse_tomtom, | ||
}, | ||
"photon": { | ||
"geocode_args": { | ||
"domain": "photon.komoot.io", | ||
}, | ||
"parser": parse_photon, | ||
}, | ||
"nominatim": { | ||
"geocode_args": {"user_agent": "librephotos"}, | ||
"parser": parse_nominatim, | ||
}, | ||
"opencage": { | ||
"geocode_args": { | ||
"api_key": settings.MAP_API_KEY, | ||
}, | ||
"parser": parse_opencage, | ||
}, | ||
} | ||
|
||
|
||
def get_provider_config(provider) -> dict: | ||
if provider not in config: | ||
raise Exception(f"Map provider not found: {provider}.") | ||
return config[provider]["geocode_args"] | ||
|
||
|
||
def get_provider_parser(provider) -> callable: | ||
if provider not in config: | ||
raise Exception(f"Map provider not found: {provider}.") | ||
return config[provider]["parser"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import geopy | ||
from constance import config as site_config | ||
|
||
from .config import get_provider_config, get_provider_parser | ||
|
||
|
||
class Geocode: | ||
def __init__(self, provider): | ||
provider_config = get_provider_config(provider) | ||
self._parser = get_provider_parser(provider) | ||
self._geocoder = geopy.get_geocoder_for_service(provider)(**provider_config) | ||
|
||
def reverse(self, lat: float, lon: float) -> dict: | ||
location = self._geocoder.reverse(f"{lat},{lon}") | ||
return self._parser(location) | ||
|
||
|
||
def reverse_geocode(lat: float, lon: float) -> dict: | ||
return Geocode(site_config.MAP_API_PROVIDER).reverse(lat, lon) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
def parse(location): | ||
context = location.raw["context"] | ||
center = location.raw["center"] | ||
local_name = location.raw["text"] | ||
places = [local_name] + [ | ||
i["text"] for i in context if not i["id"].startswith("post") | ||
] | ||
return { | ||
"features": [{"text": place} for place in places], | ||
"places": places, | ||
"address": location.address, | ||
"center": [center[1], center[0]], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def parse(location): | ||
data = location.raw["address"] | ||
props = [ | ||
"road", | ||
"town", | ||
"neighbourhood", | ||
"suburb", | ||
"hamlet", | ||
"borough", | ||
"city", | ||
"county", | ||
"state", | ||
"country", | ||
] | ||
places = [data[prop] for prop in props if prop in data] | ||
return { | ||
"features": [{"text": place} for place in places], | ||
"places": places, | ||
"address": location.address, | ||
"center": [float(location.raw["lon"]), float(location.raw["lat"])], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
def parse(location): | ||
data = location.raw["components"] | ||
center = location.raw["geometry"] | ||
props = [ | ||
data["_type"], | ||
"road", | ||
"suburb", | ||
"municipality", | ||
"hamlet", | ||
"town" "city", | ||
"borough", | ||
"state", | ||
"county", | ||
"country", | ||
] | ||
places = [data[prop] for prop in props if prop in data] | ||
return { | ||
"features": [{"text": place} for place in places], | ||
"places": places, | ||
"address": location.address, | ||
"center": [center["lat"], center["lng"]], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def parse(location): | ||
data = location.raw["properties"] | ||
props = [ | ||
"street", | ||
"locality", | ||
"district", | ||
"city", | ||
"state", | ||
"country", | ||
] | ||
places = [data[prop] for prop in props if prop in data] | ||
return { | ||
"features": [{"text": place} for place in places], | ||
"places": places, | ||
"address": location.address, | ||
"center": location.raw["geometry"]["coordinates"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from functools import reduce | ||
|
||
|
||
def _dedup(iterable): | ||
unique_items = set() | ||
|
||
def reducer(acc, item): | ||
if item not in unique_items: | ||
unique_items.add(item) | ||
acc.append(item) | ||
return acc | ||
|
||
return reduce(reducer, iterable, []) | ||
|
||
|
||
def parse(location): | ||
data = location.raw["address"] | ||
address = location.address | ||
center = list(map(lambda x: float(x), location.raw["position"].split(","))) | ||
props = [ | ||
"street", | ||
"streetName", | ||
"municipalitySubdivision", | ||
"countrySubdivision", | ||
"countrySecondarySubdivision", | ||
"municipality", | ||
"municipalitySubdivision", | ||
"country", | ||
] | ||
places = _dedup( | ||
[data[prop] for prop in props if prop in data and len(data[prop]) > 2] | ||
) | ||
return { | ||
"features": [{"text": place} for place in places], | ||
"places": places, | ||
"address": address, | ||
"center": center, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
wordcloud_expectation = { | ||
"captions": [ | ||
{"label": "outdoor", "y": 1.9459101490553132}, | ||
{"label": "indoor", "y": 0.6931471805599453}, | ||
{"label": "ticket booth", "y": 0.0}, | ||
{"label": "boardwalk", "y": 0.0}, | ||
{"label": "phone booth", "y": 0.0}, | ||
{"label": "delicatessen", "y": 0.0}, | ||
{"label": "lagoon", "y": 0.0}, | ||
{"label": "tundra", "y": 0.0}, | ||
{"label": "marsh", "y": 0.0}, | ||
{"label": "bakery shop", "y": 0.0}, | ||
{"label": "market outdoor", "y": 0.0}, | ||
{"label": "butchers shop", "y": 0.0}, | ||
{"label": "playground", "y": 0.0}, | ||
{"label": "picnic area", "y": 0.0}, | ||
], | ||
"people": [], | ||
"locations": [ | ||
{"label": "New South Wales", "y": 1.3862943611198906}, | ||
{"label": "Sydney", "y": 1.3862943611198906}, | ||
{"label": "Australia", "y": 1.3862943611198906}, | ||
{"label": "Maroubra", "y": 1.0986122886681098}, | ||
{"label": "Ladakh", "y": 0.6931471805599453}, | ||
{"label": "Leh", "y": 0.6931471805599453}, | ||
{"label": "Berlin", "y": 0.6931471805599453}, | ||
{"label": "Germany", "y": 0.6931471805599453}, | ||
{"label": "India", "y": 0.6931471805599453}, | ||
{"label": "Lakeshore Road", "y": 0.0}, | ||
{"label": "Shachokol", "y": 0.0}, | ||
{"label": "Kreuzberg", "y": 0.0}, | ||
{"label": "Canada", "y": 0.0}, | ||
{"label": "Bondi Beach", "y": 0.0}, | ||
{"label": "Peterborough County", "y": 0.0}, | ||
{"label": "Lakefield", "y": 0.0}, | ||
{"label": "Main Bazaar", "y": 0.0}, | ||
{"label": "Ontario", "y": 0.0}, | ||
{"label": "Chuchat Yakma", "y": 0.0}, | ||
{"label": "Friedrichshain", "y": 0.0}, | ||
{"label": "Beach Road", "y": 0.0}, | ||
{"label": "Fire Route 47", "y": 0.0}, | ||
], | ||
} |
Oops, something went wrong.