Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions custom-recipes/forward_geocoding/recipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,37 +200,66 @@
"label" : "Authentication",
"visibilityCondition" : "['baidu', 'bing', 'canadapost', 'gaode', 'geonames', 'google', 'here', 'locationiq', 'mapbox', 'mapquest', 'mapzen', 'opencage', 'tamu', 'tomtom', 'w3w'].indexOf(model.provider) >= 0"
},
{
"name": "use_preset",
"label" : "Use preset",
"type": "BOOLEAN",
"mandatory": false,
"description":"Get the authentication parameters from a shared configuration in DSS.",
"visibilityCondition" : "['baidu', 'bing', 'canadapost', 'gaode', 'geonames', 'google', 'here', 'locationiq', 'mapbox', 'mapquest', 'mapzen', 'opencage', 'tamu', 'tomtom', 'w3w'].indexOf(model.provider) >= 0"
},
{
"name": "api_key_preset",
"label": "Geocoder Api Key Preset",
"type": "PRESET",
"parameterSetId": "geocoder_api_key",
"visibilityCondition": "['baidu', 'bing', 'canadapost', 'gaode', 'geonames', 'locationiq', 'mapbox', 'mapquest', 'mapzen', 'opencage', 'tamu', 'tomtom', 'w3w'].indexOf(model.provider) >= 0 && model.use_preset == true"
},
{
"name": "google_geocoder_preset",
"label": "Geocoder Api Key Preset",
"type": "PRESET",
"parameterSetId": "google_geocoder_auth",
"visibilityCondition": "model.provider === 'google' && model.use_preset == true"
},
{
"name": "here_geocoder_preset",
"label": "Geocoder Api Key Preset",
"type": "PRESET",
"parameterSetId": "here_geocoder_auth",
"visibilityCondition": "model.provider === 'here' && model.use_preset == true"
},
{
"name": "api_key",
"type": "STRING",
"type": "PASSWORD",
"label" : "API key",
"visibilityCondition" : "['baidu', 'bing', 'canadapost', 'gaode', 'geonames', 'google', 'locationiq', 'mapbox', 'mapquest', 'mapzen', 'opencage', 'tamu', 'tomtom', 'w3w'].indexOf(model.provider) >= 0"
"visibilityCondition" : "['baidu', 'bing', 'canadapost', 'gaode', 'geonames', 'google', 'locationiq', 'mapbox', 'mapquest', 'mapzen', 'opencage', 'tamu', 'tomtom', 'w3w'].indexOf(model.provider) >= 0 && model.use_preset == false"
},
{
"name": "here_app_id",
"type": "STRING",
"label" : "HERE App ID",
"visibilityCondition" : "model.provider === 'here'"
"visibilityCondition" : "model.provider === 'here' && model.use_preset == false"
},
{
"name": "here_app_code",
"type": "STRING",
"type": "PASSWORD",
"label" : "HERE App Code",
"visibilityCondition" : "model.provider === 'here'"
"visibilityCondition" : "model.provider === 'here' && model.use_preset == false"
},
{
"name": "google_client",
"type": "STRING",
"label" : "Google client ID",
"description": "Only if using a premium plan - optional otherwise",
"visibilityCondition" : "model.provider === 'google'"
"visibilityCondition" : "model.provider === 'google' && model.use_preset == false"
},
{
"name": "google_client_secret",
"type": "STRING",
"type": "PASSWORD",
"label" : "Google secret",
"description": "Only if using a premium plan - optional otherwise",
"visibilityCondition" : "model.provider === 'google'"
"visibilityCondition" : "model.provider === 'google' && model.use_preset == false"
}
],

