Subversion Repositories eFlore/Projets.eflore-projets

Rev

Blame | Last modification | View Log | RSS feed

<?php
// declare(encoding='UTF-8');

// Inclusion des dépendances à Proj4Php.
require 'vendor/autoload.php';

/**
 * Transforme les coordonnées X et y d'un point en fonction d'un EPSG source (epsg-src) et d'un EPSG de
 * destination (epsg-dest).
 *
 * Exemples d'EPSG fonctionnels :
 * - Lambert 93 : EPSG:2154
 * - WGS84 : EPSG:4326
 *
 * @category   eFlore
 * @package    Services
 * @subpackage Coord-transfo
 * @version    0.1
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
 */
class Point {

        private $parametres = array();
        private $ressources = array();

        private $coordonnees = array();

        public function consulter($ressources, $parametres) {
                $this->ressources = $ressources;
                $this->parametres = $parametres;

                $retour = null;
                try {
                        $this->transformerCoordonnees();
                        $retour = $this->coordonnees;
                } catch (Exception $erreur) {
                        $retour = $erreur->getMessage();
                }
                return $retour;
        }

        private function transformerCoordonnees() {
                $proj4 = new Proj4php();
                $projSource = new Proj4phpProj('EPSG:'.$this->parametres['epsg-src'], $proj4);
                $projDestination = new Proj4phpProj('EPSG:'.$this->parametres['epsg-dest'], $proj4);
                $pointSrc = new proj4phpPoint($this->parametres['x'], $this->parametres['y']);
                $pointDest = $proj4->transform($projSource, $projDestination, $pointSrc);

                $this->coordonnees['x'] = round($pointDest->x, 5);
                $this->coordonnees['y'] = round($pointDest->y, 5);
                $this->coordonnees['EPSG'] = $this->parametres['epsg-dest'];
        }
}