Imagine a few km long pipeline. Pipeline consists of 4 types of pipe. Those types are alternating.

  • 0 - 200m A type of pipe go. (Green color)
  • 200 - 230m B type of pipe etc..(RED color)
  • 230 - 380m C type of pipe etc..(YELLOW color)
  • .. 10 000m A type of pipe go. (Green color)

In QGIS I have whole line in one color, no point, just line*. Line is not straight. Is it possible to change color, part by part?

*EDIT: its kml file so I have no data, just line

  • This is a relatively straight forward task and easy. Given... how is your linestring categorized? Has it been actually split into segments and attributed with the "Types"? If not you should do that as a first step. – SaultDon May 1 at 17:51
  • @SaultDon no it wasnt, its kml file so I have no data, just line. – R2D2 May 1 at 18:10
  • You should give those kind of 'details' right from the start ... if you have no data the answers given so far won't fit your needs ... – snaileater May 1 at 18:20
  • I have updated question. but @MrXsquared mentioned B) Using Line length, I was thinking this may work. – R2D2 May 1 at 18:23
  • Just updated my answer and added an expression in case your layer is not projected. However, option B should work for you. – MrXsquared May 1 at 18:30

Yes. Apply a categorized or rule-based style on it.

A) Using a type field

Go to layer properties and open symbology tab. Choose "Categorized" and for "Column" choose your type field:

enter image description here


enter image description here

B) Using Line length

If you do not have a type field you can also categorize it directly by its length. Note that your layer needs to be in a projected CRS.

Apply a rule based style and use the expression $length. It will return the length of line in meters (given you use a projected CRS!). So your rules will look like e.g. $length > 0 AND $length <= 200

enter image description here

You could also add length information to your attribute table if you want.

If your layer is not in a projected CRS and you do not want to reproject it, you could use an expression like this instead of $length:

length(transform($geometry, layer_property(@layer_name, 'crs'), 'EPSG:3395'))

Instead of EPSG:3395 use one that fits your region the best.

  • I have updated question. – R2D2 May 1 at 18:26

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.