Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 jpm 1
<?php
2
// declare(encoding='UTF-8');
3
 
4
// Inclusion des dépendances à Proj4Php.
5
require 'vendor/autoload.php';
6
 
7
/**
8
 * Transforme les coordonnées X et y d'un point en fonction d'un EPSG source (epsg-src) et d'un EPSG de
9
 * destination (epsg-dest).
10
 *
11
 * Exemples d'EPSG fonctionnels :
12
 * - Lambert 93 : EPSG:2154
13
 * - WGS84 : EPSG:4326
14
 *
15
 * @category   eFlore
16
 * @package    Services
17
 * @subpackage Coord-transfo
18
 * @version    0.1
19
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
20
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
21
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
22
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
23
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
24
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
25
 */
26
class Point {
27
 
28
	private $parametres = array();
29
	private $ressources = array();
30
 
31
	private $coordonnees = array();
32
 
33
	public function consulter($ressources, $parametres) {
34
		$this->ressources = $ressources;
35
		$this->parametres = $parametres;
36
 
37
		$retour = null;
38
		try {
39
			$this->transformerCoordonnees();
40
			$retour = $this->coordonnees;
41
		} catch (Exception $erreur) {
42
			$retour = $erreur->getMessage();
43
		}
44
		return $retour;
45
	}
46
 
47
	private function transformerCoordonnees() {
48
		$proj4 = new Proj4php();
49
		$projSource = new Proj4phpProj('EPSG:'.$this->parametres['epsg-src'], $proj4);
50
		$projDestination = new Proj4phpProj('EPSG:'.$this->parametres['epsg-dest'], $proj4);
51
		$pointSrc = new proj4phpPoint($this->parametres['x'], $this->parametres['y']);
52
		$pointDest = $proj4->transform($projSource, $projDestination, $pointSrc);
53
 
54
		$this->coordonnees['x'] = round($pointDest->x, 5);
55
		$this->coordonnees['y'] = round($pointDest->y, 5);
56
		$this->coordonnees['EPSG'] = $this->parametres['epsg-dest'];
57
	}
58
}