svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / VectorialAdapter.java @ 10665
History | View | Annotate | Download (5.28 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 |
|
46 |
import com.hardcode.driverManager.DriverLoadException; |
47 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
48 |
import com.hardcode.gdbms.engine.data.DataSource; |
49 |
import com.hardcode.gdbms.engine.values.Value; |
50 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
51 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
52 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
53 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
54 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
55 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
56 |
|
57 |
/**
|
58 |
* Clase padre de los adaptadores de los drivers. De momento mantiene solo el
|
59 |
* ?ndice creado sobre la capa
|
60 |
*/
|
61 |
public abstract class VectorialAdapter implements ReadableVectorial { |
62 |
protected VectorialDriver driver;
|
63 |
|
64 |
/**
|
65 |
* Establece el driver sobre el que act?a el adaptador
|
66 |
*
|
67 |
* @param driver
|
68 |
*/
|
69 |
public void setDriver(VectorialDriver driver) { |
70 |
this.driver = driver;
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Obtiene una referencia al objeto que implementa la interfaz vectorial con
|
75 |
* el fin de que las Strategy puedan optimizar en funci?n del driver.
|
76 |
*
|
77 |
* @return VectorialDriver
|
78 |
*/
|
79 |
public VectorialDriver getDriver() {
|
80 |
return driver;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Devuelve el DataSource a pasrtir del nombre.
|
85 |
*
|
86 |
* @return DataSource.
|
87 |
*
|
88 |
* @throws ReadDriverException
|
89 |
*/
|
90 |
public abstract SelectableDataSource getRecordset() |
91 |
throws ReadDriverException;
|
92 |
|
93 |
/**
|
94 |
* Por defecto devuelve null, y se le pone el icono por defecto. Si el
|
95 |
* driver reescribe este m?todo, se usar? este icono en el TOC.
|
96 |
*
|
97 |
* @return
|
98 |
*/
|
99 |
public Image getImageIcon() { |
100 |
return null; |
101 |
} |
102 |
|
103 |
public DriverAttributes getDriverAttributes() {
|
104 |
if (driver != null) |
105 |
return driver.getDriverAttributes();
|
106 |
return null; |
107 |
} |
108 |
|
109 |
/**
|
110 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
|
111 |
*/
|
112 |
public int getShapeCount() throws ReadDriverException { |
113 |
return getDriver().getShapeCount();
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
|
118 |
*/
|
119 |
public Rectangle2D getFullExtent() throws ReadDriverException { |
120 |
try {
|
121 |
Rectangle2D aux = getDriver().getFullExtent();
|
122 |
// Para evitar que una nueva capa a?adida a una vista vac?a no
|
123 |
// tenga un lienzo para pintar.
|
124 |
if (aux == null) |
125 |
aux = new Rectangle2D.Double(1,1,10,10); |
126 |
return aux;
|
127 |
} catch (ExpansionFileReadException e) {
|
128 |
throw new ReadDriverException(getDriver().getName(),e); |
129 |
} |
130 |
} |
131 |
|
132 |
/**
|
133 |
* En la implementaci?n por defecto podemos hacer que cada feature tenga ID =
|
134 |
* numero de registro. En el DBAdapter podr?amos "overrride" este m?todo y
|
135 |
* poner como ID de la Feature el campo ?nico escogido en la base de datos.
|
136 |
*
|
137 |
* @param numReg
|
138 |
* @return
|
139 |
*/
|
140 |
public IFeature getFeature(int numReg) throws ReadDriverException { |
141 |
IGeometry geom; |
142 |
IFeature feat = null;
|
143 |
try {
|
144 |
geom = getShape(numReg); |
145 |
DataSource rs = getRecordset();
|
146 |
Value[] regAtt = new Value[rs.getFieldCount()]; |
147 |
for (int fieldId = 0; fieldId < rs.getFieldCount(); fieldId++) { |
148 |
regAtt[fieldId] = rs.getFieldValue(numReg, fieldId); |
149 |
} |
150 |
|
151 |
feat = new DefaultFeature(geom, regAtt, numReg + ""); |
152 |
} catch (ExpansionFileReadException e) {
|
153 |
throw new ReadDriverException(getDriver().getName(),e); |
154 |
} |
155 |
return feat;
|
156 |
} |
157 |
|
158 |
/*
|
159 |
* (non-Javadoc)
|
160 |
*
|
161 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFeatureIterator(java.awt.geom.Rectangle2D,
|
162 |
* java.lang.String) Lo sobreescribir?n los adapters para base de datos
|
163 |
* espacial. Por defecto, suponemos un buen acceso aleatorio y usamos
|
164 |
* getFeature(i)
|
165 |
*/
|
166 |
/* public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG)
|
167 |
throws DriverException {
|
168 |
try {
|
169 |
return new RandomAccessFeatureIterator(driver, getRecordset(), r,
|
170 |
strEPSG);
|
171 |
} catch (DriverLoadException e) {
|
172 |
throw new DriverException(e);
|
173 |
}
|
174 |
}
|
175 |
|
176 |
public IFeatureIterator getFeatureIterator(String strEPSG)
|
177 |
throws DriverException {
|
178 |
try {
|
179 |
return new RandomAccessFeatureIterator(driver, getRecordset(), strEPSG);
|
180 |
} catch (DriverLoadException e) {
|
181 |
throw new DriverException(e);
|
182 |
}
|
183 |
} */
|
184 |
|
185 |
} |