root / tags / v1_1_Build_1003 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / VectorialAdapter.java @ 12271
History | View | Annotate | Download (5.82 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.awt.Image; |
44 |
import java.awt.geom.Rectangle2D; |
45 |
import java.io.IOException; |
46 |
|
47 |
import com.hardcode.driverManager.DriverLoadException; |
48 |
import com.hardcode.gdbms.engine.data.DataSource; |
49 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
50 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
51 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
52 |
import com.hardcode.gdbms.engine.values.Value; |
53 |
import com.iver.cit.gvsig.fmap.DriverException; |
54 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
55 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
56 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
57 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
58 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
59 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
60 |
import com.iver.cit.gvsig.fmap.drivers.RandomAccessFeatureIterator; |
61 |
import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver; |
62 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
63 |
|
64 |
/**
|
65 |
* Clase padre de los adaptadores de los drivers. De momento mantiene solo el
|
66 |
* ?ndice creado sobre la capa
|
67 |
*/
|
68 |
public abstract class VectorialAdapter implements ReadableVectorial { |
69 |
protected VectorialDriver driver;
|
70 |
|
71 |
/**
|
72 |
* Establece el driver sobre el que act?a el adaptador
|
73 |
*
|
74 |
* @param driver
|
75 |
*/
|
76 |
public void setDriver(VectorialDriver driver) { |
77 |
this.driver = driver;
|
78 |
} |
79 |
|
80 |
/**
|
81 |
* Obtiene una referencia al objeto que implementa la interfaz vectorial con
|
82 |
* el fin de que las Strategy puedan optimizar en funci?n del driver.
|
83 |
*
|
84 |
* @return VectorialDriver
|
85 |
*/
|
86 |
public VectorialDriver getDriver() {
|
87 |
return driver;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* Devuelve el DataSource a pasrtir del nombre.
|
92 |
*
|
93 |
* @return DataSource.
|
94 |
*
|
95 |
* @throws DriverLoadException
|
96 |
*/
|
97 |
public abstract SelectableDataSource getRecordset() |
98 |
throws DriverLoadException;
|
99 |
|
100 |
/**
|
101 |
* Por defecto devuelve null, y se le pone el icono por defecto. Si el
|
102 |
* driver reescribe este m?todo, se usar? este icono en el TOC.
|
103 |
*
|
104 |
* @return
|
105 |
*/
|
106 |
public Image getImageIcon() { |
107 |
return null; |
108 |
} |
109 |
|
110 |
public DriverAttributes getDriverAttributes() {
|
111 |
if (driver != null) |
112 |
return driver.getDriverAttributes();
|
113 |
return null; |
114 |
} |
115 |
|
116 |
/**
|
117 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
|
118 |
*/
|
119 |
public int getShapeCount() throws DriverIOException { |
120 |
try {
|
121 |
return getDriver().getShapeCount();
|
122 |
} catch (IOException e) { |
123 |
throw new DriverIOException(e); |
124 |
} |
125 |
} |
126 |
|
127 |
/**
|
128 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
|
129 |
*/
|
130 |
public Rectangle2D getFullExtent() throws DriverIOException { |
131 |
try {
|
132 |
Rectangle2D aux = getDriver().getFullExtent();
|
133 |
// Para evitar que una nueva capa a?adida a una vista vac?a no
|
134 |
// tenga un lienzo para pintar.
|
135 |
if (aux == null) |
136 |
aux = new Rectangle2D.Double(1,1,10,10); |
137 |
return aux;
|
138 |
} catch (IOException e) { |
139 |
throw new DriverIOException(e); |
140 |
} |
141 |
} |
142 |
|
143 |
/**
|
144 |
* En la implementaci?n por defecto podemos hacer que cada feature tenga ID =
|
145 |
* numero de registro. En el DBAdapter podr?amos "overrride" este m?todo y
|
146 |
* poner como ID de la Feature el campo ?nico escogido en la base de datos.
|
147 |
*
|
148 |
* @param numReg
|
149 |
* @return
|
150 |
* @throws DriverException
|
151 |
*/
|
152 |
public IFeature getFeature(int numReg) throws DriverException { |
153 |
IGeometry geom; |
154 |
IFeature feat = null;
|
155 |
try {
|
156 |
geom = getShape(numReg); |
157 |
DataSource rs = getRecordset();
|
158 |
Value[] regAtt = new Value[rs.getFieldCount()]; |
159 |
for (int fieldId = 0; fieldId < rs.getFieldCount(); fieldId++) { |
160 |
regAtt[fieldId] = rs.getFieldValue(numReg, fieldId); |
161 |
} |
162 |
|
163 |
feat = new DefaultFeature(geom, regAtt, numReg + ""); |
164 |
} catch (DriverIOException e) {
|
165 |
throw new DriverException(e); |
166 |
} catch (DriverLoadException e) {
|
167 |
throw new DriverException(e); |
168 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
169 |
throw new DriverException(e); |
170 |
} |
171 |
return feat;
|
172 |
} |
173 |
|
174 |
/*
|
175 |
* (non-Javadoc)
|
176 |
*
|
177 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFeatureIterator(java.awt.geom.Rectangle2D,
|
178 |
* java.lang.String) Lo sobreescribir?n los adapters para base de datos
|
179 |
* espacial. Por defecto, suponemos un buen acceso aleatorio y usamos
|
180 |
* getFeature(i)
|
181 |
*/
|
182 |
/* public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG)
|
183 |
throws DriverException {
|
184 |
try {
|
185 |
return new RandomAccessFeatureIterator(driver, getRecordset(), r,
|
186 |
strEPSG);
|
187 |
} catch (DriverLoadException e) {
|
188 |
throw new DriverException(e);
|
189 |
}
|
190 |
}
|
191 |
|
192 |
public IFeatureIterator getFeatureIterator(String strEPSG)
|
193 |
throws DriverException {
|
194 |
try {
|
195 |
return new RandomAccessFeatureIterator(driver, getRecordset(), strEPSG);
|
196 |
} catch (DriverLoadException e) {
|
197 |
throw new DriverException(e);
|
198 |
}
|
199 |
} */
|
200 |
|
201 |
} |