View Javadoc
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        * http://schemas.opengis.net/gml/3.2.1/geometryBasic0d1d.xsd
10       * 
11       * <complexType name="DirectPositionType"> <annotation>
12       * <documentation>Direct position instances hold the coordinates for a
13       * position within some coordinate reference system (CRS). Since direct
14       * positions, as data types, will often be included in larger objects (such
15       * as geometry elements) that have references to CRS, the srsName attribute
16       * will in general be missing, if this particular direct position is
17       * included in a larger element with such a reference to a CRS. In this
18       * case, the CRS is implicitly assumed to take on the value of the
19       * containing object's CRS. if no srsName attribute is given, the CRS shall
20       * be specified as part of the larger context this geometry element is part
21       * of, typically a geometric object like a point, curve,
22       * etc.</documentation> </annotation> <simpleContent> <extension
23       * base="gml:doubleList"> <attributeGroup ref="gml:SRSReferenceGroup"/>
24       * </extension> </simpleContent> </complexType> <element name="pos"
25       * type="gml:DirectPositionType"/>
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 }