QGIS User 0052 - Contour Labels Aggregate function

Поділитися
Вставка
  • Опубліковано 10 лют 2025
  • Label placement geometry generator code:
    -- Name the (line) layer that "cuts" the layer
    -- where the labels should be placed.
    -- Also define the placement width for the labels.
    with_variable('label_position_layer', 'layer_name',
    with_variable('label_placement_width', 10, -- coordinate units
    if( -- First, only apply to lines that actually are to be labled (improve speed)
    intersects(
    geometry1:=@geometry,
    geometry2:=aggregate(
    layer:=@label_position_layer,
    aggregate:='collect',
    expression:=$geometry
    )
    ),
    aggregate( -- The actual label placment
    layer:=@label_position_layer,
    aggregate:='collect',
    expression:=intersection(
    geometry1:=geometry(@parent),
    geometry2:=buffer($geometry, @label_placement_width)
    )
    ),
    '') -- End of if-statement
    ))

КОМЕНТАРІ • 17

  • @ridjsaduhakkani3959
    @ridjsaduhakkani3959 10 місяців тому

    Mr. Klas karlsson, I envision you as a tranquil, modest, and benevolent gentleman.
    Thank you very much.

  • @caiocouto3168
    @caiocouto3168 Рік тому

    absolutely awsome!

  • @chaknorrisvattake
    @chaknorrisvattake Рік тому

    very useful, huge thank You))

  • @Ben-NMN
    @Ben-NMN 13 днів тому

    Hi Klas, very handy script. I'm not sure if it is chjanges in QGIS since you posted this, but when I set it up and run it as you have shown, it will only allow one single label per parent contour. so if multiple label line geometries cross the parent contours, it will only label one of the intersections, not all of them as happens in your video. is there a missing setting somewhere?

    • @KlasKarlsson
      @KlasKarlsson  13 днів тому

      @@Ben-NMN could it be a question of multi part or singel part geometries?

    • @Ben-NMN
      @Ben-NMN 12 днів тому

      @@KlasKarlsson The contours were generated using Raster->Extraction->Contour from a DEM geotiff and are type "MultiLineStringZ. the label line geometries were drawn in QGIS as type "MultiLineString" and saved as a shapefile. What were the types in your example?

  • @yorkzhao8169
    @yorkzhao8169 Рік тому +1

    how the hillshade effect made?

  • @petterson1971
    @petterson1971 Рік тому +2

    does anybody know a solution to display the altitude labels correctly - always facing to the top?

    • @KlasKarlsson
      @KlasKarlsson  Рік тому +1

      Try this (at 8 min): ua-cam.com/video/-xzoVF7Z7u0/v-deo.htmlsi=co42L6mgXGlstQhU

  • @felipediniz2048
    @felipediniz2048 Рік тому

    Are you having trouble exporting maps with masks on QGIS 3.32?

  • @CxcSerpentine
    @CxcSerpentine Рік тому

    i'm the winner... 1 hundred
    ... thank you

  • @roelmsantiago
    @roelmsantiago Рік тому

    Hello Klas..can I ask your inputs how to do a symbology bypass for two lines (of same layer) intersecting each other with geometry generator? Thanks

  • @Bos_Taurus
    @Bos_Taurus 6 місяців тому

    My labels don't apear on the intersections. The label line only dictates witch contur gets a label

  • @swissfreek
    @swissfreek Рік тому

    To me the next step after this is making the contour labels “aggregate” with the zoom level. That is, as you zoom out you see fewer. How would this be accomplished? Just using a zoom range modifier to make every third or fourth one visible, etc? Would that also be possible to do with SVG objects so that as you zoom out they “combine” to reduce clutter.

    • @KlasKarlsson
      @KlasKarlsson  Рік тому +2

      Not sure about SVG, but for selective rendering depending on scale you can absolutely use geometry generators:
      with_variable(
      'factor',
      to_int(
      scale_linear(
      value:=@map_scale,
      domain_min:=1000000,
      domain_max:=10000000,
      range_min:=1,
      range_max:=10)),
      if("ELEV"%(@factor*100)=0,
      $geometry,'')
      )

  • @thomasdevos408
    @thomasdevos408 Рік тому

    Am I wrong that for the intersect you can use the overlay_intersects function?

    • @KlasKarlsson
      @KlasKarlsson  Рік тому

      You can usually do a lot of things multiple ways. In this case you are right, overlay_intersects() gets you the same result as intersects(aggregate...) but with less code. Well spotted!