root / tags / v1_0_1_RELEASE / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / gml / FMAPGeometryFactory.java @ 9531
History | View | Annotate | Download (6.18 KB)
1 |
package com.iver.cit.gvsig.fmap.drivers.gml; |
---|---|
2 |
|
3 |
import java.awt.geom.Point2D; |
4 |
import java.util.ArrayList; |
5 |
import java.util.Date; |
6 |
|
7 |
import org.apache.log4j.Logger; |
8 |
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory; |
9 |
|
10 |
import com.hardcode.gdbms.engine.values.ComplexValue; |
11 |
import com.hardcode.gdbms.engine.values.Value; |
12 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
13 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
14 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
15 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
16 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
17 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
18 |
import com.vividsolutions.jts.geom.Geometry; |
19 |
import com.vividsolutions.jts.geom.GeometryFactory; |
20 |
import com.vividsolutions.jts.io.gml2.GMLReader; |
21 |
|
22 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
23 |
*
|
24 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
25 |
*
|
26 |
* This program is free software; you can redistribute it and/or
|
27 |
* modify it under the terms of the GNU General Public License
|
28 |
* as published by the Free Software Foundation; either version 2
|
29 |
* of the License, or (at your option) any later version.
|
30 |
*
|
31 |
* This program is distributed in the hope that it will be useful,
|
32 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
33 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
34 |
* GNU General Public License for more details.
|
35 |
*
|
36 |
* You should have received a copy of the GNU General Public License
|
37 |
* along with this program; if not, write to the Free Software
|
38 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
39 |
*
|
40 |
* For more information, contact:
|
41 |
*
|
42 |
* Generalitat Valenciana
|
43 |
* Conselleria d'Infraestructures i Transport
|
44 |
* Av. Blasco Ib??ez, 50
|
45 |
* 46010 VALENCIA
|
46 |
* SPAIN
|
47 |
*
|
48 |
* +34 963862235
|
49 |
* gvsig@gva.es
|
50 |
* www.gvsig.gva.es
|
51 |
*
|
52 |
* or
|
53 |
*
|
54 |
* IVER T.I. S.A
|
55 |
* Salamanca 50
|
56 |
* 46005 Valencia
|
57 |
* Spain
|
58 |
*
|
59 |
* +34 963163400
|
60 |
* dac@iver.es
|
61 |
*/
|
62 |
/* CVS MESSAGES:
|
63 |
*
|
64 |
* $Id: FMAPGeometryFactory.java 8765 2006-11-15 00:08:29Z jjdelcerro $
|
65 |
* $Log$
|
66 |
* Revision 1.1.4.1 2006-11-15 00:08:23 jjdelcerro
|
67 |
* *** empty log message ***
|
68 |
*
|
69 |
* Revision 1.2 2006/10/10 12:55:27 jorpiell
|
70 |
* Se ha a?adido el soporte de features complejas
|
71 |
*
|
72 |
* Revision 1.1 2006/08/10 12:03:43 jorpiell
|
73 |
* Se usa el nuevo driver de GML de remoteServices
|
74 |
*
|
75 |
*
|
76 |
*/
|
77 |
/**
|
78 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
79 |
*/
|
80 |
public class FMAPGeometryFactory implements IGeometriesFactory{ |
81 |
private static Logger logger = Logger.getLogger(FMAPGeometryFactory.class); |
82 |
|
83 |
public Object createPoint2D(double x, double y){ |
84 |
return ShapeFactory.createPoint2D(x,y);
|
85 |
} |
86 |
|
87 |
public Object createPoint2D(Point2D point2D) { |
88 |
return createPoint2D(point2D.getX(),point2D.getY());
|
89 |
} |
90 |
|
91 |
public Object createMultipoint2D(double[] x, double[] y){ |
92 |
return ShapeFactory.createMultipoint2D(x,y);
|
93 |
} |
94 |
|
95 |
public Object createSimpleFeature(String element, Object geometry, ArrayList params, ArrayList values) { |
96 |
ArrayList fmapParams = getParams((ArrayList)params.get(1)); |
97 |
Value[] fmapValues = getValues((ArrayList)params.get(1),(ArrayList)values.get(1)); |
98 |
IFeature feature = new DefaultFeature((IGeometry)geometry,fmapValues);
|
99 |
return new FeatureWithAttributes(feature,fmapParams,fmapValues); |
100 |
} |
101 |
|
102 |
public Object createGeometry(String gmlGeometry) { |
103 |
GMLReader reader = new GMLReader();
|
104 |
try {
|
105 |
Geometry geom = reader.read(gmlGeometry,new GeometryFactory());
|
106 |
return ShapeFactory.createGeometry(FConverter.jts_to_java2d(geom));
|
107 |
} catch (Exception e){ |
108 |
logger.error("Can't parse: " + gmlGeometry,e);
|
109 |
} |
110 |
return null; |
111 |
} |
112 |
|
113 |
private ArrayList getParams(ArrayList params){ |
114 |
ArrayList fmapParams = new ArrayList(); |
115 |
for (int i=0 ; i<params.size() ; i++){ |
116 |
if (!(params.get(i) instanceof ArrayList)){ |
117 |
fmapParams.add(params.get(i)); |
118 |
} |
119 |
} |
120 |
return fmapParams;
|
121 |
} |
122 |
|
123 |
private Value[] getValues(ArrayList params,ArrayList values){ |
124 |
int i = 0; |
125 |
ArrayList fmapValues = new ArrayList(); |
126 |
while(i<params.size()){
|
127 |
if ((i+1 < params.size()) && (params.get(i+1) instanceof ArrayList)){ |
128 |
ComplexValue value = ValueFactory.createComplexValue((String)params.get(i));
|
129 |
ArrayList subParams = getParams((ArrayList)params.get(i+1)); |
130 |
Value[] subValues = getValues((ArrayList)params.get(i+1),(ArrayList)values.get(i+1)); |
131 |
for (int j=0 ; j<subParams.size() ; j++){ |
132 |
value.put(subParams.get(j),subValues[j]); |
133 |
} |
134 |
fmapValues.add(value); |
135 |
i = i + 2;
|
136 |
}else{
|
137 |
fmapValues.add(getValue(values.get(i))); |
138 |
i++; |
139 |
} |
140 |
} |
141 |
Value[] returnValues = new Value[fmapValues.size()]; |
142 |
for (int k=0 ; k<fmapValues.size() ; k++){ |
143 |
returnValues[k] = (Value)fmapValues.get(k); |
144 |
} |
145 |
return returnValues;
|
146 |
} |
147 |
|
148 |
/**
|
149 |
* Gets the attributes
|
150 |
* @param attr
|
151 |
* @return
|
152 |
*/
|
153 |
private Value getValue(Object attr) { |
154 |
if (attr instanceof Double){ |
155 |
return ValueFactory.createValue(((Double)attr).doubleValue()); |
156 |
}else if (attr instanceof String){ |
157 |
return ValueFactory.createValue(String.valueOf(attr)); |
158 |
}else if (attr instanceof Long){ |
159 |
return ValueFactory.createValue(((Long)attr).longValue()); |
160 |
}else if (attr instanceof Integer){ |
161 |
return ValueFactory.createValue(((Integer)attr).intValue()); |
162 |
}else if (attr instanceof Float){ |
163 |
return ValueFactory.createValue(((Float)attr).floatValue()); |
164 |
}else if (attr instanceof Short){ |
165 |
return ValueFactory.createValue(((Short)attr).shortValue()); |
166 |
}else if (attr instanceof Boolean){ |
167 |
return ValueFactory.createValue(((Boolean)attr).booleanValue()); |
168 |
}else if (attr instanceof Date){ |
169 |
return ValueFactory.createValue(((Date)attr)); |
170 |
} |
171 |
return ValueFactory.createValue(((String)"")); |
172 |
} |
173 |
|
174 |
public class FeatureWithAttributes{ |
175 |
private IFeature feature;
|
176 |
private ArrayList attributeName; |
177 |
private Value[] attributeValue; |
178 |
|
179 |
public FeatureWithAttributes(IFeature feature, ArrayList attributeName, Value[] attributeValue) { |
180 |
super();
|
181 |
this.feature = feature;
|
182 |
this.attributeName = attributeName;
|
183 |
this.attributeValue = attributeValue;
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* @return Returns the attributeName.
|
188 |
*/
|
189 |
public ArrayList getAttributeName() { |
190 |
return attributeName;
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* @return Returns the feature.
|
195 |
*/
|
196 |
public IFeature getFeature() {
|
197 |
return feature;
|
198 |
} |
199 |
|
200 |
/**
|
201 |
* @return Returns the attributeValue.
|
202 |
*/
|
203 |
public Value[] getAttributeValue() { |
204 |
return attributeValue;
|
205 |
} |
206 |
|
207 |
} |
208 |
|
209 |
} |