gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.legend / org.gvsig.raster.lib.legend.impl / src / test / java / org / gvsig / raster / lib / legend / impl / DefaultRasterLegendTest.java @ 6899
History | View | Annotate | Download (24.5 KB)
1 |
package org.gvsig.raster.lib.legend.impl; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.image.BufferedImage; |
6 |
import java.io.File; |
7 |
import java.io.IOException; |
8 |
import java.net.URL; |
9 |
import java.util.ArrayList; |
10 |
import java.util.Arrays; |
11 |
import java.util.List; |
12 |
|
13 |
import javax.imageio.ImageIO; |
14 |
|
15 |
import org.apache.commons.lang3.tuple.Pair; |
16 |
import org.cresques.cts.IProjection; |
17 |
|
18 |
import org.gvsig.fmap.crs.CRSFactory; |
19 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
20 |
import org.gvsig.fmap.geom.GeometryLocator; |
21 |
import org.gvsig.fmap.geom.GeometryManager; |
22 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
23 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
24 |
import org.gvsig.fmap.geom.primitive.Envelope; |
25 |
import org.gvsig.fmap.mapcontext.ViewPort; |
26 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
27 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
28 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
29 |
import org.gvsig.raster.lib.buffer.api.NoData; |
30 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException; |
31 |
import org.gvsig.raster.lib.legend.api.ColorInterpretation; |
32 |
import org.gvsig.raster.lib.legend.api.RasterLegend; |
33 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
34 |
import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
35 |
import org.gvsig.raster.lib.legend.api.Transparency; |
36 |
import org.gvsig.raster.lib.legend.api.colortable.ColorTable; |
37 |
import org.gvsig.raster.lib.legend.api.colortable.ColorTableClass; |
38 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
39 |
|
40 |
/**
|
41 |
*
|
42 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
43 |
*
|
44 |
*/
|
45 |
@SuppressWarnings("javadoc") |
46 |
public class DefaultRasterLegendTest extends AbstractLibraryAutoInitTestCase { |
47 |
|
48 |
private final Number defaultNoDataValue = 10; |
49 |
private final Number noDataValue = 20; |
50 |
|
51 |
private RasterLegend rasterLegend;
|
52 |
|
53 |
@Override
|
54 |
protected void doSetUp() throws Exception { |
55 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
56 |
rasterLegend = rasterLegendManager.createLegend(); |
57 |
} |
58 |
|
59 |
public void testDrawRGBBuffer() { |
60 |
|
61 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
62 |
|
63 |
int[] bandDataTypes = |
64 |
new int[] { BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE }; |
65 |
|
66 |
NoData[] bandNodata = new NoData[6]; |
67 |
Arrays.fill(bandNodata,
|
68 |
BufferLocator.getBufferManager().createNoData(noDataValue, defaultNoDataValue)); |
69 |
|
70 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
71 |
Envelope envelope = null;
|
72 |
try {
|
73 |
envelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
74 |
} catch (CreateEnvelopeException e) {
|
75 |
fail("Can create envelope of buffer");
|
76 |
} |
77 |
try {
|
78 |
envelope.setLowerCorner(geometryManager.createPoint(100475.75, 3987254.0, |
79 |
SUBTYPES.GEOM2D)); |
80 |
envelope.setUpperCorner(geometryManager.createPoint(621675.75, 4301354.0, |
81 |
SUBTYPES.GEOM2D)); |
82 |
} catch (CreateGeometryException e) {
|
83 |
fail("Can create point to set envelope");
|
84 |
} |
85 |
|
86 |
Buffer buffer = null; |
87 |
IProjection projection = CRSFactory.getCRS("EPSG:25830");
|
88 |
try {
|
89 |
byte[] byteData = new byte[] { -86, 72, 102, -70, -3, -59, -36, 76, 66, 20 }; |
90 |
buffer = |
91 |
bufferManager.createBuffer(10, 10, bandDataTypes, bandNodata, projection, envelope); |
92 |
|
93 |
for (int i = 0; i < 10; i++) { |
94 |
buffer.getBand(0).putRow(i, byteData);
|
95 |
buffer.getBand(1).putRow(i, byteData);
|
96 |
buffer.getBand(2).putRow(i, byteData);
|
97 |
} |
98 |
|
99 |
} catch (BufferException e) {
|
100 |
fail("Error creating buffer");
|
101 |
} |
102 |
|
103 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
104 |
ColorInterpretation colorInterpretation = |
105 |
rasterLegendManager.createColorInterpretation(ColorInterpretation.RGB); |
106 |
rasterLegend = rasterLegendManager.createLegend(colorInterpretation); |
107 |
|
108 |
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); |
109 |
ViewPort viewPort = new ViewPort(projection);
|
110 |
viewPort.setEnvelope(envelope); |
111 |
viewPort.setImageSize(new Dimension(500, 500)); |
112 |
viewPort.refreshExtent(); |
113 |
|
114 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null);
|
115 |
} |
116 |
|
117 |
public void testDrawRGBBufferWithTransparency() { |
118 |
|
119 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
120 |
|
121 |
int[] bandDataTypes = |
122 |
new int[] { BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE}; |
123 |
|
124 |
NoData[] bandNodata = new NoData[6]; |
125 |
Arrays.fill(bandNodata,
|
126 |
BufferLocator.getBufferManager().createNoData(noDataValue, defaultNoDataValue)); |
127 |
|
128 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
129 |
Envelope envelope = null;
|
130 |
try {
|
131 |
envelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
132 |
} catch (CreateEnvelopeException e) {
|
133 |
fail("Can create envelope of buffer");
|
134 |
} |
135 |
try {
|
136 |
envelope.setLowerCorner(geometryManager.createPoint(100475.75, 3987254.0, |
137 |
SUBTYPES.GEOM2D)); |
138 |
envelope.setUpperCorner(geometryManager.createPoint(621675.75, 4301354.0, |
139 |
SUBTYPES.GEOM2D)); |
140 |
} catch (CreateGeometryException e) {
|
141 |
fail("Can create point to set envelope");
|
142 |
} |
143 |
|
144 |
Buffer buffer = null; |
145 |
IProjection projection = CRSFactory.getCRS("EPSG:25830");
|
146 |
try {
|
147 |
byte[] byteData = new byte[] { -86, 72, 102, -70, -3, -59, -36, 76, 66, 20 }; |
148 |
buffer = |
149 |
bufferManager.createBuffer(10, 10, bandDataTypes, bandNodata, projection, envelope); |
150 |
|
151 |
for (int i = 0; i < 10; i++) { |
152 |
buffer.getBand(0).putRow(i, byteData);
|
153 |
buffer.getBand(1).putRow(i, byteData);
|
154 |
buffer.getBand(2).putRow(i, byteData);
|
155 |
} |
156 |
|
157 |
} catch (BufferException e) {
|
158 |
fail("Error creating buffer");
|
159 |
} |
160 |
|
161 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
162 |
ColorInterpretation colorInterpretation = |
163 |
rasterLegendManager.createColorInterpretation(ColorInterpretation.RGB); |
164 |
Transparency transparency = rasterLegendManager.createTransparency(30, null); |
165 |
rasterLegend = |
166 |
rasterLegendManager.createLegend(colorInterpretation, null, transparency, null); |
167 |
|
168 |
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); |
169 |
ViewPort viewPort = new ViewPort(projection);
|
170 |
viewPort.setEnvelope(envelope); |
171 |
viewPort.setImageSize(new Dimension(500, 500)); |
172 |
viewPort.refreshExtent(); |
173 |
|
174 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null);
|
175 |
} |
176 |
|
177 |
public void testDrawRGBBufferProjected(){ |
178 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
179 |
|
180 |
int[] bandDataTypes = |
181 |
new int[] { BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE}; |
182 |
|
183 |
NoData[] bandNodata = new NoData[6]; |
184 |
Arrays.fill(bandNodata,
|
185 |
BufferLocator.getBufferManager().createNoData(noDataValue, defaultNoDataValue)); |
186 |
|
187 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
188 |
Envelope envelope = null;
|
189 |
Envelope bufferEnvelope = null;
|
190 |
try {
|
191 |
bufferEnvelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
192 |
envelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
193 |
} catch (CreateEnvelopeException e) {
|
194 |
fail("Can create envelope of buffer");
|
195 |
} |
196 |
try {
|
197 |
bufferEnvelope.setLowerCorner(geometryManager.createPoint(625397.5, 4446997.5, |
198 |
SUBTYPES.GEOM2D)); |
199 |
bufferEnvelope.setUpperCorner(geometryManager.createPoint(654602.5, 4466602.5, |
200 |
SUBTYPES.GEOM2D)); |
201 |
envelope.setLowerCorner(geometryManager.createPoint(-1.58, 40.06, SUBTYPES.GEOM2D)); |
202 |
envelope.setUpperCorner(geometryManager.createPoint(-1.12, 40.45, SUBTYPES.GEOM2D)); |
203 |
} catch (CreateGeometryException e) {
|
204 |
fail("Can create point to set envelope");
|
205 |
} |
206 |
|
207 |
Buffer buffer = null; |
208 |
IProjection epsg25830 = CRSFactory.getCRS("EPSG:25830");
|
209 |
try {
|
210 |
byte[] byteData = new byte[1000]; |
211 |
for(int i = 0; i < 1000; i++){ |
212 |
byteData[i] = (byte) (i * 255 / 1000); |
213 |
} |
214 |
|
215 |
buffer = |
216 |
bufferManager.createBuffer(1000, 1000, bandDataTypes, bandNodata, epsg25830, bufferEnvelope); |
217 |
|
218 |
for (int i = 0; i < 1000; i++) { |
219 |
buffer.getBand(0).putRow(i, byteData);
|
220 |
buffer.getBand(1).putRow(i, byteData);
|
221 |
buffer.getBand(2).putRow(i, byteData);
|
222 |
} |
223 |
|
224 |
} catch (BufferException e) {
|
225 |
fail("Error creating buffer");
|
226 |
} |
227 |
|
228 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
229 |
ColorInterpretation colorInterpretation = |
230 |
rasterLegendManager.createColorInterpretation(ColorInterpretation.RGB); |
231 |
rasterLegend = |
232 |
rasterLegendManager.createLegend(colorInterpretation, null, null, null); |
233 |
|
234 |
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); |
235 |
IProjection epsg4326 = CRSFactory.getCRS("EPSG:4326");
|
236 |
ViewPort viewPort = new ViewPort(epsg4326);
|
237 |
viewPort.setEnvelope(envelope); |
238 |
viewPort.setImageSize(new Dimension(500, 500)); |
239 |
viewPort.refreshExtent(); |
240 |
|
241 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null);
|
242 |
} |
243 |
|
244 |
public void testDrawRGBBufferProjected2(){ |
245 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
246 |
|
247 |
int[] bandDataTypes = |
248 |
new int[] { BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE}; |
249 |
|
250 |
NoData[] bandNodata = new NoData[6]; |
251 |
Arrays.fill(bandNodata,
|
252 |
BufferLocator.getBufferManager().createNoData(noDataValue, defaultNoDataValue)); |
253 |
|
254 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
255 |
Envelope envelope = null;
|
256 |
Envelope bufferEnvelope = null;
|
257 |
try {
|
258 |
bufferEnvelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
259 |
envelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
260 |
} catch (CreateEnvelopeException e) {
|
261 |
fail("Can create envelope of buffer");
|
262 |
} |
263 |
try {
|
264 |
bufferEnvelope.setLowerCorner(geometryManager.createPoint(625397.5, 4446997.5, |
265 |
SUBTYPES.GEOM2D)); |
266 |
bufferEnvelope.setUpperCorner(geometryManager.createPoint(654602.5, 4466602.5, |
267 |
SUBTYPES.GEOM2D)); |
268 |
envelope.setLowerCorner(geometryManager.createPoint(-1.29, 40.089, SUBTYPES.GEOM2D)); |
269 |
envelope.setUpperCorner(geometryManager.createPoint(-0.95, 40.43, SUBTYPES.GEOM2D)); |
270 |
} catch (CreateGeometryException e) {
|
271 |
fail("Can create point to set envelope");
|
272 |
} |
273 |
|
274 |
Buffer buffer = null; |
275 |
IProjection epsg25830 = CRSFactory.getCRS("EPSG:25830");
|
276 |
try {
|
277 |
byte[] byteData = new byte[1000]; |
278 |
for(int i = 0; i < 1000; i++){ |
279 |
byteData[i] = (byte) (i * 255 / 1000); |
280 |
} |
281 |
|
282 |
buffer = |
283 |
bufferManager.createBuffer(1000, 1000, bandDataTypes, bandNodata, epsg25830, bufferEnvelope); |
284 |
|
285 |
for (int i = 0; i < 1000; i++) { |
286 |
buffer.getBand(0).putRow(i, byteData);
|
287 |
buffer.getBand(1).putRow(i, byteData);
|
288 |
buffer.getBand(2).putRow(i, byteData);
|
289 |
} |
290 |
|
291 |
} catch (BufferException e) {
|
292 |
fail("Error creating buffer");
|
293 |
} |
294 |
|
295 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
296 |
ColorInterpretation colorInterpretation = |
297 |
rasterLegendManager.createColorInterpretation(ColorInterpretation.RGB); |
298 |
rasterLegend = |
299 |
rasterLegendManager.createLegend(colorInterpretation, null, null, null); |
300 |
|
301 |
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); |
302 |
IProjection epsg4326 = CRSFactory.getCRS("EPSG:4326");
|
303 |
ViewPort viewPort = new ViewPort(epsg4326);
|
304 |
viewPort.setEnvelope(envelope); |
305 |
viewPort.setImageSize(new Dimension(500, 500)); |
306 |
viewPort.refreshExtent(); |
307 |
|
308 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null);
|
309 |
} |
310 |
|
311 |
public void testDrawRGBBufferProjected3(){ |
312 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
313 |
|
314 |
int[] bandDataTypes = |
315 |
new int[] { BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE}; |
316 |
|
317 |
NoData[] bandNodata = new NoData[6]; |
318 |
Arrays.fill(bandNodata,
|
319 |
BufferLocator.getBufferManager().createNoData(noDataValue, defaultNoDataValue)); |
320 |
|
321 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
322 |
Envelope envelope = null;
|
323 |
Envelope bufferEnvelope = null;
|
324 |
try {
|
325 |
bufferEnvelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
326 |
envelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
327 |
} catch (CreateEnvelopeException e) {
|
328 |
fail("Can create envelope of buffer");
|
329 |
} |
330 |
try {
|
331 |
bufferEnvelope.setLowerCorner(geometryManager.createPoint(625397.5, 4446997.5, |
332 |
SUBTYPES.GEOM2D)); |
333 |
bufferEnvelope.setUpperCorner(geometryManager.createPoint(654602.5, 4466602.5, |
334 |
SUBTYPES.GEOM2D)); |
335 |
envelope.setLowerCorner(geometryManager.createPoint(-1.38, 40.19, SUBTYPES.GEOM2D)); |
336 |
envelope.setUpperCorner(geometryManager.createPoint(-1.27, 40.29, SUBTYPES.GEOM2D)); |
337 |
} catch (CreateGeometryException e) {
|
338 |
fail("Can create point to set envelope");
|
339 |
} |
340 |
|
341 |
Buffer buffer = null; |
342 |
IProjection epsg25830 = CRSFactory.getCRS("EPSG:25830");
|
343 |
try {
|
344 |
byte[] byteData = new byte[1000]; |
345 |
for(int i = 0; i < 1000; i++){ |
346 |
byteData[i] = (byte) (i * 255 / 1000); |
347 |
} |
348 |
|
349 |
buffer = |
350 |
bufferManager.createBuffer(1000, 1000, bandDataTypes, bandNodata, epsg25830, bufferEnvelope); |
351 |
|
352 |
for (int i = 0; i < 1000; i++) { |
353 |
buffer.getBand(0).putRow(i, byteData);
|
354 |
buffer.getBand(1).putRow(i, byteData);
|
355 |
buffer.getBand(2).putRow(i, byteData);
|
356 |
} |
357 |
|
358 |
} catch (BufferException e) {
|
359 |
fail("Error creating buffer");
|
360 |
} |
361 |
|
362 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
363 |
ColorInterpretation colorInterpretation = |
364 |
rasterLegendManager.createColorInterpretation(ColorInterpretation.RGB); |
365 |
rasterLegend = |
366 |
rasterLegendManager.createLegend(colorInterpretation, null, null, null); |
367 |
|
368 |
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); |
369 |
IProjection epsg4326 = CRSFactory.getCRS("EPSG:4326");
|
370 |
ViewPort viewPort = new ViewPort(epsg4326);
|
371 |
viewPort.setEnvelope(envelope); |
372 |
viewPort.setImageSize(new Dimension(500, 500)); |
373 |
viewPort.refreshExtent(); |
374 |
|
375 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null);
|
376 |
} |
377 |
|
378 |
public void testDrawARGBBuffer() { |
379 |
|
380 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
381 |
|
382 |
int[] bandDataTypes = |
383 |
new int[] { BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE, |
384 |
BufferManager.TYPE_BYTE }; |
385 |
|
386 |
NoData[] bandNodata = new NoData[6]; |
387 |
Arrays.fill(bandNodata,
|
388 |
BufferLocator.getBufferManager().createNoData(noDataValue, defaultNoDataValue)); |
389 |
|
390 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
391 |
Envelope envelope = null;
|
392 |
Envelope bufferEnvelope = null;
|
393 |
try {
|
394 |
envelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
395 |
bufferEnvelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
396 |
} catch (CreateEnvelopeException e) {
|
397 |
fail("Can create envelope of buffer");
|
398 |
} |
399 |
try {
|
400 |
envelope.setLowerCorner(geometryManager.createPoint(232474, 4029567, SUBTYPES.GEOM2D)); |
401 |
envelope.setUpperCorner(geometryManager.createPoint(492587, 4251757, SUBTYPES.GEOM2D)); |
402 |
bufferEnvelope.setLowerCorner(geometryManager.createPoint(100475.75, 3987254.0, |
403 |
SUBTYPES.GEOM2D)); |
404 |
bufferEnvelope.setUpperCorner(geometryManager.createPoint(621675.75, 4301354.0, |
405 |
SUBTYPES.GEOM2D)); |
406 |
} catch (CreateGeometryException e) {
|
407 |
fail("Can create point to set envelope");
|
408 |
} |
409 |
|
410 |
Buffer buffer = null; |
411 |
IProjection projection = CRSFactory.getCRS("EPSG:25830");
|
412 |
try {
|
413 |
byte[] redByteData = new byte[] { -86, 72, 102, -70, -3, -59, -36, 76, 66, 20 }; |
414 |
byte[] greenByteData = new byte[] { 45, 02, 41, 41, -3, 74, 96, -10, 10, -4 }; |
415 |
byte[] blueByteData = new byte[] { 0, 45, 04, 78, 54, -3, 02, 62, 43, 36 }; |
416 |
byte[] alphaByteData = new byte[] { -10, -5, 47, 14, 0, -127, 44, 48, -66, -20 }; |
417 |
buffer = |
418 |
bufferManager.createBuffer(10, 10, bandDataTypes, bandNodata, projection, |
419 |
bufferEnvelope); |
420 |
|
421 |
for (int i = 0; i < 10; i++) { |
422 |
buffer.getBand(0).putRow(i, redByteData);
|
423 |
buffer.getBand(1).putRow(i, greenByteData);
|
424 |
buffer.getBand(2).putRow(i, blueByteData);
|
425 |
buffer.getBand(3).putRow(i, alphaByteData);
|
426 |
} |
427 |
|
428 |
} catch (BufferException e) {
|
429 |
fail("Error creating buffer");
|
430 |
} |
431 |
|
432 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
433 |
ColorInterpretation colorInterpretation = |
434 |
rasterLegendManager.createColorInterpretation(ColorInterpretation.ARGB); |
435 |
rasterLegend = rasterLegendManager.createLegend(colorInterpretation); |
436 |
|
437 |
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); |
438 |
ViewPort viewPort = new ViewPort(projection);
|
439 |
viewPort.setEnvelope(envelope); |
440 |
viewPort.setImageSize(new Dimension(500, 500)); |
441 |
viewPort.refreshExtent(); |
442 |
|
443 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null);
|
444 |
} |
445 |
|
446 |
public void testDrawGreyBuffer() { |
447 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
448 |
|
449 |
int[] bandDataTypes = new int[] { BufferManager.TYPE_FLOAT }; |
450 |
|
451 |
NoData[] bandNodata = new NoData[6]; |
452 |
Arrays.fill(bandNodata,
|
453 |
BufferLocator.getBufferManager().createNoData(noDataValue, defaultNoDataValue)); |
454 |
|
455 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
456 |
Envelope envelope = null;
|
457 |
Envelope bufferEnvelope = null;
|
458 |
try {
|
459 |
envelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
460 |
bufferEnvelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
461 |
} catch (CreateEnvelopeException e) {
|
462 |
fail("Can create envelope of buffer");
|
463 |
} |
464 |
try {
|
465 |
bufferEnvelope.setLowerCorner(geometryManager.createPoint(232474, 4029567, |
466 |
SUBTYPES.GEOM2D)); |
467 |
bufferEnvelope.setUpperCorner(geometryManager.createPoint(492587, 4251757, |
468 |
SUBTYPES.GEOM2D)); |
469 |
envelope.setLowerCorner(geometryManager.createPoint(100475.75, 3987254.0, |
470 |
SUBTYPES.GEOM2D)); |
471 |
envelope.setUpperCorner(geometryManager.createPoint(621675.75, 4301354.0, |
472 |
SUBTYPES.GEOM2D)); |
473 |
} catch (CreateGeometryException e) {
|
474 |
fail("Can create point to set envelope");
|
475 |
} |
476 |
|
477 |
Buffer buffer = null; |
478 |
IProjection projection = CRSFactory.getCRS("EPSG:25830");
|
479 |
try {
|
480 |
float[] valueData = new float[] { -20, 25, 85, 41, 0, 120, 41, 74, 38, 01 }; |
481 |
buffer = |
482 |
bufferManager.createBuffer(10, 10, bandDataTypes, bandNodata, projection, |
483 |
bufferEnvelope); |
484 |
|
485 |
for (int i = 0; i < 10; i++) { |
486 |
buffer.getBand(0).putRow(i, valueData);
|
487 |
} |
488 |
|
489 |
} catch (BufferException e) {
|
490 |
fail("Error creating buffer");
|
491 |
} |
492 |
|
493 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
494 |
ColorInterpretation colorInterpretation = |
495 |
rasterLegendManager.createColorInterpretation(ColorInterpretation.GRAYSCALE); |
496 |
|
497 |
List<ColorTableClass> colorTableClasses = new ArrayList<ColorTableClass>(); |
498 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("0", 0, 50, Color.BLACK)); |
499 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("1", 20, 50, Color.CYAN)); |
500 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("2", 40, 50, Color.RED)); |
501 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("3", 60, 50, Color.BLUE)); |
502 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("4", 80, 50, Color.WHITE)); |
503 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("5", 100, 50, Color.GRAY)); |
504 |
|
505 |
ColorTable colorTable = |
506 |
rasterLegendManager.createColorTable("testColorTable", colorTableClasses, false); |
507 |
Transparency transparency = rasterLegendManager.createTransparency(160, null); |
508 |
rasterLegend = |
509 |
rasterLegendManager.createLegend(colorInterpretation, colorTable, transparency, null);
|
510 |
|
511 |
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); |
512 |
ViewPort viewPort = new ViewPort(projection);
|
513 |
viewPort.setEnvelope(envelope); |
514 |
viewPort.setImageSize(new Dimension(500, 500)); |
515 |
viewPort.refreshExtent(); |
516 |
|
517 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null);
|
518 |
} |
519 |
|
520 |
public void testGetColorTable() { |
521 |
|
522 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
523 |
ColorTable colorTable = |
524 |
rasterLegendManager.createColorTable("testColorTable",
|
525 |
new ArrayList<ColorTableClass>(), false); |
526 |
|
527 |
assertNull(rasterLegend.getColorTable()); |
528 |
rasterLegend.setColorTable(colorTable); |
529 |
assertNotNull(rasterLegend.getColorTable()); |
530 |
assertEquals("testColorTable", rasterLegend.getColorTable().getName());
|
531 |
} |
532 |
|
533 |
public void testSetColorTable() { |
534 |
|
535 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
536 |
ColorTable colorTable = |
537 |
rasterLegendManager.createColorTable("testColorTable",
|
538 |
new ArrayList<ColorTableClass>(), false); |
539 |
|
540 |
assertNull(rasterLegend.getColorTable()); |
541 |
rasterLegend.setColorTable(colorTable); |
542 |
assertNotNull(rasterLegend.getColorTable()); |
543 |
} |
544 |
|
545 |
public void testGetColorInterpretation() { |
546 |
|
547 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
548 |
ColorInterpretation colorInterpretation = |
549 |
rasterLegendManager.createColorInterpretation(ColorInterpretation.RGB); |
550 |
|
551 |
assertNull(rasterLegend.getColorInterpretation()); |
552 |
rasterLegend.setColorInterpretation(colorInterpretation); |
553 |
assertNotNull(rasterLegend.getColorInterpretation()); |
554 |
} |
555 |
|
556 |
public void testSetColorInterpretation() { |
557 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
558 |
ColorInterpretation colorInterpretation = |
559 |
rasterLegendManager.createColorInterpretation(ColorInterpretation.RGB); |
560 |
|
561 |
assertNull(rasterLegend.getColorInterpretation()); |
562 |
rasterLegend.setColorInterpretation(colorInterpretation); |
563 |
assertNotNull(rasterLegend.getColorInterpretation()); |
564 |
} |
565 |
|
566 |
public void testGetColorTablesFile(){ |
567 |
|
568 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
569 |
URL resource = this.getClass().getClassLoader().getResource("colorTables"); |
570 |
File colorTableFoler = new File(resource.getFile()); |
571 |
List<Pair<File, ColorTable>> colorTables = rasterLegendManager.getColorTables(colorTableFoler); |
572 |
|
573 |
assertEquals(3, colorTables.size());
|
574 |
for (Pair<File, ColorTable> colorTable : colorTables) { |
575 |
if (!colorTable.getValue().getName().equals("GIMP Gradient") |
576 |
&& colorTable.getValue().getName().equals("GIMP Palette")
|
577 |
&& colorTable.getValue().getName().equals("1 Forest - Soil (100)")) {
|
578 |
fail(colorTable.getValue().getName().concat(" is not recognised"));
|
579 |
} |
580 |
} |
581 |
} |
582 |
} |