Expand Down
45 changes: 37 additions & 8 deletions custom-recipes/reverse_geocoding/recipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,37 +190,66 @@
"label" : "Authentication",
"visibilityCondition" : "['baidu', 'bing', 'canadapost', 'gaode', 'geonames', 'google', 'here', 'locationiq', 'mapbox', 'mapquest', 'mapzen', 'opencage', 'tamu', 'tomtom', 'w3w'].indexOf(model.provider) >= 0"
},
{
"name": "use_preset",
"label" : "Use preset",
"type": "BOOLEAN",
"mandatory": false,
"description":"Get the authentication parameters from a shared configuration in DSS.",
"visibilityCondition" : "['baidu', 'bing', 'canadapost', 'gaode', 'geonames', 'google', 'here', 'locationiq', 'mapbox', 'mapquest', 'mapzen', 'opencage', 'tamu', 'tomtom', 'w3w'].indexOf(model.provider) >= 0"
},
{
"name": "api_key_preset",
"label": "Geocoder Api Key Preset",
"type": "PRESET",
"parameterSetId": "geocoder_api_key",
"visibilityCondition": "['baidu', 'bing', 'canadapost', 'gaode', 'geonames', 'locationiq', 'mapbox', 'mapquest', 'mapzen', 'opencage', 'tamu', 'tomtom', 'w3w'].indexOf(model.provider) >= 0 && model.use_preset == true"
},
{
"name": "google_geocoder_preset",
"label": "Geocoder Api Key Preset",
"type": "PRESET",
"parameterSetId": "google_geocoder_auth",
"visibilityCondition": "model.provider === 'google' && model.use_preset == true"
},
{
"name": "here_geocoder_preset",
"label": "Geocoder Api Key Preset",
"type": "PRESET",
"parameterSetId": "here_geocoder_auth",
"visibilityCondition": "model.provider === 'here' && model.use_preset == true"
},
{
"name": "api_key",
"type": "STRING",
"type": "PASSWORD",
"label" : "API key",
"visibilityCondition" : "['baidu', 'bing', 'canadapost', 'gaode', 'geonames', 'google', 'locationiq', 'mapbox', 'mapquest', 'mapzen', 'opencage', 'tamu', 'tomtom', 'w3w'].indexOf(model.provider) >= 0"
"visibilityCondition" : "['baidu', 'bing', 'canadapost', 'gaode', 'geonames', 'google', 'locationiq', 'mapbox', 'mapquest', 'mapzen', 'opencage', 'tamu', 'tomtom', 'w3w'].indexOf(model.provider) >= 0 && model.use_preset == false"
},
{
"name": "here_app_id",
"type": "STRING",
"label" : "HERE App ID",
"visibilityCondition" : "model.provider === 'here'"
"visibilityCondition" : "model.provider === 'here' && model.use_preset == false"
},
{
"name": "here_app_code",
"type": "STRING",
"type": "PASSWORD",
"label" : "HERE App Code",
"visibilityCondition" : "model.provider === 'here'"
"visibilityCondition" : "model.provider === 'here' && model.use_preset == false"
},
{
"name": "google_client",
"type": "STRING",
"label" : "Google client ID",
"description": "Only if using a premium plan - optional otherwise",
"visibilityCondition" : "model.provider === 'google'"
"visibilityCondition" : "model.provider === 'google' && model.use_preset == false"
},
{
"name": "google_client_secret",
"type": "STRING",
"type": "PASSWORD",
"label" : "Google secret",
"description": "Only if using a premium plan - optional otherwise",
"visibilityCondition" : "model.provider === 'google'"
"visibilityCondition" : "model.provider === 'google' && model.use_preset == false"
}
],

Expand Down
20 changes: 20 additions & 0 deletions parameter-sets/geocoder_api_key/parameter-set.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"meta" : {
"label": "Geocoder Api Key Preset",
"description": "Authentication key for providers: 'Baidu', 'Bing', 'CanadaPost', 'Gaode', 'Geonames', 'LocationIQ', 'Mapbox', 'MapQuest', 'OpenCage', 'Tamu', 'TomTom', 'What3Words'",
"icon": "icon-key"
},
"defaultDefinableInline": true,
"defaultDefinableAtProjectLevel": true,

"pluginParams": [],

"params": [
{
"name": "api_key",
"label": "API key",
"type": "PASSWORD",
"mandatory": true
}
]
}
31 changes: 31 additions & 0 deletions parameter-sets/google_geocoder_auth/parameter-set.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"meta" : {
"label": "Google Geocoder Auth Preset",
"description": "Authentication data for Google provider",
"icon": "icon-map-marker"
},
"defaultDefinableInline": true,
"defaultDefinableAtProjectLevel": true,

"pluginParams": [],

"params": [
{
"name": "api_key",
"label": "API key",
"type": "PASSWORD"
},
{
"name": "google_client",
"type": "STRING",
"label" : "Google client ID",
"description": "Only if using a premium plan - optional otherwise"
},
{
"name": "google_client_secret",
"type": "PASSWORD",
"label" : "Google secret",
"description": "Only if using a premium plan - optional otherwise"
}
]
}
26 changes: 26 additions & 0 deletions parameter-sets/here_geocoder_auth/parameter-set.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"meta" : {
"label": "Here Geocoder Auth Preset",
"description": "Authentication data for HERE provider",
"icon": "icon-map-marker"
},
"defaultDefinableInline": true,
"defaultDefinableAtProjectLevel": true,

"pluginParams": [],

"params": [
{
"name": "here_app_id",
"type": "STRING",
"label" : "HERE App ID",
"mandatory": true
},
{
"name": "here_app_code",
"type": "PASSWORD",
"label" : "HERE App Code",
"mandatory": true
}
]
}
24 changes: 17 additions & 7 deletions python-lib/dataframe_forward_geocoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,26 @@ def get_forward_geocode_function(config):
"""
Handle authentication mechanism with respect to the chosen geocoding service provider `provider_function`
"""
provider_function = getattr(geocoder, config['provider'])
provider = config['provider']
provider_function = getattr(geocoder, provider)
use_preset = config.get('use_preset', False)
if use_preset:
preset_name = {
'google': 'google_geocoder_preset',
'here': 'here_geocoder_preset'
}.get(provider, 'api_key_preset')
authentication_config = config.get(preset_name) or {}
else:
authentication_config = config

