Mapping

Show Only ...
Maps - Photos - Videos

How to label a point in QGIS based on a vector layer below it

How to label a point in QGIS based on a vector layer below it

For example, you might have a point layer and want to label what town it is in. You might have the Census Tiger County Subdivision layer named ‘tl_2020_36_cousub20’, with the field ‘NAMELSAD20’ that you want to return from your point or polygon layer.

attribute(array_first(overlay_nearest(‘tl_2020_36_cousub20′,$currentfeature)),’NAMELSAD20’)

This will give you the nearest feature.

You need to wrap it in array_first as shown above, as overlay_nearest returns an array with one element. Then attribute just returns the attribute based on the object provided.

Alternatives include overlay_contains, overlay_crosses, overlay_intersects, overlay_touches, overlay_within which will return what you want. Try searching the QGIS Help in the QGIS Expressions builder.

You can also use this style of expression to create a spatial join or nearest neighbor join, inside the field calculator.

I’ve noticed that QGIS doesn’t always do a good job simplifying geometries when exporting to an SVG file

I’ve noticed that QGIS doesn’t always do a good job simplifying geometries when exporting to an SVG file. While you can manually simplify layers, an easier method is as follows:

1) Open Layer Styling

2) Go to Symbology

3) Switch fill to Geometry Generator

4) Use the Simplify Expression to Simplify on the Fly, such as simplifying by 100 map units, which when projected in UTM would be meters.

simplify($geometry,100)