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