Skip to content

Commit

Permalink
GEOS-11484: mapWrapping/advProjectionHandler format_options supported…
Browse files Browse the repository at this point in the history
… by DirectRasterRenderer
  • Loading branch information
dromagnoli authored and aaime committed Jul 30, 2024
1 parent 3d59f5d commit 2777016
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
*/
package org.geoserver.wms.map;

import static org.geoserver.wms.map.RenderedImageMapOutputFormat.ADV_PROJECTION_HANDLING_FORMAT_OPTION;
import static org.geoserver.wms.map.RenderedImageMapOutputFormat.MAP_WRAPPING_FORMAT_OPTION;
import static org.geoserver.wms.map.RenderedImageMapOutputFormat.getConfiguredLayerInterpolation;
import static org.geoserver.wms.map.RenderedImageMapOutputFormat.getFormatOptionAsBoolean;
import static org.geoserver.wms.map.RenderedImageMapOutputFormat.toInterpolationObject;
import static org.geotools.renderer.lite.gridcoverage2d.ChannelSelectionUpdateStyleVisitor.getBandIndicesFromSelectionChannels;

Expand Down Expand Up @@ -243,7 +246,11 @@ public RenderedImage render() throws FactoryException {
try {
final Color readerBgColor = transparent ? null : bgColor;
CoordinateReferenceSystem mapCRS = mapEnvelope.getCoordinateReferenceSystem();
if (transformation == null && wms.isAdvancedProjectionHandlingEnabled()) {
boolean advancedProjectionHandling =
wms.isAdvancedProjectionHandlingEnabled()
&& getFormatOptionAsBoolean(
mapContent.getRequest(), ADV_PROJECTION_HANDLING_FORMAT_OPTION);
if (transformation == null && advancedProjectionHandling) {
image = readWithProjectionHandling(interpolationHints, readerBgColor, mapCRS);
} else {
//
Expand Down Expand Up @@ -623,12 +630,21 @@ private Object readAndTransform(
CoordinateReferenceSystem coverageCRS,
GridGeometry2D readGG)
throws IOException, SchemaException, TransformException, FactoryException {

boolean advancedProjectionHandling =
wms.isAdvancedProjectionHandlingEnabled()
&& getFormatOptionAsBoolean(
mapContent.getRequest(), ADV_PROJECTION_HANDLING_FORMAT_OPTION);
boolean continuousMapWrapping =
wms.isContinuousMapWrappingEnabled()
&& getFormatOptionAsBoolean(
mapContent.getRequest(), MAP_WRAPPING_FORMAT_OPTION);
RenderingTransformationHelper helper =
new GCRRenderingTransformationHelper(
mapContent,
interpolation,
wms.isAdvancedProjectionHandlingEnabled(),
wms.isContinuousMapWrappingEnabled());
advancedProjectionHandling,
continuousMapWrapping);
Object result =
helper.applyRenderingTransformation(
transformation,
Expand Down Expand Up @@ -716,7 +732,11 @@ private RenderedImage readWithProjectionHandling(
new GridCoverageRenderer(
mapCRS, mapEnvelope, mapRasterArea, worldToScreen, interpolationHints);
gcr.setAdvancedProjectionHandlingEnabled(true);
gcr.setWrapEnabled(wms.isContinuousMapWrappingEnabled());
boolean continuousMapWrappingEnabled =
wms.isContinuousMapWrappingEnabled()
&& getFormatOptionAsBoolean(
mapContent.getRequest(), MAP_WRAPPING_FORMAT_OPTION);
gcr.setWrapEnabled(continuousMapWrappingEnabled);
// use null background here, background color is handled afterwards
RenderedImage image =
gcr.renderImage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ public class RenderedImageMapOutputFormat extends AbstractMapOutputFormat {

private static final List<String> AA_SETTINGS = Arrays.asList(AA_NONE, AA_TEXT, AA_FULL);

private static final String MAP_WRAPPING_FORMAT_OPTION = "mapWrapping";
private static final String ADV_PROJECTION_HANDLING_FORMAT_OPTION =
"advancedProjectionHandling";
public static final String MAP_WRAPPING_FORMAT_OPTION = "mapWrapping";
public static final String ADV_PROJECTION_HANDLING_FORMAT_OPTION = "advancedProjectionHandling";
private static final String ADV_PROJECTION_DENSIFICATION_FORMAT_OPTION =
"advancedProjectionHandlingDensification";
private static final String DISABLE_DATELINE_WRAPPING_HEURISTIC_FORMAT_OPTION =
Expand Down Expand Up @@ -638,7 +637,7 @@ protected StreamingRenderer buildRenderer() {
return new StreamingRenderer();
}

private boolean getFormatOptionAsBoolean(
public static boolean getFormatOptionAsBoolean(
final GetMapRequest request, final String formatOptionKey) {
if (request.getFormatOptions().get(formatOptionKey) != null) {
String formatOptionValue = (String) request.getFormatOptions().get(formatOptionKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import org.geotools.geometry.GeneralBounds;
import org.geotools.geometry.jts.LiteShape2;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.image.ImageWorker;
import org.geotools.image.test.ImageAssert;
import org.geotools.image.util.ImageUtilities;
import org.geotools.map.FeatureLayer;
Expand Down Expand Up @@ -685,12 +686,87 @@ public void testDirectVsNonDirectRasterRender() throws Exception {

RenderedImageMap imageMap = this.rasterMapProducer.produceMap(map);
ImageAssert.assertEquals(
new File("src/test/resources/org/geoserver/wms/map/direct-raster-expected.tif"),
new File("src/test/resources/org/geoserver/wms/map/direct-raster-expected.png"),
imageMap.getImage(),
0);
imageMap.dispose();
}

@Test
public void testDirectRasterRenderRespectingFormatOptions() throws Exception {
Catalog catalog = getCatalog();
CoverageInfo ci =
catalog.getCoverageByName(
SystemTestData.WORLD.getPrefix(), SystemTestData.WORLD.getLocalPart());

CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;

// Request an area going over the dateline
ReferencedEnvelope bbox =
new ReferencedEnvelope(new Envelope(115.0, 315.0, -60.0, 60.0), crs);

GetMapRequest request = new GetMapRequest();
request.setBbox(bbox);
request.setSRS("urn:x-ogc:def:crs:EPSG:4326");
request.setFormat("image/png");

testWithFormatOptions(ci, request, bbox, false);
testWithFormatOptions(ci, request, bbox, true);
}

private void testWithFormatOptions(
CoverageInfo ci,
GetMapRequest request,
ReferencedEnvelope bbox,
boolean formatOptionsEnabled)
throws IOException {
request.getFormatOptions().put("mapWrapping", Boolean.toString(formatOptionsEnabled));
request.getFormatOptions()
.put("advancedProjectionHandling", Boolean.toString(formatOptionsEnabled));

final WMSMapContent map = new WMSMapContent(request);
final float width = 400;
map.setMapWidth((int) width);
map.setMapHeight(240);
map.setBgColor(Color.red);
map.setTransparent(false);
map.getViewport().setBounds(bbox);

StyleBuilder builder = new StyleBuilder();
GridCoverage2DReader reader = (GridCoverage2DReader) ci.getGridCoverageReader(null, null);
reader.getCoordinateReferenceSystem();
Layer l =
new CachedGridReaderLayer(
reader, builder.createStyle(builder.createRasterSymbolizer()));
map.addLayer(l);

RenderedImageMap imageMap = this.rasterMapProducer.produceMap(map);
RenderedImage image = imageMap.getImage();
float xOffset = 150;
ImageWorker worker =
new ImageWorker(image)
.crop(xOffset, 0, width - xOffset, 240)
.translate(-xOffset, 0, null);

if (formatOptionsEnabled) {
// We have enabled continuous map wrapping.
// So cropping over the dateline we will see again
// North and South America
ImageAssert.assertEquals(
new File(
"src/test/resources/org/geoserver/wms/map/direct-raster-format-options-expected.png"),
worker.getRenderedImage(),
10);
} else {
// We have disabled the continuous map wrapping format option.
// So cropping over the dateline we will only see RED background color
// filling the image
// Assert that we get everything red
assertArrayEquals(new double[] {255, 0, 0}, worker.getMinimums(), 1E-6);
assertArrayEquals(new double[] {255, 0, 0}, worker.getMaximums(), 1E-6);
}
}

@Test
public void testTimeoutOption() throws Exception {
Catalog catalog = getCatalog();
Expand Down Expand Up @@ -1497,7 +1573,7 @@ public void testBandSelectionToNormalCoverage() throws Exception {

RenderedImageMap imageMap = this.rasterMapProducer.produceMap(map);
ImageAssert.assertEquals(
new File("src/test/resources/org/geoserver/wms/map/direct-raster-expected.tif"),
new File("src/test/resources/org/geoserver/wms/map/direct-raster-expected.png"),
imageMap.getImage(),
0);
imageMap.dispose();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2777016

Please sign in to comment.