FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
proj4php/src/Point.php at master · proj4php/proj4php · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
proj4php
/
proj4php
Public
Notifications
You must be signed in to change notification settings
Fork
49
Star
133
Code
Issues
29
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
proj4php
/
src
/
Point.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
169 lines (148 loc) · 4.37 KB
Breadcrumbs
proj4php
/
src
/
Point.php
Copy path
File metadata and controls
169 lines (148 loc) · 4.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
namespace
proj4php
;
/**
* Author : Julien Moquet
*
* Inspired by Proj4js from Mike Adair madairATdmsolutions.ca
* and Richard Greenwood rich@greenwoodmap.com
* License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
*/
/**
* Point object, nothing fancy, just allows values to be
* passed back and forth by reference rather than by value.
* Other point classes may be used as long as they have
* x and y properties, which will get modified in the transform method.
*/
use
Proj4php
\
Proj
;
use
InvalidArgumentException
;
class
Point
{
protected
$
x
;
protected
$
y
;
protected
$
z
;
protected
$
projection
=
null
;
public
function
getProjection
() {
return
$
this
->
projection
;
}
public
function
setProjection
(
$
projection
) {
$
this
->
projection
=
$
projection
;
}
/**
* Constructor: Proj4js.Point
*
* Parameters:
* - x {float} or {Array} either the first coordinates component or
* the full coordinates
* - y {float} the second component
* - z {float} the third component, optional.
* - projection {Proj} the point projection, optional.
*
* Notice z can be ommitted when projection still present.
*/
public
function
__construct
(
$
x
=
null
,
$
y
=
null
,
$
z
=
null
, ?
Proj
$
projection
=
null
)
{
if
(
$
projection
===
null
and
$
z
instanceof
Proj)
{
$
projection
=
$
z
;
$
z
=
null
;
}
$
this
->
projection
=
$
projection
;
if
(
is_array
(
$
x
)) {
// [x, y] or [x, y, z]
$
this
->
__set
(
'
x
'
,
$
x
[
0
]);
$
this
->
__set
(
'
y
'
,
$
x
[
1
]);
$
this
->
__set
(
'
z
'
,
isset
(
$
x
[
2
]) ?
$
x
[
2
] :
null
);
}
elseif
(
is_string
(
$
x
) &&
is_null
(
$
y
)) {
// "x y" or "x y z"
$
coord
=
explode
(
'
'
,
$
x
);
$
this
->
__set
(
'
x
'
,
$
coord
[
0
]);
$
this
->
__set
(
'
y
'
,
$
coord
[
1
]);
$
this
->
__set
(
'
z
'
,
isset
(
$
coord
[
2
]) ?
$
coord
[
2
] :
null
);
}
else
{
// Separate x, y, z
$
this
->
__set
(
'
x
'
,
$
x
);
$
this
->
__set
(
'
y
'
,
$
y
);
$
this
->
__set
(
'
z
'
,
$
z
);
}
}
/**
* APIMethod: clone
* Build a copy of a Point object.
*
* renamed because of PHP keyword.
*
* Return:
* proj4php\Point the cloned point.
*/
public
function
__clone
()
{
return
new
static
(
$
this
->
x
,
$
this
->
y
,
$
this
->
z
);
}
/**
* APIMethod: toString
* Return a readable string version of the point
*
* Return:
* {String} String representation of Proj4js.Point object.
* (ex. "x=5,y=42")
*/
public
function
toString
()
{
return
'
x=
'
.
$
this
->
x
.
'
,y=
'
.
$
this
->
y
;
}
/**
* APIMethod: toShortString
* Return a short string version of the point.
*
* Return:
* {String} Shortened String representation of Proj4js.Point object.
* (ex. "5, 42")
* FIXME: actually "4 42" - a single space as separator, not commas.
*/
public
function
toShortString
()
{
return
$
this
->
x
.
'
'
.
$
this
->
y
;
}
/**
* Getter for x, y and z.
*/
public
function
__get
(
$
name
)
{
$
name
=
strtolower
(
$
name
);
if
(
$
name
!=
'
x
'
&&
$
name
!=
'
y
'
&&
$
name
!=
'
z
'
) {
// Invalid property exception.
throw
new
InvalidArgumentException
(
sprintf
(
'
Invalid property "%s"; expects x, y or z.
'
,
$
name
));
}
return
$
this
->
$
name
;
}
/**
* Setter for x, y and z.
*/
public
function
__set
(
$
name
,
$
value
)
{
$
name
=
strtolower
(
$
name
);
if
(
$
name
!=
'
x
'
&&
$
name
!=
'
y
'
&&
$
name
!=
'
z
'
) {
// Invalid property exception.
throw
new
InvalidArgumentException
(
sprintf
(
'
Invalid property "%s"; expects x, y or z.
'
,
$
name
));
}
$
this
->
$
name
= (
isset
(
$
value
) ? (
float
)
$
value
:
0.0
);
}
/**
* Setter for x, y and z.
*/
public
function
__isset
(
$
name
)
{
$
name
=
strtolower
(
$
name
);
if
(
$
name
!=
'
x
'
&&
$
name
!=
'
y
'
&&
$
name
!=
'
z
'
) {
return
false
;
}
return
isset
(
$
this
->
$
name
);
}
/**
* Return as an [x, y, z] array.
*/
public
function
toArray
()
{
return
[
$
this
->
x
,
$
this
->
y
,
$
this
->
z
];
}
}
Back
|
FazBrowse Home
|
New Git URL