Postgis - one environment contains another
I am using postgis with gps data and am trying to figure out if one circle with GPS coordinate and radius (in meters) contains another.
I can do this if I don't use GPS coordinates, but just points on the graph, but it doesn't work if I replace the lat and lon points:
-- A circle within a circle
SELECT ST_Contains(bigc,smallc) As bigcontainssmall
FROM (SELECT ST_Buffer(ST_MakePoint(21, 38)::geography, 40) As smallc,
ST_Buffer(ST_MakePoint(21, 39)::geography, 400) AS bigc) foo;
Thoughts?
+3
source to share
1 answer
My approach:
- Assign CRS (Coordinate Reference System) to gps data (I assume it is in WGS84, so srid 4326) via SRID (
ST_SetSRID(your_geom, 4326)
does this) - Then (maybe only if you assigned srid 4326) cast them to geography (
::geography
does this) to enable the buffer setting in meters, - And put them back in geometry (
::geometry
does this) for a functionst_contains
to work
Query:
SELECT ST_Contains(bigc::geometry,smallc::geometry) as bigcontainssmall
from (select
st_buffer(ST_SetSRID(ST_MakePoint(-71.10434, 42.31506),4326)::geography,40) as smallc,
st_buffer(ST_SetSRID(ST_MakePoint(-71.10434, 42.31507),4326)::geography,400) as bigc) foo
+5
source to share