Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev Author Line No. Line
1001 delphine 1
<?php
2
/**
3
 * Author : Julien Moquet
4
 *
5
 * Inspired by Proj4js from Mike Adair madairATdmsolutions.ca
6
 *                      and Richard Greenwood rich@greenwoodmap.com
7
 * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
8
 */
9
 
10
/**
11
 * point object, nothing fancy, just allows values to be
12
 * passed back and forth by reference rather than by value.
13
 * Other point classes may be used as long as they have
14
 * x and y properties, which will get modified in the transform method.
15
*/
16
class proj4phpPoint {
17
 
18
    public $x;
19
    public $y;
20
    public $z;
21
 
22
    /**
23
     * Constructor: Proj4js.Point
24
     *
25
     * Parameters:
26
     * - x {float} or {Array} either the first coordinates component or
27
     *     the full coordinates
28
     * - y {float} the second component
29
     * - z {float} the third component, optional.
30
     */
31
    public function __construct( $x = null, $y = null, $z = null ) {
32
 
33
        if( is_array( $x ) ) {
34
            $this->x = $x[0];
35
            $this->y = $x[1];
36
            $this->z = isset($x[2]) ? $x[2] : 0.0;#(count( $x ) > 2) ? $x[2] : 0.0;
37
        } else if( is_string( $x ) && !is_numeric( $y ) ) {
38
            $coord = explode( ' ', $x );
39
            $this->x = floatval( $coord[0] );
40
            $this->y = floatval( $coord[1] );
41
            $this->z = (count( $coord ) > 2) ? floatval( $coord[2] ) : 0.0;
42
        } else {
43
            $this->x = $x !== null ? $x : 0.0;
44
            $this->y = $y !== null ? $y : 0.0;
45
            $this->z = $z !== null ? $z : 0.0;
46
        }
47
    }
48
 
49
    /**
50
     * APIMethod: clone
51
     * Build a copy of a Proj4js.Point object.
52
     *
53
     * renamed because of PHP keyword.
54
     *
55
     * Return:
56
     * {Proj4js}.Point the cloned point.
57
     */
58
    public function _clone() {
59
        return new Proj4phpPoint( $this->x, $this->y, $this->z );
60
    }
61
 
62
    /**
63
     * APIMethod: toString
64
     * Return a readable string version of the point
65
     *
66
     * Return:
67
     * {String} String representation of Proj4js.Point object.
68
     *           (ex. <i>"x=5,y=42"</i>)
69
     */
70
    public function toString() {
71
        return "x=" . $this->x . ",y=" . $this->y;
72
    }
73
 
74
    /**
75
     * APIMethod: toShortString
76
     * Return a short string version of the point.
77
     *
78
     * Return:
79
     * {String} Shortened String representation of Proj4js.Point object.
80
     *         (ex. <i>"5, 42"</i>)
81
     */
82
    public function toShortString() {
83
        return $this->x . " " . $this->y;
84
    }
85
 
86
}