MacaScull
MacaScull

Reputation: 181

ST_WITHIN function does not exist

Im confused on how to use this function within my query. My code that I am using is as follows:

$res = pg_query($conn, 'SELECT "Coordinates" FROM "Shapes" WHERE st_within(point(0,0)::geometry, "Coordinates") ');

When I try run this I get this error:


Warning: pg_query_params(): Query failed: ERROR: function st_within(geometry, geography) does not exist

HINT: No function matches the given name and argument types. You might need to add explicit type casts.

I want Coordinates to a polygon, so this may need to be an array of geometries

Upvotes: 0

Views: 2553

Answers (2)

MacaScull
MacaScull

Reputation: 181

I did some research and tried some different functions, with this I got different errors, one appeared as such:

Warning: pg_query_params(): Query failed: ERROR: contains: Operation on mixed SRID geometries (Polygon, 4326) != (Point, 0) in /var/www/html/watchlist/coordChange.php on line 45

Using the following code:

pg_query($conn, 'SELECT "Coordinates" FROM "Shapes" WHERE st_within( ST_MakePoint(130, -25), "Coordinates"::geometry) ');

From here I searched some more and used another function ST_SetSRID(), like so:

pg_query($conn, 'SELECT "Coordinates" FROM "Shapes" WHERE st_within( ST_SetSRID( ST_MakePoint(130, -25), 4326), "Coordinates"::geometry) '); 

This then produced the result I want.

Upvotes: 0

Emre Tuna
Emre Tuna

Reputation: 115

ST_Within function takes two geometry parameters like this "ST_Within(geometry A, geometry B)". You should make sure the parameters of "Coordinates" is actually geometry.

Upvotes: 1

Related Questions