PolygonDecoder.java

  1. package de.turnertech.ows.gml;

  2. import org.w3c.dom.Element;
  3. import org.w3c.dom.Node;
  4. import org.w3c.dom.NodeList;

  5. import de.turnertech.ows.srs.SpatialReferenceSystem;

  6. public class PolygonDecoder implements GmlDecoder<Polygon> {

  7.     @Override
  8.     public Polygon decode(Node root, GmlDecoderContext context) {
  9.         Polygon returnPolygon = new Polygon();
  10.        
  11.         Node srsNode = root.getAttributes().getNamedItem("srsName");
  12.         SpatialReferenceSystem srs = null;
  13.         if(srsNode != null) {
  14.             srs = SpatialReferenceSystem.from(srsNode.getNodeValue());
  15.             if(srs != null) {
  16.                 context.getSrsDeque().push(srs);
  17.             }
  18.         }

  19.         NodeList children = root.getChildNodes();
  20.         for(int i = 0; i < children.getLength(); ++i) {
  21.             Node child = children.item(i);
  22.             if(child.getNodeType() != Node.ELEMENT_NODE) {
  23.                 continue;
  24.             }
  25.             if("exterior".equals(child.getNodeName())) {
  26.                 Element element = (Element)child;
  27.                 LinearRing exterior = new LinearRingDecoder().decode(element.getElementsByTagName("LinearRing").item(0), context);
  28.                 returnPolygon.setExterior(exterior);
  29.             }
  30.         }

  31.         if(srs != null) {
  32.             context.getSrsDeque().pop();
  33.         }

  34.         return returnPolygon;
  35.     }
  36.    
  37. }