Reputation: 909
I am new to postgis and I cant figure out why this returns false(in the ST_contains function) for any value I try in the point
select st_astext(geoma),
st_astext(geomb),
st_contains(geoma,geomb)
from (
select
ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[25.64214,-100.27873]],[[25.69505,-100.37006]],[[25.72599,-100.27702]],[[25.680978320466,-100.25384240723]]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}') as geomA,
ST_GeomFromGeoJSON('{"type":"Point","coordinates":[25.683096, -100.311577]}') as geomB
) as p
I drew the points in google maps to confirm my data supposedly, but it returns false when according to google maps it should be true
Upvotes: 0
Views: 544
Reputation: 43692
The GeoJSON has several errors, and does not conform to the specification, such as:
Try this:
SELECT ST_AsText(geomA),
ST_AsText(geomB),
ST_Contains(geomA, geomB)
FROM (
SELECT
ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-100.27873,25.64214],[-100.37006,25.69505],[-100.27702,25.72599],[-100.25384240723,25.680978320466],[-100.27873,25.64214]]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}') AS geomA,
ST_GeomFromGeoJSON('{"type":"Point","coordinates":[-100.311577,25.683096],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}') AS geomB
) AS p;
-[ RECORD 1 ]----------------------------------------------------------------------------------------------------------------------------
st_astext | POLYGON((-100.27873 25.64214,-100.37006 25.69505,-100.27702 25.72599,-100.25384240723 25.680978320466,-100.27873 25.64214))
st_astext | POINT(-100.311577 25.683096)
st_contains | t
Upvotes: 3