if config['provider'] == 'here':
return lambda address: provider_function(address, app_id=config['here_app_id'], app_code=config['here_app_code'])
elif config['provider'] == 'google':
return lambda address: provider_function(address, key=config['api_key'], client=config['google_client'], client_secret=config['google_client_secret'])
if provider == 'here':
return lambda address: provider_function(address, app_id=authentication_config.get('here_app_id', ''), app_code=authentication_config.get('here_app_code', ''))
elif provider == 'google':
return lambda address: provider_function(address, key=authentication_config.get('api_key', ''), client=authentication_config.get('google_client', ''), client_secret=authentication_config.get('google_client_secret', ''))
elif config['batch_enabled']:
return lambda addresses: provider_function(addresses, key=config['api_key'], method='batch', timeout=config['batch_timeout'])
return lambda addresses: provider_function(addresses, key=authentication_config.get('api_key', ''), method='batch', timeout=config['batch_timeout'])
else:
return lambda address: provider_function(address, key=config['api_key'])
return lambda address: provider_function(address, key=authentication_config.get('api_key', ''))


def perform_forward_geocode(df, config, fun, cache):
Expand Down
24 changes: 17 additions & 7 deletions python-lib/dataframe_reverse_geocoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,26 @@ def add_reverse_geocode_columns(cache, config, current_df, geocode_function):


def get_reverse_geocode_function(config):
provider_function = getattr(geocoder, config['provider'])
provider = config['provider']
provider_function = getattr(geocoder, provider)
use_preset = config.get('use_preset', False)
if use_preset:
preset_name = {
'google': 'google_geocoder_preset',
'here': 'here_geocoder_preset'
}.get(provider, 'api_key_preset')
authentication_config = config.get(preset_name) or {}
else:
authentication_config = config

if config['provider'] == 'here':
return lambda lat, lng: provider_function([lat, lng], method='reverse', app_id=config['here_app_id'], app_code=config['here_app_code'])
elif config['provider'] == 'google':
return lambda lat, lng: provider_function([lat, lng], method='reverse', key=config['api_key'], client=config['google_client'], client_secret=config['google_client_secret'])
if provider == 'here':
return lambda lat, lng: provider_function([lat, lng], method='reverse', app_id=authentication_config.get('here_app_id', ''), app_code=authentication_config.get('here_app_code', ''))
elif provider == 'google':
return lambda lat, lng: provider_function([lat, lng], method='reverse', key=authentication_config.get('api_key', ''), client=authentication_config.get('google_client', ''), client_secret=authentication_config.get('google_client_secret', ''))
elif config['batch_enabled']:
return lambda locations: provider_function(locations, method='batch_reverse', key=config['api_key'])
return lambda locations: provider_function(locations, method='batch_reverse', key=authentication_config.get('api_key', ''))
else:
return lambda lat, lng: provider_function([lat, lng], method='reverse', key=config['api_key'])
return lambda lat, lng: provider_function([lat, lng], method='reverse', key=authentication_config.get('api_key', ''))


def perform_reverse_geocode(df, config, fun, cache):
Expand Down
4 changes: 2 additions & 2 deletions python-lib/dku_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_config_forward_geocoding(plugin_config, recipe_config):
:return:
"""
processed_config = {}
for param in ['address_column', 'cache_enabled', 'provider', 'api_key', 'here_app_id', 'here_app_code', 'google_client', 'google_client_secret']:
for param in ['address_column', 'cache_enabled', 'provider', 'api_key', 'api_key_preset', 'google_geocoder_preset', 'here_geocoder_preset', 'use_preset', 'here_app_id', 'here_app_code', 'google_client', 'google_client_secret']:
processed_config[param] = recipe_config.get(param, None)

if processed_config['provider'] is None:
Expand Down Expand Up @@ -70,7 +70,7 @@ def get_config_reverse_geocoding(plugin_config, recipe_config):

processed_config = {}

for param in ['lat_column', 'lng_column', 'provider', 'cache_enabled', 'api_key', 'here_app_id', 'here_app_code', 'google_client', 'google_client_secret']:
for param in ['lat_column', 'lng_column', 'provider', 'cache_enabled', 'api_key', 'api_key_preset', 'google_geocoder_preset', 'here_geocoder_preset', 'use_preset', 'here_app_id', 'here_app_code', 'google_client', 'google_client_secret']:
processed_config[param] = recipe_config.get(param, None)

if processed_config['provider'] is None:
Expand Down