Skip to content

Instantly share code, notes, and snippets.

@hrwgc
Last active December 19, 2015 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrwgc/5910232 to your computer and use it in GitHub Desktop.
Save hrwgc/5910232 to your computer and use it in GitHub Desktop.
postgis select across polygon layers based on nearest adjacent polygon from other layer.
create table
closest_point as
select distinct on (a.featureid) a.featureid as image_id,
(select b.eventid from fl_events as b order by st_distance(a.wkb_geometry,b.wkb_geometry) limit 1) as event_id,
a.wkb_geometry from images as a,
fl_events as b;
update images set eventid = closest_point.event_id from closest_point where images.featureid = closest_point.image_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment