PHP 查询(包括 PostGiS 函数)returns 无

PHP query (including PostGiS functions) returns nothing

我编写了一个脚本,根据某个点是否在多边形内向我发送 return ID。目前,当我在我的数据库或 Postman 上调用脚本时,这是有效的,但当我在其他地方调用它时,它不起作用。

我查看了 post 请求正文并且 'Coordinates' 不是地理编码版本(我的猜测),我试图在查询中解压缩它没有'工作。我能够在不同查询中解压缩它的唯一方法是 st_asgeojson 然后在结果上使用 json_decode 但我希望在一个查询中完成此操作。

坐标按以下代码传递:

"0101000020E6100000000000000040604000000000000039C0"

我想在查询外或查询内转换它,然后从我的查询中获取结果。我的PHP代码如下:

<?php

require_once('../db.php');

$rawdata = file_get_contents("php://input");
$decoded = json_decode($rawdata, true);
$coordVar = handleCoords($decoded['event']['data']['new']['Coordinates']['coordinates']);

$res = pg_query_params($conn, 'SELECT "ShapeID" FROM "Shapes" WHERE st_within( ST_SetSRID( ST_MakePoint(, ), 4326), "Coordinates"::geometry) ', array($coordVar[0], $coordVar[1]));
while ($row = pg_fetch_assoc($res) ){
    print_r($row['ShapeID]);
}
   

function handleCoords($data) {
    return array($data[0], $data[1]);
}

?>

在测试我的查询时,我从我的一个表中获得了“坐标”,在查看结果时这是一个 bytea 代码,因为这是一种地理数据类型。我通过使用 ::geometry 转换解决了这个问题,考虑到这一点,我遇到的问题是一个简单的修复。由于通过 POST 请求正文传递的坐标也是相同的数据类型,地理,因此应用相同的转换将允许查询在从任何应用程序调用时工作。

代码如下:

<?php

require_once('../db.php');

$rawdata = file_get_contents("php://input");
$decoded = json_decode($rawdata, true);
$coordVar = handleCoords($decoded['event']['data']['new']['Coordinates']);

$res = pg_query_params($conn, 'SELECT "ShapeID" FROM "Shapes" WHERE st_within( ST_SetSRID( ::geometry, 4326), "Coordinates"::geometry) ', array($coordVar));
while ($row = pg_fetch_assoc($res) ){
    print_r($row['ShapeID]);
}
   
?>