Sorting features in legend
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I have a map with a polygon layer containing 100+ features.
I want them to display on the legend and the Layer Tree using the Polygon's ID and then its name i.e: "Id - Name".
I'm using the following steps in QGIS:
Symbology -> Categorized -> concat(Id, ' - ', Name).
However, after following the above steps they are displayed in the Legend and Layer Tree in this order :
1 - Name1
10 - Name10
100 - Name100
101 - Name101
11 - Name11
12 - Name12....
2 - Name2
20 - Name20
3 - Name3
So I read that it's sorting them as strings, and I want to know if there is a way to have them sorted by Id while still display like "ID - Name".
qgis legend
add a comment |Â
up vote
2
down vote
favorite
I have a map with a polygon layer containing 100+ features.
I want them to display on the legend and the Layer Tree using the Polygon's ID and then its name i.e: "Id - Name".
I'm using the following steps in QGIS:
Symbology -> Categorized -> concat(Id, ' - ', Name).
However, after following the above steps they are displayed in the Legend and Layer Tree in this order :
1 - Name1
10 - Name10
100 - Name100
101 - Name101
11 - Name11
12 - Name12....
2 - Name2
20 - Name20
3 - Name3
So I read that it's sorting them as strings, and I want to know if there is a way to have them sorted by Id while still display like "ID - Name".
qgis legend
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have a map with a polygon layer containing 100+ features.
I want them to display on the legend and the Layer Tree using the Polygon's ID and then its name i.e: "Id - Name".
I'm using the following steps in QGIS:
Symbology -> Categorized -> concat(Id, ' - ', Name).
However, after following the above steps they are displayed in the Legend and Layer Tree in this order :
1 - Name1
10 - Name10
100 - Name100
101 - Name101
11 - Name11
12 - Name12....
2 - Name2
20 - Name20
3 - Name3
So I read that it's sorting them as strings, and I want to know if there is a way to have them sorted by Id while still display like "ID - Name".
qgis legend
I have a map with a polygon layer containing 100+ features.
I want them to display on the legend and the Layer Tree using the Polygon's ID and then its name i.e: "Id - Name".
I'm using the following steps in QGIS:
Symbology -> Categorized -> concat(Id, ' - ', Name).
However, after following the above steps they are displayed in the Legend and Layer Tree in this order :
1 - Name1
10 - Name10
100 - Name100
101 - Name101
11 - Name11
12 - Name12....
2 - Name2
20 - Name20
3 - Name3
So I read that it's sorting them as strings, and I want to know if there is a way to have them sorted by Id while still display like "ID - Name".
qgis legend
edited Sep 3 at 1:37
Vince
14k32444
14k32444
asked Sep 2 at 23:20
Mouad
111
111
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
You can use lpad()
function to add zeros (0) on the left side of the ID numbers based on the number of digits that cover the maximum ID number. For example, if the maximum number of digits of the ID number is 3, as in your case (100), then you need to write the following:
concat(lpad("ID",3,'0'),' - ',"Name" )
In this case the legend will be sorted correctly.
In the following example, I have to convert the NEW_ID
field from numerical to text, therefore, I used to_string()
function:
concat(lpad(to_string("NEW_ID"),3,'0'),' - ',"Name" )
Here is the output:
It is also sorted correctly in print composer:
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
You can use lpad()
function to add zeros (0) on the left side of the ID numbers based on the number of digits that cover the maximum ID number. For example, if the maximum number of digits of the ID number is 3, as in your case (100), then you need to write the following:
concat(lpad("ID",3,'0'),' - ',"Name" )
In this case the legend will be sorted correctly.
In the following example, I have to convert the NEW_ID
field from numerical to text, therefore, I used to_string()
function:
concat(lpad(to_string("NEW_ID"),3,'0'),' - ',"Name" )
Here is the output:
It is also sorted correctly in print composer:
add a comment |Â
up vote
5
down vote
You can use lpad()
function to add zeros (0) on the left side of the ID numbers based on the number of digits that cover the maximum ID number. For example, if the maximum number of digits of the ID number is 3, as in your case (100), then you need to write the following:
concat(lpad("ID",3,'0'),' - ',"Name" )
In this case the legend will be sorted correctly.
In the following example, I have to convert the NEW_ID
field from numerical to text, therefore, I used to_string()
function:
concat(lpad(to_string("NEW_ID"),3,'0'),' - ',"Name" )
Here is the output:
It is also sorted correctly in print composer:
add a comment |Â
up vote
5
down vote
up vote
5
down vote
You can use lpad()
function to add zeros (0) on the left side of the ID numbers based on the number of digits that cover the maximum ID number. For example, if the maximum number of digits of the ID number is 3, as in your case (100), then you need to write the following:
concat(lpad("ID",3,'0'),' - ',"Name" )
In this case the legend will be sorted correctly.
In the following example, I have to convert the NEW_ID
field from numerical to text, therefore, I used to_string()
function:
concat(lpad(to_string("NEW_ID"),3,'0'),' - ',"Name" )
Here is the output:
It is also sorted correctly in print composer:
You can use lpad()
function to add zeros (0) on the left side of the ID numbers based on the number of digits that cover the maximum ID number. For example, if the maximum number of digits of the ID number is 3, as in your case (100), then you need to write the following:
concat(lpad("ID",3,'0'),' - ',"Name" )
In this case the legend will be sorted correctly.
In the following example, I have to convert the NEW_ID
field from numerical to text, therefore, I used to_string()
function:
concat(lpad(to_string("NEW_ID"),3,'0'),' - ',"Name" )
Here is the output:
It is also sorted correctly in print composer:
edited Sep 3 at 5:08
answered Sep 3 at 1:29
ahmadhanb
18.7k21543
18.7k21543
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f294745%2fsorting-features-in-legend%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password