GIS and Media fusion

"The explosive growth of the GeoWeb and geographic information has made GIS powerful media for the general public to communicate, but perhaps more importantly, GIS have also become media for constructive dialogs and interactions about social issues." - Sui & Goodchild

User Tools

Site Tools


geoinf15:postgis0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
geoinf15:postgis0 [2017/11/15 23:16]
oertz
geoinf15:postgis0 [2018/05/16 10:05] (current)
Line 26: Line 26:
 </​code>​ </​code>​
  
-===== Géoservice Get4Capitals.php ===== 
-Cet exemple montre comment créer un service sur mesure qui va //publier// l'​information géographique de la géotable. Il est notamment fait usage du format GeoJSON pour transmettre ces données au client. OpenLayers saura par exemple l'​exploiter facilement au travers d'une couche ol.Vector et le format ol.format.GeoJSON. 
- 
-<​code>​ 
-<?php 
-require_once '​GeoManager.php';​ 
-$conn = new Connection("​host=127.0.0.1 port=5432 dbname=php user=admintoto password=blablatutu"​);​ 
- 
-$query = "​SELECT name, ST_AsGeoJSON(the_geom) from my4capitals";​ 
-$result = $conn->​selectQuery($query);​ 
- 
-$i = 0; 
-$fc = new FeatureCollection();​ 
-while ($row = pg_fetch_row($result)) { 
-    $fc->​addFeature(new Feature($i++,​ (json_decode($row[1])),​ array("​name"​ => $row[0]))); 
-} 
-echo json_encode($fc);​ 
-?> 
-</​code>​ 
- 
-On a besoin d'un GeoManager (GeoManager.php) qui sait gérer les requêtes avec la geodatabase et encoder les résultats par un flux GeoJSON. 
-<​code>​ 
-<?php 
-class Connection { 
- 
-    private $CONFIG; 
-    private $CONN; 
- 
-    function __construct($cfg) { 
-        $this->​CONFIG = $cfg; 
-        return $this->​CONN = pg_connect($this->​CONFIG) or die('​connection failed'​);​ 
-    } 
- 
-    function selectQuery($query) { 
-        $result = pg_query($this->​CONN,​ $query); 
-        if (!$result) throw new ErrorException($query);​ 
-        return $result; 
-    } 
- 
-    function insertQuery($query) { 
-        pg_query($this->​CONN,​ "BEGIN WORK"​);​ 
-        $result = pg_query($this->​CONN,​ $query); 
-        if (!$result) { 
-            pg_query($this->​CONN,​ "​ROLLBACK"​);​ 
-        } else { 
-            pg_query($this->​CONN,​ "​COMMIT"​);​ 
-        } 
-    } 
-} 
- 
-class Feature 
-{ 
- var $type; 
- var $geometry; 
- var $id; 
- var $properties;​ 
- 
- function Feature($id,​$geom,​$properties) { 
- $this->​type = "​Feature";​ 
- $this->​geometry = $geom; 
- $this->​id = $id; 
- $this->​properties = $properties;​ 
-              
- } 
-} 
- 
-class FeatureCollection 
-{ 
- var $type; 
- var $features; 
-  
- function FeatureCollection() 
- { 
- $this->​type = "​FeatureCollection";​ 
- $this->​features = array(); 
- } 
-  
- function addFeature($feature) { 
- array_push($this->​features,​$feature);​ 
- 
-} 
-?> 
-</​code>​ 
- 
-__TODO__ 
-  - Tester ce géoservice et analyser les différentes étapes du processus (veiller à reconfigurer les paramètres de connexion) - évt utiliser l'​astuce de Daniel http://​mediamaps.ch/​wiki/​doku.php?​id=geoinf14:​postgis0 
-  - Terminer l'​exemple en exploitant le géoservice dans OpenLayers avec une ol.layer.Vector comme vu dans [[geoinf15:​ol3tuto#​ex5asource_de_donnees_openlayersformat|Ex5A]]. 
  
geoinf15/postgis0.1510784204.txt.gz · Last modified: 2018/05/16 10:05 (external edit)