svn-gvsig-desktop / tags / J2ME_compat_v1_2_Build_1209 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / FeatureCollectionMemoryDriver.java @ 19509
History | View | Annotate | Download (6.31 KB)
1 |
/*
|
---|---|
2 |
* Created on 18-sep-2007
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: FeatureCollectionMemoryDriver.java 14143 2007-09-27 16:58:37Z azabala $
|
47 |
* $Log: FeatureCollectionMemoryDriver.java,v $
|
48 |
* Revision 1.1 2007/09/19 15:27:41 azabala
|
49 |
* first version in cvs
|
50 |
*
|
51 |
*
|
52 |
*/
|
53 |
package com.iver.cit.gvsig.fmap.drivers; |
54 |
|
55 |
import java.awt.geom.Rectangle2D; |
56 |
import java.util.ArrayList; |
57 |
import java.util.Iterator; |
58 |
import java.util.List; |
59 |
|
60 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
61 |
import com.hardcode.gdbms.driver.exceptions.ReloadDriverException; |
62 |
import com.hardcode.gdbms.driver.exceptions.WriteDriverException; |
63 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
64 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
65 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
66 |
import com.hardcode.gdbms.engine.values.Value; |
67 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
68 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
69 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
70 |
|
71 |
/**
|
72 |
* Driver to work with a collection of IFeature.
|
73 |
*
|
74 |
* If offers a layer to work with a collection of a features as a vectorial driver.
|
75 |
* It doesnt allow to write or edit existing features.
|
76 |
*
|
77 |
* @author azabala
|
78 |
*
|
79 |
*/
|
80 |
public class FeatureCollectionMemoryDriver implements VectorialDriver, |
81 |
ObjectDriver, |
82 |
BoundedShapes { |
83 |
|
84 |
public static final Rectangle2D EMPTY_FULL_EXTENT = new Rectangle2D.Double(); |
85 |
/**
|
86 |
* Name of the data source of this driver
|
87 |
*/
|
88 |
String name;
|
89 |
/**
|
90 |
* contains all features this driver allows to access.
|
91 |
*/
|
92 |
List features;
|
93 |
|
94 |
/**
|
95 |
* Definition of the features.
|
96 |
*/
|
97 |
LayerDefinition layerDefinition; |
98 |
|
99 |
/**
|
100 |
* Full extent of all features
|
101 |
*/
|
102 |
Rectangle2D fullExtent;
|
103 |
|
104 |
//TODO Remove this class
|
105 |
DriverAttributes attributes = null;
|
106 |
|
107 |
/**
|
108 |
* Constructor
|
109 |
* @param name descriptive name of the data source
|
110 |
* @param features collection of features in memory
|
111 |
* @param definition definition of the layer of these features
|
112 |
*/
|
113 |
public FeatureCollectionMemoryDriver(String name, |
114 |
List features,
|
115 |
LayerDefinition definition){ |
116 |
this.name = name;
|
117 |
this.features = features;
|
118 |
this.layerDefinition = definition;
|
119 |
this.attributes = new DriverAttributes(); |
120 |
attributes.setLoadedInMemory(true);
|
121 |
computeFullExtent(); |
122 |
} |
123 |
|
124 |
|
125 |
public int getShapeType() { |
126 |
return layerDefinition.getShapeType();
|
127 |
} |
128 |
|
129 |
public String getName() { |
130 |
return name;
|
131 |
} |
132 |
|
133 |
|
134 |
public int getShapeCount() throws ReadDriverException { |
135 |
return features.size();
|
136 |
} |
137 |
|
138 |
|
139 |
public DriverAttributes getDriverAttributes() {
|
140 |
return attributes;
|
141 |
} |
142 |
|
143 |
|
144 |
public Rectangle2D getFullExtent() throws ReadDriverException, ExpansionFileReadException { |
145 |
if(fullExtent == null){ |
146 |
//collection is empty
|
147 |
return EMPTY_FULL_EXTENT;
|
148 |
} |
149 |
return fullExtent;
|
150 |
} |
151 |
|
152 |
|
153 |
public IGeometry getShape(int index) throws ReadDriverException { |
154 |
if(index < features.size())
|
155 |
return ((IFeature) features.get(index)).getGeometry();
|
156 |
else
|
157 |
return null; |
158 |
} |
159 |
|
160 |
|
161 |
public void reload() throws ReloadDriverException { |
162 |
this.name = ""; |
163 |
this.features = new ArrayList(); |
164 |
this.fullExtent = null; |
165 |
this.layerDefinition = null; |
166 |
} |
167 |
|
168 |
|
169 |
public boolean isWritable() { |
170 |
return false; |
171 |
} |
172 |
|
173 |
|
174 |
public int[] getPrimaryKeys() throws ReadDriverException { |
175 |
return null; |
176 |
} |
177 |
|
178 |
|
179 |
public void write(DataWare dataWare) throws WriteDriverException, ReadDriverException { |
180 |
} |
181 |
|
182 |
|
183 |
public void setDataSourceFactory(DataSourceFactory dsf) { |
184 |
} |
185 |
|
186 |
|
187 |
public Value getFieldValue(long rowIndex, int fieldId) throws ReadDriverException { |
188 |
IFeature feature = (IFeature) features.get((int) rowIndex);
|
189 |
return feature.getAttributes()[fieldId];
|
190 |
} |
191 |
|
192 |
|
193 |
public int getFieldCount() throws ReadDriverException { |
194 |
return layerDefinition.getFieldsDesc().length;
|
195 |
} |
196 |
|
197 |
|
198 |
public String getFieldName(int fieldId) throws ReadDriverException { |
199 |
FieldDescription[] fields = layerDefinition.getFieldsDesc();
|
200 |
return fields[fieldId].getFieldName();
|
201 |
} |
202 |
|
203 |
|
204 |
public long getRowCount() throws ReadDriverException { |
205 |
return features.size();
|
206 |
} |
207 |
|
208 |
|
209 |
public int getFieldType(int i) throws ReadDriverException { |
210 |
FieldDescription[] fields = layerDefinition.getFieldsDesc();
|
211 |
return fields[i].getFieldType();
|
212 |
} |
213 |
|
214 |
|
215 |
public int getFieldWidth(int i) throws ReadDriverException { |
216 |
FieldDescription[] fields = layerDefinition.getFieldsDesc();
|
217 |
return fields[i].getFieldLength();
|
218 |
} |
219 |
|
220 |
|
221 |
public Rectangle2D getShapeBounds(int index) throws ReadDriverException, ExpansionFileReadException { |
222 |
IGeometry geometry = getShape(index); |
223 |
return geometry.getBounds2D();
|
224 |
} |
225 |
|
226 |
|
227 |
public int getShapeType(int index) throws ReadDriverException { |
228 |
IGeometry geometry = getShape(index); |
229 |
return geometry.getGeometryType();
|
230 |
} |
231 |
|
232 |
private void computeFullExtent() { |
233 |
Iterator featuresIt = features.iterator();
|
234 |
while(featuresIt.hasNext()){
|
235 |
IFeature feature = (IFeature) featuresIt.next(); |
236 |
Rectangle2D rAux = feature.getGeometry().getBounds2D();
|
237 |
if(fullExtent == null) |
238 |
fullExtent = rAux; |
239 |
else
|
240 |
fullExtent.add(rAux); |
241 |
} |
242 |
} |
243 |
|
244 |
|
245 |
|
246 |
} |
247 |
|