Statistics
| Revision:

root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.core / src / main / java / es / unex / sextante / core / OutputFactory.java @ 187

History | View | Annotate | Download (15.7 KB)

1

    
2

    
3
package es.unex.sextante.core;
4

    
5
import java.io.File;
6

    
7
import javax.swing.JDialog;
8

    
9
import es.unex.sextante.dataObjects.I3DRasterLayer;
10
import es.unex.sextante.dataObjects.IRasterLayer;
11
import es.unex.sextante.dataObjects.ITable;
12
import es.unex.sextante.dataObjects.IVectorLayer;
13
import es.unex.sextante.exceptions.UnsupportedOutputChannelException;
14
import es.unex.sextante.io3d.Default3DRasterLayer;
15
import es.unex.sextante.outputs.FileOutputChannel;
16
import es.unex.sextante.outputs.IOutputChannel;
17
import es.unex.sextante.outputs.Output;
18
import es.unex.sextante.outputs.Output3DRasterLayer;
19
import es.unex.sextante.outputs.OutputRasterLayer;
20
import es.unex.sextante.outputs.OutputTable;
21
import es.unex.sextante.outputs.OutputVectorLayer;
22

    
23

    
24
/**
25
 * An OutputFactory defines how new data objects (layers and tables) are created. Method in this class are called from
26
 * geoalgorithms to create output objects
27
 *
28
 * @author Victor Olaya volaya@unex.es
29
 *
30
 */
