gvsig-gazetteer / org.gvsig.gazetteer / trunk / org.gvsig.gazetteer / org.gvsig.gazetteer.lib / src / main / java / org / gvsig / gazetteer / wfs / drivers / WFSGPEContentHandler.java @ 103
History | View | Annotate | Download (5.03 KB)
1 | 29 | jldominguez | package org.gvsig.gazetteer.wfs.drivers; |
---|---|---|---|
2 | |||
3 | import java.awt.geom.Point2D; |
||
4 | import java.util.ArrayList; |
||
5 | |||
6 | 103 | dmartinezizquierdo | import org.gvsig.fmap.geom.primitive.Point; |
7 | 29 | jldominguez | import org.gvsig.gazetteer.querys.Feature; |
8 | import org.gvsig.gpe.lib.impl.parser.GPEContentHandler; |
||
9 | |||
10 | |||
11 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
12 | *
|
||
13 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
14 | *
|
||
15 | * This program is free software; you can redistribute it and/or
|
||
16 | * modify it under the terms of the GNU General Public License
|
||
17 | * as published by the Free Software Foundation; either version 2
|
||
18 | * of the License, or (at your option) any later version.
|
||
19 | *
|
||
20 | * This program is distributed in the hope that it will be useful,
|
||
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
23 | * GNU General Public License for more details.
|
||
24 | *
|
||
25 | * You should have received a copy of the GNU General Public License
|
||
26 | * along with this program; if not, write to the Free Software
|
||
27 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
28 | *
|
||
29 | * For more information, contact:
|
||
30 | *
|
||
31 | * Generalitat Valenciana
|
||
32 | * Conselleria d'Infraestructures i Transport
|
||
33 | * Av. Blasco Ib??ez, 50
|
||
34 | * 46010 VALENCIA
|
||
35 | * SPAIN
|
||
36 | *
|
||
37 | * +34 963862235
|
||
38 | * gvsig@gva.es
|
||
39 | * www.gvsig.gva.es
|
||
40 | *
|
||
41 | * or
|
||
42 | *
|
||
43 | * IVER T.I. S.A
|
||
44 | * Salamanca 50
|
||
45 | * 46005 Valencia
|
||
46 | * Spain
|
||
47 | *
|
||
48 | * +34 963163400
|
||
49 | * dac@iver.es
|
||
50 | */
|
||
51 | /* CVS MESSAGES:
|
||
52 | *
|
||
53 | * $Id$
|
||
54 | * $Log$
|
||
55 | *
|
||
56 | */
|
||
57 | /**
|
||
58 | * ContentHandler for the WFS
|
||
59 | * @author Jorge Piera Llodr? (jorge.piera@iver.es)
|
||
60 | */
|
||
61 | public class WFSGPEContentHandler extends GPEContentHandler{ |
||
62 | 103 | dmartinezizquierdo | private ArrayList features = null; |
63 | 29 | jldominguez | private String searchField = null; |
64 | |||
65 | public WFSGPEContentHandler(String searchField) { |
||
66 | super();
|
||
67 | this.searchField = searchField;
|
||
68 | features = new ArrayList(); |
||
69 | } |
||
70 | |||
71 | /*
|
||
72 | * (non-Javadoc)
|
||
73 | * @see org.gvsig.gpe.GPEContentHandler#addElementToFeature(java.lang.Object, java.lang.Object)
|
||
74 | */
|
||
75 | public void addElementToFeature(Object element, Object feature) { |
||
76 | if ((element != null) && (((Element)element).getName().equals(searchField))){ |
||
77 | ((Feature)feature).setName(String.valueOf(((Element)element).getValue())); |
||
78 | ((Feature)feature).setDescription(String.valueOf(((Element)element).getValue())); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | /*
|
||
83 | * (non-Javadoc)
|
||
84 | * @see org.gvsig.gpe.GPEContentHandler#addGeometryToFeature(java.lang.Object, java.lang.Object)
|
||
85 | */
|
||
86 | public void addGeometryToFeature(Object geometry, Object feature) { |
||
87 | 103 | dmartinezizquierdo | ((Feature)feature).setCoordinates((Point)geometry);
|
88 | 29 | jldominguez | } |
89 | |||
90 | /*
|
||
91 | * (non-Javadoc)
|
||
92 | * @see org.gvsig.gpe.GPEContentHandler#endFeature(java.lang.Object)
|
||
93 | */
|
||
94 | public void endFeature(Object feature) { |
||
95 | features.add(feature); |
||
96 | } |
||
97 | |||
98 | /*
|
||
99 | * (non-Javadoc)
|
||
100 | * @see org.gvsig.gpe.GPEContentHandler#startElement(java.lang.String, java.lang.Object, java.lang.String, java.lang.Object)
|
||
101 | */
|
||
102 | public Object startElement(String name, Object value, String xsElementName, |
||
103 | Object parentElement) {
|
||
104 | return new Element(name, value); |
||
105 | } |
||
106 | |||
107 | /*
|
||
108 | * (non-Javadoc)
|
||
109 | * @see org.gvsig.gpe.GPEContentHandler#startFeature(java.lang.String, java.lang.String, java.lang.String, java.lang.Object)
|
||
110 | */
|
||
111 | public Object startFeature(String id, String name, String xsElementName, |
||
112 | Object layer) {
|
||
113 | 103 | dmartinezizquierdo | return new Feature(id, name, name, null); |
114 | 29 | jldominguez | } |
115 | |||
116 | /*
|
||
117 | * (non-Javadoc)
|
||
118 | * @see org.gvsig.gpe.GPEContentHandler#startPoint(java.lang.String, double, double, double, java.lang.String)
|
||
119 | */
|
||
120 | public Object startPoint(String id, double x, double y, double z, String srs) { |
||
121 | return new Point2D.Double(x, y); |
||
122 | 103 | dmartinezizquierdo | } |
123 | 29 | jldominguez | |
124 | /* (non-Javadoc)
|
||
125 | * @see org.gvsig.gpe.GPEContentHandler#startLineString(java.lang.String, double[], double[], double[], java.lang.String)
|
||
126 | */
|
||
127 | public Object startLineString(String id, double[] x, double[] y, |
||
128 | double[] z, String srs) { |
||
129 | return getPoint(x, y);
|
||
130 | } |
||
131 | |||
132 | /* (non-Javadoc)
|
||
133 | * @see org.gvsig.gpe.GPEContentHandler#startPolygon(java.lang.String, double[], double[], double[], java.lang.String)
|
||
134 | */
|
||
135 | public Object startPolygon(String id, double[] x, double[] y, double[] z, |
||
136 | String srs) {
|
||
137 | return getPoint(x, y);
|
||
138 | } |
||
139 | 103 | dmartinezizquierdo | |
140 | private Point2D getPoint(double[] x, double y[]) { |
||
141 | 29 | jldominguez | double xs = 0.0; |
142 | double ys = 0.0; |
||
143 | for (int i=0 ; i<x.length ; i++){ |
||
144 | xs = xs + x[i]; |
||
145 | ys = ys + y[i]; |
||
146 | } |
||
147 | if (x.length == 0){ |
||
148 | return new Point2D.Double(xs,ys); |
||
149 | }else{
|
||
150 | return new Point2D.Double(xs/x.length,ys/x.length); |
||
151 | } |
||
152 | 103 | dmartinezizquierdo | } |
153 | |||
154 | 29 | jldominguez | /**
|
155 | * @author Jorge Piera Llodr? (jorge.piera@iver.es)
|
||
156 | */
|
||
157 | private class Element{ |
||
158 | private String name = null; |
||
159 | private Object value = null; |
||
160 | 103 | dmartinezizquierdo | |
161 | 29 | jldominguez | public Element(String name, Object value) { |
162 | super();
|
||
163 | this.name = name;
|
||
164 | this.value = value;
|
||
165 | } |
||
166 | 103 | dmartinezizquierdo | |
167 | 29 | jldominguez | /**
|
168 | * @return the name
|
||
169 | */
|
||
170 | public String getName() { |
||
171 | return name;
|
||
172 | } |
||
173 | 103 | dmartinezizquierdo | |
174 | 29 | jldominguez | /**
|
175 | * @param name the name to set
|
||
176 | */
|
||
177 | public void setName(String name) { |
||
178 | this.name = name;
|
||
179 | } |
||
180 | 103 | dmartinezizquierdo | |
181 | 29 | jldominguez | /**
|
182 | * @return the value
|
||
183 | */
|
||
184 | public Object getValue() { |
||
185 | return value;
|
||
186 | } |
||
187 | 103 | dmartinezizquierdo | |
188 | 29 | jldominguez | /**
|
189 | * @param value the value to set
|
||
190 | */
|
||
191 | public void setValue(Object value) { |
||
192 | this.value = value;
|
||
193 | 103 | dmartinezizquierdo | } |
194 | 29 | jldominguez | } |
195 | |||
196 | /**
|
||
197 | * @return the features
|
||
198 | */
|
||
199 | public ArrayList getFeatures() { |
||
200 | return features;
|
||
201 | } |
||
202 | |||
203 | } |