PostGIS 関数を使用して、postgreSQL データベースのクライアントを作成しています。もちろん、このクライアントはphpを介して通信します。ただし、php ファイルから呼び出すことができる利用可能な postGIS 関数の適切なドキュメントを探しています。
postGIS関数がphpにどのように統合されているかの簡単な例を得ることができれば、本当に感謝しています.
乾杯 :)
PostGIS 関数を使用して、postgreSQL データベースのクライアントを作成しています。もちろん、このクライアントはphpを介して通信します。ただし、php ファイルから呼び出すことができる利用可能な postGIS 関数の適切なドキュメントを探しています。
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() );
}
?>
PostGIS lists all its types and functions on its website, for example here is the Version 1.5 reference documentation. You can call these functions as SQL, just as you are calling any other SQL from the PHP.
So using PHP's built-in PostgreSQL function, you could do something like:
$result = pg_query_params('
SELECT ST_Distance( location, ST_SetSRID(ST_Point($1, $2), 27700) )
FROM table WHERE id=$3', array(400000, 300000, 123) );
To get the distance in metres from (400,000, 300,000) in the British grid-reference system to the location column of row 123 in your database table.
There might well be PHP wrappers around PostGIS functions, but I'm afraid I'm not aware of any