Revision 103 org.gvsig.gazetteer/trunk/org.gvsig.gazetteer/org.gvsig.gazetteer.lib/src/main/java/org/gvsig/gazetteer/wfsg/parsers/WfsgFeatureParser.java

View differences:

WfsgFeatureParser.java
44 44

  
45 45
import org.gvsig.catalog.metadataxml.XMLNode;
46 46
import org.gvsig.catalog.metadataxml.XMLTree;
47
import org.gvsig.fmap.geom.GeometryLocator;
48
import org.gvsig.fmap.geom.GeometryManager;
49
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
50
import org.gvsig.fmap.geom.exception.CreateGeometryException;
51
import org.gvsig.fmap.geom.primitive.Point;
52
import org.gvsig.gazetteer.idec.parsers.IdecFeatureParser;
47 53
import org.gvsig.gazetteer.querys.Feature;
54
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
48 56

  
49 57

  
50 58
/**
51 59
 * This class is used to parse the getFeature request
52
 * 
53
 * 
60
 *
61
 *
54 62
 * @author Jorge Piera Llodra (piera_jor@gva.es)
55 63
 */
56 64
public class WfsgFeatureParser {
65
    private static final Logger logger =
66
        LoggerFactory.getLogger(WfsgFeatureParser.class);
57 67
	private String geomType = null;
58 68
	private String namespace = null;
59 69
	private static final String POSITION_NODE = "position->gml:Point->gml:coordinates";
......
62 72

  
63 73
	/**
64 74
	 * It parses the answer
65
	 * 
66
	 * 
75
	 *
76
	 *
67 77
	 * @return Array of features
68 78
	 * @param node XML tree that contains the getFeature Answer
69 79
	 * @param featureType FEature selected in the thesaurus list
70 80
	 * @param attribute Attribute to do the search
71 81
	 */
72
	public Feature[] parse(XMLNode node) {        
82
	public Feature[] parse(XMLNode node) {
73 83
		XMLNode[] nodeFeatures = XMLTree.searchMultipleNode(node,FEATUREMEMBER);
74
		namespace = "";       
84
		namespace = "";
75 85

  
76 86
		if ((nodeFeatures != null) && (nodeFeatures.length > 0)){
77 87
			if (nodeFeatures[0].getSubnodes().length > 0){
78 88
				String nodeName = nodeFeatures[0].getSubnodes()[0].getName();
79 89
				if (nodeName.split(":").length == 2){
80 90
					namespace = nodeName.split(":")[0] + ":";
81
				}  
91
				}
82 92
				return parseWFS(nodeFeatures,nodeName);
83
			}        	
84
		}       
93
			}
94
		}
85 95
		return null;
86
	} 
96
	}
87 97

  
88 98
	/**
89 99
	 * It parses the a WFS answer
90
	 * 
91
	 * 
100
	 *
101
	 *
92 102
	 * @return Array of features
93 103
	 * @param nodeFeatures XML tree that contains the Features
94 104
	 * @param featureType FEature selected in the thesaurus list
95 105
	 * @param attribute Attribute to do the search
96 106
	 * @param geomField Field that contains the geometry
97 107
	 */
98
	public Feature[] parseWFS(XMLNode[] nodeFeatures, String featureType) {        
108
	public Feature[] parseWFS(XMLNode[] nodeFeatures, String featureType) {
99 109
		Feature[] features = new Feature[nodeFeatures.length];
100 110

  
101 111

  
102 112
		for (int i=0 ; i<nodeFeatures.length ; i++){
103 113
			XMLNode nodeName = XMLTree.searchNode(nodeFeatures[i],featureType + "->" + GEOGRAPHICIDENTIFIER_NODE);
104
			String name = "";  
114
			String name = "";
105 115

  
106 116
			if (nodeName != null){
107 117
				if ((nodeName.getText() != null) && (!(nodeName.getText().equals("")))){
108 118
					name = nodeName.getText();
109 119
				} else if ((nodeName.getCdata() != null) && (!(nodeName.getCdata().equals("")))){
110
					name = nodeName.getCdata();                   
111
				}       
120
					name = nodeName.getCdata();
121
				}
112 122
			}
113 123

  
114 124
			String id = XMLTree.searchNodeAtribute(nodeFeatures[i],featureType,"fid");
115 125
			String description = name;
116
			Point2D point = getCoordinates(XMLTree.searchNodeValue(nodeFeatures[i],
126
			Point point = getCoordinates(XMLTree.searchNodeValue(nodeFeatures[i],
117 127
					featureType + "->" + POSITION_NODE));
118 128

  
119 129
			features[i] = new Feature(id,name,description,point);
120 130
		}
121 131
		return features;
122
	} 
132
	}
123 133

  
124 134
	/**
125 135
	 * It returns a pair of coordinates of the Feature
126
	 * @return 
136
	 * @return
127 137
	 * @param sCoordinates String that contains the coordinates
128 138
	 */
129
	private Point2D getCoordinates(String sCoordinates) {        
139
	private Point getCoordinates(String sCoordinates) {
140
	    GeometryManager geomManager = GeometryLocator.getGeometryManager();
130 141
		if (sCoordinates != null){
131 142
			double x = Double.parseDouble(sCoordinates.split(",")[0]);
132 143
			double y = Double.parseDouble(sCoordinates.split(",")[1]);
133
			return new Point2D.Double(x,y);
134
		}return null;    
135
	} 
144
			Point point =null;
145
			try {
146
                point = geomManager.createPoint(x, y, SUBTYPES.GEOM2D);
147
            } catch (CreateGeometryException | NumberFormatException e) {
148
                StringBuilder builder = new StringBuilder();
149
                builder.append("Can't create point: (");
150
                builder.append(x);
151
                builder.append(",");
152
                builder.append(y);
153
                builder.append(")");
154
                logger.warn(builder.toString());
155
            }
156
			return point;
157
		}return null;
158
	}
136 159

  
137 160

  
138 161

  

Also available in: Unified diff