root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / LayerFactory.java @ 2859
History | View | Annotate | Download (18.3 KB)
1 | 1100 | fjp | /* 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 | 214 | fernando | package com.iver.cit.gvsig.fmap.layers; |
42 | |||
43 | 2277 | vcaballero | import java.awt.geom.Rectangle2D; |
44 | import java.io.File; |
||
45 | import java.io.IOException; |
||
46 | import java.net.URL; |
||
47 | import java.sql.SQLException; |
||
48 | import java.sql.Types; |
||
49 | import java.util.TreeMap; |
||
50 | |||
51 | import org.apache.log4j.Logger; |
||
52 | import org.cresques.cts.IProjection; |
||
53 | |||
54 | 408 | fernando | import com.hardcode.driverManager.Driver; |
55 | import com.hardcode.driverManager.DriverLoadException; |
||
56 | import com.hardcode.driverManager.DriverManager; |
||
57 | 1828 | fernando | import com.hardcode.gdbms.engine.customQuery.QueryManager; |
58 | 2183 | fernando | import com.hardcode.gdbms.engine.data.DataSource; |
59 | 408 | fernando | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
60 | 2183 | fernando | import com.hardcode.gdbms.engine.data.NoSuchTableException; |
61 | import com.hardcode.gdbms.engine.data.edition.DataWare; |
||
62 | 470 | fjp | import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
63 | 2183 | fernando | import com.hardcode.gdbms.engine.values.Value; |
64 | import com.hardcode.gdbms.engine.values.ValueFactory; |
||
65 | 651 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
66 | 2183 | fernando | import com.iver.cit.gvsig.fmap.ProgressListener; |
67 | 2850 | nacho | import com.iver.cit.gvsig.fmap.ViewPort; |
68 | 422 | fjp | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
69 | 303 | fernando | import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
70 | import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
||
71 | 408 | fernando | import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
72 | 438 | fernando | import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
73 | 2183 | fernando | import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver; |
74 | 714 | fjp | import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
75 | 1828 | fernando | import com.iver.cit.gvsig.fmap.operations.arcview.ArcJoin; |
76 | 458 | fjp | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
77 | 714 | fjp | import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
78 | 2183 | fernando | import com.iver.utiles.StringUtilities; |
79 | 303 | fernando | |
80 | |||
81 | 214 | fernando | /**
|
82 | * Crea un adaptador del driver que se le pasa como par?metro en los m?todos
|
||
83 | * createLayer. Si hay memoria suficiente se crea un FLyrMemory que pasa todas
|
||
84 | * las features del driver a memoria
|
||
85 | */
|
||
86 | public class LayerFactory { |
||
87 | 732 | fernando | private static Logger logger = Logger.getLogger(LayerFactory.class.getName()); |
88 | 439 | luisw | private static String driversPath = "../FMap 03/drivers"; |
89 | 732 | fernando | private static DriverManager driverManager; |
90 | 408 | fernando | |
91 | 1828 | fernando | private static DataSourceFactory dataSourceFactory; |
92 | 1773 | fernando | |
93 | 732 | fernando | /**
|
94 | * Map en el que se guarda para cada fuente de datos a?adida al sistema, el
|
||
95 | * adaptador que la maneja. Ha de ser un TreeMap ya que esta clase define
|
||
96 | * la igualdad entre las claves a traves del m?todo equals de las mismas.
|
||
97 | * Los objetos FileSource, DBSource y WFSSource tienen definido el m?todo
|
||
98 | * equals de forma que devuelven true cuando dos objetos apuntan a la
|
||
99 | * misma fuente de datos
|
||
100 | */
|
||
101 | private static TreeMap sourceAdapter; |
||
102 | 214 | fernando | |
103 | 1828 | fernando | /*
|
104 | 732 | fernando | * Crea un RandomVectorialFile con el driver que se le pasa como par?metro
|
105 | * y guard?ndose el nombre del fichero para realizar los accesos, la capa
|
||
106 | * tendr? asociada la proyecci?n que se pasa como parametro tambi?n
|
||
107 | *
|
||
108 | 1034 | vcaballero | * @param layerName Nombre de la capa.
|
109 | * @param driverName Nombre del driver.
|
||
110 | * @param f fichero.
|
||
111 | * @param proj Proyecci?n.
|
||
112 | 732 | fernando | *
|
113 | 1034 | vcaballero | * @return FLayer.
|
114 | 1060 | fjp | * @throws DriverException
|
115 | 732 | fernando | *
|
116 | * @throws DriverException
|
||
117 | 1034 | vcaballero | * @throws DriverIOException
|
118 | 2183 | fernando | */
|
119 | 732 | fernando | public static FLayer createLayer(String layerName, String driverName, |
120 | 1060 | fjp | File f, IProjection proj) throws DriverException { |
121 | 732 | fernando | //Se obtiene el driver que lee
|
122 | DriverManager dm = getDM();
|
||
123 | 438 | fernando | |
124 | 732 | fernando | try {
|
125 | Driver d = dm.getDriver(driverName);
|
||
126 | 438 | fernando | |
127 | 732 | fernando | if (d instanceof VectorialFileDriver) { |
128 | return createLayer(layerName, (VectorialFileDriver) d, f, proj);
|
||
129 | } else if (d instanceof RasterDriver) { |
||
130 | return createLayer(layerName, (RasterDriver) d, f, proj);
|
||
131 | } |
||
132 | } catch (DriverLoadException e) {
|
||
133 | 1060 | fjp | throw new DriverException(e); |
134 | 732 | fernando | } |
135 | 438 | fernando | |
136 | 732 | fernando | return null; |
137 | } |
||
138 | 2183 | fernando | |
139 | 1034 | vcaballero | /**
|
140 | * Crea un RandomVectorialFile con el driver que se le pasa como par?metro
|
||
141 | * y guard?ndose el nombre del fichero para realizar los accesos, la capa
|
||
142 | * tendr? asociada la proyecci?n que se pasa como parametro tambi?n
|
||
143 | *
|
||
144 | * @param layerName Nombre del Layer.
|
||
145 | * @param d VectorialAdapter.
|
||
146 | * @param f Fichero.
|
||
147 | * @param proj Proyecci?n.
|
||
148 | *
|
||
149 | * @return FLayer creado.
|
||
150 | *
|
||
151 | * @throws DriverException
|
||
152 | */
|
||
153 | public static FLayer createLayer(String layerName, VectorialFileDriver d, |
||
154 | File f, IProjection proj) throws DriverException { |
||
155 | //TODO Comprobar si hay un adaptador ya
|
||
156 | VectorialFileAdapter adapter = new VectorialFileAdapter(f);
|
||
157 | adapter.setDriver((VectorialDriver) d); |
||
158 | 214 | fernando | |
159 | 1034 | vcaballero | FLyrVect capa = new FLyrVect();
|
160 | capa.setName(layerName); |
||
161 | 214 | fernando | |
162 | 1034 | vcaballero | //TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
163 | if (false) { |
||
164 | } else {
|
||
165 | capa.setSource(adapter); |
||
166 | capa.setProjection(proj); |
||
167 | } |
||
168 | |||
169 | try {
|
||
170 | 1828 | fernando | |
171 | 470 | fjp | // Le asignamos tambi?n una legenda por defecto acorde con
|
172 | // el tipo de shape que tenga. Tampoco s? si es aqu? el
|
||
173 | // sitio adecuado, pero en fin....
|
||
174 | 1034 | vcaballero | if (d instanceof WithDefaultLegend) { |
175 | WithDefaultLegend aux = (WithDefaultLegend) d; |
||
176 | adapter.start(); |
||
177 | capa.setLegend((VectorialLegend) aux.getDefaultLegend()); |
||
178 | adapter.stop(); |
||
179 | } else {
|
||
180 | capa.setLegend(LegendFactory.createSingleSymbolLegend( |
||
181 | capa.getShapeType())); |
||
182 | } |
||
183 | 470 | fjp | } catch (FieldNotFoundException e) {
|
184 | 651 | fernando | //Esta no puede saltar
|
185 | 714 | fjp | } catch (DriverIOException e) {
|
186 | throw new DriverException(e); |
||
187 | 1034 | vcaballero | } |
188 | 408 | fernando | |
189 | 1034 | vcaballero | return capa;
|
190 | } |
||
191 | 567 | luisw | |
192 | 732 | fernando | /**
|
193 | 1034 | vcaballero | * Crea una capa WMS con el driver que se le pasa como par?metro y
|
194 | * guard?ndose el nombre del fichero para realizar los accesos, la capa
|
||
195 | * tendr? asociada la proyecci?n que se pasa como parametro tambi?n
|
||
196 | 732 | fernando | *
|
197 | 1034 | vcaballero | * @param layerName Nombre de la capa.
|
198 | * @param rect extent
|
||
199 | * @param host URL.
|
||
200 | * @param format Formato
|
||
201 | * @param query Consulta.
|
||
202 | * @param infoQuery inforamci?n de la consulta.
|
||
203 | * @param srs SRS.
|
||
204 | 732 | fernando | *
|
205 | 1034 | vcaballero | * @return Capa creada.
|
206 | 732 | fernando | */
|
207 | 1034 | vcaballero | public static FLayer createLayer(String layerName, Rectangle2D rect, |
208 | URL host, String format, String query, String infoQuery, String srs) { |
||
209 | FLyrWMS layer = new FLyrWMS();
|
||
210 | layer.setHost(host); |
||
211 | layer.setFullExtent(rect); |
||
212 | layer.setFormat(format); |
||
213 | layer.setLayerQuery(query); |
||
214 | layer.setInfoLayerQuery(infoQuery); |
||
215 | layer.setSRS(srs); |
||
216 | layer.setName(layerName); |
||
217 | |||
218 | return layer;
|
||
219 | } |
||
220 | |||
221 | /**
|
||
222 | * Crea una capa Raster a partir del nombre driver, fichero y proyecci?n.
|
||
223 | *
|
||
224 | * @param layerName Nombre de la capa.
|
||
225 | * @param d RasterDriver.
|
||
226 | * @param f Fichero.
|
||
227 | * @param proj Proyecci?n.
|
||
228 | *
|
||
229 | * @return Nueva capa de tipo raster.
|
||
230 | *
|
||
231 | * @throws DriverIOException
|
||
232 | */
|
||
233 | 732 | fernando | public static FLyrRaster createLayer(String layerName, RasterDriver d, |
234 | 1046 | fernando | File f, IProjection proj) throws DriverException { |
235 | 732 | fernando | RasterAdapter adapter = new RasterFileAdapter(f);
|
236 | adapter.setDriver(d); |
||
237 | |||
238 | FLyrRaster capa = new FLyrRaster();
|
||
239 | capa.setName(layerName); |
||
240 | |||
241 | //TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
||
242 | if (false) { |
||
243 | } else {
|
||
244 | capa.setSource(adapter); |
||
245 | capa.setProjection(proj); |
||
246 | 1046 | fernando | try {
|
247 | capa.load(); |
||
248 | } catch (DriverIOException e) {
|
||
249 | throw new DriverException(e); |
||
250 | } |
||
251 | 732 | fernando | } |
252 | |||
253 | 567 | luisw | return capa;
|
254 | 732 | fernando | } |
255 | 567 | luisw | |
256 | 732 | fernando | /**
|
257 | 2850 | nacho | * Crea una capa Raster a partir del nombre driver, fichero y proyecci?n y
|
258 | * coordenadas de georeferenciaci?n. Esta funci?n es para georeferenciar
|
||
259 | * capas raster. Para imagenes que no tienen georeferenciaci?n hay que asignarle
|
||
260 | * una temporal, normalmente a partir de la vista activa.
|
||
261 | *
|
||
262 | * @param layerName Nombre de la capa.
|
||
263 | * @param d RasterDriver.
|
||
264 | * @param f Fichero.
|
||
265 | * @param proj Proyecci?n.
|
||
266 | * @param extent Extent de la vista activa
|
||
267 | *
|
||
268 | * @return Nueva capa de tipo raster.
|
||
269 | *
|
||
270 | * @throws DriverIOException
|
||
271 | */
|
||
272 | public static FLyrRaster createLayer(String layerName, RasterDriver d, |
||
273 | File f, IProjection proj, ViewPort vp) throws DriverException { |
||
274 | RasterAdapter adapter = new RasterFileAdapter(f);
|
||
275 | adapter.setDriver(d); |
||
276 | |||
277 | FLyrRaster capa = new FLyrRaster();
|
||
278 | capa.setName(layerName); |
||
279 | |||
280 | //TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
||
281 | if (false) { |
||
282 | } else {
|
||
283 | capa.setSource(adapter); |
||
284 | capa.setProjection(proj); |
||
285 | capa.setTempExtent(vp); |
||
286 | try {
|
||
287 | capa.load(); |
||
288 | } catch (DriverIOException e) {
|
||
289 | throw new DriverException(e); |
||
290 | } |
||
291 | } |
||
292 | |||
293 | return capa;
|
||
294 | } |
||
295 | |||
296 | /**
|
||
297 | 732 | fernando | * Crea un RandomVectorialWFS con el driver que se le pasa como par?metro y
|
298 | * guard?ndose la URL del servidor que se pasa como par?metro
|
||
299 | *
|
||
300 | 1034 | vcaballero | * @param driver Driver WFS.
|
301 | * @param host URL.
|
||
302 | * @param proj Proyecci?n.
|
||
303 | 732 | fernando | *
|
304 | 1034 | vcaballero | * @return Capa creada.
|
305 | 732 | fernando | *
|
306 | 1034 | vcaballero | * @throws UnsupportedOperationException
|
307 | 732 | fernando | */
|
308 | 2277 | vcaballero | public static FLayer createWFSLayer(String layerName,VectorialDriver driver, URL host, |
309 | 732 | fernando | IProjection proj) { |
310 | 2183 | fernando | //throw new UnsupportedOperationException();
|
311 | FLyrVect layer=new FLyrVect();
|
||
312 | //layer.setName(name);
|
||
313 | VectorialAdapter adapter=new WFSAdapter();
|
||
314 | adapter.setDriver(driver); |
||
315 | //WithDefaultLegend aux=(WithDefaultLegend)driver;
|
||
316 | |||
317 | layer.setName(layerName); |
||
318 | layer.setSource(adapter); |
||
319 | layer.setProjection(proj); |
||
320 | try {
|
||
321 | layer.setLegend(LegendFactory.createSingleSymbolLegend( |
||
322 | layer.getShapeType())); |
||
323 | } catch (FieldNotFoundException e) {
|
||
324 | e.printStackTrace(); |
||
325 | } catch (DriverException e) {
|
||
326 | e.printStackTrace(); |
||
327 | } |
||
328 | //layer.setHost(host);
|
||
329 | return layer;
|
||
330 | 732 | fernando | } |
331 | 2277 | vcaballero | public static FLayer createArcSDELayer(String layerName,VectorialDatabaseDriver driver, IProjection proj) { |
332 | 2183 | fernando | //throw new UnsupportedOperationException();
|
333 | FLyrVect layer=new FLyrVect();
|
||
334 | VectorialAdapter adapter=new VectorialDBAdapter();
|
||
335 | adapter.setDriver(driver); |
||
336 | |||
337 | layer.setName(layerName); |
||
338 | layer.setSource(adapter); |
||
339 | layer.setProjection(proj); |
||
340 | try {
|
||
341 | if (driver instanceof WithDefaultLegend) { |
||
342 | WithDefaultLegend aux = (WithDefaultLegend) driver; |
||
343 | adapter.start(); |
||
344 | layer.setLegend((VectorialLegend) aux.getDefaultLegend()); |
||
345 | adapter.stop(); |
||
346 | } else {
|
||
347 | layer.setLegend(LegendFactory.createSingleSymbolLegend( |
||
348 | layer.getShapeType())); |
||
349 | } |
||
350 | } catch (FieldNotFoundException e) {
|
||
351 | throw new UnsupportedOperationException(e.getMessage()); |
||
352 | } catch (DriverIOException e) {
|
||
353 | throw new UnsupportedOperationException(e.getMessage()); |
||
354 | } catch (DriverException e) {
|
||
355 | // TODO Auto-generated catch block
|
||
356 | e.printStackTrace(); |
||
357 | } |
||
358 | |||
359 | try {
|
||
360 | layer.setLegend(LegendFactory.createSingleSymbolLegend( |
||
361 | layer.getShapeType())); |
||
362 | } catch (FieldNotFoundException e) {
|
||
363 | e.printStackTrace(); |
||
364 | } catch (DriverException e) {
|
||
365 | e.printStackTrace(); |
||
366 | } |
||
367 | return layer;
|
||
368 | } |
||
369 | 214 | fernando | |
370 | 732 | fernando | /**
|
371 | * Crea un RandomVectorialWFS con el driver que se le pasa como par?metro y
|
||
372 | * guard?ndose la URL del servidor que se pasa como par?metro
|
||
373 | *
|
||
374 | 1034 | vcaballero | * @param driver
|
375 | * @param host
|
||
376 | * @param port
|
||
377 | * @param user
|
||
378 | * @param password
|
||
379 | * @param dbName
|
||
380 | * @param tableName
|
||
381 | * @param proj
|
||
382 | 732 | fernando | *
|
383 | 1034 | vcaballero | * @return Capa creada.
|
384 | 732 | fernando | *
|
385 | 1034 | vcaballero | * @throws UnsupportedOperationException
|
386 | 732 | fernando | */
|
387 | public static FLayer createLayer(VectorialDatabaseDriver driver, |
||
388 | String host, int port, String user, String password, String dbName, |
||
389 | String tableName, IProjection proj) {
|
||
390 | throw new UnsupportedOperationException(); |
||
391 | } |
||
392 | 1691 | fjp | public static FLayer createDBLayer(VectorialDatabaseDriver driver,String layerName, IProjection proj) |
393 | { |
||
394 | |||
395 | |||
396 | FLyrVect capa = new FLyrVect();
|
||
397 | |||
398 | capa.setName(layerName); |
||
399 | VectorialDBAdapter dbAdapter = new VectorialDBAdapter();
|
||
400 | dbAdapter.setDriver(driver); |
||
401 | |||
402 | capa.setSource(dbAdapter); |
||
403 | capa.setProjection(proj); |
||
404 | try {
|
||
405 | if (driver instanceof WithDefaultLegend) { |
||
406 | WithDefaultLegend aux = (WithDefaultLegend) driver; |
||
407 | dbAdapter.start(); |
||
408 | capa.setLegend((VectorialLegend) aux.getDefaultLegend()); |
||
409 | dbAdapter.stop(); |
||
410 | } else {
|
||
411 | capa.setLegend(LegendFactory.createSingleSymbolLegend( |
||
412 | capa.getShapeType())); |
||
413 | } |
||
414 | } catch (FieldNotFoundException e) {
|
||
415 | throw new UnsupportedOperationException(e.getMessage()); |
||
416 | } catch (DriverException e) {
|
||
417 | throw new UnsupportedOperationException(e.getMessage()); |
||
418 | } |
||
419 | 303 | fernando | |
420 | 1691 | fjp | return capa;
|
421 | |||
422 | |||
423 | |||
424 | } |
||
425 | |||
426 | 2183 | fernando | /**
|
427 | * @param driver
|
||
428 | * @param layerName
|
||
429 | * @param object
|
||
430 | * @return
|
||
431 | * @throws SQLException
|
||
432 | * @throws DriverIOException
|
||
433 | * @throws IOException
|
||
434 | * @throws DriverLoadException
|
||
435 | * @throws com.hardcode.gdbms.engine.data.driver.DriverException
|
||
436 | * @throws NoSuchTableException
|
||
437 | * @throws ClassNotFoundException
|
||
438 | * @throws
|
||
439 | */
|
||
440 | public static FLayer createDisconnectedDBLayer(VectorialJDBCDriver driver, String layerName, IProjection proj, ProgressListener listener) throws SQLException, IOException, DriverIOException, DriverLoadException, NoSuchTableException, com.hardcode.gdbms.engine.data.driver.DriverException, ClassNotFoundException { |
||
441 | VectorialDisconnectedDBAdapter dbAdapter = new VectorialDisconnectedDBAdapter();
|
||
442 | dbAdapter.setDriver(driver); |
||
443 | DataSource ds = dbAdapter.getRecordset();
|
||
444 | ds.start(); |
||
445 | String database = dataSourceFactory.getTempFile();
|
||
446 | String[] fieldNames = new String[ds.getFieldCount() + 1]; |
||
447 | System.arraycopy(ds.getFieldNames(), 0, fieldNames, 1, ds.getFieldCount()); |
||
448 | fieldNames[0] = "the_geom"; |
||
449 | int[] types = new int[fieldNames.length]; |
||
450 | types[0] = Types.BINARY; |
||
451 | for (int i = 1; i < types.length; i++) { |
||
452 | types[i] = ds.getFieldType(i-1);
|
||
453 | } |
||
454 | String dsName = dataSourceFactory.createTable(database, ds.getPKNames(), fieldNames, types);
|
||
455 | |||
456 | 2217 | fernando | dataSourceFactory.addDBDataSourceByTable(dsName, null, 0, "sa", "", database, dsName, "GDBMS HSQLDB Transactional driver"); |
457 | 2667 | fernando | DataSource local = dataSourceFactory.createRandomDataSource(dsName, DataSourceFactory.MANUAL_OPENING);
|
458 | 2183 | fernando | local.start(); |
459 | 2217 | fernando | DataWare dw = local.getDataWare(DataSourceFactory.DATA_WARE_COHERENT_ROW_ORDER); |
460 | 2183 | fernando | dw.start(); |
461 | long t1 = System.currentTimeMillis(); |
||
462 | dw.beginTrans(); |
||
463 | |||
464 | if (listener == null){ |
||
465 | listener = new ProgressListener() {
|
||
466 | /**
|
||
467 | * @see com.iver.cit.gvsig.fmap.ProgressListener#progress(int)
|
||
468 | */
|
||
469 | public void progress(int n) { |
||
470 | //do nothing
|
||
471 | } |
||
472 | }; |
||
473 | } |
||
474 | |||
475 | for (int i = 0; i < dbAdapter.getShapeCount(); i++) { |
||
476 | Value[] row = new Value[ds.getFieldCount() + 1]; |
||
477 | |||
478 | byte[] bytes = dbAdapter.getShape(i).toWKB(); |
||
479 | row[0] = ValueFactory.createValue(bytes);
|
||
480 | |||
481 | for (int j = 0; j < ds.getFieldCount(); j++) { |
||
482 | row[j+1] = ds.getFieldValue(i, j);
|
||
483 | } |
||
484 | |||
485 | dw.insertFilledRow(row); |
||
486 | listener.progress(100 * i / dbAdapter.getShapeCount());
|
||
487 | } |
||
488 | |||
489 | long t2 = System.currentTimeMillis(); |
||
490 | dw.commitTrans(); |
||
491 | long t3 = System.currentTimeMillis(); |
||
492 | System.out.println((t2 - t1) + " - " + (t3 - t2)); |
||
493 | dw.stop(); |
||
494 | local.stop(); |
||
495 | ds.stop(); |
||
496 | VectorialJDBCDriver cacheDriver = (VectorialJDBCDriver) LayerFactory.getDM().getDriver("HSQLDB Driver");
|
||
497 | Class.forName("org.hsqldb.jdbcDriver"); |
||
498 | |||
499 | cacheDriver.setData(java.sql.DriverManager.getConnection("jdbc:hsqldb:file:" + database, "sa", ""), dsName, StringUtilities.getComaSeparated(local.getFieldNames()), "", local.getPrimaryKeys()[0]+1); |
||
500 | cacheDriver.setWorkingArea(driver.getWorkingArea()); |
||
501 | return createDBLayer(cacheDriver, layerName, proj);
|
||
502 | } |
||
503 | 1691 | fjp | |
504 | 2183 | fernando | |
505 | 732 | fernando | /**
|
506 | * Obtiene el adaptador de un driver si ya se ha a?adido el origen de datos
|
||
507 | * o null si es un origen de datos nuevo
|
||
508 | *
|
||
509 | 1034 | vcaballero | * @param source Adaptador.
|
510 | 732 | fernando | */
|
511 | private static void getAdapter(Source source) { |
||
512 | } |
||
513 | 303 | fernando | |
514 | 732 | fernando | /**
|
515 | * Registra la asociaci?n entre la fuente de datos que se pasa como
|
||
516 | * par?metro y el VectorialAdapter que se pasa como par?metro, para
|
||
517 | * satisfacer futuras llamadas a getAdapter
|
||
518 | *
|
||
519 | 1034 | vcaballero | * @param s Adaptador
|
520 | * @param a VectorialAdapter.
|
||
521 | 732 | fernando | */
|
522 | private static void saveSourceAdapter(Source s, VectorialAdapter a) { |
||
523 | } |
||
524 | 303 | fernando | |
525 | 732 | fernando | /**
|
526 | * Crea una FLyrComplexRaster que ataca al driver que se pasa como
|
||
527 | * par?metro.
|
||
528 | *
|
||
529 | 1034 | vcaballero | * @param driver
|
530 | * @param f
|
||
531 | * @param proj
|
||
532 | 732 | fernando | *
|
533 | * @throws IllegalArgumentException Si se pasa un driver que no implementa
|
||
534 | * GeorreferencedRasterDriver o NotGeorreferencedRasterDriver
|
||
535 | */
|
||
536 | public static void createLayer(RasterDriver driver, File f, IProjection proj) |
||
537 | throws IllegalArgumentException { |
||
538 | } |
||
539 | 408 | fernando | |
540 | 732 | fernando | /**
|
541 | 1034 | vcaballero | * Devuelve el DriverManager.
|
542 | 732 | fernando | *
|
543 | 1034 | vcaballero | * @return DriverManager.
|
544 | 732 | fernando | */
|
545 | public static DriverManager getDM() { |
||
546 | 1839 | fernando | initializeDriverManager(); |
547 | 732 | fernando | |
548 | return driverManager;
|
||
549 | } |
||
550 | |||
551 | /**
|
||
552 | 1034 | vcaballero | * Inicializa el DriverManager.
|
553 | 732 | fernando | */
|
554 | private static void initializeDriverManager() { |
||
555 | if (driverManager == null) { |
||
556 | driverManager = new DriverManager(); |
||
557 | driverManager.loadDrivers(new File(LayerFactory.driversPath)); |
||
558 | |||
559 | Throwable[] failures = driverManager.getLoadFailures(); |
||
560 | |||
561 | for (int i = 0; i < failures.length; i++) { |
||
562 | 2183 | fernando | logger.error("", failures[i]);
|
563 | 626 | fernando | } |
564 | |||
565 | 1828 | fernando | getDataSourceFactory().setDriverManager(driverManager); |
566 | 2183 | fernando | getDataSourceFactory().initialize(); |
567 | 1836 | fernando | QueryManager.registerQuery(new ArcJoin());
|
568 | 732 | fernando | } |
569 | } |
||
570 | 408 | fernando | |
571 | 732 | fernando | /**
|
572 | * sets drivers Directory
|
||
573 | *
|
||
574 | * @param path
|
||
575 | */
|
||
576 | public static void setDriversPath(String path) { |
||
577 | LayerFactory.driversPath = path; |
||
578 | initializeDriverManager(); |
||
579 | } |
||
580 | 1773 | fernando | |
581 | 2183 | fernando | |
582 | 1773 | fernando | /**
|
583 | * @return Returns the dataSourceFactory.
|
||
584 | */
|
||
585 | public static DataSourceFactory getDataSourceFactory() { |
||
586 | 1828 | fernando | if (dataSourceFactory == null){ |
587 | dataSourceFactory = new DataSourceFactory();
|
||
588 | } |
||
589 | 1773 | fernando | return dataSourceFactory;
|
590 | } |
||
591 | 214 | fernando | } |