1 |
package appl.data; |
2 |
|
3 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
4 |
|
5 |
import schmitzm.data.WritableGrid; |
6 |
import appl.util.RasterMetaData; |
7 |
import edu.bonn.xulu.appl.XuluRegistry; |
8 |
import edu.bonn.xulu.io.ImportFactory; |
9 |
import edu.bonn.xulu.plugin.io.grid.WritableGridFactory; |
10 |
|
11 |
/** |
12 |
* This is an a late loading implementation for {@link WritableGrid WritableGrids}. |
13 |
* |
14 |
* @author Dominik Appl |
15 |
*/ |
16 |
public class WritableGridLLProxy extends LateLoadingProxy implements |
17 |
WritableGrid { |
18 |
|
19 |
protected RasterMetaData metaData; |
20 |
|
21 |
public WritableGridLLProxy(ImportFactory importFac, |
22 |
RasterMetaData metaData, Object inputPara, XuluRegistry reg) { |
23 |
super(new ImportFactoryLoader(importFac, inputPara, reg)); |
24 |
this.metaData = metaData; |
25 |
} |
26 |
|
27 |
public WritableGridLLProxy(WritableGridFactory targetFactory, |
28 |
RasterMetaData metaData) { |
29 |
super(new FactoryLoader(targetFactory, metaData)); |
30 |
this.metaData = metaData; |
31 |
} |
32 |
|
33 |
public WritableGridLLProxy(RasterMetaData metaData) { |
34 |
super(new WritableGridArrayLoader(metaData)); |
35 |
baseObject = null; |
36 |
loaded = false; |
37 |
this.metaData = metaData; |
38 |
} |
39 |
|
40 |
protected WritableGridLLProxy(RasterMetaData metaData, DataLoader loader) { |
41 |
super(loader); |
42 |
loaded = false; |
43 |
this.metaData = metaData; |
44 |
} |
45 |
|
46 |
public double convertRasterToReal(int cell, int dim) { |
47 |
if (!loaded) |
48 |
tryLoadingGrid(); |
49 |
; |
50 |
return ((WritableGrid) baseObject).convertRasterToReal(cell, dim); |
51 |
} |
52 |
|
53 |
public int convertRealToRaster(double coord, int dim) { |
54 |
if (!loaded) |
55 |
tryLoadingGrid(); |
56 |
return ((WritableGrid) baseObject).convertRealToRaster(coord, dim); |
57 |
} |
58 |
|
59 |
/** @see WritableGrid#dispose() */ |
60 |
public void dispose() { |
61 |
if (baseObject != null) |
62 |
((WritableGrid) baseObject).dispose(); |
63 |
} |
64 |
|
65 |
public Object getGridSample(double... coord) { |
66 |
if (!loaded) |
67 |
tryLoadingGrid(); |
68 |
return ((WritableGrid) baseObject).getGridSample(); |
69 |
} |
70 |
|
71 |
public byte getGridSampleAsByte(double... coord) { |
72 |
if (!loaded) |
73 |
tryLoadingGrid(); |
74 |
return ((WritableGrid) baseObject).getGridSampleAsByte(coord); |
75 |
} |
76 |
|
77 |
public double getGridSampleAsDouble(double... coord) { |
78 |
if (!loaded) |
79 |
tryLoadingGrid(); |
80 |
return ((WritableGrid) baseObject).getGridSampleAsDouble(coord); |
81 |
} |
82 |
|
83 |
public float getGridSampleAsFloat(double... coord) { |
84 |
if (!loaded) |
85 |
tryLoadingGrid(); |
86 |
return ((WritableGrid) baseObject).getGridSampleAsFloat(coord); |
87 |
} |
88 |
|
89 |
public int getGridSampleAsInt(double... coord) { |
90 |
if (!loaded) |
91 |
tryLoadingGrid(); |
92 |
return ((WritableGrid) baseObject).getGridSampleAsInt(coord); |
93 |
} |
94 |
|
95 |
public long getGridSampleAsLong(double... coord) { |
96 |
if (!loaded) |
97 |
tryLoadingGrid(); |
98 |
return ((WritableGrid) baseObject).getGridSampleAsLong(coord); |
99 |
} |
100 |
|
101 |
public short getGridSampleAsShort(double... coord) { |
102 |
if (!loaded) |
103 |
tryLoadingGrid(); |
104 |
return ((WritableGrid) baseObject).getGridSampleAsShort(coord); |
105 |
} |
106 |
|
107 |
public CoordinateReferenceSystem getCoordinateReferenceSystem() { |
108 |
return metaData.getCoordinateReferenceSystem(); |
109 |
} |
110 |
|
111 |
public int getHeight() { |
112 |
return metaData.getHeight(); |
113 |
} |
114 |
|
115 |
public int getMinX() { |
116 |
return metaData.getMinX(); |
117 |
|
118 |
} |
119 |
|
120 |
public int getMinY() { |
121 |
return metaData.getMinY(); |
122 |
} |
123 |
|
124 |
public Object getRasterSample(int... cell) { |
125 |
if (!loaded) |
126 |
tryLoadingGrid(); |
127 |
return ((WritableGrid) baseObject).getRasterSample(cell); |
128 |
} |
129 |
|
130 |
public byte getRasterSampleAsByte(int... cell) { |
131 |
if (!loaded) |
132 |
tryLoadingGrid(); |
133 |
return ((WritableGrid) baseObject).getRasterSampleAsByte(cell); |
134 |
} |
135 |
|
136 |
public double getRasterSampleAsDouble(int... cell) { |
137 |
if (!loaded) |
138 |
tryLoadingGrid(); |
139 |
return ((WritableGrid) baseObject).getRasterSampleAsDouble(cell); |
140 |
} |
141 |
|
142 |
public float getRasterSampleAsFloat(int... cell) { |
143 |
if (!loaded) |
144 |
tryLoadingGrid(); |
145 |
return ((WritableGrid) baseObject).getRasterSampleAsFloat(cell); |
146 |
} |
147 |
|
148 |
public int getRasterSampleAsInt(int... cell) { |
149 |
if (!loaded) |
150 |
tryLoadingGrid(); |
151 |
return ((WritableGrid) baseObject).getRasterSampleAsInt(cell); |
152 |
} |
153 |
|
154 |
public long getRasterSampleAsLong(int... cell) { |
155 |
if (!loaded) |
156 |
tryLoadingGrid(); |
157 |
return ((WritableGrid) baseObject).getRasterSampleAsLong(cell); |
158 |
} |
159 |
|
160 |
public short getRasterSampleAsShort(int... cell) { |
161 |
if (!loaded) |
162 |
tryLoadingGrid(); |
163 |
return ((WritableGrid) baseObject).getRasterSampleAsShort(cell); |
164 |
} |
165 |
|
166 |
public double getRealHeight() { |
167 |
return metaData.getRealHeight(); |
168 |
} |
169 |
|
170 |
public double getRealWidth() { |
171 |
return metaData.getRealWidth(); |
172 |
} |
173 |
|
174 |
public int getSampleType() { |
175 |
return metaData.getDataType(); |
176 |
} |
177 |
|
178 |
/** Returns the Width of the Grid */ |
179 |
public int getWidth() { |
180 |
return metaData.getWidth(); |
181 |
} |
182 |
|
183 |
public double getX() { |
184 |
return metaData.getX(); |
185 |
} |
186 |
|
187 |
public double getY() { |
188 |
return metaData.getY(); |
189 |
} |
190 |
|
191 |
public void setGridSample(Object value, double... coord) { |
192 |
if (!loaded) |
193 |
tryLoadingGrid(); |
194 |
((WritableGrid) baseObject).setGridSample(value, coord); |
195 |
} |
196 |
|
197 |
public void setRasterSample(Object value, int... cell) { |
198 |
if (!loaded) |
199 |
tryLoadingGrid(); |
200 |
((WritableGrid) baseObject).setRasterSample(value, cell); |
201 |
|
202 |
} |
203 |
|
204 |
/** |
205 |
* Trys to load the grid and gives out an error to the LOG, if the loading |
206 |
* fails. |
207 |
*/ |
208 |
protected void tryLoadingGrid() { |
209 |
try { |
210 |
super.loadData(); |
211 |
} catch (LoadingException e) { |
212 |
LOG.error("Error while Loading Grid " + this + " from Source " |
213 |
+ e.getLoadSource()); |
214 |
e.printStackTrace(); |
215 |
} |
216 |
|
217 |
} |
218 |
|
219 |
/* |
220 |
* (non-Javadoc) |
221 |
* |
222 |
* @see schmitzm.data.WritableGrid#getCellHeight() |
223 |
*/ |
224 |
public double getCellHeight() { |
225 |
// TODO Auto-generated method stub |
226 |
return metaData.getCellHeight(); |
227 |
} |
228 |
|
229 |
/* |
230 |
* (non-Javadoc) |
231 |
* |
232 |
* @see schmitzm.data.WritableGrid#getCellWidth() |
233 |
*/ |
234 |
public double getCellWidth() { |
235 |
// TODO Auto-generated method stub |
236 |
return metaData.getCellWidth(); |
237 |
} |
238 |
|
239 |
/** |
240 |
* This class supports late loading |
241 |
* |
242 |
* @see appl.data.LateLoadable#unloadData() |
243 |
* @return true; |
244 |
* @see appl.data.LateLoadable#isLateLoadable() |
245 |
*/ |
246 |
public boolean isLateLoadable() { |
247 |
return true; |
248 |
} |
249 |
} |