Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgis: function st_contains does not exist

I am struggling to get a simple Postgresql/Postgis statement to work, I need all points within a polygon (in this case a rectangle)

SELECT * FROM points_table WHERE ST_Contains( ST_GEOMFROMTEXT('POLYGON((51.8121, 0.13712199999997665, 51.9078, 0.21444399999995767))'), points_table.geom)

The error reads

ERROR:  function st_contains(geometry, geography) does not exist
LINE 1: SELECT * FROM points_table WHERE ST_Contains( ST_GEOMFRO...
                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

********** Error **********

ERROR: function st_contains(geometry, geography) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Character: 38

The answer from this question amongst others suggests my statement is correct.

like image 526
ggdx Avatar asked Oct 20 '25 16:10

ggdx


2 Answers

Seems you are comparing GEOMETRY and GEOGRAPHY

As in your message error st_contains(geometry, geography)

be sure that your column points_table.geom is a valid GEOMETRY data type and not a GEOGRAPHY data type .. for this chek also for the SR you are using and eventually convert you geomtext as a valid SR for geography

eg assuming you using as SR 4326

SELECT * 
FROM points_table 
WHERE ST_Contains(
  ST_Transform(
  ST_GEOMFROMTEXT('POLYGON((51.8121, 0.13712199999997665, 51.9078, 0.21444399999995767))')
  ,4326)
, points_table.geom) 
like image 197
ScaisEdge Avatar answered Oct 23 '25 06:10

ScaisEdge


I solved this problem by joining on public.ST_CONTAINS(geom, coords) instead of ST_CONTAINS(geom, coords)

I don't really understand enough about Postgresql to know why this worked though. I just skimmed https://gis.stackexchange.com/questions/132103/postgis-st-within-does-not-exist and hoped for the best.

like image 42
Jeremy Avatar answered Oct 23 '25 06:10

Jeremy