31
public abstract class OutputFactory {
32

    
33
   private int    m_iCount       = 0;
34
   private double m_dNoDataValue = -99999;
35

    
36

    
37
   /**
38
    * Use this method to create a new IVectorLayer that can be used to generate new vector layers as output from the geo-algorithm
39
    *
40
    * @param sName
41
    *                the name of the layer
42
    * @param iShapeType
43
    *                the type of shapes in the layer
44
    * @param types
45
    *                the data type of the fields
46
    * @param sFields
47
    *                the name of the fields in the attributes table
48
    * @param channel
49
    *                the output channel associated to the output layer
50
    * @param crs
51
    *                An object with information to set the CRS of this layer (i.e. a string with a EPSG code)
52
    * @return an empty vector layer
53
    */
54
   public abstract IVectorLayer getNewVectorLayer(String sName,
55
                                                  int iShapeType,
56
                                                  Class[] types,
57
                                                  String[] sFields,
58
                                                  IOutputChannel channel,
59
                                                  Object crs) throws UnsupportedOutputChannelException;
60

    
61
   /**
62
    * Use this method to create a new IVectorLayer that can be used to generate new vector layers as output from the geo-algorithm
63
    *
64
    * @param sName
65
    *                the name of the layer
66
    * @param iShapeType
67
    *                the type of shapes in the layer
68
    * @param types
69
    *                the data type of the fields
70
    * @param sFields
71
    *                the name of the fields in the attributes table
72
    * @param channel
73
    *                the output channel associated to the output layer
74
    * @param crs
75
    *                An object with information to set the CRS of this layer (i.e. a string with a EPSG code)
76
    * @param subtype
77
    *                the subtype of the geometries in the layer
78
    * @return an empty vector layer
79
 * @throws UnsupportedOutputChannelException
80
    */
81
   public abstract IVectorLayer getNewVectorLayer(String sName,
82
                                                  int iShapeType,
83
                                                  Class[] types,
84
                                                  String[] sFields,
85
                                                  IOutputChannel channel,
86
                                                  Object crs, int subtype) throws UnsupportedOutputChannelException;
87

    
88

    
89
   /**
90
    * Use this method to create a new IVectorLayer that can be used to generate new vector layers as output from the geo-algorithm
91
    *
92
    * @param sName
93
    *                the name of the layer
94
    * @param iShapeType
95
    *                the type of shapes in the layer
96
    * @param types
97
    *                the data type of the fields
98
    * @param sFields
99
    *                the name of the fields in the attributes table
100
    * @param channel
101
    *                the output channel associated to the output layer
102
    * @param crs
103
    *                An object with information to set the CRS of this layer (i.e. a string with a EPSG code)
104
    * @param fieldSize
105
    *                A list of integers. Each value represents the size of a table field.
106
    * @return an empty vector layer
107
    */
108
   public abstract IVectorLayer getNewVectorLayer(String sName,
109
                                                  int iShapeType,
110
                                                  Class[] types,
111
                                                  String[] sFields,
112
                                                  IOutputChannel channel,
113
                                                  Object crs,
114
                                                  int[] fieldSize) throws UnsupportedOutputChannelException;
115

    
116
   /**
117
    * Use this method to create a new IVectorLayer that can be used to generate new vector layers as output from the geo-algorithm
118
    *
119
    * @param sName
120
    *                the name of the layer
121
    * @param iShapeType
122
    *                the type of shapes in the layer
123
    * @param types
124
    *                the data type of the fields
125
    * @param sFields
126
    *                the name of the fields in the attributes table
127
    * @param channel
128
    *                the output channel associated to the output layer
129
    * @param crs
130
    *                An object with information to set the CRS of this layer (i.e. a string with a EPSG code)
131
    * @param fieldSize
132
    *                A list of integers. Each value represents the size of a table field.
133
    * @param subtype
134
    *                the subtype of the geometries in the layer
135
    * @return an empty vector layer
136
 * @throws UnsupportedOutputChannelException
137
    */
138
   public abstract IVectorLayer getNewVectorLayer(String sName,
139
                                                  int iShapeType,
140
                                                  Class[] types,
141
                                                  String[] sFields,
142
                                                  IOutputChannel channel,
143
                                                  Object crs,
144
                                                  int[] fieldSize, int subtype) throws UnsupportedOutputChannelException;
145

    
146
   /**
147
    * Use this method to create a new raster layer as output from the geo-algorithm. The characteristics of the raster layer
148
    * (extent and cellsize) are taken from the extent parameter.
149
    *
150
    * @param sName
151
    *                the name of the layer
152
    * @param iDataType
153
    *                the type of data in the layer
154
    * @param extent
155
    *                the AnalysisExtent to use
156
    * @param iBands
157
    *                the number of bands of the new layer
158
    * @param channel
159
    *                the output channel associated to the output layer
160
    * @param crs
161
    *                An object with information to set the CRS of this layer (i.e. a string with a EPSG code)
162
    * @return a raster layer
163
    * @throws UnsupportedOutputChannelException
164
    */
165
   public abstract IRasterLayer getNewRasterLayer(String sName,
166
                                                  int iDataType,
167
                                                  AnalysisExtent extent,
168
                                                  int iBands,
169
                                                  IOutputChannel channel,
170
                                                  Object crs) throws UnsupportedOutputChannelException;
171

    
172

    
173
   /**
174
    * Use this method to create a new 3D raster layer as output from the geo-algorithm. The characteristics of the raster layer
175
    * (extent and cellsizes) are taken from the extent parameter.
176
    *
177
    * A default implementation is given, which uses the Default3dRasterLayer class. This way, 3D algorithms can be executed within
178
    * the context of a GIS that does not support 3D layer, and there is no need to overwrite this method in the corresponding
179
    * binding
180
    *
181
    * @param sName
182
    *                the name of the layer
183
    * @param iDataType
184
    *                the type of data in the layer
185
    * @param extent
186
    *                the AnalysisExtent to use
187
    * @param channel
188
    *                the output channel associated to the output layer
189
    * @param crs
190
    *                An object with information to set the CRS of this layer (i.e. a string with a EPSG code)
191
    * @return a 3D raster layer
192
    */
193
   public I3DRasterLayer getNew3DRasterLayer(final String sName,
194
                                             final int iDataType,
195
                                             final AnalysisExtent extent,
196
                                             final IOutputChannel channel,
197
                                             final Object crs) throws UnsupportedOutputChannelException {
198

    
199
      if (channel instanceof FileOutputChannel) {
200
         final String sFilename = ((FileOutputChannel) channel).getFilename();
201
         final Default3DRasterLayer layer = new Default3DRasterLayer();
202
         layer.create(sName, sFilename, extent, crs);
203
         return layer;
204
      }
205
      else {
206
         throw new UnsupportedOutputChannelException();
207
      }
208

    
209

    
210
   }
211

    
212

    
213
   /**
214
    * Use this method to create a new table.
215
    *
216
    * @param sName
217
    *                the name of the table
218
    * @param types
219
    *                the data type of the fields
220
    * @param sFields
221
    *                The names of the fields in the table
222
    * @param channel
223
    *                the output channel associated to the output layer
224
    * @return a new empty table object
225
    */
226
   public abstract ITable getNewTable(String sName,
227
                                      Class[] types,
228
                                      String[] sFields,
229
                                      IOutputChannel channel) throws UnsupportedOutputChannelException;
230

    
231

    
232
   /**
233
    *
234
    * @return A temporary filename with the default file extension for vector layers
235
    */
236
   public String getTempVectorLayerFilename() {
237

    
238
      return getTempFilenameWithoutExtension() + "." + getVectorLayerOutputExtensions()[0];
239

    
240
   }
241

    
242

    
243
   /**
244
    *
245
    * @return A temporary filename with the default file extension for raster layers
246
    */
247
   public String getTempRasterLayerFilename() {
248

    
249
      return getTempFilenameWithoutExtension() + "." + getRasterLayerOutputExtensions()[0];
250

    
251
   }
252

    
253

    
254
   /**
255
    *
256
    * @return A temporary filename with the default file extension for 3D raster layers
257
    */
258
   public String getTemp3DRasterLayerFilename() {
259

    
260
      return getTempFilenameWithoutExtension() + "." + get3DRasterLayerOutputExtensions()[0];
261

    
262
   }
263

    
264

    
265
   /**
266
    *
267
    * @return A temporary filename with the default file extension for tables
268
    */
269
   public String getTempTableFilename() {
270

    
271
      return getTempFilenameWithoutExtension() + "." + getTableOutputExtensions()[0];
272
   }
273

    
274

    
275
   /**
276
    *
277
    * @return A temporary folder name
278
    */
279
   public String getTempFoldername() {
280

    
281
      return getTempFilenameWithoutExtension();
282
   }
283

    
284

    
285
   /**
286
    *
287
    * @param out
288
    *                an Output object
289
    * @return A temporary filename with the default file extension for the specified type of output
290
    */
291
   public String getTempFilename(final Output out) {
292

    
293
      if (out instanceof OutputVectorLayer) {
294
         return getTempVectorLayerFilename();
295
      }
296
      if (out instanceof OutputRasterLayer) {
297
         return getTempRasterLayerFilename();
298
      }
299
      if (out instanceof OutputTable) {
300
         return getTempTableFilename();
301
      }
302
      if (out instanceof Output3DRasterLayer) {
303
         return getTemp3DRasterLayerFilename();
304
      }
305

    
306
      else {
307
         return null;
308
      }
309

    
310
   }
311

    
312

    
313
   /**
314
    * Returns a temporary filename with no extension
315
    *
316
    * @returns a temporary filename with no extension.
317
    */
318
   public String getTempFilenameWithoutExtension() {
319

    
320
      return getTempFolder() + File.separator + Long.toString(System.currentTimeMillis()) + Integer.toString(m_iCount++);
321

    
322
   }
323

    
324

    
325
   /**
326
    * Returns the temporary folder. This will be used to store outputs when they do not have an associated filename an it is
327
    * needed
328
    *
329
    * @return a temporary folder
330
    */
331
   public abstract String getTempFolder();
332

    
333

    
334
   /**
335
    * Returns the extensions supported by this factory for creating raster layers. If a filename with an extension not found in
336
    * this list of extensions is used to create a raster layer, the default extension (the first one of the list) will be added to
337
    * the filename when creating that layer.
338
    *
339
    * @return the list of supported extensions for raster layers
340
    */
341
   public abstract String[] getRasterLayerOutputExtensions();
342

    
343

    
344
   /**
345
    * Returns the extensions supported by this factory for creating 3d raster layers. If a filename with an extension not found in
346
    * this list of extensions is used to create a 3d raster layer, the default extension (the first one of the list) will be added
347
    * to the filename when creating that layer.
348
    *
349
    * A default implementation is given, which returns just the "asc" extension used by the default implementation of the
350
    * getNew3DRasterLayer method, which uses the Default3DRasterLayer class
351
    *
352
    * @return the list of supported extensions for 3d raster layers
353
    */
354
   public String[] get3DRasterLayerOutputExtensions() {
355

    
356
      return new String[] { "asc3d" };
357

    
358
   }
359

    
360

    
361
   /**
362
    * Returns the extensions supported by this factory for creating vector layers. If a filename with an extension not found in
363
    * this list of extensions is used to create a vector layer, the default extension (the first one of the list) will be added to
364
    * the filename when creating that layer.
365
    *
366
    * @return the list of supported extensions for vector layers
367
    */
368
   public abstract String[] getVectorLayerOutputExtensions();
369

    
370

    
371
   /**
372
    * Returns the extensions supported by this factory for creating raster layers. If a filename with an extension not found in
373
    * this list of extensions is used to create a raster layer, the default extension (the first one of the list) will be added to
374
    * the filename when creating that layer.
375
    *
376
    * @return the list of supported extensions for raster layers
377
    */
378
   public abstract String[] getTableOutputExtensions();
379

    
380

    
381
   /**
382
    * Returns the task monitor that will be used to monitor algorithm execution
383
    *
384
    * @param sTitle
385
    *                a String used to identify the monitor. This will be used, for instance, as the title string of a progress
386
    *                dialog.
387
    * @param bDeterminate
388
    *                true if the task monitor will monitor a determinated process (i.e. number of steps to complete the process is
389
    *                know)
390
    * @return the task monitor used to monitor algorithm execution
391
    */
392
   public abstract ITaskMonitor getTaskMonitor(String sTitle,
393
                                               boolean bDeterminate,
394
                                               JDialog parent);
395

    
396

    
397
   /**
398
    * Returns the default CRS for new layers. This will be used when the geoalgorithm generates new layers but does not take any
399
    * other layer as input, so the CRS cannot be defined from the inputs
400
    *
401
    * @return an object containing information about the default CRS (i.e. a String with the EPSG code of the CRS)
402
    */
403
   public abstract Object getDefaultCRS();
404

    
405

    
406
   /**
407
    * Returns the default no data value for raster layers created by this output factory
408
    *
409
    * @return the default no data value for raster layers created by this output factory
410
    */
411
   public double getDefaultNoDataValue() {
412

    
413
      return m_dNoDataValue;
414

    
415
   }
416

    
417

    
418
   /**
419
    * Sets the default no data value to use when this output factory cretes a new raster layer
420
    *
421
    * @param dValue
422
    *                the default no data value to use when this output factory cretes a new raster layer
423
    */
424
   public void setDefaultNoDataValue(final double dValue) {
425

    
426
      m_dNoDataValue = dValue;
427

    
428
   }
429

    
430

    
431
}