Revision 3566 trunk/applications/appCatalogYNomenclatorClient/src/es/gva/cit/gazetteer/wfsg/parsers/WfsgFeatureParser.java
WfsgFeatureParser.java | ||
---|---|---|
1 |
|
|
1 | 2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
2 | 3 |
* |
3 | 4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
... | ... | |
39 | 40 |
* dac@iver.es |
40 | 41 |
*/ |
41 | 42 |
package es.gva.cit.gazetteer.wfsg.parsers; |
42 |
|
|
43 |
import java.awt.geom.Point2D; |
|
44 |
|
|
45 | 43 |
import es.gva.cit.catalogClient.metadataXML.XMLNode; |
46 | 44 |
import es.gva.cit.catalogClient.metadataXML.XMLTree; |
47 | 45 |
import es.gva.cit.gazetteer.querys.Feature; |
48 | 46 |
import es.gva.cit.gazetteer.querys.ThesaurusName; |
47 |
import java.awt.geom.Point2D; |
|
49 | 48 |
|
50 | 49 |
/** |
51 | 50 |
* This class is used to parse the getFeature request |
52 | 51 |
* |
52 |
* |
|
53 | 53 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
54 | 54 |
*/ |
55 | 55 |
public class WfsgFeatureParser { |
56 |
|
|
57 |
/** |
|
58 |
* |
|
59 |
* |
|
60 |
*/ |
|
56 | 61 |
private String geomType = null; |
57 |
|
|
58 |
/** |
|
59 |
* It parses the answer |
|
60 |
* @param node |
|
61 |
* XML tree that contains the getFeature Answer |
|
62 |
* @param feature |
|
63 |
* FEature selected in the thesaurus list |
|
64 |
* @param attribute |
|
65 |
* Attribute to do the search |
|
66 |
* @return |
|
67 |
* Array of features |
|
68 |
*/ |
|
69 |
public Feature[] parse(XMLNode node,ThesaurusName feature, String attribute){ |
|
62 |
|
|
63 |
/** |
|
64 |
* It parses the answer |
|
65 |
* |
|
66 |
* |
|
67 |
* @return Array of features |
|
68 |
* @param node XML tree that contains the getFeature Answer |
|
69 |
* @param thesaurus FEature selected in the thesaurus list |
|
70 |
* @param attribute Attribute to do the search |
|
71 |
*/ |
|
72 |
public Feature[] parse(XMLNode node, ThesaurusName thesaurus, String attribute) { |
|
70 | 73 |
XMLNode[] nodeFeatures = XMLTree.searchMultipleNode(node,"gml:featureMember"); |
71 | 74 |
|
72 |
String prefix = feature.getName().split(":")[0];
|
|
73 |
String geomField = getGeomField(prefix,feature);
|
|
75 |
String prefix = thesaurus.getName().split(":")[0];
|
|
76 |
String geomField = getGeomField(prefix,thesaurus);
|
|
74 | 77 |
|
75 | 78 |
if ((node.getName().equals("ResultCollection")) || |
76 | 79 |
(node.getName().equals("feature_collection"))){ |
77 |
return parseWFS(nodeFeatures,feature,"geographicIdentifier",geomField);
|
|
80 |
return parseWFS(nodeFeatures,thesaurus,"geographicIdentifier",geomField);
|
|
78 | 81 |
}else{ |
79 |
return parseWFS(nodeFeatures,feature,prefix + ":" + attribute,geomField);
|
|
82 |
return parseWFS(nodeFeatures,thesaurus,prefix + ":" + attribute,geomField);
|
|
80 | 83 |
} |
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* It parses the a WFS answer |
|
85 |
* @param nodeFeatures |
|
86 |
* XML tree that contains the Features |
|
87 |
* @param feature |
|
88 |
* FEature selected in the thesaurus list |
|
89 |
* @param attribute |
|
90 |
* Attribute to do the search |
|
91 |
* @param geomField |
|
92 |
* Field that contains the geometry |
|
93 |
* @return |
|
94 |
* Array of features |
|
95 |
*/ |
|
96 |
public Feature[] parseWFS(XMLNode[] nodeFeatures,ThesaurusName feature, String attribute, String geomField){ |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* It parses the a WFS answer |
|
88 |
* |
|
89 |
* |
|
90 |
* @return Array of features |
|
91 |
* @param nodeFeatures XML tree that contains the Features |
|
92 |
* @param thesaurusName FEature selected in the thesaurus list |
|
93 |
* @param attribute Attribute to do the search |
|
94 |
* @param geomField Field that contains the geometry |
|
95 |
*/ |
|
96 |
public Feature[] parseWFS(XMLNode[] nodeFeatures, ThesaurusName thesaurusName, String attribute, String geomField) { |
|
97 | 97 |
Feature[] features = new Feature[nodeFeatures.length]; |
98 | 98 |
|
99 | 99 |
for (int i=0 ; i<nodeFeatures.length ; i++){ |
100 |
String id = XMLTree.searchNodeAtribute(nodeFeatures[i],feature.getName(),"fid");
|
|
100 |
String id = XMLTree.searchNodeAtribute(nodeFeatures[i],thesaurusName.getName(),"fid");
|
|
101 | 101 |
|
102 |
XMLNode nodeName = XMLTree.searchNode(nodeFeatures[i],feature.getName() + "->" + attribute);
|
|
102 |
XMLNode nodeName = XMLTree.searchNode(nodeFeatures[i],thesaurusName.getName() + "->" + attribute);
|
|
103 | 103 |
String name = ""; |
104 | 104 |
|
105 | 105 |
if (nodeName != null){ |
... | ... | |
117 | 117 |
} |
118 | 118 |
|
119 | 119 |
return features; |
120 |
} |
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
/** |
|
126 |
* If returns the Geom route of the XML tree |
|
127 |
* @param prefix |
|
128 |
* Typename |
|
129 |
* @param feature |
|
130 |
* Feature selected in the thesaurus list |
|
131 |
* @return |
|
132 |
*/ |
|
133 |
|
|
134 |
//cv300:entity:layer:level:elevation:color:text:clave:the_geom->gml:MultiLineString->gml:lineStringMember->gml:LineString->gml:coordinates |
|
135 |
private String getGeomField(String prefix,ThesaurusName feature){ |
|
136 |
if (feature.getFields() == null){ |
|
120 |
} |
|
121 |
//cv300:entity:layer:level:elevation:color:text:clave:the_geom->gml:MultiLineString->gml:lineStringMember->gml:LineString->gml:coordinates |
|
122 |
|
|
123 |
/** |
|
124 |
* If returns the Geom route of the XML tree |
|
125 |
* |
|
126 |
* |
|
127 |
* @return |
|
128 |
* @param prefix Typename |
|
129 |
* @param thesaurus Feature selected in the thesaurus list |
|
130 |
*/ |
|
131 |
private String getGeomField(String prefix, ThesaurusName thesaurus) { |
|
132 |
if (thesaurus.getFields() == null){ |
|
137 | 133 |
geomType = "Point"; |
138 |
return feature.getName() + "->" + "position->gml:Point->gml:coordinates";
|
|
134 |
return thesaurus.getName() + "->" + "position->gml:Point->gml:coordinates";
|
|
139 | 135 |
} |
140 | 136 |
|
141 |
for (int i=0 ; i<feature.getFields().length ; i++){
|
|
142 |
if (feature.getFields()[i].getType().equals("gml:MultiLineStringPropertyType")){
|
|
143 |
prefix = feature.getName() + "->" + prefix + ":" + feature.getFields()[i].getName();
|
|
137 |
for (int i=0 ; i<thesaurus.getFields().length ; i++){
|
|
138 |
if (thesaurus.getFields()[i].getType().equals("gml:MultiLineStringPropertyType")){
|
|
139 |
prefix = thesaurus.getName() + "->" + prefix + ":" + thesaurus.getFields()[i].getName();
|
|
144 | 140 |
geomType = "MultiLine"; |
145 | 141 |
return prefix + |
146 | 142 |
"->gml:MultiLineString->gml:lineStringMember->gml:LineString->" + |
147 | 143 |
"gml:coordinates"; |
148 | 144 |
} |
149 | 145 |
|
150 |
if (feature.getFields()[i].getType().equals("gml:MultiPolygonPropertyType")){
|
|
151 |
prefix = feature.getName() + "->" + prefix + ":" + feature.getFields()[i].getName();
|
|
146 |
if (thesaurus.getFields()[i].getType().equals("gml:MultiPolygonPropertyType")){
|
|
147 |
prefix = thesaurus.getName() + "->" + prefix + ":" + thesaurus.getFields()[i].getName();
|
|
152 | 148 |
geomType = "MultiPolygon"; |
153 | 149 |
return prefix + |
154 | 150 |
"->gml:MultiPolygon->gml:polygonMember->gml:Polygon->gml:outerBoundaryIs->" + |
155 | 151 |
"gml:LinearRing->gml:coordinates"; |
156 | 152 |
} |
157 | 153 |
|
158 |
if (feature.getFields()[i].getType().equals("gml:PointPropertyType")){
|
|
159 |
prefix = feature.getName() + "->" + prefix + ":" + feature.getFields()[i].getName();
|
|
154 |
if (thesaurus.getFields()[i].getType().equals("gml:PointPropertyType")){
|
|
155 |
prefix = thesaurus.getName() + "->" + prefix + ":" + thesaurus.getFields()[i].getName();
|
|
160 | 156 |
geomType = "Point"; |
161 | 157 |
return prefix + |
162 | 158 |
"->gml:Point->gml:coordinates"; |
163 | 159 |
} |
164 | 160 |
|
161 |
|
|
165 | 162 |
|
166 | 163 |
|
167 | 164 |
} |
168 | 165 |
|
169 | 166 |
return ""; |
170 |
|
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* It returns a pair of coordinates of the Feature |
|
175 |
* @param sCoordinates |
|
176 |
* String that contains the coordinates |
|
177 |
* @return |
|
178 |
*/ |
|
179 |
|
|
180 |
private Point2D getCoordinates(String sCoordinates){ |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* It returns a pair of coordinates of the Feature |
|
171 |
* |
|
172 |
* |
|
173 |
* @return |
|
174 |
* @param sCoordinates String that contains the coordinates |
|
175 |
*/ |
|
176 |
private Point2D getCoordinates(String sCoordinates) { |
|
181 | 177 |
if (geomType.equals("MultiLine")){ |
182 | 178 |
return getCoordinatesMultiline(sCoordinates); |
183 | 179 |
} |
... | ... | |
188 | 184 |
return getCoordinatesPoint(sCoordinates); |
189 | 185 |
} |
190 | 186 |
return null; |
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* It returns a pair of coordinates from a Multiline string |
|
195 |
* @param sCoordinates |
|
196 |
* String |
|
197 |
* @return |
|
198 |
*/ |
|
199 |
private Point2D.Double getCoordinatesMultiline(String sCoordinates){ |
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
190 |
* It returns a pair of coordinates from a Multiline string |
|
191 |
* |
|
192 |
* |
|
193 |
* @return |
|
194 |
* @param sCoordinates String |
|
195 |
*/ |
|
196 |
private java.awt.geom.Point2D.Double getCoordinatesMultiline(String sCoordinates) { |
|
200 | 197 |
return getAverage(sCoordinates.split(" ")); |
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* It returns a pair of coordinates from a MultiPolygon string |
|
205 |
* @param sCoordinates |
|
206 |
* String |
|
207 |
* @return |
|
208 |
*/ |
|
209 |
private Point2D.Double getCoordinatesMultiPolygon(String sCoordinates){ |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* It returns a pair of coordinates from a MultiPolygon string |
|
202 |
* |
|
203 |
* |
|
204 |
* @return |
|
205 |
* @param sCoordinates String |
|
206 |
*/ |
|
207 |
private java.awt.geom.Point2D.Double getCoordinatesMultiPolygon(String sCoordinates) { |
|
210 | 208 |
return getAverage(sCoordinates.split(" ")); |
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* It returns a pair of coordinates from a Point |
|
215 |
* @param sCoordinates |
|
216 |
* String |
|
217 |
* @return |
|
218 |
*/ |
|
219 |
private Point2D.Double getCoordinatesPoint(String sCoordinates){ |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* It returns a pair of coordinates from a Point |
|
213 |
* |
|
214 |
* |
|
215 |
* @return |
|
216 |
* @param sCoordinates String |
|
217 |
*/ |
|
218 |
private java.awt.geom.Point2D.Double getCoordinatesPoint(String sCoordinates) { |
|
220 | 219 |
return getAverage(sCoordinates.split(" ")); |
221 |
} |
|
222 |
|
|
223 |
|
|
224 |
/** |
|
225 |
* It returns the average of a set of coordinates |
|
226 |
* @param sCoordinates |
|
227 |
* Coordinates: X,Y |
|
228 |
* @return |
|
229 |
* Average |
|
230 |
*/ |
|
231 |
private Point2D.Double getAverage(String[] sCoordinates){ |
|
232 |
double x = 0.0; |
|
233 |
double y = 0.0; |
|
220 |
} |
|
221 |
|
|
222 |
/** |
|
223 |
* It returns the average of a set of coordinates |
|
224 |
* |
|
225 |
* |
|
226 |
* @return Average |
|
227 |
* @param sCoordinates Coordinates: X,Y |
|
228 |
*/ |
|
229 |
private java.awt.geom.Point2D.Double getAverage(String[] sCoordinates) { |
|
230 |
double x = 0.0; |
|
231 |
double y = 0.0; |
|
234 | 232 |
for (int i=0 ; i<sCoordinates.length ; i++){ |
235 | 233 |
x = x + Double.parseDouble(sCoordinates[i].split(",")[0]); |
236 | 234 |
y = y + Double.parseDouble(sCoordinates[i].split(",")[1]); |
... | ... | |
238 | 236 |
x = x / sCoordinates.length; |
239 | 237 |
y = y / sCoordinates.length; |
240 | 238 |
return new Point2D.Double(x,y); |
241 |
} |
|
242 |
|
|
243 |
} |
|
239 |
} |
|
240 |
} |
Also available in: Unified diff