简体   繁体   中英

postgis st_contains not seems

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

The GeoJSON has several errors, and does not conform to the specification , such as:

  1. You need to flip the axis order to (XY) or (lng lat). It might not matter now, but it will if you try to do anything else.
  2. The LinearRing for the Polygon is really broken, and needs to consist of a single sequence of closed coordinates.
  3. The CRS property is provided for one geometry but not the other, which would normally raise a "Operation on mixed SRID geometries" error from PostGIS. Provide the CRS for both or none of the geometries.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM