Skip to content

Instantly share code, notes, and snippets.

@Linell
Created November 23, 2015 21:49
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 Linell/ad89b43b4075569cad4b to your computer and use it in GitHub Desktop.
Save Linell/ad89b43b4075569cad4b to your computer and use it in GitHub Desktop.
-- Works perfectly!
SELECT COUNT(*),
ST_Union(geom) as location_union,
ST_SnapToGrid(ST_Transform(ST_SnapToGrid(ST_Transform(geom, _ST_BestSRID(geom)), 10,10),4326),0.0001, 0.0001) AS snap_pt
FROM locations
GROUP BY snap_pt
HAVING COUNT(*) > 1;
-- But what's a decent way to figure out which groups contain a given user?
-- I can use the following query to get the list of users in an example ST_Union from above:
select distinct(user_id)
from locations
where ST_Contains('0104000020E610000003000000010100000074EFE192E38656C019E25817B735404001010000006284F068E38656C019E25817B735404001010000002D431CEBE28656C068B3EA73B5354040', geom);
-- If it was only valid SQL
SELECT COUNT(*),
ST_Union(geom) as location_union,
ST_SnapToGrid(ST_Transform(ST_SnapToGrid(ST_Transform(geom, _ST_BestSRID(geom)), 10,10),4326),0.0001, 0.0001) AS snap_pt
FROM locations
GROUP BY snap_pt
HAVING COUNT(*) > 1
and '1' in (
select user_id from locations where ST_Contains(location_union)
)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment