Skip to content

Instantly share code, notes, and snippets.

@zimmicz
Created September 21, 2016 18:09
Show Gist options
  • Save zimmicz/01131920f3560dc294c1e279cd1ac2b0 to your computer and use it in GitHub Desktop.
Save zimmicz/01131920f3560dc294c1e279cd1ac2b0 to your computer and use it in GitHub Desktop.
SELECT
a.id,
b.*
FROM (
VALUES(
1,
ST_SetSRID(
ST_GeomFromText(
'POLYGON((0 0, -1 0, -1 -1, 0 -1, 0 0))'
),
4326)
)
UNION ALL
VALUES(
2,
ST_SetSRID(
ST_GeomFromText(
'POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'
),
4326)
)
) a(id, geom)
CROSS JOIN LATERAL (
SELECT ST_SetSRID(ST_MakePoint(tmp.x, tmp.y), 4326) geom
FROM (
SELECT
random() * (ST_XMax(a.geom) - ST_XMin(a.geom)) + ST_XMin(a.geom) x,
random() * (ST_YMax(a.geom) - ST_YMin(a.geom)) + ST_YMin(a.geom) y
FROM generate_series(0,200)
) tmp
) b;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment