3

I want to classify a gpx file by elevation in QGIS.

This is what I have done:

  1. Imported track_points from gpx file (because only this part of file containes elevations)

  2. Saved that file as shp (just in case)

  3. Classified shp as categorized

Now I would like to connect points as line but I would like to preserve categorization color of points. I have tried the plugins Points2one and Recostruction Line. But I haven't had luck and I also got errors in some cases.

Images below

Left: what I have achieved Right: created line by IDs with Points2one plugin (colors are not preserved) enter image description here

EDIT

After suggestion given by mgri I end up having this in SAGA:

enter image description here * I have tried to choose couple of combinations

Result:

enter image description here

newbie_girl
  • 375
  • 2
  • 14

1 Answers1

5

I don't know it is possible to achieve what you are asking because you don't know how to proceed when you pass from a category to another one. I will explain it with an example.


You may try using the Convert points to line(s) SAGA tool from Processing Toolbox: it leads the creation of lines starting from a point layer for which you specify the order for the creation of the line features and how to separate them.

Starting from this point layer:

enter image description here

which stores its ids in the "FID" field and the categories in the "AUTO" field:

enter image description here

You may run the above tool by setting the "FID" field as Order by... parameter and the "AUTO" field as Separate by... parameter.

You will get this result:

enter image description here

which still stores the "AUTO" field (so, you can still apply the classification).

As I specified above, it is correct that a line is not created when passing from a category to the next one because QGIS doesn't know what to do. Starting from this result, you should, however, be able to add some feature lines with custom values for completing the task.

EDIT

If you have many elevation values, you may create a new field which stores a classification of them. For doing this, create a new field and then, in the field calculator, use this expression (the following values are an example):

CASE
WHEN
"Altitude" <= 300
THEN
"Altitude_range" = 0
WHEN
"Altitude" > 300 AND "Altitude" <= 600
THEN
"Altitude_range" = 1
WHEN
"Altitude" > 600 AND "Altitude" <= 900
THEN
"Altitude_range" = 2
END

where "Altitude" is the field in you point shapefile which stores the altitudes and "Altitude_range" is the name of the new field (adapt the name and the code to your case).

The following image will help to undestand:

enter image description here

mgri
  • 16,159
  • 6
  • 47
  • 80
  • At what point I will end up having AUTO field. I assume in the beginning. Gpx track is recorded with Geo Tracker. I dont have that field anywhere. – newbie_girl Mar 28 '17 at 22:00
  • @newbie_girl Sorry, I didn't specify that you need to use the field that you used for the classification of the points instead of mine (the "AUTO" field is only an example). The same for the FID field: you need to use the field in your shapefile that stores the ids. – mgri Mar 28 '17 at 22:05
  • so i have...order by: id, separate by: elevation. this is unfortunally impossible because of the elevation that varies from 600 to 900 m. I dont have unique segments for classification, althought I am not sure if I have saved file correctly from QGIS because style is not imported right in SAGA. I have sld from shp, with same name, but I dont see SAGA is reading it. – newbie_girl Mar 28 '17 at 22:21
  • For the issue with SAGA, try selecting a different field from the one initially proposed by the tool and then try to set again the field you want to use: it should work. For the problem about the elevation, see the edit on my answer. – mgri Mar 28 '17 at 22:28
  • This is such a beautiful solution! Thnx! However I got stucked! I am not able to create a new field in the Field calculator, but I have created it in window after you click on a table Open attribute table - New Field. Then I enter Field calculator, choose Update existing field, enter your code and nothing happens! I have followed http://gis.stackexchange.com/questions/201024/how-to-update-a-text-column-of-selected-features-in-qgis and tried alternative by removing "" around name columns http://gis.stackexchange.com/questions/39168/elseif-conditional-statement-in-qgis-field-calculator – newbie_girl Mar 29 '17 at 11:10
  • Alright, I figured out how to do it. This code worked for me. Example: CASE WHEN "ele"<=450 THEN 0 WHEN "ele">450 AND "ele"<=500 THEN 1 END because I was updated existing field which I had to specify in dropdown. – newbie_girl Mar 29 '17 at 12:08
  • @newbie_girl Sorry, I was away. So, does it work everything by now? – mgri Mar 29 '17 at 12:47
  • No prob, I am not by comp all the time either. This is not working. Example: I have ID: 1-5, ele_range: 1; ID: 6-10, ele_range: 2; ID: 11-15, ele_range: 1. So created lines will be ordered by ID, but separation by ele_range will end up by order AND with cris-cros lines. I will edit my question. – newbie_girl Mar 29 '17 at 13:48
  • Oh, I understand. However, if you don't need to manage too many points, you may also run the tool on selected features only: it should work (practically, make a selection of all points and then deselect the points having ids 11-15. Finally, run the SAGA tool and it should create a line only on selected features). I know, it is a horrible solution, otherwise some python will help... – mgri Mar 29 '17 at 13:55
  • That might be a solution to it! I will try to do it later and then I will give a feedback – newbie_girl Mar 29 '17 at 14:04
  • @mgri : the best solution is the one that works, even if it looks "horrible" from our point of view sometimes ;) – gisnside Mar 29 '17 at 14:47
  • @gisnside Oh yes, I agree with you, but I generally prefer programmatically solutions. I already know that the last solution couldn't work (I wrote it before the last edit on the question). So, I'm ready for the next issue/solution! =) – mgri Mar 29 '17 at 14:51
  • 2
    @mgri I too hate dirty quickies, I like good structured script, making sure everything is perfectly done :) – gisnside Mar 29 '17 at 15:08
  • @mgri I got stuck on this: http://gis.stackexchange.com/questions/234116/convert-shp-to-gpx-with-predefined-shp-style-in-qgis – newbie_girl Mar 30 '17 at 13:00
  • @newbie_girl If I find a solution, I will help you on it by answering on the related question! Did you solve the issue you reported in this question? If yes, the best way to say thanks for the effort would be accepting the answer. – mgri Mar 30 '17 at 13:08
  • @mgri I am very thankful and I always accept answer as soon as I do it plus I would click your answer 5x more then it is allowed. I realized in the between I dont know how to export it, at that point it seemed to me that this is step before this one, so I got stuck spinning in the circle. – newbie_girl Mar 30 '17 at 13:22
  • I also got mislead and thought of creating new column in table as color, and assigning each elevation_range its color, just for not doing it with hand, but I didnt know how to do it until the end. Possible solution is given by wastek: http://gis.stackexchange.com/questions/20404/how-to-give-multiple-colors-to-features-within-a-single-shapefile (I have created column name: color, and values are defined like rgb(255, 0, 255) without color in color_rgb(...)), but nothing happens, I dont know how to run a code. What do you think on that solution? – newbie_girl Mar 30 '17 at 13:27
  • @newbie_girl Maybe I'm making some confusion. The current question is about the creation of categorized lines and every comment/answer should be related to this specific issue. This justifies why I asked you if you solved the current problem: if yes, please accept the answer for helping future readers; otherwise, I can try to find another solution. For the other question you linked, you need do edit it for explaining what have you tried (instead of doing it here). =) – mgri Mar 30 '17 at 13:35