28 |
28 |
|
29 |
29 |
from wcs.workflows import WorkflowStatusItem, register_item_class
|
30 |
30 |
|
31 |
|
from ..qommon import _, force_str, get_logger
|
|
31 |
from ..qommon import _, force_str
|
32 |
32 |
from ..qommon.errors import ConnectionError
|
33 |
33 |
from ..qommon.form import CheckboxWidget, ComputedExpressionWidget, RadiobuttonsWidget
|
34 |
34 |
from ..qommon.misc import http_get_page, normalize_geolocation
|
... | ... | |
145 |
145 |
address = self.address_string
|
146 |
146 |
|
147 |
147 |
if not address:
|
148 |
|
get_logger().debug('error geolocating string (empty string)')
|
149 |
148 |
return
|
150 |
149 |
url = get_publisher().get_geocoding_service_url()
|
151 |
150 |
if '?' in url:
|
... | ... | |
166 |
165 |
try:
|
167 |
166 |
data = json.loads(force_str(data))
|
168 |
167 |
except ValueError:
|
169 |
|
get_logger().debug('non-JSON response from geocoding service')
|
170 |
168 |
return
|
171 |
169 |
if len(data) == 0 or isinstance(data, dict):
|
172 |
|
get_logger().debug('error finding location')
|
173 |
170 |
return
|
174 |
171 |
coords = data[0]
|
175 |
172 |
return normalize_geolocation({'lon': coords['lon'], 'lat': coords['lat']})
|
... | ... | |
192 |
189 |
|
193 |
190 |
def geolocate_photo_variable(self, formdata):
|
194 |
191 |
if Image is None:
|
195 |
|
get_logger().debug('error geolocating from file (missing PIL)')
|
196 |
192 |
return
|
197 |
193 |
|
198 |
194 |
value = self.compute(self.photo_variable)
|
199 |
195 |
if not value:
|
200 |
|
get_logger().debug('error geolocating from photo, no image')
|
201 |
196 |
return
|
202 |
197 |
|
203 |
198 |
if not hasattr(value, 'get_file_pointer'):
|
204 |
|
get_logger().debug('error geolocating from photo, invalid variable')
|
205 |
199 |
return
|
206 |
200 |
|
207 |
201 |
try:
|
208 |
202 |
image = Image.open(value.get_file_pointer())
|
209 |
203 |
except OSError:
|
210 |
|
get_logger().debug('error geolocating from photo, invalid file')
|
211 |
204 |
return
|
212 |
205 |
|
213 |
206 |
try:
|
214 |
207 |
exif_data = image._getexif()
|
215 |
208 |
except AttributeError:
|
216 |
|
get_logger().debug('error geolocating from photo, failed to get EXIF data')
|
217 |
209 |
return
|
218 |
210 |
|
219 |
211 |
if exif_data:
|
... | ... | |
248 |
240 |
+ 1.0 * lon[2][0] / lon[2][1] / 3600
|
249 |
241 |
)
|
250 |
242 |
except ZeroDivisionError:
|
251 |
|
get_logger().debug(
|
252 |
|
'error geolocating from photo, invalid EXIF data (%r / %r)'
|
253 |
|
% (gps_info[2], gps_info[4])
|
254 |
|
)
|
255 |
243 |
return
|
256 |
244 |
if lat_ref == 'S':
|
257 |
245 |
lat = -lat
|
258 |
|
-
|