Skip to content

Commit f07480a

Browse files
committed
test: extend COG export georeferencing coverage
1 parent a64baf1 commit f07480a

3 files changed

Lines changed: 137 additions & 0 deletions

File tree

core/src/test/java/org/mapfish/print/output/MapCogExportOutputFormatTest.java

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.HashMap;
1010
import java.util.Map;
1111
import org.geotools.api.coverage.grid.GridCoverageReader;
12+
import org.geotools.api.referencing.operation.MathTransform;
1213
import org.geotools.coverage.grid.GridCoverage2D;
1314
import org.geotools.gce.geotiff.GeoTiffFormat;
1415
import org.junit.jupiter.api.Test;
@@ -71,4 +72,112 @@ public void testCogExport() throws Exception {
7172
reader.dispose();
7273
}
7374
}
75+
76+
@Test
77+
public void testCogExportWithCenterAndScale() throws Exception {
78+
final Configuration config = configurationFactory.getConfig(getFile(BASE_DIR + "config.yaml"));
79+
80+
final PJsonObject requestData =
81+
parseJSONObjectFromFile(
82+
MapCogExportOutputFormatTest.class, BASE_DIR + "requestData-center.json");
83+
84+
final OutputFormat format = this.outputFormat.get("cogMapOutputFormat");
85+
86+
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
87+
88+
format.print(
89+
new HashMap<>(),
90+
requestData,
91+
config,
92+
getFile(MapCogExportOutputFormatTest.class, BASE_DIR),
93+
getTaskDirectory(),
94+
outputStream);
95+
96+
final GeoTiffFormat geoTiffFormat = new GeoTiffFormat();
97+
final GridCoverageReader reader =
98+
geoTiffFormat.getReader(new ByteArrayInputStream(outputStream.toByteArray()));
99+
100+
assertNotNull(reader);
101+
102+
try {
103+
final GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
104+
105+
final MathTransform gridToCRS = coverage.getGridGeometry().getGridToCRS();
106+
107+
final double[] gridCenter = {
108+
coverage.getRenderedImage().getWidth() / 2.0, coverage.getRenderedImage().getHeight() / 2.0
109+
};
110+
111+
final double[] worldCenter = new double[2];
112+
113+
gridToCRS.transform(gridCenter, 0, worldCenter, 0, 1);
114+
115+
assertEquals(637395.386, worldCenter[0], 0.000001);
116+
assertEquals(5788326.345, worldCenter[1], 0.000001);
117+
118+
} finally {
119+
reader.dispose();
120+
}
121+
}
122+
123+
@Test
124+
public void testCogExportWithRotation() throws Exception {
125+
final Configuration config = configurationFactory.getConfig(getFile(BASE_DIR + "config.yaml"));
126+
127+
final PJsonObject requestData =
128+
parseJSONObjectFromFile(
129+
MapCogExportOutputFormatTest.class, BASE_DIR + "requestData-center-rotation.json");
130+
131+
final OutputFormat format = this.outputFormat.get("cogMapOutputFormat");
132+
133+
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
134+
135+
format.print(
136+
new HashMap<>(),
137+
requestData,
138+
config,
139+
getFile(MapCogExportOutputFormatTest.class, BASE_DIR),
140+
getTaskDirectory(),
141+
outputStream);
142+
143+
final GeoTiffFormat geoTiffFormat = new GeoTiffFormat();
144+
final GridCoverageReader reader =
145+
geoTiffFormat.getReader(new ByteArrayInputStream(outputStream.toByteArray()));
146+
147+
assertNotNull(reader);
148+
149+
try {
150+
final GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
151+
152+
final MathTransform gridToCRS = coverage.getGridGeometry().getGridToCRS();
153+
154+
final double[] gridCenter = {
155+
coverage.getRenderedImage().getWidth() / 2.0, coverage.getRenderedImage().getHeight() / 2.0
156+
};
157+
158+
final double[] worldCenter = new double[2];
159+
160+
gridToCRS.transform(gridCenter, 0, worldCenter, 0, 1);
161+
162+
assertEquals(637395.386, worldCenter[0], 0.000001);
163+
assertEquals(5788326.345, worldCenter[1], 0.000001);
164+
165+
final double[] gridRight = {gridCenter[0] + 100.0, gridCenter[1]};
166+
167+
final double[] worldRight = new double[2];
168+
169+
gridToCRS.transform(gridRight, 0, worldRight, 0, 1);
170+
171+
final double expectedDistance = 100.0 * 3600.0 * 0.0254 / 72.0;
172+
173+
final double expectedOffset = expectedDistance / Math.sqrt(2.0);
174+
175+
assertEquals(expectedOffset, worldRight[0] - worldCenter[0], 0.000001);
176+
177+
assertEquals(expectedOffset, worldRight[1] - worldCenter[1], 0.000001);
178+
179+
} finally {
180+
reader.dispose();
181+
}
182+
}
74183
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"layout": "main",
3+
"outputFormat": "cog",
4+
"attributes": {
5+
"map": {
6+
"center": [637395.386, 5788326.345],
7+
"scale": 3600,
8+
"projection": "EPSG:25832",
9+
"dpi": 72,
10+
"rotation": 45,
11+
"layers": []
12+
}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"layout": "main",
3+
"outputFormat": "cog",
4+
"attributes": {
5+
"map": {
6+
"center": [637395.386, 5788326.345],
7+
"scale": 3600,
8+
"projection": "EPSG:25832",
9+
"dpi": 72,
10+
"rotation": 0,
11+
"layers": []
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)