Skip to content

Instantly share code, notes, and snippets.

@renzok
Created October 23, 2015 07:39
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 renzok/3fd2071038d74f6af5fe to your computer and use it in GitHub Desktop.
Save renzok/3fd2071038d74f6af5fe to your computer and use it in GitHub Desktop.
CREATE MATERIALIZED VIEW osdregistry.sample_boundaries_tagging AS
WITH boundary AS (
SELECT DISTINCT ON (osd.submission_id)
osd.submission_id,
osd.osd_id,
b.gid,
b.iso3_code,
st_distance(osd.start_geog, b.geog) as dist_m
FROM elayers.boundary_polygons b
JOIN osdregistry.samples osd
ON ( st_dwithin(osd.start_geog, b.geog, 1000000::double precision) )
ORDER BY osd.submission_id, st_distance(osd.start_geog, b.geog)
)
SELECT *
FROM boundary b
ORDER BY b.osd_id DESC
;
ALTER TABLE osdregistry.sample_boundaries_tagging
OWNER TO megdb_admin;
GRANT ALL ON TABLE osdregistry.sample_boundaries_tagging TO megdb_admin;
GRANT SELECT ON TABLE osdregistry.sample_boundaries_tagging TO megx_team WITH GRANT OPTION;
COMMENT ON MATERIALIZED VIEW osdregistry.sample_boundaries_tagging
IS 'Distance to OSD sampling site to nearest country border taken as coastline based on elayers.boundaries.';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment