root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / VectorialEditableAdapter.java @ 3996
History | View | Annotate | Download (21.5 KB)
1 |
/*
|
---|---|
2 |
* Created on 12-ene-2006 by fjp
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: VectorialEditableAdapter.java 3996 2006-02-08 15:21:08Z caballero $
|
47 |
* $Log$
|
48 |
* Revision 1.18 2006-02-08 15:18:45 caballero
|
49 |
* control de las rows eliminadas
|
50 |
*
|
51 |
* Revision 1.17 2006/02/07 10:18:44 caballero
|
52 |
* Con BoundedShape
|
53 |
*
|
54 |
* Revision 1.16 2006/02/06 12:01:41 caballero
|
55 |
* driver del ova
|
56 |
*
|
57 |
* Revision 1.15 2006/02/03 14:09:32 fjp
|
58 |
* Preparando edici?n
|
59 |
*
|
60 |
* Revision 1.14 2006/02/03 12:16:33 fjp
|
61 |
* Preparando edici?n
|
62 |
*
|
63 |
* Revision 1.13 2006/02/03 11:54:12 caballero
|
64 |
* tablas con vectorialEditableAdapter en edici?n
|
65 |
*
|
66 |
* Revision 1.11 2006/01/31 08:10:05 caballero
|
67 |
* cambio de feature a row
|
68 |
*
|
69 |
* Revision 1.10 2006/01/30 08:18:14 caballero
|
70 |
* m?todos para deshacer y rehacer
|
71 |
*
|
72 |
* Revision 1.9 2006/01/23 17:30:28 caballero
|
73 |
* coger los datos del ova
|
74 |
*
|
75 |
* Revision 1.8 2006/01/23 16:16:16 caballero
|
76 |
* getRowIndex
|
77 |
*
|
78 |
* Revision 1.7 2006/01/20 08:37:10 fjp
|
79 |
* Preparando la edici?n
|
80 |
*
|
81 |
* Revision 1.6 2006/01/19 12:48:20 caballero
|
82 |
* poder modificar su vectorial Adapter
|
83 |
*
|
84 |
* Revision 1.5 2006/01/19 09:28:11 fjp
|
85 |
* Preparando la edici?n
|
86 |
*
|
87 |
* Revision 1.4 2006/01/17 10:24:02 fjp
|
88 |
* Preparando edici?n
|
89 |
*
|
90 |
* Revision 1.3 2006/01/16 12:47:38 fjp
|
91 |
* Preparando edici?n
|
92 |
*
|
93 |
* Revision 1.2 2006/01/16 11:23:00 fjp
|
94 |
* Preparando edici?n
|
95 |
*
|
96 |
* Revision 1.1 2006/01/12 13:39:14 fjp
|
97 |
* preaparar edicion
|
98 |
*
|
99 |
*
|
100 |
*/
|
101 |
package com.iver.cit.gvsig.fmap.edition; |
102 |
|
103 |
import java.awt.geom.Rectangle2D; |
104 |
import java.io.IOException; |
105 |
import java.util.List; |
106 |
|
107 |
import com.hardcode.driverManager.DriverLoadException; |
108 |
import com.hardcode.gdbms.engine.data.DataSource; |
109 |
import com.hardcode.gdbms.engine.values.Value; |
110 |
import com.iver.cit.gvsig.fmap.DriverException; |
111 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
112 |
import com.iver.cit.gvsig.fmap.core.FShape; |
113 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
114 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
115 |
import com.iver.cit.gvsig.fmap.core.IRow; |
116 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
117 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
118 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
119 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
120 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
121 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
122 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
123 |
import com.vividsolutions.jts.geom.Envelope; |
124 |
import com.vividsolutions.jts.index.quadtree.Quadtree; |
125 |
|
126 |
/**
|
127 |
* @author fjp
|
128 |
*
|
129 |
*/
|
130 |
public class VectorialEditableAdapter extends EditableAdapter implements ReadableVectorial, BoundedShapes { |
131 |
private VectorialAdapter ova;
|
132 |
//private VectorialDriver driver;
|
133 |
private Quadtree index;
|
134 |
public VectorialEditableAdapter(){
|
135 |
super();
|
136 |
} |
137 |
public void setOriginalVectorialAdapter(ReadableVectorial rv){ |
138 |
ova=(VectorialAdapter)rv; |
139 |
try {
|
140 |
setOriginalDataSource(rv.getRecordset()); |
141 |
} catch (DriverLoadException e) {
|
142 |
// TODO Auto-generated catch block
|
143 |
e.printStackTrace(); |
144 |
} |
145 |
} |
146 |
/*
|
147 |
* (non-Javadoc)
|
148 |
*
|
149 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#start()
|
150 |
*/
|
151 |
public void start() throws DriverIOException { |
152 |
ova.start(); |
153 |
} |
154 |
|
155 |
/*
|
156 |
* (non-Javadoc)
|
157 |
*
|
158 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#stop()
|
159 |
*/
|
160 |
public void stop() throws DriverIOException { |
161 |
ova.stop(); |
162 |
} |
163 |
|
164 |
/*
|
165 |
* (non-Javadoc)
|
166 |
*
|
167 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int)
|
168 |
*/
|
169 |
public IGeometry getShape(int rowIndex) throws DriverIOException { |
170 |
// Si no est? en el fichero de expansi?n
|
171 |
int calculatedIndex=getCalculatedIndex(rowIndex);
|
172 |
Integer integer = new Integer(calculatedIndex); |
173 |
if (!relations.containsKey(integer)) {
|
174 |
// Si ha sido eliminada
|
175 |
/*if (delRows.get(integer.intValue())) {
|
176 |
return null;
|
177 |
} else {*/
|
178 |
return ova.getShape(calculatedIndex);
|
179 |
//}
|
180 |
} else {
|
181 |
int num = ((Integer) relations.get(integer)).intValue(); |
182 |
DefaultRowEdited feat; |
183 |
try {
|
184 |
feat = (DefaultRowEdited) expansionFile.getRow(num); |
185 |
if (feat.getStatus() == IRowEdited.STATUS_DELETED)
|
186 |
return null; |
187 |
return ((IFeature)feat.getLinkedRow()).getGeometry().cloneGeometry();//getGeometry(); |
188 |
} catch (IOException e) { |
189 |
e.printStackTrace(); |
190 |
throw new DriverIOException(e); |
191 |
} |
192 |
} |
193 |
|
194 |
} |
195 |
|
196 |
/*
|
197 |
* (non-Javadoc)
|
198 |
*
|
199 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
|
200 |
*/
|
201 |
public int getShapeType() throws DriverIOException { |
202 |
return ova.getShapeType();
|
203 |
} |
204 |
public VectorialAdapter getOriginalAdapter(){
|
205 |
return ova;
|
206 |
} |
207 |
public VectorialDriver getDriver() {
|
208 |
return ova.getDriver();
|
209 |
} |
210 |
public void setDriver(VectorialDriver driver) { |
211 |
this.ova.setDriver(driver);
|
212 |
} |
213 |
public DriverAttributes getDriverAttributes(){
|
214 |
return ova.getDriverAttributes();
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* DOCUMENT ME!
|
219 |
*
|
220 |
* @throws EditionException DOCUMENT ME!
|
221 |
*/
|
222 |
public void startEdition() throws EditionException { |
223 |
super.startEdition();
|
224 |
|
225 |
try {
|
226 |
expansionFile.open(); |
227 |
|
228 |
// TODO: Si la capa dispone de un ?ndice espacial, hacer
|
229 |
// algo aqu? para que se use ese ?ndice espacial.
|
230 |
index = new Quadtree();
|
231 |
|
232 |
for (int i = 0; i < ova.getShapeCount(); i++) { |
233 |
IGeometry g=null;
|
234 |
try {
|
235 |
g = ((DefaultFeature) ova.getFeature(i)).getGeometry(); |
236 |
} catch (DriverException e1) {
|
237 |
// TODO Auto-generated catch block
|
238 |
e1.printStackTrace(); |
239 |
} |
240 |
|
241 |
if (g == null) { |
242 |
continue;
|
243 |
} |
244 |
|
245 |
Rectangle2D r = g.getBounds2D();
|
246 |
Envelope e = new Envelope(r.getX(), r.getX() + r.getWidth(),
|
247 |
r.getY(), r.getY() + r.getHeight()); |
248 |
index.insert(e, new Integer(i)); |
249 |
} |
250 |
} catch (DriverIOException e) {
|
251 |
throw new EditionException(e); |
252 |
} catch (IOException e) { |
253 |
throw new EditionException(e); |
254 |
} |
255 |
|
256 |
System.err.println("Se han metido en el ?ndice " + |
257 |
index.queryAll().size() + " geometr?as");
|
258 |
} |
259 |
|
260 |
/* (non-Javadoc)
|
261 |
* @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
|
262 |
*/
|
263 |
public IRowEdited getRow(int index) throws DriverIOException, IOException { |
264 |
Integer integer = new Integer(index); |
265 |
//Si no est? en el fichero de expansi?n
|
266 |
if (!relations.containsKey(integer)) {
|
267 |
//Si ha sido eliminada
|
268 |
if (delRows.get(index)) {
|
269 |
return null; |
270 |
} else {
|
271 |
DefaultRowEdited edRow=null;
|
272 |
try {
|
273 |
edRow = new DefaultRowEdited(ova.getFeature(index),
|
274 |
DefaultRowEdited.STATUS_ORIGINAL); |
275 |
} catch (DriverException e) {
|
276 |
// TODO Auto-generated catch block
|
277 |
e.printStackTrace(); |
278 |
} |
279 |
|
280 |
return edRow;
|
281 |
} |
282 |
} else {
|
283 |
int num = ((Integer) relations.get(integer)).intValue(); |
284 |
|
285 |
return expansionFile.getRow(num);
|
286 |
} |
287 |
} |
288 |
/**
|
289 |
* Elimina una geometria. Si es una geometr?a original de la capa en
|
290 |
* edici?n se marca como eliminada (haya sido modificada o no). Si es una
|
291 |
* geometr?a a?adida posteriormente se invalida en el fichero de
|
292 |
* expansi?n, para que una futura compactaci?n termine con ella.
|
293 |
*
|
294 |
* @param index ?ndice de la geometr?a.
|
295 |
*
|
296 |
* @throws DriverIOException
|
297 |
* @throws IOException
|
298 |
*/
|
299 |
public void doRemoveRow(int index) throws DriverIOException, IOException { |
300 |
//Llega el calculatedIndex
|
301 |
Integer integer = new Integer(index); |
302 |
|
303 |
IFeature feat = null;
|
304 |
delRows.set(index, true);
|
305 |
//Si la geometr?a no ha sido modificada
|
306 |
if (!relations.containsKey(integer)) {
|
307 |
|
308 |
try {
|
309 |
feat = (DefaultFeature) (ova.getFeature(index)); |
310 |
} catch (DriverException e) {
|
311 |
// TODO Auto-generated catch block
|
312 |
e.printStackTrace(); |
313 |
} |
314 |
} else {
|
315 |
int num = ((Integer) relations.get(integer)).intValue(); |
316 |
feat = (IFeature) expansionFile.getRow(num).getLinkedRow(); |
317 |
//expansionFile.invalidateRow(num);
|
318 |
} |
319 |
System.err.println("Elimina una Row en la posici?n: " + index); |
320 |
//Se actualiza el ?ndice
|
321 |
if (feat != null) { |
322 |
Rectangle2D r = feat.getGeometry().getBounds2D();
|
323 |
boolean borrado=this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
324 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
325 |
System.out.println("Est? borrado : "+ borrado); |
326 |
System.out.println("Index.lenght : "+ this.index.size()); |
327 |
|
328 |
} |
329 |
} |
330 |
/**
|
331 |
* Si se intenta modificar una geometr?a original de la capa en edici?n se
|
332 |
* a?ade al fichero de expansi?n y se registra la posici?n en la que se
|
333 |
* a?adi?. Si se intenta modificar una geometria que se encuentra en el
|
334 |
* fichero de expansi?n (por ser nueva o original pero modificada) se
|
335 |
* invoca el m?todo modifyGeometry y se actualiza el ?ndice de la
|
336 |
* geometria en el fichero.
|
337 |
*
|
338 |
* @param index DOCUMENT ME!
|
339 |
* @param feat DOCUMENT ME!
|
340 |
*
|
341 |
* @return DOCUMENT ME!
|
342 |
*
|
343 |
* @throws IOException
|
344 |
* @throws DriverIOException
|
345 |
*/
|
346 |
public int doModifyRow(int index, IRow feat) |
347 |
throws IOException, DriverIOException { |
348 |
int pos = -1; |
349 |
Integer integer = new Integer(index); |
350 |
|
351 |
IFeature featAnt = null;
|
352 |
System.err.println("Modifica una Row en la posici?n: " + index); |
353 |
//Si la geometr?a no ha sido modificada
|
354 |
if (!relations.containsKey(integer)) {
|
355 |
int expansionIndex = expansionFile.addRow(feat);
|
356 |
relations.put(integer, new Integer(expansionIndex)); |
357 |
|
358 |
//Se actualiza el ?ndice espacial
|
359 |
try {
|
360 |
featAnt = (DefaultFeature) (ova.getFeature(index)); |
361 |
} catch (DriverException e) {
|
362 |
// TODO Auto-generated catch block
|
363 |
e.printStackTrace(); |
364 |
} |
365 |
|
366 |
Rectangle2D rAnt = featAnt.getGeometry().getBounds2D();
|
367 |
Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
|
368 |
this.index.remove(new Envelope(rAnt.getX(), |
369 |
rAnt.getX() + rAnt.getWidth(), rAnt.getY(), |
370 |
rAnt.getY() + rAnt.getHeight()), new Integer(index)); |
371 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
372 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
373 |
} else {
|
374 |
//Obtenemos el ?ndice en el fichero de expansi?n
|
375 |
int num = ((Integer) relations.get(integer)).intValue(); |
376 |
pos = num; |
377 |
|
378 |
//Obtenemos la geometr?a para actualiza el ?ndice espacialposteriormente
|
379 |
featAnt = (IFeature) expansionFile.getRow(num).getLinkedRow(); |
380 |
|
381 |
/*
|
382 |
* Se modifica la geometr?a y nos guardamos el ?ndice dentro del fichero
|
383 |
* de expansi?n en el que se encuentra la geometr?a modificada
|
384 |
*/
|
385 |
num = expansionFile.modifyRow(num, feat); |
386 |
|
387 |
/*
|
388 |
* Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el fichero
|
389 |
* de expansi?n.
|
390 |
*/
|
391 |
relations.put(integer, new Integer(num)); |
392 |
|
393 |
//Se modifica el ?ndice espacial
|
394 |
Rectangle2D rAnt = featAnt.getGeometry().getBounds2D();
|
395 |
Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
|
396 |
this.index.remove(new Envelope(rAnt.getX(), |
397 |
rAnt.getX() + rAnt.getWidth(), rAnt.getY(), |
398 |
rAnt.getY() + rAnt.getHeight()), new Integer(index)); |
399 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
400 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
401 |
} |
402 |
|
403 |
return pos;
|
404 |
} |
405 |
/**
|
406 |
* Actualiza en el mapa de ?ndices, la posici?n en la que estaba la
|
407 |
* geometr?a antes de ser modificada. Se marca como v?lida, en caso de que
|
408 |
* fuera una modificaci?n de una geometr?a que estuviese en el fichero de
|
409 |
* expansi?n antes de ser modificada y se pone el puntero de escritura del
|
410 |
* expansion file a justo despues de la penultima geometr?a
|
411 |
*
|
412 |
* @param geometryIndex ?ndice de la geometr?a que se quiere deshacer su
|
413 |
* modificaci?n
|
414 |
* @param previousExpansionFileIndex ?ndice que ten?a antes la geometr?a en
|
415 |
* el expansionFile. Si vale -1 quiere decir que es una
|
416 |
* modificaci?n de una geometr?a original y por tanto no hay que
|
417 |
* actualizar el mapa de indices sino eliminar su entrada.
|
418 |
*
|
419 |
* @throws IOException
|
420 |
* @throws DriverIOException
|
421 |
*/
|
422 |
public void undoModifyRow(int geometryIndex, int previousExpansionFileIndex) |
423 |
throws IOException, DriverIOException { |
424 |
//Llega el CalculatedIndex
|
425 |
/*
|
426 |
* Si la acci?n de modificar se realiz? sobre una geometr?a original
|
427 |
*/
|
428 |
if (previousExpansionFileIndex == -1) { |
429 |
//Se obtiene la geometr?a para actualizar el ?ndice
|
430 |
IGeometry g = ((DefaultFeature) getRow(geometryIndex).getLinkedRow()).getGeometry(); |
431 |
Rectangle2D r = g.getBounds2D();
|
432 |
|
433 |
//Se elimina de las relaciones y del fichero de expansi?n
|
434 |
relations.remove(new Integer(geometryIndex)); |
435 |
expansionFile.deleteLastRow(); |
436 |
|
437 |
//Se actualizan los ?ndices
|
438 |
IGeometry gAnt = ((DefaultFeature) getRow(geometryIndex) |
439 |
.getLinkedRow()).getGeometry(); |
440 |
Rectangle2D rAnt = gAnt.getBounds2D();
|
441 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
442 |
r.getY(), r.getY() + r.getHeight()), |
443 |
new Integer(geometryIndex)); |
444 |
this.index.insert(new Envelope(rAnt.getX(), |
445 |
rAnt.getX() + rAnt.getWidth(), rAnt.getY(), |
446 |
rAnt.getY() + rAnt.getHeight()), new Integer(geometryIndex)); |
447 |
} else {
|
448 |
//Se obtiene la geometr?a para actualizar el ?ndice
|
449 |
IGeometry g = null;
|
450 |
g = ((DefaultFeature) getRow(geometryIndex).getLinkedRow()).getGeometry(); |
451 |
|
452 |
Rectangle2D r = g.getBounds2D();
|
453 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
454 |
r.getY(), r.getY() + r.getHeight()), |
455 |
new Integer(geometryIndex)); |
456 |
|
457 |
//Se actualiza la relaci?n de ?ndices
|
458 |
//Integer integer = new Integer(geometryIndex);
|
459 |
relations.put(new Integer(geometryIndex), |
460 |
new Integer(previousExpansionFileIndex)); |
461 |
|
462 |
//Se recupera la geometr?a
|
463 |
//expansionFile.validateRow(previousExpansionFileIndex);
|
464 |
|
465 |
//Se actualizan los ?ndices
|
466 |
g = ((DefaultFeature) getRow(geometryIndex).getLinkedRow()).getGeometry(); |
467 |
r = g.getBounds2D(); |
468 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
469 |
r.getY(), r.getY() + r.getHeight()), |
470 |
new Integer(geometryIndex)); |
471 |
} |
472 |
} |
473 |
|
474 |
/**
|
475 |
* A?ade una geometria al fichero de expansi?n y guarda la correspondencia
|
476 |
* en la tabla relations.
|
477 |
*
|
478 |
* @param feat geometr?a a guardar.
|
479 |
*
|
480 |
* @return DOCUMENT ME!
|
481 |
*
|
482 |
* @throws DriverIOException
|
483 |
* @throws IOException
|
484 |
*/
|
485 |
public int doAddRow(IRow feat) throws DriverIOException, IOException { |
486 |
int virtualIndex=super.doAddRow(feat); |
487 |
// Actualiza el ?ndice espacial
|
488 |
IGeometry g = ((IFeature) feat).getGeometry(); |
489 |
Rectangle2D r = g.getBounds2D();
|
490 |
index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
|
491 |
r.getY() + r.getHeight()), new Integer(virtualIndex)); |
492 |
|
493 |
return virtualIndex;
|
494 |
} |
495 |
/**
|
496 |
* Se desmarca como invalidada en el fichero de expansion o como eliminada
|
497 |
* en el fichero original
|
498 |
*
|
499 |
* @param index DOCUMENT ME!
|
500 |
*
|
501 |
* @throws IOException
|
502 |
* @throws DriverIOException
|
503 |
*/
|
504 |
public void undoRemoveRow(int index) throws IOException, DriverIOException { |
505 |
super.undoRemoveRow(index);
|
506 |
|
507 |
IGeometry g = null;
|
508 |
g = ((IFeature) getRow(index).getLinkedRow()).getGeometry(); |
509 |
|
510 |
Rectangle2D r = g.getBounds2D();
|
511 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
512 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
513 |
} |
514 |
/**
|
515 |
* Se elimina del final del fichero de expansi?n poniendo el puntero de
|
516 |
* escritura apuntando al final de la pen?ltima geometr?a. Deber? quitar
|
517 |
* la relaci?n del mapa de relaciones
|
518 |
*
|
519 |
* @param index ?ndice de la geometr?a que se a?adi?
|
520 |
*
|
521 |
* @throws DriverIOException
|
522 |
* @throws IOException
|
523 |
*/
|
524 |
public void undoAddRow(int index) throws DriverIOException, IOException { |
525 |
IGeometry g = ((IFeature) getRow(index).getLinkedRow()).getGeometry(); |
526 |
Rectangle2D r = g.getBounds2D();
|
527 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
528 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
529 |
|
530 |
super.undoAddRow(index);
|
531 |
} |
532 |
/**
|
533 |
* Obtiene las geometr?as que se encuentran en el rect?ngulo que se pasa
|
534 |
* como par?metro haciendo uso del ?ndice espacial
|
535 |
*
|
536 |
* @param r Rect?ngulo indicando la porci?n del espacio para el cual se
|
537 |
* quiere saber los ?ndices de las geometr?as que se encuentran
|
538 |
* dentro de ?l
|
539 |
*
|
540 |
* @return Array de ?ndices para su uso con getGeometry, removeGeometry,
|
541 |
* ...
|
542 |
*/
|
543 |
public int[] getRowsIndexes(Rectangle2D r) { |
544 |
Envelope e = new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
|
545 |
r.getY() + r.getHeight()); |
546 |
List l = index.query(e);
|
547 |
int[] indexes = new int[l.size()]; |
548 |
|
549 |
for (int index = 0; index < l.size(); index++) { |
550 |
Integer i = (Integer) l.get(index); |
551 |
indexes[index] = getInversedIndex(i.intValue()); |
552 |
} |
553 |
|
554 |
return indexes;
|
555 |
} |
556 |
/**
|
557 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
|
558 |
*/
|
559 |
public int getShapeCount() throws DriverIOException { |
560 |
try {
|
561 |
return getRowCount();
|
562 |
} catch (IOException e) { |
563 |
throw new DriverIOException(e); |
564 |
} |
565 |
} |
566 |
|
567 |
/**
|
568 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
|
569 |
*/
|
570 |
public Rectangle2D getFullExtent() throws DriverIOException { |
571 |
// TODO: Recalcularlo cada vez que se a?ade un addRow
|
572 |
return ova.getFullExtent();
|
573 |
} |
574 |
/**
|
575 |
* En la implementaci?n por defecto podemos hacer que cada
|
576 |
* feature tenga ID = numero de registro.
|
577 |
* En el DBAdapter podr?amos "overrride" este m?todo y poner
|
578 |
* como ID de la Feature el campo ?nico escogido en
|
579 |
* la base de datos.
|
580 |
* @param numReg
|
581 |
* @return
|
582 |
* @throws DriverException
|
583 |
*/
|
584 |
public IFeature getFeature(int numReg) throws DriverException |
585 |
{ |
586 |
IGeometry geom; |
587 |
IFeature feat = null;
|
588 |
try {
|
589 |
geom = getShape(numReg); |
590 |
DataSource rs = getRecordset();
|
591 |
Value[] regAtt = new Value[rs.getFieldCount()]; |
592 |
for (int fieldId=0; fieldId < rs.getFieldCount(); fieldId++ ) |
593 |
{ |
594 |
regAtt[fieldId] = rs.getFieldValue(numReg, fieldId); |
595 |
} |
596 |
|
597 |
feat = new DefaultFeature(geom, regAtt, numReg + ""); |
598 |
} catch (DriverIOException e) {
|
599 |
throw new DriverException(e); |
600 |
} catch (DriverLoadException e) {
|
601 |
throw new DriverException(e); |
602 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
603 |
throw new DriverException(e); |
604 |
} |
605 |
return feat;
|
606 |
} |
607 |
public void stopEdition(IWriter writer) throws EditionException { |
608 |
super.stopEdition(writer);
|
609 |
try {
|
610 |
ova.getDriver().reLoad(); |
611 |
} catch (IOException e) { |
612 |
e.printStackTrace(); |
613 |
throw new EditionException(e); |
614 |
} |
615 |
} |
616 |
public Rectangle2D getShapeBounds(int index) throws IOException { |
617 |
//Solo se utiliza cuando el driver es BoundedShapes
|
618 |
// Si no est? en el fichero de expansi?n
|
619 |
Integer integer = new Integer((int) index); |
620 |
if (!relations.containsKey(integer)) {
|
621 |
if (ova.getDriver() instanceof BoundedShapes){ |
622 |
BoundedShapes bs = (BoundedShapes) ova.getDriver(); |
623 |
return bs.getShapeBounds(index);
|
624 |
}else{
|
625 |
return ova.getDriver().getShape(index).getBounds2D();
|
626 |
} |
627 |
|
628 |
} else {
|
629 |
int num = ((Integer) relations.get(integer)).intValue(); |
630 |
DefaultRowEdited feat; |
631 |
feat = (DefaultRowEdited) expansionFile.getRow(num); |
632 |
if (feat.getStatus() == IRowEdited.STATUS_DELETED)
|
633 |
return null; |
634 |
IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry(); |
635 |
return geom.getBounds2D();//getGeometry(); |
636 |
} |
637 |
|
638 |
} |
639 |
public int getShapeType(int index) { |
640 |
try {
|
641 |
return ova.getShapeType();
|
642 |
} catch (DriverIOException e) {
|
643 |
// TODO Auto-generated catch block
|
644 |
e.printStackTrace(); |
645 |
} |
646 |
return FShape.MULTI;
|
647 |
} |
648 |
|
649 |
} |