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
Advertisement
Answer
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.