1
2
3
4
5
6
7 package nl.mineleni.openls.databinding.gml;
8
9 import nl.mineleni.openls.XmlNamespaceConstants;
10
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
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 public class Pos implements XmlNamespaceConstants {
48
49
50
51 private static final long serialVersionUID = -1063398145364381070L;
52
53
54 private static final Logger LOGGER = LoggerFactory.getLogger(Pos.class);
55
56
57 private Double x;
58
59
60 private Double y;
61
62
63 private int dimension;
64
65
66 private boolean hasX;
67
68
69 private boolean hasY;
70
71
72 private boolean hasXY;
73
74
75 private boolean hasDimension;
76
77
78
79
80 public Pos() {
81 this.hasX = false;
82 this.hasY = false;
83 this.hasXY = false;
84 this.hasDimension = false;
85 }
86
87
88
89
90
91
92
93 public void setXY(final String xy) {
94 try {
95 final String[] xySplit = xy.split(" ");
96 if (xySplit.length == 2) {
97 this.setX(Double.parseDouble(xySplit[0]));
98 this.setY(Double.parseDouble(xySplit[1]));
99 }
100 this.hasXY = true;
101 } catch (final NumberFormatException e) {
102 LOGGER.error("Verwerken van puntlocatie mislukt, waarde: " + xy
103 + ": ", e);
104 }
105 }
106
107
108
109
110
111
112
113 public void setX(final Double x) {
114 this.hasX = true;
115 if (this.hasY) {
116 this.hasXY = true;
117 }
118 this.x = x;
119 }
120
121
122
123
124
125
126 public Double getX() {
127 return this.x;
128 }
129
130
131
132
133
134
135
136 public void setY(final Double y) {
137 this.hasY = true;
138 if (this.hasX) {
139 this.hasXY = true;
140 }
141 this.y = y;
142 }
143
144
145
146
147
148
149 public Double getY() {
150 return this.y;
151 }
152
153
154
155
156
157
158 public String getXY() {
159 return this.x.toString() + " " + this.y.toString();
160 }
161
162
163
164
165
166
167 public boolean hasXY() {
168 return this.hasXY;
169 }
170
171
172
173
174
175
176
177 public void setDimension(final int dimension) {
178 this.hasDimension = true;
179 this.dimension = dimension;
180 }
181
182
183
184
185
186
187 public int getDimension() {
188 return this.dimension;
189 }
190
191
192
193
194
195
196 public boolean hasDimension() {
197 return this.hasDimension;
198 }
199
200
201
202
203
204
205 @Override
206 public String toXML() {
207 String xml = "<" + XmlNamespaceConstants.OGC_GML_NAMESPACE_PREFIX
208 + ":pos";
209 if (this.hasDimension()) {
210 xml += " dimension=\"" + this.getDimension() + "\"";
211 }
212 xml += ">";
213 if (this.hasXY()) {
214 xml += this.getXY();
215 }
216 xml += "</" + XmlNamespaceConstants.OGC_GML_NAMESPACE_PREFIX + ":pos>";
217 return xml;
218 }
219 }