Skip to content

Instantly share code, notes, and snippets.

@minostro
Last active December 29, 2015 19:08
Show Gist options
  • Save minostro/7714901 to your computer and use it in GitHub Desktop.
Save minostro/7714901 to your computer and use it in GitHub Desktop.
Select the points belonging to a given checkpoint area. First, I create the tables checkpoint and point. Then, two checkpoints are created, and five points are inserted. Finally, I define the query that fulfill the statement.
CREATE TABLE public.checkpoint (
id SERIAL PRIMARY KEY,
geom GEOMETRY(Point, 26910),
radio int,
name VARCHAR(128)
);
CREATE INDEX public.checkpoint_geom_index
ON public.checkpoint
USING GIST (geom);
INSERT INTO public.checkpoint (geom, radio) VALUES (
ST_GeomFromText('POINT(0 0)', 26910),
50
);
INSERT INTO public.checkpoint (geom, radio) VALUES (
ST_GeomFromText('POINT(100 100)', 26910),
50
);
CREATE TABLE public.point (
id SERIAL PRIMARY KEY,
geom GEOMETRY(Point, 26910)
);
CREATE INDEX public.point_geom_index
ON public.point
USING GIST (geom);
INSERT INTO public.point (geom) VALUES (
ST_GeomFromText('POINT(0 0)', 26910)
);
INSERT INTO public.point (geom) VALUES (
ST_GeomFromText('POINT(0 25)', 26910)
);
INSERT INTO public.point (geom) VALUES (
ST_GeomFromText('POINT(0 50)', 26910)
);
INSERT INTO public.point (geom) VALUES (
ST_GeomFromText('POINT(0 51)', 26910)
);
INSERT INTO public.point (geom) VALUES (
ST_GeomFromText('POINT(101 101)', 26910)
);
SELECT
*
FROM public.checkpoint
INNER JOIN public.point ON ST_DWithin(public.point.geom, public.checkpoint.geom, public.checkpoint.radio);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment