Last active
March 22, 2024 02:36
-
-
Save sebastian-meier/5461e2af42f674ad47027fb774597947 to your computer and use it in GitHub Desktop.
QGIS Geometry Generators - CartoHack #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| collect_geometries( | |
| array_foreach( | |
| generate_series(1, to_int("count"), 1), | |
| translate( | |
| geom_from_wkt( | |
| concat( | |
| 'LINESTRING(0 50,', | |
| to_string(rand(-25, 25, concat("fid", '_x', @element))), | |
| ' ', | |
| to_string(rand(-5, 5, concat("fid", '_y', @element))), | |
| ')' | |
| ) | |
| ), | |
| x($geometry), | |
| y($geometry) | |
| ) | |
| ) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| collect_geometries( | |
| array_foreach( | |
| generate_series(1, to_int("count"), 1), | |
| translate( | |
| translate( | |
| rotate( | |
| geom_from_wkt( | |
| 'CURVEPOLYGON( | |
| COMPOUNDCURVE( | |
| CIRCULARSTRING( | |
| 0 0, 15 -5, 30 0, | |
| 15 5, 0 0 | |
| ) | |
| ) | |
| )' | |
| ), rand(-200, 20, concat("fid", '_r', @element)), make_point(0, 0) | |
| ), x($geometry), y($geometry) | |
| ), rand(-25, 25, concat("fid", '_x', @element) ), rand(-5, 5, concat("fid", '_y', @element) ) | |
| ) | |
| ) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from qgis.core import * | |
| from qgis.gui import * | |
| import math | |
| @qgsfunction(args='auto', group='Custom') | |
| def polar_point(radius, angle, feature, parent): | |
| """ | |
| Calculates the polar coordinate from radius and angle (in radians) | |
| <h2>Example usage:</h2> | |
| <ul> | |
| <li>polar_point(5, pi) -> 5</li> | |
| </ul> | |
| """ | |
| x = radius * math.cos(angle) | |
| y = radius * math.sin(angle) | |
| # point = QgsPoint(x, y) | |
| return str(x) + ' ' + str(y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with_variable( | |
| 'radius', | |
| 20, | |
| collect_geometries( | |
| array_foreach( | |
| generate_series(1, "count" * 5, 1), | |
| translate( | |
| geom_from_wkt( | |
| concat( | |
| 'LINESTRING(0 0,', | |
| polar_point( | |
| @radius + randf(0, 15), | |
| pi() * 2 / ("count" * 5) * @element | |
| ), | |
| ')' | |
| ) | |
| ), | |
| x($geometry), | |
| y($geometry) | |
| ) | |
| ) | |
| ) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with_variable( | |
| 'config', | |
| map( | |
| 'steps_x', 50, | |
| 'steps_y', 50, | |
| 'elevation', 0.0002, | |
| 'raster_layer', 'srtm_germany_dtm' | |
| ), | |
| collect_geometries( | |
| array_foreach( | |
| generate_series( | |
| y_min($geometry), | |
| y_max($geometry), | |
| (y_max($geometry) - y_min($geometry)) / @config['steps_y'] | |
| ), | |
| with_variable( | |
| 'cY', | |
| @element, | |
| geom_from_wkt( | |
| concat( | |
| 'LINESTRING(', | |
| array_to_string( | |
| array_foreach( | |
| generate_series( | |
| x_min($geometry), | |
| x_max($geometry), | |
| (x_max($geometry) - x_min($geometry)) / @config['steps_x'] | |
| ), | |
| concat( | |
| to_string(@element), | |
| ' ', | |
| to_string( | |
| @cY + | |
| coalesce( | |
| raster_value( | |
| @config['raster_layer'], | |
| 1, | |
| make_point( | |
| @element, | |
| @cY | |
| ) | |
| ), | |
| 0 | |
| ) * @config['elevation'] | |
| ) | |
| ) | |
| ), | |
| ',' | |
| ), | |
| ')' | |
| ) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment