Start and end point of route - points (1 layer)

Hello everyone
I am recently using ORS Tools pluging in QGIS. I can’t get the route to end at the arrival point. Does anyone know how to solve it? Should I change any concept in the data table? I use ID 1 for the departure point and 999 for the arrival point. Batch Jobs → Points (1 Layer) ->…
Thank you.

Hi, @hopelost3.

Did you solve it? I have the same problem… I have just some information to contribute. ORS Tools use FID to calculate the directions, so I do not understand why we have the option to put “Layer ID Field”.
To solve the problem (FID) when you create the layer its necessary you put the first point as first line and the last point as the last line (I did not try this solution).

Hi @Diego_Camargo, Hi @hopelost3,

Sorry this seems to have gotten lost.

There is a workaround for your problem.
If you add the first point as a last point in the layer, you should be able to get a round trip.

Reagrding FIDs: The purpose is in batch jobs to be able to join the output layers by features again
as explained here.
The FID has no effect on the algorithm.

Not sure about this. OR Tools seems to select the start point based on the lowest FID, so the layer has to be ‘correctly’ ordered. Unless I’m mistaken, that ordering has to be done outside QGis. But I’ve tried only csv and shapefile layers for the sources.

Hey @graham8

indeed, the QGIS-Plugin currently uses the Feature ID of points to determine the order in which the given waypoints are traversed.

As a consequence, as you stated, the layer has to be sorted accordingly, and I couldn’t find any way to do that in QGIS either. Please let me know if you find one :slight_smile:

This is also the “solution” to the original problem by @hopelost3 - the IDs from the id field of their data are not used to determine the ordering of waypoints, which leads to confusion.

I have created an issue regarding this.

Best regards

Well the plug-in seems to know how to reorder them. If I start with a csv in which the first and last waypoints are coincident and run Points (1 Layer), when I re-open the Features table for the csv source layer the waypoints are listed in a different order which I can’t make sense of. It’s not sorted on any of the fields and it’s not (sadly) the order in which the waypoints are visited. The order is the same whether I use ‘Optimize’ or not.

Starting order

After batch job

Hey,

do not confuse the order that your points appear in in the attribute table with the order that is given by the feature id and is used by the plugin.

The order they appear in in the attribute table is (as of now) a mystery to me - as an example, you can select a point and click Move selection to top - which will change the displayed order, but nothing about the points themselves.

If you hover over the row numbers on the left, it’ll show the feature ID of the feature.
I’d assume that these didn’t change.

Best regards

1 Like

Am I missing something? The output layer I get from a Points (1 layer) batch job contains just one feature - a polyline. That layer seems to be ignorant of the input layer features.

Thank you for PR#146 (so quick!). Will the proposed selection of a field on which to order the input features in a batch job be coming soon?

I could have a go myself but would need a crash course in Qt :thinking:

Hey,

we’re currently in the midst of a large cleanup and refactoring that should hopefully be done by the beginning of next week. We’re looking to add that feature next.

Best regards,
Jakob

1 Like

@graham8 ,
with the common usage, yes.
But you can also use a MultiPoint layer, where one feature is generated per MultiPoint.
In this case, the ID can be used for joining features again.

I can’t make that work. If I just copy my Points layer as a multi-points layer I get this:

QGIS version: 3.14.16-Pi
QGIS code revision: df27394552
Qt version: 5.11.2
GDAL version: 3.0.4
GEOS version: 3.8.1-CAPI-1.13.3
PROJ version: Rel. 6.3.2, May 1st, 2020
Processing algorithm…
Algorithm 'Directions From Points 1 Layer' starting…
Input parameters:
{ 'INPUT_LAYER_FIELD' : 'postcode', 'INPUT_OPTIMIZE' : True, 'INPUT_POINT_LAYER' : 'W Hythe multi.shp|layername=W Hythe multi', 'INPUT_PREFERENCE' : 0, 'INPUT_PROFILE' : 0, 'INPUT_PROVIDER' : 0, 'OUTPUT' : 'TEMPORARY_OUTPUT' }

Traceback (most recent call last):
File "C:/Users/graham/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ORStools\proc\directions_points_layer_proc.py", line 240, in processAlgorithm
params = self._get_params_optimize(points, profile)
File "C:/Users/graham/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ORStools\proc\directions_points_layer_proc.py", line 318, in _get_params_optimize
end = points.pop(-1)
IndexError: pop from empty list

Execution failed after 0.06 seconds

Loading resulting layers
Algorithm 'Directions From Points 1 Layer' finished

Which ORStools version are you using?

1.3.0 loaded from 3.14.16 but I get the same result using the code from your git.

I guess I do only have single points in each multi-point. How should that multi-point layer be constructed?

Could it be, you only have a single point within a multi point?
Not that it shouldn’t have a proper error message, but just wondering about your layer

Checking optimization and using MultiPoint layers defenitely is not working well right now.
Even for MultiPoints with 2 or more coordinates i get a Bad Request error.

1 Like

Hey @graham8

I’m currently investigating this. If your multi-point-layer consists of only one point per part, this’ll fail, since the plugin assumes every part of your multi-point layer to define one route and consequently to consist of at least two coordinates.

Could you provide me with the layer you’re using, so we’re talking about the same thing?

Best regards

It’s a very simple layer, just a points layer exported as a multi-point layer.

Please understand, I don’t think this workflow will solve my problem, but I’ll PM the layer if it will help you find bugs. I was just trying to understand whether joining the source and sink layers would produce what I want - a list of features in the order they should be visited.

I have added some code to directions_core.py and directions_points_layer_proc.py that writes back values to a numeric field in the source layer that define the order each feature will be visited. This is exactly what I want for my use. Using that field as a label, I can see whether the route makes sense and using it as a sort index I get the features listed in the correct order.

All I want now is the ability to specify the start point and, optionally, the end point. This would be best done as a drop-down in the GUI but I don’t have the skills to do that and may not be what you have in mind for implementing this feature. An alternative is to use the field I’m using for the routing order as input, say, the start is labelled 0 and the end labelled -1. For a round trip there would be no feature labelled 0. I can’t think of a case where you would want the end fixed but not the start.

So I’m nearly there with getting what I want. Except one more thing: there’s no option for shortest distance in the optimization API. The algo will pick a single-lane country road with a 60mph speed limit over a two-way shorter road with a 50mph speed limit or route around 20mph zones in urban areas. A shortest distance preference would give more sensible answers.

OK, I now understand what this is trying to do. It will calculate a route for each feature and the ‘Layer ID Field’ lets you associate the resulting polylines with each source feature.

So having only 1 or two points per feature doesn’t make sense. Sorry if I’m being slow.