# Halftone effect: gridded points inside polygon with QGIS Geometry Generator

I am trying to create smooth looking polygons by gridded points in QGIS (2.18.16), with a fading effect towards the boundary of the polygons (halftone effect).

By using the 'fillGrid' function from @Rob J (Currently the Error 526), I managed to create gridded point pattern in Geometry Generator.

Now I would like to add a size decrease of the point marker towards the boundary of each polygon starting from a maximum size (e.g. 2 mm) to a minimum size (0 mm). What is the best way to do this? Maybe there is a faster way by using the standard 'point pattern' option as symbol layer type?

Example image demonstrates the desired effect inside each polygon. • Could you please edit your question to include some screenshots of what you have? :) May 9, 2018 at 9:25
• Hope this helps! The code is exactly as in the link, let me know if I should insert this code here too :) May 9, 2018 at 9:32
• I suggest adding a field to the points layer that calculates the distance between that point and the centroid of the polygon. Then base the size of the point on that field.
– csk
May 9, 2018 at 19:19
• My previous comment was based on the points being in a separate layer. I don't think you can do a distance calculation using a generated geometry.
– csk
May 9, 2018 at 19:35
• Thanks @csk for the option. I might consider this for now, but I would still prefer to know whether it is possible using geometry generator. May 15, 2018 at 12:46

You can fill your polygon with regularily spaced points using this expression with geometry generator. Points are spaced 20 km (20000m, change this at the end of line 4 and 10 if needed). Be sure to have the data in a projected CRS with units in meters to get correctly spaced points.

`````` intersection (
collect_geometries(
array_foreach (
generate_series(0,y_max(\$geometry)-ymin(\$geometry),20000),
with_variable (
'ydist',
@element,
collect_geometries(
array_foreach(
generate_series(0,x_max(\$geometry)-x_min(\$geometry),20000),
project (
make_point (x_min(\$geometry),y_min(\$geometry)+@ydist),
@element,
)
)
)
)
)
),
\$geometry
)
`````` However, you can't individually set the size of each point as you still deal with just one single (multipart) feature - so you can only set the size for all dots at once. To solve this, use the same expression as above with Geometry by expression to turn these points to actual (multipart) geometries. Convert the resulting layer to single parts using Multipart to singleparts.

Now you can individually style each point separately. Set a data driven override for the size of the symbol and choose assistant: Now you can make what @CSK proposed: calculate the length from each point to the centroid of the polygon shape and divide 1 with this value (the get shrinking size with increasing distance). For this, you can use the following expression. Be aware: you could insert it directly to the `source` field, but depending on how many points you have, rendering will get very slow and you even risk QGIS crashing. So it's better to create this value as an attribute called `size` using Field calculator. Whatever option you use, the expression remains the same (replace `countries` with the name of the polygon layer containing the country shapes and adapt the multiplication factor `*10` at the end to get reasonable numbers):

``````1 / length (
make_line (
\$geometry,
centroid (
array_first(
overlay_within(
'countries',
\$geometry
)
)
)
)
)*10
``````

Now set the calculated `size` field as source in the assistant, then load values for `Values from/to` (double arrow icon) and set `Size from/To`. Apply a transformation curve if needed and experiment with `Scale method/Exponent` to get optimal results: 