0

I am using postegresql with php (specifically the postgis extension and the ST_Contains function) for a spatial related query.

The query is the following:

$within = pg_exec($db, 
"select st_contains(st_geomfromtext('POLYGON((
                                             41.7750000000 19.3666666667,
                                             34.4750000000 19.3666666667,
                                             34.4750000000 29.6500000000,
                                             41.7750000000 29.6500000000, 
                                             41.7750000000 19.3666666667))'), 
                                             ST_MakePoint('$lat', '$lng'))" );



$rows = pg_fetch_all ($within);
echo json_encode($rows);

The result of this is [{"st_contains":"t"}] or [{"st_contains":"f"}], however i want it to be just true or false/ 0 or 1 so i can be able to use it on an if condition. I tried using the EXISTS on the postgresql query but it messes up the query and gives wrong results. Is there any way to get a normal true/fase/0/1 out of this query so i can use it latter on? Thanks.

3
  • Um... $result = ($rows[0]['st_contains'] == 't');? Commented May 5, 2016 at 17:44
  • I think this will work, thank you. Commented May 5, 2016 at 17:52
  • Have a look to stackoverflow.com/questions/31643297/… Commented May 6, 2016 at 9:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.