Created
May 15, 2019 11:58
-
-
Save pigreco/0baedb2f7249ba8df8bc16b417880637 to your computer and use it in GitHub Desktop.
Genera 1000 punti random all'interno di un BoundingBox di un poligono
This file contains 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
-- creo una tabella vuota che conterrà i random point | |
CREATE TABLE point_bb | |
(id INTEGER PRIMARY KEY AUTOINCREMENT,cir_id INTEGER); | |
-- popolo ID tabella | |
INSERT INTO point_bb | |
WITH RECURSIVE | |
cnt(id) AS ( SELECT 1 UNION ALL SELECT id + 1 FROM cnt LIMIT 1000) | |
SELECT id,0 FROM cnt; | |
-- aggiorno tabella con i punti casuali usando bounding box del poligono | |
SELECT AddGeometryColumn ('point_bb','geom',4326,'POINT','XY'); | |
UPDATE point_bb SET | |
geom = (SELECT makepoint ( | |
CAST ((select (0.5 - RANDOM()/CAST(-9223372036854775808 AS REAL)/ 2)*(extent_max_x - extent_min_x) + extent_min_x | |
FROM "vector_layers_statistics" WHERE id=point_bb.id AND table_name = 'poly') AS REAL), | |
CAST ((select (0.5 - RANDOM()/CAST(-9223372036854775808 AS REAL)/ 2)*(extent_max_y - extent_min_y) + extent_min_y | |
FROM "vector_layers_statistics" WHERE id=point_bb.id AND table_name = 'poly') AS REAL), 4326) WHERE id=point_bb.id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ecco output in QGIS:
qui database sqlite con poligono:
https://bit.ly/2HlvAoQ