gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.extension / src / main / java / org / gvsig / geoprocess / core / gvOutputFactory.java @ 172
History | View | Annotate | Download (6.12 KB)
1 |
package org.gvsig.geoprocess.core; |
---|---|
2 |
|
3 |
import java.util.Date; |
4 |
|
5 |
import javax.swing.JDialog; |
6 |
|
7 |
import es.unex.sextante.core.AnalysisExtent; |
8 |
import es.unex.sextante.core.ITaskMonitor; |
9 |
import es.unex.sextante.core.OutputFactory; |
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.dataObjects.TiledRasterLayer; |
14 |
import es.unex.sextante.exceptions.UnsupportedOutputChannelException; |
15 |
import es.unex.sextante.gui.core.DefaultTaskMonitor; |
16 |
import es.unex.sextante.outputs.FileOutputChannel; |
17 |
import es.unex.sextante.outputs.IOutputChannel; |
18 |
|
19 |
import org.gvsig.andami.Utilities; |
20 |
import org.gvsig.andami.messages.NotificationManager; |
21 |
import org.gvsig.app.ApplicationLocator; |
22 |
import org.gvsig.app.project.ProjectPreferences; |
23 |
|
24 |
/**
|
25 |
* An OutputFactory based on the gvSIG data model. Supports only file-based
|
26 |
* outputs.
|
27 |
*
|
28 |
* @author volaya
|
29 |
*
|
30 |
*/
|
31 |
public class gvOutputFactory extends OutputFactory { |
32 |
|
33 |
private static final int THRESHOLD = 100000000; |
34 |
|
35 |
@Override
|
36 |
public IVectorLayer getNewVectorLayer(final String name, |
37 |
final int shapeType, final Class[] types, final String[] fields, |
38 |
final IOutputChannel channel, final Object crs) |
39 |
throws UnsupportedOutputChannelException {
|
40 |
|
41 |
final int[] sizes = new int[types.length]; |
42 |
for (int i = 0; i < sizes.length; i++) { |
43 |
sizes[i] = getSizeFromTypeClass(types[i]); |
44 |
} |
45 |
return getNewVectorLayer(name, shapeType, types, fields, channel, crs,
|
46 |
sizes); |
47 |
|
48 |
} |
49 |
|
50 |
@Override
|
51 |
public IVectorLayer getNewVectorLayer(final String sName, |
52 |
final int iShapeType, final Class[] types, final String[] sFields, |
53 |
final IOutputChannel channel, final Object crs, final int[] fieldSize) |
54 |
throws UnsupportedOutputChannelException {
|
55 |
|
56 |
if (channel instanceof FileOutputChannel) { |
57 |
final String sFilename = |
58 |
((FileOutputChannel) channel).getFilename(); |
59 |
final gvVectorLayer layer = new gvVectorLayer(); |
60 |
layer.create(sName, sFilename, iShapeType, types, sFields, crs, |
61 |
fieldSize); |
62 |
|
63 |
return layer;
|
64 |
} else {
|
65 |
throw new UnsupportedOutputChannelException(); |
66 |
} |
67 |
|
68 |
} |
69 |
|
70 |
@Override
|
71 |
public IRasterLayer getNewRasterLayer(final String sName, |
72 |
final int iDataType, final AnalysisExtent extent, final int iBands, |
73 |
final IOutputChannel channel, final Object crs) |
74 |
throws UnsupportedOutputChannelException {
|
75 |
|
76 |
if (channel instanceof FileOutputChannel) { |
77 |
final String sFilename = |
78 |
((FileOutputChannel) channel).getFilename(); |
79 |
if (extent.getNX() * extent.getNY() * iBands > THRESHOLD) {// should |
80 |
// consider
|
81 |
// data
|
82 |
// type
|
83 |
// check that file extension is tif!!!
|
84 |
final TiledRasterLayer layer = new TiledRasterLayer(); |
85 |
layer.create(sName, sFilename, extent, iDataType, iBands, crs); |
86 |
return layer;
|
87 |
} else {
|
88 |
final gvRasterLayerWrite layer = new gvRasterLayerWrite(); |
89 |
layer.create(sName, sFilename, extent, iDataType, iBands, crs); |
90 |
return layer;
|
91 |
} |
92 |
} else {
|
93 |
throw new UnsupportedOutputChannelException(); |
94 |
} |
95 |
|
96 |
} |
97 |
|
98 |
@Override
|
99 |
public ITable getNewTable(final String sName, final Class types[], |
100 |
final String[] sFields, final IOutputChannel channel) |
101 |
throws UnsupportedOutputChannelException {
|
102 |
|
103 |
if (channel instanceof FileOutputChannel) { |
104 |
final String sFilename = |
105 |
((FileOutputChannel) channel).getFilename(); |
106 |
final gvTable table = new gvTable(); |
107 |
table.create(sName, sFilename, types, sFields); |
108 |
return table;
|
109 |
} else {
|
110 |
throw new UnsupportedOutputChannelException(); |
111 |
} |
112 |
|
113 |
} |
114 |
|
115 |
@Override
|
116 |
public String getTempFolder() { |
117 |
|
118 |
return Utilities.createTempDirectory(); |
119 |
|
120 |
} |
121 |
|
122 |
@Override
|
123 |
public String[] getRasterLayerOutputExtensions() { |
124 |
|
125 |
return FileTools.RASTER_EXT_IN;
|
126 |
|
127 |
} |
128 |
|
129 |
@Override
|
130 |
public String[] getVectorLayerOutputExtensions() { |
131 |
|
132 |
return new String[] { "shp", "dxf" }; |
133 |
|
134 |
} |
135 |
|
136 |
@Override
|
137 |
public String[] getTableOutputExtensions() { |
138 |
|
139 |
return new String[] { "dbf" }; |
140 |
|
141 |
} |
142 |
|
143 |
public void addMessage(final String s) { |
144 |
|
145 |
NotificationManager.addInfo(s, null);
|
146 |
|
147 |
} |
148 |
|
149 |
@Override
|
150 |
public ITaskMonitor getTaskMonitor(final String sTitle, |
151 |
final boolean bDeterminate, final JDialog parent) { |
152 |
|
153 |
return new DefaultTaskMonitor(sTitle, bDeterminate, parent); |
154 |
|
155 |
} |
156 |
|
157 |
@Override
|
158 |
public Object getDefaultCRS() { |
159 |
|
160 |
return ((ProjectPreferences) ApplicationLocator.getManager()
|
161 |
.getPreferences("project")).getDefaultProjection();
|
162 |
|
163 |
} |
164 |
|
165 |
private int getSizeFromTypeClass(final Class<?> type) { |
166 |
|
167 |
if (type.equals(Integer.class)) { |
168 |
return 10; |
169 |
} else
|
170 |
if (type.equals(Long.class)) { |
171 |
return 20; |
172 |
} else
|
173 |
if (type.equals(Double.class)) { |
174 |
return 20; |
175 |
} else
|
176 |
if (type.equals(Float.class)) { |
177 |
return 15; |
178 |
} else
|
179 |
if (type.equals(String.class)) { |
180 |
return 80; |
181 |
} else
|
182 |
if (type.equals(Date.class)) { |
183 |
return 10; |
184 |
} else
|
185 |
if (type.equals(Boolean.class)) { |
186 |
return 1; |
187 |
} else {
|
188 |
return 20; |
189 |
} |
190 |
|
191 |
} |
192 |
|
193 |
} |