Skip to content

Instantly share code, notes, and snippets.

@alotau
Created June 20, 2017 15:21
Show Gist options
  • Save alotau/5c5cfb0233a53ef2263e5256239d6d3c to your computer and use it in GitHub Desktop.
Save alotau/5c5cfb0233a53ef2263e5256239d6d3c to your computer and use it in GitHub Desktop.
Needed to create circles of varying radii from point-distance data in PostGIS table
# Assumptions:
# 1. You have a table (sample) with a Geography column (loc).
# 2. That column contains only points (not a hard reqmt).
# 3. You have a double precision column representing radius.
# 4. That radius is in METERS (otherwise need to convert something somewhere).
# Found it easiest to create a new table rather than
# a view for use within QGIS.
CREATE TABLE sample_buffers AS
SELECT ST_Buffer(sample.loc,sample.radius_meters)
FROM sample;
# More clarity for me to rename the column here than in
# the query above.
ALTER TABLE sample_buffers RENAME COLUMN st_buffer TO my_circles;
# Make the sole column the primary key (req'd for QGIS)
ALTER TABLE sample_buffers ADD PRIMARY KEY (my_circles);
# Now just add a PostGIS layer as normal to QGIS pointing at sample_buffers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment