Changeset - ff3feebc890a
[Not reviewed]
default
0 2 0
Luca Allulli (luca) - 2 years ago 2019-03-02 17:26:34
luca@skeed.it
* Servizi: improved use of ESRI geocoder
2 files changed with 11 insertions and 19 deletions:
0 comments (0 inline, 0 general)
servizi/autocomplete.py
Show inline comments
...
 
@@ -81,18 +81,16 @@ class AutocompleteEsri(object):
 
		Return a list of pairs (item_data, resource)
 
		"""
 
		url = ESRI_GEOCODER_URL_PREFIX + '/suggest'
 
		location = json.dumps({
 
			"x": 41.892055,
 
			"y": 12.483559,
 
			"spatialReference": {
 
				"wkid": 4326,
 
			},
 
		})
 
		res = requests.get(url, params={
 
			"text": lookup,
 
			"location": location,
 
			'countryCode': 'IT',
 
			'searchExtent': '12.37602,42.00589,12.6163,41.7650',
 
			'location': '12.483559,41.892055',
 
			"f": "pjson",
 
		})
 
		out = []
 
		print res.status_code
 
		print res.text
 
		for elem in res.json()['suggestions']:
 
			t = elem['text']
 
			out.append((-1, t))
servizi/infopoint.py
Show inline comments
...
 
@@ -44,7 +44,6 @@ ESRI_GEOCODER_MIN_SCORE = 60
 
ESRI_GEOCODER_MIN_DELTA = 5
 
ESRI_GEOCODER_MAX_DELTA = 8
 
ESRI_GEOCODER_URL_PREFIX = r'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer'
 
ESRI_GEOCODER_URL_PREFIX = r'http://geocoding.romamobilita.it/full'
 

 
map_width = 200
 
map_height = 150
...
 
@@ -210,24 +209,19 @@ def geocode_place_infotpdati(request, co
 

 

 
def geocode_place_esri(request, composite_address):
 
	location = json.dumps({
 
		"x": 41.892055,
 
		"y": 12.483559,
 
		"spatialReference": {
 
			"wkid": 4326,
 
		},
 
	})
 
	res = requests.get(
 
		ESRI_GEOCODER_URL_PREFIX + '/findAddressCandidates',
 
		params={
 
			'SingleLine': composite_address,
 
			'forStorage': 'false',
 
			'location': location,
 
			'f': 'pjson',
 
			'countryCode': 'IT',
 
			'searchExtent': '12.37602,42.00589,12.6163,41.7650',
 
			'location': '12.483559,41.892055'
 
		}
 
	)
 
	print(res.status_code)
 
	print(res.text)
 
	# print(res.status_code)
 
	# print(res.text)
 
	res = res.json()['candidates']
 
	# cs = [(c['score'], c['address'], c['location']['x'], c['location']['y']) for c in res['candidates'] if c['score'] >= ESRI_GEOCODER_MIN_SCORE]
 
	res.sort(key=lambda c: c['score'], reverse=True)
0 comments (0 inline, 0 general)