svn-gvsig-desktop / tags / v1_0_2_Build_898 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / VectorialEditableAdapter.java @ 10513
History | View | Annotate | Download (30.8 KB)
1 | 3612 | fjp | /*
|
---|---|---|---|
2 | * Created on 12-ene-2006 by fjp
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | 3722 | caballero | *
|
6 | 3612 | fjp | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 | 3722 | caballero | *
|
8 | 3612 | fjp | * 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 | 3722 | caballero | *
|
13 | 3612 | fjp | * 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 | 3722 | caballero | *
|
18 | 3612 | fjp | * 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 | 3722 | caballero | *
|
22 | 3612 | fjp | * 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 | 3722 | caballero | *
|
34 | 3612 | fjp | * or
|
35 | 3722 | caballero | *
|
36 | 3612 | fjp | * IVER T.I. S.A
|
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | 3722 | caballero | *
|
41 | 3612 | fjp | * +34 963163400
|
42 | * dac@iver.es
|
||
43 | */
|
||
44 | /* CVS MESSAGES:
|
||
45 | 3722 | caballero | *
|
46 | 3612 | fjp | * $Id$
|
47 | * $Log$
|
||
48 | 10234 | caballero | * Revision 1.62.4.4 2007-02-09 11:25:44 caballero
|
49 | * gr?fico o alfanum?rico
|
||
50 | *
|
||
51 | * Revision 1.62.4.3 2006/11/22 09:23:09 fjp
|
||
52 | 8913 | fjp | * Fallo al editar una capa de postgis 8.0 o superior. Y de paso, para que al guardar los cambios no haga falta leer todos los registros.
|
53 | *
|
||
54 | * Revision 1.62.4.2 2006/11/15 00:08:24 jjdelcerro
|
||
55 | 8765 | jjdelcerro | * *** empty log message ***
|
56 | 7272 | jaume | *
|
57 | 8765 | jjdelcerro | * Revision 1.64 2006/09/21 17:32:11 azabala
|
58 | * *** empty log message ***
|
||
59 | *
|
||
60 | 7272 | jaume | * Revision 1.62 2006/08/10 08:20:31 caballero
|
61 | 6714 | caballero | * flatness
|
62 | *
|
||
63 | * Revision 1.61 2006/07/20 13:03:07 fjp
|
||
64 | 6478 | fjp | * nuevos campos
|
65 | *
|
||
66 | * Revision 1.60 2006/07/12 11:48:41 fjp
|
||
67 | 6212 | fjp | * Draft to add, remove and delete fields
|
68 | *
|
||
69 | 6323 | fjp | * Revision 1.59 2006/07/12 10:34:52 fjp
|
70 | * Draft to add, remove and delete fields
|
||
71 | *
|
||
72 | 6313 | fjp | * Revision 1.58 2006/07/06 08:31:29 fjp
|
73 | * Draft to add, remove and delete fields
|
||
74 | *
|
||
75 | 6212 | fjp | * Revision 1.57 2006/06/22 11:38:12 caballero
|
76 | 5987 | caballero | * soluci?n error al borrar geometr?as
|
77 | *
|
||
78 | * Revision 1.56 2006/06/16 10:44:01 fjp
|
||
79 | 5880 | fjp | * Por mandato de Vicente
|
80 | 5879 | caballero | *
|
81 | * Revision 1.54 2006/06/01 16:15:16 fjp
|
||
82 | 5595 | fjp | * Escritura que permite crear drivers de manera m?s sencilla.
|
83 | *
|
||
84 | * Revision 1.53 2006/05/30 13:03:41 fjp
|
||
85 | 5535 | fjp | * setFlatness solo se debe aplicar a bases de datos espaciales.
|
86 | *
|
||
87 | * Revision 1.52 2006/05/24 09:29:30 caballero
|
||
88 | 5389 | caballero | * a?adir flatness
|
89 | *
|
||
90 | * Revision 1.51 2006/05/16 16:07:19 fjp
|
||
91 | 5223 | fjp | * snapping. Revisar
|
92 | *
|
||
93 | * Revision 1.50 2006/05/16 07:07:46 caballero
|
||
94 | 5197 | caballero | * Modificar la geometr?a desde fuera
|
95 | *
|
||
96 | * Revision 1.49 2006/05/15 10:52:23 caballero
|
||
97 | 5184 | caballero | * Saber si se realiza una operaci?n desde la vista o desde la tabla.
|
98 | *
|
||
99 | * Revision 1.48 2006/05/09 15:58:37 caballero
|
||
100 | 5115 | caballero | * Para el IGN
|
101 | *
|
||
102 | * Revision 1.47 2006/05/09 10:28:28 caballero
|
||
103 | 5114 | caballero | * faltaba controlar undo y redo
|
104 | *
|
||
105 | * Revision 1.46 2006/04/27 06:44:56 caballero
|
||
106 | 4954 | caballero | * Soluci?n undo y redo de anotaciones
|
107 | *
|
||
108 | * Revision 1.45 2006/04/18 06:56:55 caballero
|
||
109 | 4847 | caballero | * Cambiar VectorialAdapter por ReadableVectorial
|
110 | *
|
||
111 | * Revision 1.44 2006/04/12 17:13:39 fjp
|
||
112 | 4835 | fjp | * *** empty log message ***
|
113 | *
|
||
114 | * Revision 1.43 2006/04/11 12:12:29 fjp
|
||
115 | 4799 | fjp | * Con edici?n en PostGIS y guardando pseudo-arcos en los shapes.
|
116 | *
|
||
117 | * Revision 1.42 2006/04/11 06:53:20 fjp
|
||
118 | 4792 | fjp | * Preparando el driver de escritura PostGIS
|
119 | *
|
||
120 | * Revision 1.41 2006/04/04 11:27:16 fjp
|
||
121 | 4727 | fjp | * Consola escuchando bien y selecci?n en tabla sincronizada cuando hay edici?n
|
122 | *
|
||
123 | * Revision 1.40 2006/04/03 11:04:48 caballero
|
||
124 | 4709 | caballero | * Posibilidad de a?adir una anotaci?n
|
125 | *
|
||
126 | * Revision 1.39 2006/03/29 06:26:37 caballero
|
||
127 | 4637 | caballero | * acelerar con una imagen las herramientas
|
128 | *
|
||
129 | * Revision 1.38 2006/03/23 16:20:52 fjp
|
||
130 | 4568 | fjp | * Un fallo un tanto inverosimil con el mapOverview
|
131 | *
|
||
132 | * Revision 1.37 2006/03/23 10:08:11 caballero
|
||
133 | 4554 | caballero | * calculo del fullExtent recorriendo todas las geometr?as
|
134 | *
|
||
135 | * Revision 1.36 2006/03/22 11:46:29 caballero
|
||
136 | 4523 | caballero | * Editar capa de anotaciones
|
137 | *
|
||
138 | * Revision 1.35 2006/02/28 18:15:22 fjp
|
||
139 | 4225 | fjp | * Consola de CAD
|
140 | *
|
||
141 | * Revision 1.34 2006/02/24 11:30:32 fjp
|
||
142 | 4193 | fjp | * FUNCIONA!!! (Creo)
|
143 | *
|
||
144 | 4195 | fjp | * Revision 1.33 2006/02/24 07:57:58 fjp
|
145 | * FUNCIONA!!! (Creo)
|
||
146 | *
|
||
147 | 4193 | fjp | * Revision 1.32 2006/02/23 17:55:45 fjp
|
148 | 4147 | fjp | * Preparando para poder editar con el EditionManager
|
149 | *
|
||
150 | 4191 | fjp | * Revision 1.31 2006/02/21 16:44:08 fjp
|
151 | * Preparando para poder editar con el EditionManager
|
||
152 | *
|
||
153 | 4181 | fjp | * Revision 1.30 2006/02/20 18:14:59 fjp
|
154 | * Preparando para poder editar con el EditionManager
|
||
155 | *
|
||
156 | 4171 | fjp | * Revision 1.29 2006/02/20 10:32:54 fjp
|
157 | * Preparando para poder editar con el EditionManager
|
||
158 | *
|
||
159 | 4159 | fjp | * Revision 1.28 2006/02/17 13:40:03 fjp
|
160 | * Preparando para poder editar con el EditionManager
|
||
161 | *
|
||
162 | 4147 | fjp | * Revision 1.27 2006/02/17 10:41:14 fjp
|
163 | 4144 | fjp | * Evento de edici?n lanzado cuando una capa se pone en edici?n
|
164 | *
|
||
165 | * Revision 1.26 2006/02/17 08:21:19 fjp
|
||
166 | 4135 | fjp | * *** empty log message ***
|
167 | *
|
||
168 | * Revision 1.25 2006/02/16 09:38:10 fjp
|
||
169 | 4123 | fjp | * Preparando compatibilidad para bases de datos (y de paso, acelerando :-)
|
170 | *
|
||
171 | * Revision 1.24 2006/02/16 09:06:28 caballero
|
||
172 | 4120 | caballero | * commandStack
|
173 | *
|
||
174 | * Revision 1.23 2006/02/15 18:16:02 fjp
|
||
175 | 4085 | fjp | * POR TERMINAR
|
176 | *
|
||
177 | 4115 | fjp | * Revision 1.22 2006/02/13 18:18:31 fjp
|
178 | * POR TERMINAR
|
||
179 | *
|
||
180 | 4085 | fjp | * Revision 1.21 2006/02/10 13:28:23 caballero
|
181 | 4061 | caballero | * poder cambiar la selecci?n
|
182 | *
|
||
183 | * Revision 1.20 2006/02/09 13:11:54 caballero
|
||
184 | 4026 | caballero | * *** empty log message ***
|
185 | *
|
||
186 | * Revision 1.19 2006/02/08 16:45:29 caballero
|
||
187 | 4000 | caballero | * elimnar c?dio no usado
|
188 | *
|
||
189 | * Revision 1.18 2006/02/08 15:18:45 caballero
|
||
190 | 3996 | caballero | * control de las rows eliminadas
|
191 | *
|
||
192 | * Revision 1.17 2006/02/07 10:18:44 caballero
|
||
193 | 3980 | caballero | * Con BoundedShape
|
194 | *
|
||
195 | * Revision 1.16 2006/02/06 12:01:41 caballero
|
||
196 | 3958 | caballero | * driver del ova
|
197 | *
|
||
198 | * Revision 1.15 2006/02/03 14:09:32 fjp
|
||
199 | 3943 | fjp | * Preparando edici?n
|
200 | *
|
||
201 | 3952 | fjp | * Revision 1.14 2006/02/03 12:16:33 fjp
|
202 | * Preparando edici?n
|
||
203 | *
|
||
204 | 3943 | fjp | * Revision 1.13 2006/02/03 11:54:12 caballero
|
205 | 3940 | caballero | * tablas con vectorialEditableAdapter en edici?n
|
206 | 3936 | fjp | *
|
207 | * Revision 1.11 2006/01/31 08:10:05 caballero
|
||
208 | 3849 | caballero | * cambio de feature a row
|
209 | *
|
||
210 | * Revision 1.10 2006/01/30 08:18:14 caballero
|
||
211 | 3836 | caballero | * m?todos para deshacer y rehacer
|
212 | *
|
||
213 | * Revision 1.9 2006/01/23 17:30:28 caballero
|
||
214 | 3728 | caballero | * coger los datos del ova
|
215 | *
|
||
216 | * Revision 1.8 2006/01/23 16:16:16 caballero
|
||
217 | 3722 | caballero | * getRowIndex
|
218 | *
|
||
219 | * Revision 1.7 2006/01/20 08:37:10 fjp
|
||
220 | 3695 | fjp | * Preparando la edici?n
|
221 | *
|
||
222 | * Revision 1.6 2006/01/19 12:48:20 caballero
|
||
223 | 3688 | caballero | * poder modificar su vectorial Adapter
|
224 | *
|
||
225 | * Revision 1.5 2006/01/19 09:28:11 fjp
|
||
226 | 3686 | fjp | * Preparando la edici?n
|
227 | *
|
||
228 | * Revision 1.4 2006/01/17 10:24:02 fjp
|
||
229 | 3651 | fjp | * Preparando edici?n
|
230 | *
|
||
231 | 3653 | fjp | * Revision 1.3 2006/01/16 12:47:38 fjp
|
232 | * Preparando edici?n
|
||
233 | *
|
||
234 | 3652 | fjp | * Revision 1.2 2006/01/16 11:23:00 fjp
|
235 | * Preparando edici?n
|
||
236 | *
|
||
237 | 3651 | fjp | * Revision 1.1 2006/01/12 13:39:14 fjp
|
238 | 3612 | fjp | * preaparar edicion
|
239 | *
|
||
240 | *
|
||
241 | */
|
||
242 | package com.iver.cit.gvsig.fmap.edition; |
||
243 | |||
244 | 4727 | fjp | import java.awt.Image; |
245 | 3612 | fjp | import java.awt.geom.Rectangle2D; |
246 | 4637 | caballero | import java.awt.image.BufferedImage; |
247 | 3612 | fjp | import java.io.IOException; |
248 | 3722 | caballero | import java.util.List; |
249 | 3612 | fjp | |
250 | 5595 | fjp | import com.hardcode.driverManager.Driver; |
251 | 3612 | fjp | import com.hardcode.driverManager.DriverLoadException; |
252 | 3943 | fjp | import com.hardcode.gdbms.engine.data.DataSource; |
253 | import com.hardcode.gdbms.engine.values.Value; |
||
254 | 3940 | caballero | import com.iver.cit.gvsig.fmap.DriverException; |
255 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.DriverIOExceptionType; |
256 | import com.iver.cit.gvsig.fmap.DriverNotLoadedExceptionType; |
||
257 | 3940 | caballero | import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
258 | 3980 | caballero | import com.iver.cit.gvsig.fmap.core.FShape; |
259 | 3612 | fjp | import com.iver.cit.gvsig.fmap.core.IFeature; |
260 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
261 | 3652 | fjp | import com.iver.cit.gvsig.fmap.core.IRow; |
262 | 4159 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
263 | 3980 | caballero | import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
264 | 3940 | caballero | import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
265 | 3612 | fjp | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
266 | 3940 | caballero | import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
267 | 4061 | caballero | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
268 | 3940 | caballero | import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
269 | 3652 | fjp | import com.vividsolutions.jts.geom.Envelope; |
270 | 4523 | caballero | import com.vividsolutions.jts.index.SpatialIndex; |
271 | 3652 | fjp | import com.vividsolutions.jts.index.quadtree.Quadtree; |
272 | 3612 | fjp | |
273 | /**
|
||
274 | * @author fjp
|
||
275 | 5389 | caballero | *
|
276 | 3612 | fjp | */
|
277 | 5223 | fjp | public class VectorialEditableAdapter extends EditableAdapter implements |
278 | ReadableVectorial, BoundedShapes { |
||
279 | 4847 | caballero | protected ReadableVectorial ova;
|
280 | 5223 | fjp | |
281 | 4159 | fjp | protected Quadtree index;
|
282 | 4523 | caballero | |
283 | 4225 | fjp | protected Rectangle2D fullExtent; |
284 | 5223 | fjp | |
285 | 4792 | fjp | protected Image selectionImage; |
286 | 5223 | fjp | |
287 | 4792 | fjp | protected BufferedImage handlersImage; |
288 | 4523 | caballero | |
289 | 6714 | caballero | //private double flatness=0.8;
|
290 | 5223 | fjp | /*
|
291 | * private class MyFeatureIterator implements IFeatureIterator { int numReg =
|
||
292 | * 0; Rectangle2D rect; String epsg; IFeatureIterator origFeatIt; boolean
|
||
293 | * bHasNext = true;
|
||
294 | 5389 | caballero | *
|
295 | 5223 | fjp | * public MyFeatureIterator(Rectangle2D r, String strEPSG) throws
|
296 | * DriverException { rect = r; epsg = strEPSG; origFeatIt =
|
||
297 | * ova.getFeatureIterator(r, epsg); } public boolean hasNext() throws
|
||
298 | * DriverException { return bHasNext; }
|
||
299 | 5389 | caballero | *
|
300 | 5223 | fjp | * public IFeature next() throws DriverException { IFeature aux =
|
301 | * origFeatIt.next(); return null; }
|
||
302 | 5389 | caballero | *
|
303 | 5223 | fjp | * public void closeIterator() throws DriverException {
|
304 | * }
|
||
305 | * }
|
||
306 | */
|
||
307 | 4523 | caballero | |
308 | 5223 | fjp | public VectorialEditableAdapter() {
|
309 | 3940 | caballero | super();
|
310 | 3652 | fjp | } |
311 | 5223 | fjp | |
312 | public void setOriginalVectorialAdapter(ReadableVectorial rv) { |
||
313 | ova = rv; |
||
314 | 3940 | caballero | try {
|
315 | 3958 | caballero | setOriginalDataSource(rv.getRecordset()); |
316 | 3940 | caballero | } catch (DriverLoadException e) {
|
317 | e.printStackTrace(); |
||
318 | 6212 | fjp | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
319 | // TODO Auto-generated catch block
|
||
320 | e.printStackTrace(); |
||
321 | 3652 | fjp | } |
322 | } |
||
323 | 5223 | fjp | |
324 | 3652 | fjp | /*
|
325 | * (non-Javadoc)
|
||
326 | 5389 | caballero | *
|
327 | 3652 | fjp | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#start()
|
328 | */
|
||
329 | public void start() throws DriverIOException { |
||
330 | 3653 | fjp | ova.start(); |
331 | 3652 | fjp | } |
332 | |||
333 | 5595 | fjp | public IWriter getWriter() {
|
334 | if (ova.getDriver() instanceof IWriteable) |
||
335 | { |
||
336 | IWriter writer = ((IWriteable) ova.getDriver()).getWriter(); |
||
337 | if (writer instanceof ISpatialWriter) |
||
338 | return writer;
|
||
339 | } |
||
340 | return null; |
||
341 | } |
||
342 | |||
343 | 3652 | fjp | /*
|
344 | * (non-Javadoc)
|
||
345 | 5389 | caballero | *
|
346 | 3652 | fjp | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#stop()
|
347 | */
|
||
348 | public void stop() throws DriverIOException { |
||
349 | 3653 | fjp | ova.stop(); |
350 | 3652 | fjp | } |
351 | |||
352 | /*
|
||
353 | * (non-Javadoc)
|
||
354 | 5389 | caballero | *
|
355 | 3652 | fjp | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int)
|
356 | */
|
||
357 | public IGeometry getShape(int rowIndex) throws DriverIOException { |
||
358 | // Si no est? en el fichero de expansi?n
|
||
359 | 5223 | fjp | int calculatedIndex = getCalculatedIndex(rowIndex);
|
360 | 3996 | caballero | Integer integer = new Integer(calculatedIndex); |
361 | 3652 | fjp | if (!relations.containsKey(integer)) {
|
362 | // Si ha sido eliminada
|
||
363 | 5223 | fjp | /*
|
364 | * if (delRows.get(integer.intValue())) { return null; } else {
|
||
365 | */
|
||
366 | return ova.getShape(calculatedIndex);
|
||
367 | // }
|
||
368 | 3652 | fjp | } else {
|
369 | int num = ((Integer) relations.get(integer)).intValue(); |
||
370 | 3722 | caballero | DefaultRowEdited feat; |
371 | 3652 | fjp | try {
|
372 | 3722 | caballero | feat = (DefaultRowEdited) expansionFile.getRow(num); |
373 | 5223 | fjp | return ((IFeature) feat.getLinkedRow()).getGeometry()
|
374 | .cloneGeometry();// getGeometry();
|
||
375 | 3652 | fjp | } catch (IOException e) { |
376 | e.printStackTrace(); |
||
377 | throw new DriverIOException(e); |
||
378 | } |
||
379 | } |
||
380 | |||
381 | } |
||
382 | |||
383 | /*
|
||
384 | * (non-Javadoc)
|
||
385 | 5389 | caballero | *
|
386 | 3652 | fjp | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
|
387 | */
|
||
388 | public int getShapeType() throws DriverIOException { |
||
389 | 3653 | fjp | return ova.getShapeType();
|
390 | 3652 | fjp | } |
391 | 5223 | fjp | |
392 | public ReadableVectorial getOriginalAdapter() {
|
||
393 | 3940 | caballero | return ova;
|
394 | 3652 | fjp | } |
395 | 5223 | fjp | |
396 | 3940 | caballero | public VectorialDriver getDriver() {
|
397 | 3958 | caballero | return ova.getDriver();
|
398 | 3652 | fjp | } |
399 | 5223 | fjp | |
400 | 3940 | caballero | public void setDriver(VectorialDriver driver) { |
401 | 3958 | caballero | this.ova.setDriver(driver);
|
402 | 3652 | fjp | } |
403 | 5223 | fjp | |
404 | public DriverAttributes getDriverAttributes() {
|
||
405 | 3958 | caballero | return ova.getDriverAttributes();
|
406 | 3940 | caballero | } |
407 | 3652 | fjp | |
408 | 5223 | fjp | /**
|
409 | * DOCUMENT ME!
|
||
410 | 5389 | caballero | *
|
411 | 5223 | fjp | * @throws EditionException
|
412 | * DOCUMENT ME!
|
||
413 | */
|
||
414 | public void startEdition(int sourceType) throws EditionException { |
||
415 | super.startEdition(sourceType);
|
||
416 | 5595 | fjp | Driver drv = ova.getDriver();
|
417 | if (drv instanceof IWriteable) |
||
418 | { |
||
419 | setWriter(((IWriteable) drv).getWriter()); |
||
420 | } |
||
421 | 3652 | fjp | |
422 | 5595 | fjp | |
423 | 5223 | fjp | try {
|
424 | expansionFile.open(); |
||
425 | if (index == null || fullExtent == null) { |
||
426 | // TODO: Si la capa dispone de un ?ndice espacial, hacer
|
||
427 | // algo aqu? para que se use ese ?ndice espacial.
|
||
428 | index = new Quadtree();
|
||
429 | 3653 | fjp | |
430 | 5223 | fjp | for (int i = 0; i < ova.getShapeCount(); i++) { |
431 | IGeometry g = null;
|
||
432 | try {
|
||
433 | g = ((DefaultFeature) ova.getFeature(i)).getGeometry(); |
||
434 | } catch (DriverException e1) {
|
||
435 | // TODO Auto-generated catch block
|
||
436 | e1.printStackTrace(); |
||
437 | } |
||
438 | 3653 | fjp | |
439 | 5223 | fjp | if (g == null) { |
440 | continue;
|
||
441 | } |
||
442 | 3652 | fjp | |
443 | 5223 | fjp | Rectangle2D r = g.getBounds2D();
|
444 | Envelope e = new Envelope(r.getX(),
|
||
445 | r.getX() + r.getWidth(), r.getY(), r.getY() |
||
446 | + r.getHeight()); |
||
447 | index.insert(e, new Integer(i)); |
||
448 | if (fullExtent == null) { |
||
449 | fullExtent = r; |
||
450 | } else {
|
||
451 | fullExtent = fullExtent.createUnion(r); |
||
452 | } |
||
453 | } |
||
454 | } |
||
455 | } catch (DriverIOException e) {
|
||
456 | throw new EditionException(e); |
||
457 | } catch (IOException e) { |
||
458 | throw new EditionException(e); |
||
459 | } |
||
460 | 3652 | fjp | |
461 | 5223 | fjp | System.err.println("Se han metido en el ?ndice " |
462 | + index.queryAll().size() + " geometr?as");
|
||
463 | } |
||
464 | 3652 | fjp | |
465 | 5223 | fjp | /*
|
466 | * (non-Javadoc)
|
||
467 | 5389 | caballero | *
|
468 | 5223 | fjp | * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
|
469 | */
|
||
470 | public IRowEdited getRow(int index) throws DriverIOException, IOException { |
||
471 | int calculatedIndex = getCalculatedIndex(index);
|
||
472 | Integer integer = new Integer(calculatedIndex); |
||
473 | // Si no est? en el fichero de expansi?n
|
||
474 | DefaultRowEdited edRow = null;
|
||
475 | if (!relations.containsKey(integer)) {
|
||
476 | 4115 | fjp | try {
|
477 | edRow = new DefaultRowEdited(ova.getFeature(calculatedIndex),
|
||
478 | 5223 | fjp | DefaultRowEdited.STATUS_ORIGINAL, index); |
479 | 6313 | fjp | return createExternalRow(edRow, 0); |
480 | 4115 | fjp | } catch (DriverException e) {
|
481 | e.printStackTrace(); |
||
482 | 8913 | fjp | throw new DriverIOException(e); |
483 | 4115 | fjp | } |
484 | 3652 | fjp | |
485 | 8913 | fjp | // return edRow;
|
486 | 5223 | fjp | } else {
|
487 | int num = ((Integer) relations.get(integer)).intValue(); |
||
488 | IRowEdited aux = expansionFile.getRow(num); |
||
489 | edRow = new DefaultRowEdited(aux.getLinkedRow().cloneRow(), aux
|
||
490 | .getStatus(), index); |
||
491 | 6714 | caballero | |
492 | 5223 | fjp | return edRow;
|
493 | } |
||
494 | } |
||
495 | |||
496 | /**
|
||
497 | * Elimina una geometria. Si es una geometr?a original de la capa en edici?n
|
||
498 | * se marca como eliminada (haya sido modificada o no). Si es una geometr?a
|
||
499 | * a?adida posteriormente se invalida en el fichero de expansi?n, para que
|
||
500 | * una futura compactaci?n termine con ella.
|
||
501 | 5389 | caballero | *
|
502 | 5223 | fjp | * @param index
|
503 | * ?ndice de la geometr?a.
|
||
504 | 5389 | caballero | *
|
505 | 5223 | fjp | * @throws DriverIOException
|
506 | * @throws IOException
|
||
507 | */
|
||
508 | public IRow doRemoveRow(int index, int sourceType) |
||
509 | throws DriverIOException, IOException { |
||
510 | boolean cancel = fireBeforeRemoveRow(index, sourceType);
|
||
511 | 5114 | caballero | if (cancel)
|
512 | return null; |
||
513 | 5223 | fjp | // Llega el calculatedIndex
|
514 | Integer integer = new Integer(index); |
||
515 | 3652 | fjp | |
516 | 5223 | fjp | IFeature feat = null;
|
517 | delRows.set(index, true);
|
||
518 | // Si la geometr?a no ha sido modificada
|
||
519 | if (!relations.containsKey(integer)) {
|
||
520 | 3996 | caballero | |
521 | 5223 | fjp | try {
|
522 | 3940 | caballero | feat = (DefaultFeature) (ova.getFeature(index)); |
523 | } catch (DriverException e) {
|
||
524 | // TODO Auto-generated catch block
|
||
525 | e.printStackTrace(); |
||
526 | } |
||
527 | 5223 | fjp | } else {
|
528 | 3940 | caballero | int num = ((Integer) relations.get(integer)).intValue(); |
529 | feat = (IFeature) expansionFile.getRow(num).getLinkedRow(); |
||
530 | 5223 | fjp | // expansionFile.invalidateRow(num);
|
531 | 3653 | fjp | } |
532 | 5223 | fjp | System.err.println("Elimina una Row en la posici?n: " + index); |
533 | // Se actualiza el ?ndice
|
||
534 | if (feat != null) { |
||
535 | Rectangle2D r = feat.getGeometry().getBounds2D();
|
||
536 | boolean borrado = this.index.remove(new Envelope(r.getX(), r.getX() |
||
537 | + r.getWidth(), r.getY(), r.getY() + r.getHeight()), |
||
538 | new Integer(index)); |
||
539 | System.out.println("Est? borrado : " + borrado); |
||
540 | System.out.println("Index.lenght : " + this.index.size()); |
||
541 | 8765 | jjdelcerro | isFullExtentDirty = true;
|
542 | 5223 | fjp | } |
543 | setSelection(new FBitSet());
|
||
544 | fireAfterRemoveRow(index, sourceType); |
||
545 | return feat;
|
||
546 | } |
||
547 | |||
548 | /**
|
||
549 | * Si se intenta modificar una geometr?a original de la capa en edici?n se
|
||
550 | * a?ade al fichero de expansi?n y se registra la posici?n en la que se
|
||
551 | * a?adi?. Si se intenta modificar una geometria que se encuentra en el
|
||
552 | * fichero de expansi?n (por ser nueva o original pero modificada) se invoca
|
||
553 | * el m?todo modifyGeometry y se actualiza el ?ndice de la geometria en el
|
||
554 | * fichero.
|
||
555 | 5389 | caballero | *
|
556 | 5223 | fjp | * @param calculatedIndex
|
557 | * DOCUMENT ME!
|
||
558 | * @param feat
|
||
559 | * DOCUMENT ME!
|
||
560 | 5389 | caballero | *
|
561 | 5223 | fjp | * @return position inside ExpansionFile
|
562 | 5389 | caballero | *
|
563 | 5223 | fjp | * @throws IOException
|
564 | * @throws DriverIOException
|
||
565 | */
|
||
566 | public int doModifyRow(int calculatedIndex, IRow feat, int sourceType) |
||
567 | throws IOException, DriverIOException { |
||
568 | boolean cancel = fireBeforeModifyRow(feat, calculatedIndex, sourceType);
|
||
569 | 5114 | caballero | if (cancel)
|
570 | return -1; |
||
571 | 5223 | fjp | int posAnteriorInExpansionFile = -1; |
572 | Integer integer = new Integer(calculatedIndex); |
||
573 | 3652 | fjp | |
574 | 5223 | fjp | IFeature featAnt = null;
|
575 | 10234 | caballero | // System.err.println("Modifica una Row en la posici?n: "
|
576 | // + calculatedIndex);
|
||
577 | 5223 | fjp | // Si la geometr?a no ha sido modificada
|
578 | if (!relations.containsKey(integer)) {
|
||
579 | int newPosition = expansionFile.addRow(feat,
|
||
580 | 6212 | fjp | IRowEdited.STATUS_MODIFIED, actualIndexFields); |
581 | 5223 | fjp | relations.put(integer, new Integer(newPosition)); |
582 | 3652 | fjp | |
583 | 10234 | caballero | if (sourceType == EditionEvent.GRAPHIC) {
|
584 | // Se actualiza el ?ndice espacial
|
||
585 | try {
|
||
586 | featAnt = (DefaultFeature) (ova.getFeature(calculatedIndex)); |
||
587 | } catch (DriverException e) {
|
||
588 | e.printStackTrace(); |
||
589 | } |
||
590 | IGeometry g = featAnt.getGeometry(); |
||
591 | Rectangle2D rAnt = g.getBounds2D();
|
||
592 | Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
|
||
593 | this.index.remove(new Envelope(rAnt.getX(), rAnt.getX() |
||
594 | + rAnt.getWidth(), rAnt.getY(), rAnt.getY() |
||
595 | + rAnt.getHeight()), new Integer(calculatedIndex)); |
||
596 | this.index.insert(new Envelope(r.getX(), r.getX() |
||
597 | + r.getWidth(), r.getY(), r.getY() + r.getHeight()), |
||
598 | new Integer(calculatedIndex)); |
||
599 | 3940 | caballero | } |
600 | 5223 | fjp | } else {
|
601 | // Obtenemos el ?ndice en el fichero de expansi?n
|
||
602 | int num = ((Integer) relations.get(integer)).intValue(); |
||
603 | posAnteriorInExpansionFile = num; |
||
604 | 3653 | fjp | |
605 | 5223 | fjp | // Obtenemos la geometr?a para actualiza el ?ndice
|
606 | // espacialposteriormente
|
||
607 | featAnt = (IFeature) expansionFile.getRow(num).getLinkedRow(); |
||
608 | 3652 | fjp | |
609 | 5223 | fjp | /*
|
610 | * Se modifica la geometr?a y nos guardamos el ?ndice dentro del
|
||
611 | * fichero de expansi?n en el que se encuentra la geometr?a
|
||
612 | * modificada
|
||
613 | */
|
||
614 | 6212 | fjp | num = expansionFile.modifyRow(num, feat, actualIndexFields); |
615 | 3652 | fjp | |
616 | 5223 | fjp | /*
|
617 | * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
|
||
618 | * fichero de expansi?n.
|
||
619 | */
|
||
620 | relations.put(integer, new Integer(num)); |
||
621 | 10234 | caballero | if (sourceType == EditionEvent.GRAPHIC) {
|
622 | // Se modifica el ?ndice espacial
|
||
623 | Rectangle2D rAnt = featAnt.getGeometry().getBounds2D();
|
||
624 | Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
|
||
625 | this.index.remove(new Envelope(rAnt.getX(), rAnt.getX() |
||
626 | + rAnt.getWidth(), rAnt.getY(), rAnt.getY() |
||
627 | + rAnt.getHeight()), new Integer(calculatedIndex)); |
||
628 | this.index.insert(new Envelope(r.getX(), r.getX() |
||
629 | + r.getWidth(), r.getY(), r.getY() + r.getHeight()), |
||
630 | new Integer(calculatedIndex)); |
||
631 | } |
||
632 | 5223 | fjp | } |
633 | 7272 | jaume | isFullExtentDirty = true;
|
634 | 5223 | fjp | fireAfterModifyRow(calculatedIndex, sourceType); |
635 | return posAnteriorInExpansionFile;
|
||
636 | } |
||
637 | 5197 | caballero | |
638 | 5223 | fjp | /**
|
639 | * Actualiza en el mapa de ?ndices, la posici?n en la que estaba la
|
||
640 | * geometr?a antes de ser modificada. Se marca como v?lida, en caso de que
|
||
641 | * fuera una modificaci?n de una geometr?a que estuviese en el fichero de
|
||
642 | * expansi?n antes de ser modificada y se pone el puntero de escritura del
|
||
643 | * expansion file a justo despues de la penultima geometr?a
|
||
644 | 5389 | caballero | *
|
645 | 5223 | fjp | * @param calculatedIndex
|
646 | * ?ndice de la geometr?a que se quiere deshacer su modificaci?n
|
||
647 | * @param previousExpansionFileIndex
|
||
648 | * ?ndice que ten?a antes la geometr?a en el expansionFile. Si
|
||
649 | * vale -1 quiere decir que es una modificaci?n de una geometr?a
|
||
650 | * original y por tanto no hay que actualizar el mapa de indices
|
||
651 | * sino eliminar su entrada.
|
||
652 | 5389 | caballero | *
|
653 | 5223 | fjp | * @throws IOException
|
654 | * @throws DriverIOException
|
||
655 | */
|
||
656 | public void undoModifyRow(int calculatedIndex, |
||
657 | int previousExpansionFileIndex, int sourceType) throws IOException, |
||
658 | DriverIOException { |
||
659 | 5197 | caballero | |
660 | 5223 | fjp | // Llega el CalculatedIndex
|
661 | /*
|
||
662 | * Si la acci?n de modificar se realiz? sobre una geometr?a original
|
||
663 | */
|
||
664 | if (previousExpansionFileIndex == -1) { |
||
665 | |||
666 | // Se obtiene la geometr?a para actualizar el ?ndice
|
||
667 | // IGeometry g = ((DefaultFeature)
|
||
668 | // getRow(calculatedIndex).getLinkedRow()).getGeometry();
|
||
669 | int inverse = getInversedIndex(calculatedIndex);
|
||
670 | DefaultFeature df = (DefaultFeature) getRow(inverse).getLinkedRow(); |
||
671 | boolean cancel = fireBeforeModifyRow(df, calculatedIndex,
|
||
672 | sourceType); |
||
673 | 5197 | caballero | if (cancel)
|
674 | return;
|
||
675 | 5223 | fjp | IGeometry g = df.getGeometry(); |
676 | // IGeometry g = ova.getShape(calculatedIndex);
|
||
677 | Rectangle2D r = g.getBounds2D();
|
||
678 | 3652 | fjp | |
679 | 5223 | fjp | // Se elimina de las relaciones y del fichero de expansi?n
|
680 | relations.remove(new Integer(calculatedIndex)); |
||
681 | expansionFile.deleteLastRow(); |
||
682 | 3652 | fjp | |
683 | 5223 | fjp | // Se actualizan los ?ndices
|
684 | IGeometry gAnt = ova.getShape(calculatedIndex); |
||
685 | /*
|
||
686 | * IGeometry gAnt = ((DefaultFeature) getRow(calculatedIndex)
|
||
687 | * .getLinkedRow()).getGeometry();
|
||
688 | */
|
||
689 | Rectangle2D rAnt = gAnt.getBounds2D();
|
||
690 | this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), r |
||
691 | .getY(), r.getY() + r.getHeight()), new Integer( |
||
692 | calculatedIndex)); |
||
693 | this.index.insert(new Envelope(rAnt.getX(), rAnt.getX() |
||
694 | + rAnt.getWidth(), rAnt.getY(), rAnt.getY() |
||
695 | + rAnt.getHeight()), new Integer(calculatedIndex)); |
||
696 | } else {
|
||
697 | // Se obtiene la geometr?a para actualizar el ?ndice
|
||
698 | IGeometry g = null;
|
||
699 | int inverse = getInversedIndex(calculatedIndex);
|
||
700 | DefaultFeature df = (DefaultFeature) getRow(inverse).getLinkedRow(); |
||
701 | boolean cancel = fireBeforeModifyRow(df, calculatedIndex,
|
||
702 | sourceType); |
||
703 | 5197 | caballero | if (cancel)
|
704 | return;
|
||
705 | 5223 | fjp | g = df.getGeometry(); |
706 | System.out.println("Actual: " + g.toString()); |
||
707 | 3652 | fjp | |
708 | 5223 | fjp | Rectangle2D r = g.getBounds2D();
|
709 | this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), r |
||
710 | .getY(), r.getY() + r.getHeight()), new Integer( |
||
711 | calculatedIndex)); |
||
712 | 3652 | fjp | |
713 | 5223 | fjp | // Se actualiza la relaci?n de ?ndices
|
714 | // Integer integer = new Integer(geometryIndex);
|
||
715 | relations.put(new Integer(calculatedIndex), new Integer( |
||
716 | previousExpansionFileIndex)); |
||
717 | 3652 | fjp | |
718 | 5223 | fjp | // Se recupera la geometr?a
|
719 | // expansionFile.validateRow(previousExpansionFileIndex);
|
||
720 | 3652 | fjp | |
721 | 5223 | fjp | // Se actualizan los ?ndices
|
722 | // g = ((IFeature)
|
||
723 | // (expansionFile.getRow(previousExpansionFileIndex).getLinkedRow())).getGeometry();
|
||
724 | // System.out.println("Anterior a la que volvemos : " +
|
||
725 | // g.toString());
|
||
726 | g = ((DefaultFeature) getRow(inverse).getLinkedRow()).getGeometry(); |
||
727 | r = g.getBounds2D(); |
||
728 | this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r |
||
729 | .getY(), r.getY() + r.getHeight()), new Integer( |
||
730 | calculatedIndex)); |
||
731 | 5114 | caballero | |
732 | 5223 | fjp | } |
733 | fireAfterModifyRow(calculatedIndex, sourceType); |
||
734 | } |
||
735 | 3653 | fjp | |
736 | 5223 | fjp | /**
|
737 | * A?ade una geometria al fichero de expansi?n y guarda la correspondencia
|
||
738 | * en la tabla relations.
|
||
739 | 5389 | caballero | *
|
740 | 5223 | fjp | * @param feat
|
741 | * geometr?a a guardar.
|
||
742 | 5389 | caballero | *
|
743 | 5223 | fjp | * @return calculatedIndex
|
744 | 5389 | caballero | *
|
745 | 5223 | fjp | * @throws DriverIOException
|
746 | * @throws IOException
|
||
747 | */
|
||
748 | public int doAddRow(IRow feat, int sourceType) throws DriverIOException, |
||
749 | IOException {
|
||
750 | int calculatedIndex = super.doAddRow(feat, sourceType); |
||
751 | 3940 | caballero | // Actualiza el ?ndice espacial
|
752 | 5223 | fjp | IGeometry g = ((IFeature) feat).getGeometry(); |
753 | Rectangle2D r = g.getBounds2D();
|
||
754 | index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
|
||
755 | r.getY() + r.getHeight()), new Integer(calculatedIndex)); |
||
756 | 7272 | jaume | isFullExtentDirty = true;
|
757 | 5223 | fjp | return calculatedIndex;
|
758 | } |
||
759 | 3653 | fjp | |
760 | 5223 | fjp | /**
|
761 | * Se desmarca como invalidada en el fichero de expansion o como eliminada
|
||
762 | * en el fichero original
|
||
763 | 5389 | caballero | *
|
764 | 5223 | fjp | * @param index
|
765 | * DOCUMENT ME!
|
||
766 | 5389 | caballero | *
|
767 | 5223 | fjp | * @throws IOException
|
768 | * @throws DriverIOException
|
||
769 | */
|
||
770 | public void undoRemoveRow(int index, int sourceType) throws IOException, |
||
771 | DriverIOException { |
||
772 | super.undoRemoveRow(index, sourceType);
|
||
773 | 3653 | fjp | |
774 | 5223 | fjp | IGeometry g = null;
|
775 | 5987 | caballero | g = ((IFeature) getRow(getInversedIndex(index)).getLinkedRow()).getGeometry(); |
776 | 3653 | fjp | |
777 | 5223 | fjp | Rectangle2D r = g.getBounds2D();
|
778 | this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r |
||
779 | .getY(), r.getY() + r.getHeight()), new Integer(index)); |
||
780 | } |
||
781 | 3653 | fjp | |
782 | 5223 | fjp | /**
|
783 | * Se elimina del final del fichero de expansi?n poniendo el puntero de
|
||
784 | * escritura apuntando al final de la pen?ltima geometr?a. Deber? quitar la
|
||
785 | * relaci?n del mapa de relaciones
|
||
786 | 5389 | caballero | *
|
787 | 5223 | fjp | * @param index
|
788 | * ?ndice de la geometr?a que se a?adi?
|
||
789 | 5389 | caballero | *
|
790 | 5223 | fjp | * @throws DriverIOException
|
791 | * @throws IOException
|
||
792 | */
|
||
793 | public void undoAddRow(int calculatedIndex, int sourceType) |
||
794 | throws DriverIOException, IOException { |
||
795 | int inverse = getInversedIndex(calculatedIndex);
|
||
796 | IGeometry g = ((IFeature) getRow(inverse).getLinkedRow()).getGeometry(); |
||
797 | Rectangle2D r = g.getBounds2D();
|
||
798 | this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), r |
||
799 | .getY(), r.getY() + r.getHeight()), |
||
800 | new Integer(calculatedIndex)); |
||
801 | 3653 | fjp | |
802 | 5223 | fjp | super.undoAddRow(calculatedIndex, sourceType);
|
803 | setSelection(new FBitSet());
|
||
804 | } |
||
805 | |||
806 | /**
|
||
807 | * Obtiene las geometr?as que se encuentran en el rect?ngulo que se pasa
|
||
808 | * como par?metro haciendo uso del ?ndice espacial
|
||
809 | 5389 | caballero | *
|
810 | 5223 | fjp | * @param r
|
811 | * Rect?ngulo indicando la porci?n del espacio para el cual se
|
||
812 | * quiere saber los ?ndices de las geometr?as que se encuentran
|
||
813 | * dentro de ?l
|
||
814 | 5389 | caballero | *
|
815 | 5223 | fjp | * @return Array de ?ndices para su uso con getGeometry, removeGeometry, ...
|
816 | */
|
||
817 | /*
|
||
818 | * public int[] getRowsIndexes_OL(Rectangle2D r) { Envelope e = new
|
||
819 | * Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(), r.getY() +
|
||
820 | * r.getHeight()); List l = index.query(e); int[] indexes = new
|
||
821 | * int[l.size()];
|
||
822 | 5389 | caballero | *
|
823 | 5223 | fjp | * for (int index = 0; index < l.size(); index++) { Integer i = (Integer)
|
824 | * l.get(index); indexes[index] = getInversedIndex(i.intValue()); }
|
||
825 | 5389 | caballero | *
|
826 | 5223 | fjp | * return indexes; }
|
827 | */
|
||
828 | /**
|
||
829 | 3940 | caballero | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
|
830 | 3836 | caballero | */
|
831 | 3940 | caballero | public int getShapeCount() throws DriverIOException { |
832 | 3996 | caballero | try {
|
833 | return getRowCount();
|
||
834 | 5223 | fjp | } catch (IOException e) { |
835 | 3996 | caballero | throw new DriverIOException(e); |
836 | } |
||
837 | 3836 | caballero | } |
838 | 3722 | caballero | |
839 | 3836 | caballero | /**
|
840 | 3940 | caballero | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
|
841 | 3836 | caballero | */
|
842 | 3940 | caballero | public Rectangle2D getFullExtent() throws DriverIOException { |
843 | 5223 | fjp | if (fullExtent == null) { |
844 | fullExtent = ova.getFullExtent(); |
||
845 | } |
||
846 | 7272 | jaume | |
847 | if (isFullExtentDirty) {
|
||
848 | fullExtent = reCalculateFullExtent(); |
||
849 | isFullExtentDirty = false;
|
||
850 | } |
||
851 | 5223 | fjp | return fullExtent;
|
852 | } |
||
853 | 4554 | caballero | |
854 | 5223 | fjp | /**
|
855 | * Use it BEFORE writing to a file.
|
||
856 | 5389 | caballero | *
|
857 | 5223 | fjp | * @return real full extent.
|
858 | * @throws DriverIOException
|
||
859 | */
|
||
860 | public Rectangle2D reCalculateFullExtent() throws DriverIOException { |
||
861 | if (getShapeCount() > 0) { |
||
862 | fullExtent = getShape(0).getBounds2D();
|
||
863 | for (int i = 1; i < getShapeCount(); i++) { |
||
864 | fullExtent.add(getShape(i).getBounds2D()); |
||
865 | } |
||
866 | } else {
|
||
867 | fullExtent = ova.getFullExtent(); |
||
868 | } |
||
869 | return fullExtent;
|
||
870 | 3836 | caballero | } |
871 | 3958 | caballero | |
872 | 5223 | fjp | /**
|
873 | * En la implementaci?n por defecto podemos hacer que cada feature tenga ID =
|
||
874 | * numero de registro. En el DBAdapter podr?amos "overrride" este m?todo y
|
||
875 | * poner como ID de la Feature el campo ?nico escogido en la base de datos.
|
||
876 | 5389 | caballero | *
|
877 | 5223 | fjp | * @param numReg
|
878 | * @return
|
||
879 | * @throws DriverException
|
||
880 | */
|
||
881 | public IFeature getFeature(int numReg) throws DriverException { |
||
882 | IGeometry geom; |
||
883 | IFeature feat = null;
|
||
884 | try {
|
||
885 | geom = getShape(numReg); |
||
886 | DataSource rs = getRecordset();
|
||
887 | Value[] regAtt = new Value[rs.getFieldCount()]; |
||
888 | for (int fieldId = 0; fieldId < rs.getFieldCount(); fieldId++) { |
||
889 | regAtt[fieldId] = rs.getFieldValue(numReg, fieldId); |
||
890 | } |
||
891 | feat = new DefaultFeature(geom, regAtt, numReg + ""); |
||
892 | } catch (DriverIOException e) {
|
||
893 | 8765 | jjdelcerro | DriverIOExceptionType type = |
894 | new DriverIOExceptionType();
|
||
895 | type.setDriverName(this.getDriver().getName());
|
||
896 | throw new DriverException(e, type); |
||
897 | 10234 | caballero | |
898 | 5223 | fjp | } catch (DriverLoadException e) {
|
899 | 8765 | jjdelcerro | DriverNotLoadedExceptionType type = |
900 | new DriverNotLoadedExceptionType();
|
||
901 | type.setDriverName(getDriver().getName()); |
||
902 | throw new DriverException(e, type); |
||
903 | 10234 | caballero | |
904 | |||
905 | 5223 | fjp | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
906 | 10234 | caballero | |
907 | 5223 | fjp | throw new DriverException(e); |
908 | } |
||
909 | return feat;
|
||
910 | } |
||
911 | |||
912 | public void stopEdition(IWriter writer, int sourceType) |
||
913 | throws EditionException {
|
||
914 | 5535 | fjp | ISpatialWriter spatialWriter = (ISpatialWriter) writer; |
915 | 6714 | caballero | // spatialWriter.setFlatness(FConverter.flatness);
|
916 | 5184 | caballero | super.stopEdition(writer, sourceType);
|
917 | 3952 | fjp | try {
|
918 | 6323 | fjp | ova.getDriver().reload(); |
919 | 3952 | fjp | } catch (IOException e) { |
920 | e.printStackTrace(); |
||
921 | throw new EditionException(e); |
||
922 | 6323 | fjp | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
923 | e.printStackTrace(); |
||
924 | throw new EditionException(e); |
||
925 | 3952 | fjp | } |
926 | } |
||
927 | 5223 | fjp | |
928 | 3980 | caballero | public Rectangle2D getShapeBounds(int index) throws IOException { |
929 | 5223 | fjp | // Solo se utiliza cuando el driver es BoundedShapes
|
930 | // Si no est? en el fichero de expansi?n
|
||
931 | 3980 | caballero | Integer integer = new Integer((int) index); |
932 | if (!relations.containsKey(integer)) {
|
||
933 | 5223 | fjp | if (ova.getDriver() instanceof BoundedShapes) { |
934 | 3980 | caballero | BoundedShapes bs = (BoundedShapes) ova.getDriver(); |
935 | return bs.getShapeBounds(index);
|
||
936 | 5223 | fjp | } else {
|
937 | 3980 | caballero | return ova.getDriver().getShape(index).getBounds2D();
|
938 | } |
||
939 | |||
940 | } else {
|
||
941 | int num = ((Integer) relations.get(integer)).intValue(); |
||
942 | DefaultRowEdited feat; |
||
943 | feat = (DefaultRowEdited) expansionFile.getRow(num); |
||
944 | if (feat.getStatus() == IRowEdited.STATUS_DELETED)
|
||
945 | return null; |
||
946 | 5223 | fjp | IGeometry geom = ((IFeature) feat.getLinkedRow()).getGeometry(); |
947 | return geom.getBounds2D();// getGeometry(); |
||
948 | 3980 | caballero | } |
949 | |||
950 | } |
||
951 | 5223 | fjp | |
952 | 3980 | caballero | public int getShapeType(int index) { |
953 | try {
|
||
954 | return ova.getShapeType();
|
||
955 | } catch (DriverIOException e) {
|
||
956 | // TODO Auto-generated catch block
|
||
957 | e.printStackTrace(); |
||
958 | } |
||
959 | return FShape.MULTI;
|
||
960 | } |
||
961 | 5223 | fjp | |
962 | 4115 | fjp | /**
|
963 | 5223 | fjp | * Usar solo cuando est?s seguro de que puedes gastar memoria. Nosotros lo
|
964 | * usamos para las b?squedas por ?ndice espacial con el handle. La idea es
|
||
965 | * usarlo una vez, guardar las geometr?as que necesitas en ese extent y
|
||
966 | * trabajar con ellas hasta el siguiente cambio de extent.
|
||
967 | 5389 | caballero | *
|
968 | 4115 | fjp | * @param r
|
969 | * @param strEPSG
|
||
970 | * @return
|
||
971 | * @throws DriverException
|
||
972 | */
|
||
973 | 5223 | fjp | public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) |
974 | throws DriverException {
|
||
975 | 4115 | fjp | // En esta clase suponemos random access.
|
976 | // Luego tendremos otra clase que sea VectorialEditableDBAdapter
|
||
977 | // que reescribir? este m?todo.
|
||
978 | 5223 | fjp | Envelope e = FConverter.convertRectangle2DtoEnvelope(r); |
979 | List l = index.query(e);
|
||
980 | IRowEdited[] feats = new IRowEdited[l.size()]; |
||
981 | try {
|
||
982 | for (int index = 0; index < l.size(); index++) { |
||
983 | Integer i = (Integer) l.get(index); |
||
984 | int inverse = getInversedIndex(i.intValue());
|
||
985 | 4181 | fjp | feats[index] = (IRowEdited) getRow(inverse); |
986 | 5223 | fjp | } |
987 | 8765 | jjdelcerro | } catch (IOException ex) { |
988 | DriverIOExceptionType type = |
||
989 | new DriverIOExceptionType();
|
||
990 | type.setDriverName(this.getDriver().getName());
|
||
991 | throw new DriverException(ex, type); |
||
992 | 10234 | caballero | |
993 | 8765 | jjdelcerro | } catch (DriverLoadException ex) {
|
994 | DriverNotLoadedExceptionType type = |
||
995 | new DriverNotLoadedExceptionType();
|
||
996 | type.setDriverName(getDriver().getName()); |
||
997 | throw new DriverException(ex, type); |
||
998 | } catch (DriverIOException ex) {
|
||
999 | DriverIOExceptionType type = |
||
1000 | new DriverIOExceptionType();
|
||
1001 | type.setDriverName(this.getDriver().getName());
|
||
1002 | throw new DriverException(ex, type); |
||
1003 | 10234 | caballero | } |
1004 | 4115 | fjp | return feats;
|
1005 | 4085 | fjp | } |
1006 | 5223 | fjp | |
1007 | 4523 | caballero | public void setSpatialIndex(SpatialIndex spatialIndex) { |
1008 | 5223 | fjp | index = (Quadtree) spatialIndex; |
1009 | 4523 | caballero | } |
1010 | 5223 | fjp | |
1011 | 4523 | caballero | public void setFullExtent(Rectangle2D fullExtent2) { |
1012 | 5223 | fjp | fullExtent = fullExtent2; |
1013 | 4523 | caballero | } |
1014 | 5223 | fjp | |
1015 | 4727 | fjp | /**
|
1016 | * DOCUMENT ME!
|
||
1017 | 5389 | caballero | *
|
1018 | 4727 | fjp | * @return DOCUMENT ME!
|
1019 | */
|
||
1020 | public Image getSelectionImage() { |
||
1021 | 5223 | fjp | return selectionImage;
|
1022 | 4727 | fjp | } |
1023 | 5223 | fjp | |
1024 | 4727 | fjp | public Image getHandlersImage() { |
1025 | return handlersImage;
|
||
1026 | } |
||
1027 | 5223 | fjp | |
1028 | 4792 | fjp | /**
|
1029 | * DOCUMENT ME!
|
||
1030 | 5389 | caballero | *
|
1031 | 5223 | fjp | * @param i
|
1032 | * DOCUMENT ME!
|
||
1033 | 4792 | fjp | */
|
1034 | public void setSelectionImage(Image i) { |
||
1035 | 5223 | fjp | selectionImage = i; |
1036 | 4792 | fjp | } |
1037 | 5223 | fjp | |
1038 | 4792 | fjp | public void setHandlersImage(BufferedImage handlersImage) { |
1039 | 5223 | fjp | this.handlersImage = handlersImage;
|
1040 | 4792 | fjp | } |
1041 | 5389 | caballero | |
1042 | 6714 | caballero | // public double getFlatness() {
|
1043 | // return flatness;
|
||
1044 | // }
|
||
1045 | //
|
||
1046 | // public void setFlatness(double d) {
|
||
1047 | // flatness=d;
|
||
1048 | // }
|
||
1049 | 5389 | caballero | |
1050 | 3612 | fjp | } |