Revision 564 org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/geopy/geocoders/osm.py
osm.py | ||
---|---|---|
6 | 6 |
Geocoder, |
7 | 7 |
DEFAULT_FORMAT_STRING, |
8 | 8 |
DEFAULT_TIMEOUT, |
9 |
DEFAULT_SCHEME |
|
9 | 10 |
) |
10 | 11 |
from geopy.compat import urlencode |
11 | 12 |
from geopy.location import Location |
... | ... | |
24 | 25 |
Note that Nominatim does not support SSL. |
25 | 26 |
""" |
26 | 27 |
|
27 |
structured_query_params = (
|
|
28 |
structured_query_params = {
|
|
28 | 29 |
'street', |
29 | 30 |
'city', |
30 | 31 |
'county', |
31 | 32 |
'state', |
32 | 33 |
'country', |
33 | 34 |
'postalcode', |
34 |
)
|
|
35 |
}
|
|
35 | 36 |
|
36 | 37 |
def __init__( |
37 | 38 |
self, |
38 | 39 |
format_string=DEFAULT_FORMAT_STRING, |
39 |
view_box=(-180, -90, 180, 90),
|
|
40 |
view_box=None,
|
|
40 | 41 |
country_bias=None, |
41 | 42 |
timeout=DEFAULT_TIMEOUT, |
42 | 43 |
proxies=None, |
44 |
domain='nominatim.openstreetmap.org', |
|
45 |
scheme=DEFAULT_SCHEME, |
|
46 |
user_agent=None |
|
43 | 47 |
): # pylint: disable=R0913 |
44 | 48 |
""" |
45 | 49 |
:param string format_string: String containing '%s' where the |
... | ... | |
57 | 61 |
:class:`urllib2.ProxyHandler`. |
58 | 62 |
|
59 | 63 |
.. versionadded:: 0.96 |
64 |
|
|
65 |
:param string domain: Should be the localized Openstreetmap domain to |
|
66 |
connect to. The default is 'nominatim.openstreetmap.org', but you |
|
67 |
can change it to a domain of your own. |
|
68 |
|
|
69 |
.. versionadded:: 1.8.2 |
|
70 |
|
|
71 |
:param string scheme: Use 'https' or 'http' as the API URL's scheme. |
|
72 |
Default is https. Note that SSL connections' certificates are not |
|
73 |
verified. |
|
74 |
|
|
75 |
.. versionadded:: 1.8.2 |
|
60 | 76 |
""" |
61 | 77 |
super(Nominatim, self).__init__( |
62 |
format_string, 'http', timeout, proxies
|
|
78 |
format_string, scheme, timeout, proxies, user_agent=user_agent
|
|
63 | 79 |
) |
64 | 80 |
self.country_bias = country_bias |
65 | 81 |
self.format_string = format_string |
66 | 82 |
self.view_box = view_box |
67 |
self.country_bias = country_bias
|
|
83 |
self.domain = domain.strip('/')
|
|
68 | 84 |
|
69 |
self.api = "%s://nominatim.openstreetmap.org/search" % self.scheme |
|
70 |
self.reverse_api = ( |
|
71 |
"%s://nominatim.openstreetmap.org/reverse" % self.scheme |
|
72 |
) |
|
85 |
self.api = "%s://%s/search" % (self.scheme, self.domain) |
|
86 |
self.reverse_api = "%s://%s/reverse" % (self.scheme, self.domain) |
|
73 | 87 |
|
74 | 88 |
def geocode( |
75 | 89 |
self, |
... | ... | |
131 | 145 |
""" |
132 | 146 |
|
133 | 147 |
if isinstance(query, dict): |
134 |
""" |
|
135 | 148 |
params = { |
136 | 149 |
key: val |
137 | 150 |
for key, val |
138 | 151 |
in query.items() |
139 | 152 |
if key in self.structured_query_params |
140 | 153 |
} |
141 |
""" |
|
142 |
params = {} |
|
143 |
for key,val in query.items(): |
|
144 |
if key in self.structured_query_params: |
|
145 |
params[key] = val |
|
146 | 154 |
else: |
147 | 155 |
params = {'q': self.format_string % query} |
148 | 156 |
|
149 | 157 |
params.update({ |
150 |
'view_box': self.view_box, |
|
151 | 158 |
'format': 'json' |
152 | 159 |
}) |
153 | 160 |
|
161 |
# `viewbox` apparently replaces `view_box` |
|
162 |
if self.view_box: |
|
163 |
params['viewbox'] = ','.join(self.view_box) |
|
164 |
|
|
154 | 165 |
if self.country_bias: |
155 | 166 |
params['countrycodes'] = self.country_bias |
156 | 167 |
|
Also available in: Unified diff