Skip to content

Instantly share code, notes, and snippets.

@njanakiev
Last active August 4, 2020 08:58
Show Gist options
  • Save njanakiev/47a144d3d11d249a1d347af37e9b7317 to your computer and use it in GitHub Desktop.
Save njanakiev/47a144d3d11d249a1d347af37e9b7317 to your computer and use it in GitHub Desktop.
Voronoi Diagram of the World with Capitals as Centroids
CREATE TABLE ne_voronoi AS (
WITH ne_voronoi_polygons AS (
SELECT (ST_Dump(ST_VoronoiPolygons(ST_collect(geom)))).geom AS geom
FROM ne_110m_populated_places
WHERE featurecla = 'Admin-0 capital'
)
SELECT ST_Intersection(a.geom, b.geom) AS geom
FROM (
SELECT ST_Union(wkb_geometry) AS geom
FROM ne_110m_admin_0_countries
) a
CROSS JOIN ne_voronoi_polygons b
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment