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