Kou*_*osh 2 php postgresql geocoding postgis function
我正在为具有PostGIS功能的PostgreSQL数据库编写客户端。该客户端当然通过php进行通信。但是,我正在寻找可用的postGIS功能的适当文档,这些文档可以从我的php文件调用。
如果能得到一个简单的示例说明如何将POSTGIS功能集成到PHP中,我将不胜感激。
干杯:)
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() );
}
?>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2846 次 |
最近记录: |