1

I have a linear layer with line type A,B,C (red,green,blue). For each linear feature I added MANUALLY sequence numbers (for line with name A: 1,2,3,4,5; for line with name B: 1,2,3; for line with name C: 1,2,3,4).

How can I add sequence numbers automatically with saving sequence in line direction (from start to end line)?

enter image description here

I tried the next SQL query:

DROP TABLE IF EXISTS route_lines_test;
CREATE TABLE route_lines_test AS
SELECT
t.geom,
t."name",
t."order",
row_number() OVER (PARTITION BY t."name" ORDER BY ST_X(ST_Centroid(t.geom))) AS order_sql
FROM
(
SELECT
geom,
gid,
"name",
"order"
FROM
line_layer
ORDER BY "name", ST_X(ST_Centroid(geom))
) t

where I added line ordering by line centroid 'X' coordinate, but received incorrect result for line 'B' (green)

enter image description here

  • Add feature number where? – John Powell Mar 24 at 17:18
  • Add number for each linear feature - red:1,2,3,4; green: 1,2,3 – spatialhast Mar 24 at 17:28
  • 1
    Postgis is not a drawing app. Each geometry is a single entity, so you can't add numbers to line segments, as such. Your question is not very clear. – John Powell Mar 24 at 17:36
  • Are we talking about numbering line features or line segments ? Your drawing is all but clear indeed ... what do u call "add number" : you want to associate a number following which logic ? or is your need only a display issue in QGIS for example ? – snaileater Mar 24 at 17:42
  • @JohnPowell I added updates – spatialhast Mar 25 at 9:53

Your Answer

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

Browse other questions tagged or ask your own question.