我正在为具有PostGIS函数的postgreSQL数据库编写客户机。这个客户端当然是通过php进行通信的。然而,我正在寻找一个合适的文档,为可用的postGIS函数,我可以从我的php文件调用。
如果我能得到一个简单的例子来说明postGIS函数是如何集成到php中的,我会非常感激的。
干杯:)
发布于 2012-12-17 03:04:11
Postgis是可在postgresql数据库中的某个模式中使用的存储过程。如果你有PDO,你可以编写像对象一样调用然后关闭的过程。有关可用的获取模式,请参阅PHP PDO。
<?php
require_once 'constants.php';
class Postgis extends PDO
{
public function __construct()
{
$this->pg = new PDO( PDO_DB_DSN );
$this->pg->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
public function makePoint( $x, $y )
{
$preparedStatement = $this->pg->prepare( 'SELECT public.st_makepoint( ?, ? )' );
$preparedStatement->execute( array( $x, $y ) );
return $preparedStatement->fetchColumn();
}
}
try
{
$postgis = new Postgis();
$point = $postgis->makePoint( 34, 44 ); //point holds the binary string of a point without srid
var_dump( $point );
}
catch ( PDOException $e )
{
// any errors here
var_dump( $e->getMessage() );
}
?>发布于 2012-12-01 18:41:31
PostGIS在其网站上列出了它的所有类型和功能,例如这里是Version 1.5 reference documentation。您可以将这些函数作为SQL调用,就像从PHP中调用任何其他SQL一样。
因此,使用PHP的内置PostgreSQL函数,您可以执行以下操作:
$result = pg_query_params('
SELECT ST_Distance( location, ST_SetSRID(ST_Point($1, $2), 27700) )
FROM table WHERE id=$3', array(400000, 300000, 123) );获取从英国网格参考系中的(400,000,300,000)到数据库表中第123行的位置列的距离(以米为单位)。
PostGIS函数周围可能有PHP包装器,但恐怕我不知道有什么包装器
https://stackoverflow.com/questions/13656177
复制相似问题