Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamishcampbell/62d4fd39cc231dfcaf66b5390a12fe35 to your computer and use it in GitHub Desktop.
Save hamishcampbell/62d4fd39cc231dfcaf66b5390a12fe35 to your computer and use it in GitHub Desktop.
QGIS Geometry Generator expression to approximate rock outcroppings
with_variable(
'segment_len',
11, -- the length of each segment
collect_geometries(
array_foreach(
generate_series(
0, length(boundary($geometry)) - @segment_len, @segment_len
),
with_variable('offset_inner',
offset_curve(
make_line(
line_interpolate_point(boundary($geometry), @element),
line_interpolate_point(boundary($geometry), @element + @segment_len)
),
rand(1,11), -- range offset of the inner boundaries
1
),
with_variable('offset_outer',
offset_curve(
make_line(
line_interpolate_point(boundary($geometry), @element),
line_interpolate_point(boundary($geometry), @element + @segment_len)
),
rand(12,30), -- range offset of the outer boundaries
1
),
collect_geometries(
@offset_outer,
make_line(
start_point(@offset_inner),
start_point(@offset_outer)
),
make_line(
end_point(@offset_inner),
end_point(@offset_outer)
)
)
)
)
)
)
)
@JakeOsborneDOC
Copy link

Been looking in to this again recently; and can't get this to render anything with the LINZ rock data in QGIS 3.2.3. Other than changing the geometry type to linestring is there something else I'm missing?

@hamishcampbell
Copy link
Author

Hi Jake, it still seems to work for me. You do need to set the output to Geometry Type to "LineString" though.

Example:

Screen Shot 2020-08-10 at 8 11 33 PM

@JakeOsborneDOC
Copy link

I get an expression error:
image

@JakeOsborneDOC
Copy link

Update: It was my version of QGIS in the end. Upgraded to 3.14 (I wish they'd use leading zeros) and it worked without issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment