6

I have a large dataset containing GPS points of various vehicles that are recorded every 10 seconds.

enter image description here

I have added a new id column to these GPS points in order to be able to connect them via the Points to Path tool by using the id field as order field.

car_id     LAT         LON         id
2891       4.899883    52.367300   1
2891       4.900583    52.366983   2
2891       4.901033    52.366900   3
2891       4.901100    52.366867   4
...        ...         ...         
2891       4.901572    52.367967   82
5892       4.901794    52.369302   83
5892       4.901749    52.369442   84
5892       4.901829    52.361554   85

The resulting GPS trajectory dataset contains outlying observations (the straight lines that jump across large distances not along with the road network) which I want to remove. These route points are impossible because it would require acceleration/speed that these vehicles can not achieve.

enter image description here

In order to detect these unrealistically travelled distances, I would like to calculate the distance between each point to the next point in sequence (id) for each unique car_id. This mean that the distance to the end point of each car_id should be zero, since there is no subsequent recorded GPS point (see below). Eventually I want to set a maximum distance depending on how far it is possible for a vehicle to get in 10 seconds (150 meters?) and filter out distances above this threshold.

car_id     LAT         LON         id      DISTANCE
2891       4.899883    52.367300   1       13
2891       4.900583    52.366983   2       2
2891       4.901033    52.366900   3       14
2891       4.901100    52.366867   4       10
...        ...         ...         ...          
2891       4.901572    52.367967   82      0
5892       4.901794    52.369302   83      9
5892       4.901749    52.369442   84      12
5892       4.901829    52.361554   85      6

Is this the best way to get rid of these outliers, and achievable in QGIS?

7
  • 4
    Removing lines whose length is bigger than 150(for example) doesn't solve the problem? – Kadir Şahbaz Feb 11 '20 at 12:20
  • The output of the 'Points to path' algorithm results in a single datafile where the lines are not individually identifiable.. What do you propose to get the length of each individual line? – winecity Feb 11 '20 at 12:34
  • 5
    You can use Explode lines tool. It gives you all individual lines. – Kadir Şahbaz Feb 11 '20 at 12:39
  • On a side note, the lat and long have been swapped – JGH Feb 11 '20 at 12:46
  • 3
    Be careful when removing point/line: it works ok if the outliers are lonely. It fails if you have 2 or more consecutive ones. You may want to consider not only the "next" point but rather points outside of the max distance that the car can reach in 5 minutes (or else), then to remove groups of outliers. Don't forget to consider that the very first point could be the outlier – JGH Feb 11 '20 at 12:49
3
  1. To keep your id attached to the points / vertices through line generation and other algorithms, you can add it as the M (or Z) dimension (algorithms Set M value / Set Z value) to your input GPS points layer. The id will then become a part of the geometry, and can be retrieved later using the Extract M values / Extract Z values algorithms.

  2. Have you considered the Extract vertices algorithm?

    This algorithm takes a line or polygon layer and generates a point layer with points representing the vertices in the input lines or polygons. The attributes associated to each point are the same ones associated to the line or polygon that the point belongs to.
    Additional fields are added to the point indicating the vertex index (beginning at 0), the vertex’s part and its index within the part (as well as its ring for polygons), distance along original geometry and bisector angle of vertex for original geometry.

    Unfortunately, you won't get the length of the segments, but you may be able to utilise the result, for instance by writing a script that does the subtractions.

  3. The Add geometry attributes algorithm is an alternative to the field calculator for calculating length:

    This algorithm computes geometric properties of the features in a vector layer. It generates a new vector layer with the same content as the input one, but with additional attributes in its attributes table, containing geometric measurements. Depending on the geometry type of the vector layer, the attributes added to the table will be different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.