|
46 | 46 |
|
47 | 47 | from qgis.PyQt.QtCore import QMetaType |
48 | 48 |
|
49 | | -from ORStools.common import PROFILES |
50 | 49 | from ORStools.utils import transform, exceptions, logger |
51 | 50 | from .base_processing_algorithm import ORSBaseProcessingAlgorithm |
52 | 51 | from ..utils.gui import GuiUtils |
@@ -182,41 +181,52 @@ def processAlgorithm( |
182 | 181 | endpoint = self.get_endpoint_names_from_provider(parameters[self.IN_PROVIDER])["matrix"] |
183 | 182 | response = ors_client.request(f"/v2/{endpoint}/{profile}", {}, post_json=params) |
184 | 183 |
|
185 | | - except (exceptions.ApiError, exceptions.InvalidKey, exceptions.GenericServerError) as e: |
186 | | - msg = f"{e.__class__.__name__}: {str(e)}" |
187 | | - feedback.reportError(msg) |
188 | | - logger.log(msg) |
| 184 | + (sink, dest_id) = self.parameterAsSink( |
| 185 | + parameters, self.OUT, context, sink_fields, QgsWkbTypes.Type.NoGeometry |
| 186 | + ) |
189 | 187 |
|
190 | | - (sink, dest_id) = self.parameterAsSink( |
191 | | - parameters, self.OUT, context, sink_fields, QgsWkbTypes.Type.NoGeometry |
192 | | - ) |
| 188 | + sources_attributes = [ |
| 189 | + feat.attribute(source_field_name) if source_field_name else feat.id() |
| 190 | + for feat in sources_features |
| 191 | + ] |
| 192 | + destinations_attributes = [ |
| 193 | + feat.attribute(destination_field_name) if destination_field_name else feat.id() |
| 194 | + for feat in destination_features |
| 195 | + ] |
193 | 196 |
|
194 | | - sources_attributes = [ |
195 | | - feat.attribute(source_field_name) if source_field_name else feat.id() |
196 | | - for feat in sources_features |
197 | | - ] |
198 | | - destinations_attributes = [ |
199 | | - feat.attribute(destination_field_name) if destination_field_name else feat.id() |
200 | | - for feat in destination_features |
201 | | - ] |
| 197 | + for s, source in enumerate(sources_attributes): |
| 198 | + for d, destination in enumerate(destinations_attributes): |
| 199 | + duration = response["durations"][s][d] |
| 200 | + distance = response["distances"][s][d] |
| 201 | + feat = QgsFeature() |
| 202 | + feat.setAttributes( |
| 203 | + [ |
| 204 | + source, |
| 205 | + destination, |
| 206 | + duration / 3600 if duration is not None else None, |
| 207 | + distance / 1000 if distance is not None else None, |
| 208 | + ] |
| 209 | + ) |
202 | 210 |
|
203 | | - for s, source in enumerate(sources_attributes): |
204 | | - for d, destination in enumerate(destinations_attributes): |
205 | | - duration = response["durations"][s][d] |
206 | | - distance = response["distances"][s][d] |
207 | | - feat = QgsFeature() |
208 | | - feat.setAttributes( |
209 | | - [ |
210 | | - source, |
211 | | - destination, |
212 | | - duration / 3600 if duration is not None else None, |
213 | | - distance / 1000 if distance is not None else None, |
214 | | - ] |
215 | | - ) |
| 211 | + sink.addFeature(feat) |
216 | 212 |
|
217 | | - sink.addFeature(feat) |
| 213 | + return {self.OUT: dest_id} |
| 214 | + |
| 215 | + except (exceptions.ApiError, exceptions.InvalidKey, exceptions.GenericServerError) as e: |
| 216 | + if ( |
| 217 | + isinstance(e, exceptions.ApiError) |
| 218 | + and "Parameter 'profile' has incorrect value" in e.message |
| 219 | + ): |
| 220 | + provider = self.providers[parameters[self.IN_PROVIDER]]["name"] |
| 221 | + msg = self.tr( |
| 222 | + f'The selected profile "{profile}" is not available in the chosen provider "{provider}"' |
| 223 | + ) |
| 224 | + else: |
| 225 | + msg = f"Feature ID {params['id']} caused a {e.__class__.__name__}:\n{str(e)}" |
| 226 | + feedback.reportError(msg) |
| 227 | + logger.log(msg) |
218 | 228 |
|
219 | | - return {self.OUT: dest_id} |
| 229 | + return {self.OUT: ""} |
220 | 230 |
|
221 | 231 | # TODO working source_type and destination_type differ in both name and type from get_fields in directions_core. |
222 | 232 | # Change to be consistent |
|
0 commit comments