1 |
alfonx |
1217 |
package skrueger.geotools; |
2 |
|
|
|
3 |
|
|
import static org.junit.Assert.assertNotNull; |
4 |
|
|
import static org.junit.Assert.assertTrue; |
5 |
|
|
|
6 |
|
|
import java.awt.image.BufferedImage; |
7 |
|
|
import java.net.URL; |
8 |
|
|
|
9 |
|
|
import org.geotools.coverage.grid.GridCoverage2D; |
10 |
|
|
import org.geotools.data.DataUtilities; |
11 |
|
|
import org.geotools.gce.geotiff.GeoTiffReader; |
12 |
|
|
import org.geotools.map.DefaultMapLayer; |
13 |
|
|
import org.geotools.styling.Style; |
14 |
|
|
import org.junit.Test; |
15 |
|
|
|
16 |
|
|
import schmitzm.geotools.grid.GridUtil; |
17 |
|
|
import schmitzm.geotools.io.GeoImportUtil; |
18 |
|
|
import schmitzm.geotools.io.GeoImportUtil.ARCASCII_IMPORT_TYPE; |
19 |
|
|
import schmitzm.swing.TestingUtil; |
20 |
|
|
|
21 |
|
|
public class RasterTest { |
22 |
|
|
|
23 |
|
|
@Test |
24 |
|
|
public void testJustColorsGeotiffRGB_GeoTiffReaderWithFileObject() |
25 |
|
|
throws Throwable { |
26 |
|
|
URL url = TestingUtil.TestDatasetsRaster.geotiffRGBWithoutSLD.getUrl(); |
27 |
|
|
GeoTiffReader gc = new GeoTiffReader(DataUtilities.urlToFile(url)); |
28 |
|
|
assertNotNull(gc); |
29 |
|
|
|
30 |
|
|
Style createDefaultStyle = GridUtil.createDefaultStyle(); |
31 |
|
|
DefaultMapLayer mlayer = new DefaultMapLayer(gc, createDefaultStyle); |
32 |
|
|
|
33 |
|
|
checkMapLayer_GEOTIFF_RGB(mlayer); |
34 |
|
|
|
35 |
|
|
gc.dispose(); |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
@Test |
39 |
|
|
public void testTransparencyOfGeotiffWithSLD_GeoTiffReaderWithFileObject() |
40 |
|
|
throws Throwable { |
41 |
|
|
|
42 |
|
|
URL url = TestingUtil.TestDatasetsRaster.geotiffWithSld.getUrl(); |
43 |
|
|
|
44 |
|
|
GeoTiffReader gc = new GeoTiffReader(DataUtilities.urlToFile(url)); |
45 |
|
|
assertNotNull(gc); |
46 |
|
|
|
47 |
|
|
DefaultMapLayer mlayer = new DefaultMapLayer(gc, |
48 |
|
|
TestingUtil.TestDatasetsRaster.geotiffWithSld.getSldStyle()); |
49 |
|
|
|
50 |
|
|
checkMapLayer_GEOTIFF_WITH_SLD(mlayer); |
51 |
|
|
|
52 |
|
|
gc.dispose(); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
@Test |
56 |
|
|
public void testTransparencyOfGeotiffWithSLD_GeoTiffReaderWithURL2FileObject() |
57 |
|
|
throws Throwable { |
58 |
|
|
URL url = TestingUtil.TestDatasetsRaster.geotiffWithSld.getUrl(); |
59 |
|
|
GeoTiffReader gc = new GeoTiffReader(url); |
60 |
|
|
assertNotNull(gc); |
61 |
|
|
|
62 |
|
|
DefaultMapLayer mlayer = new DefaultMapLayer(gc, |
63 |
|
|
TestingUtil.TestDatasetsRaster.geotiffWithSld.getSldStyle()); |
64 |
|
|
|
65 |
|
|
checkMapLayer_GEOTIFF_WITH_SLD(mlayer); |
66 |
|
|
|
67 |
|
|
gc.dispose(); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
@Test |
71 |
|
|
public void testTransparencyOfAAIGridWithSLD_AAIGridReaderWithFileObject_USE_ARCGRIDREADER() |
72 |
|
|
throws Throwable { |
73 |
|
|
GeoImportUtil |
74 |
|
|
.setAsciiRasterImportMode(ARCASCII_IMPORT_TYPE.USE_ARCGRIDREADER); |
75 |
|
|
GridCoverage2D gc = GeoImportUtil |
76 |
|
|
.readGridFromArcInfoASCII(DataUtilities |
77 |
|
|
.urlToFile(TestingUtil.TestDatasetsRaster.arcAscii |
78 |
|
|
.getUrl())); |
79 |
|
|
assertNotNull(gc); |
80 |
|
|
|
81 |
|
|
DefaultMapLayer mlayer = new DefaultMapLayer(gc, |
82 |
|
|
TestingUtil.TestDatasetsRaster.arcAscii.getSldStyle()); |
83 |
|
|
|
84 |
|
|
checkMapLayer_AAIGrid_Transparency_with_Sld(mlayer); |
85 |
|
|
|
86 |
|
|
gc.dispose(true); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
@Test |
90 |
|
|
// @Ignore |
91 |
|
|
public void testTransparencyOfAAIGridWithSLD_AAIGridReaderWithURL2FileObject_USE_ARCGRIDREADER() |
92 |
|
|
throws Throwable { |
93 |
|
|
GeoImportUtil |
94 |
|
|
.setAsciiRasterImportMode(ARCASCII_IMPORT_TYPE.USE_ARCGRIDREADER); |
95 |
|
|
GridCoverage2D gc = GeoImportUtil |
96 |
|
|
.readGridFromArcInfoASCII(TestingUtil.TestDatasetsRaster.arcAscii |
97 |
|
|
.getUrl()); |
98 |
|
|
assertNotNull(gc); |
99 |
|
|
|
100 |
|
|
DefaultMapLayer mlayer = new DefaultMapLayer(gc, |
101 |
|
|
TestingUtil.TestDatasetsRaster.arcAscii.getSldStyle()); |
102 |
|
|
|
103 |
|
|
checkMapLayer_AAIGrid_Transparency_with_Sld(mlayer); |
104 |
|
|
|
105 |
|
|
gc.dispose(true); |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
@Test |
109 |
|
|
public void testTransparencyOfAAIGridWithSLD_AAIGridReaderWithFileObject_USE_ARCGRIDRASTER() |
110 |
|
|
throws Throwable { |
111 |
|
|
GeoImportUtil |
112 |
|
|
.setAsciiRasterImportMode(ARCASCII_IMPORT_TYPE.USE_ARCGRIDRASTER); |
113 |
|
|
GridCoverage2D gc = GeoImportUtil |
114 |
|
|
.readGridFromArcInfoASCII(DataUtilities |
115 |
|
|
.urlToFile(TestingUtil.TestDatasetsRaster.arcAscii |
116 |
|
|
.getUrl())); |
117 |
|
|
assertNotNull(gc); |
118 |
|
|
|
119 |
|
|
DefaultMapLayer mlayer = new DefaultMapLayer(gc, |
120 |
|
|
TestingUtil.TestDatasetsRaster.arcAscii.getSldStyle()); |
121 |
|
|
|
122 |
|
|
checkMapLayer_AAIGrid_Transparency_with_Sld(mlayer); |
123 |
|
|
|
124 |
|
|
gc.dispose(true); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
@Test |
128 |
|
|
public void testTransparencyOfAAIGridWithSLD_AAIGridReaderWithURL2FileObject_USE_ARCGRIDRASTER() |
129 |
|
|
throws Throwable { |
130 |
|
|
GeoImportUtil |
131 |
|
|
.setAsciiRasterImportMode(ARCASCII_IMPORT_TYPE.USE_ARCGRIDRASTER); |
132 |
|
|
GridCoverage2D gc = GeoImportUtil |
133 |
|
|
.readGridFromArcInfoASCII(TestingUtil.TestDatasetsRaster.arcAscii |
134 |
|
|
.getUrl()); |
135 |
|
|
assertNotNull(gc); |
136 |
|
|
|
137 |
|
|
DefaultMapLayer mlayer = new DefaultMapLayer(gc, |
138 |
|
|
TestingUtil.TestDatasetsRaster.arcAscii.getSldStyle()); |
139 |
|
|
|
140 |
|
|
checkMapLayer_AAIGrid_Transparency_with_Sld(mlayer); |
141 |
|
|
|
142 |
|
|
gc.dispose(true); |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
private void checkMapLayer_AAIGrid_Transparency_with_Sld( |
146 |
|
|
DefaultMapLayer mlayer) throws Throwable { |
147 |
|
|
BufferedImage bi = TestingUtil.visualize(mlayer); |
148 |
|
|
|
149 |
|
|
assertTrue("Some blue color at 20/30", |
150 |
|
|
TestingUtil.checkPixel(bi, 20, 30, 129, 180, 217, 255)); |
151 |
|
|
assertTrue("Some blue color at 24/34", |
152 |
|
|
TestingUtil.checkPixel(bi, 24, 34, 124, 175, 215, 255)); |
153 |
|
|
assertTrue("Transparency at 10/10", |
154 |
|
|
TestingUtil.checkPixel(bi, 10, 10, 0, 0, 0, 0)); |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
public static void checkMapLayer_GEOTIFF_RGB(DefaultMapLayer mlayer) |
158 |
|
|
throws Throwable { |
159 |
|
|
BufferedImage bi = TestingUtil.visualize(mlayer); |
160 |
|
|
|
161 |
|
|
assertTrue("Some specific color at 50/50", |
162 |
|
|
TestingUtil.checkPixel(bi, 50, 50, 126, 221, 42, 255)); |
163 |
|
|
assertTrue("Some red color at 1/1", |
164 |
|
|
TestingUtil.checkPixel(bi, 1, 1, 230, 76, 0, 255)); |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
public static void checkMapLayer_GEOTIFF_WITH_SLD(DefaultMapLayer mlayer) |
168 |
|
|
throws Throwable { |
169 |
|
|
BufferedImage bi = TestingUtil.visualize(mlayer); |
170 |
|
|
|
171 |
|
|
assertTrue("Some specific color at 50/50", |
172 |
|
|
TestingUtil.checkPixel(bi, 50, 50, 161, 125, 74, 255)); |
173 |
|
|
assertTrue("Transparent in the top left corner", |
174 |
|
|
TestingUtil.checkPixel(bi, 1, 1, 0, 0, 0, 0)); |
175 |
|
|
} |
176 |
|
|
} |