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