1 package nl.geozet.openls.databinding.gml;
2
3 import nl.geozet.openls.databinding.common.XmlNamespaceConstants;
4
5 import org.apache.log4j.Logger;
6
7 public class Pos {
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 private static final Logger LOGGER = Logger.getLogger(Pos.class);
28
29 private Double x;
30 private Double y;
31 private int dimension;
32
33 private boolean hasX;
34 private boolean hasY;
35 private boolean hasXY;
36 private boolean hasDimension;
37
38 public Pos() {
39 this.hasX = false;
40 this.hasY = false;
41 this.hasXY = false;
42 this.hasDimension = false;
43 }
44
45 public void setXY(String xy) throws NumberFormatException {
46 try {
47 String[] xySplit = xy.split(" ");
48 if (xySplit.length == 2) {
49 setX(Double.parseDouble(xySplit[0]));
50 setY(Double.parseDouble(xySplit[1]));
51 }
52 this.hasXY = true;
53 } catch (NumberFormatException e) {
54 LOGGER.error("Verwerken van puntlocatie mislukt, waarde: " + xy
55 + ": ", e);
56 }
57 }
58
59 public void setX(Double x) {
60 this.hasX = true;
61 if (this.hasY)
62 this.hasXY = true;
63 this.x = x;
64 }
65
66 public Double getX() {
67 return x;
68 }
69
70 public void setY(Double y) {
71 this.hasY = true;
72 if (this.hasX)
73 this.hasXY = true;
74 this.y = y;
75 }
76
77 public Double getY() {
78 return y;
79 }
80
81 public String getXY() {
82 return x.toString() + " " + y.toString();
83 }
84
85 public boolean hasXY() {
86 return this.hasXY;
87 }
88
89 public void setDimension(int dimension) {
90 this.dimension = dimension;
91 }
92
93 public int getDimension() {
94 return dimension;
95 }
96
97 public boolean hasDimension() {
98 return this.hasDimension;
99 }
100
101 public String toXML() {
102 String xml = "<" + XmlNamespaceConstants.OGC_GML_NAMESPACE_PREFIX
103 + ":Pos";
104 if (hasDimension())
105 xml += " dimension=\"" + getDimension() + "\"";
106 xml += ">";
107 if (hasXY()) {
108 xml += getXY();
109 }
110 xml += "</" + XmlNamespaceConstants.OGC_GML_NAMESPACE_PREFIX + ":Pos>";
111 return xml;
112 }
113 }