Skip to content

Commit

Permalink
[GEOS-9242]: option to disable gutter
Browse files Browse the repository at this point in the history
  • Loading branch information
dromagnoli committed Jun 10, 2019
1 parent 733a415 commit 15a569a
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 15 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ static class ReadingContext {
private static final String DISABLE_DATELINE_WRAPPING_HEURISTIC_FORMAT_OPTION = private static final String DISABLE_DATELINE_WRAPPING_HEURISTIC_FORMAT_OPTION =
"disableDatelineWrappingHeuristic"; "disableDatelineWrappingHeuristic";


/** Disable Gutter key */
public static final String DISABLE_GUTTER_KEY = "wms.raster.disableGutter";

/** Disable Gutter */
private static Boolean DISABLE_GUTTER = Boolean.getBoolean(DISABLE_GUTTER_KEY);

/** The size of a megabyte */ /** The size of a megabyte */
private static final int KB = 1024; private static final int KB = 1024;


Expand Down Expand Up @@ -1075,23 +1081,25 @@ private RenderedImage directRasterRender(
final CoordinateReferenceSystem coverageCRS = final CoordinateReferenceSystem coverageCRS =
layer.getFeatureSource().getSchema().getCoordinateReferenceSystem(); layer.getFeatureSource().getSchema().getCoordinateReferenceSystem();
final GridGeometry2D readGG; final GridGeometry2D readGG;
final boolean equalsMetadata = CRS.equalsIgnoreMetadata(mapCRS, coverageCRS); boolean useGutter = !DISABLE_GUTTER;
boolean sameCRS; if (useGutter) {
try { final boolean equalsMetadata = CRS.equalsIgnoreMetadata(mapCRS, coverageCRS);
sameCRS = boolean sameCRS;
equalsMetadata try {
|| CRS.findMathTransform(mapCRS, coverageCRS, true) sameCRS =
.isIdentity(); equalsMetadata
} catch (FactoryException e1) { || CRS.findMathTransform(mapCRS, coverageCRS, true)
final IOException ioe = new IOException(); .isIdentity();
ioe.initCause(e1); } catch (FactoryException e1) {
throw ioe; final IOException ioe = new IOException();
ioe.initCause(e1);
throw ioe;
}
useGutter = !sameCRS || !(interpolation instanceof InterpolationNearest);
} }
final boolean needsGutter =
!sameCRS || !(interpolation instanceof InterpolationNearest);
if (!needsGutter) {
readGG = new GridGeometry2D(new GridEnvelope2D(mapRasterArea), mapEnvelope);


if (!useGutter) {
readGG = new GridGeometry2D(new GridEnvelope2D(mapRasterArea), mapEnvelope);
} else { } else {
// //
// SG added gutter to the drawing. We need to investigate much more and also we // SG added gutter to the drawing. We need to investigate much more and also we
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
import java.awt.image.RenderedImage; import java.awt.image.RenderedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Vector;
import java.util.function.Function; import java.util.function.Function;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
Expand Down Expand Up @@ -76,6 +79,8 @@
import org.geotools.feature.SchemaException; import org.geotools.feature.SchemaException;
import org.geotools.filter.IllegalFilterException; import org.geotools.filter.IllegalFilterException;
import org.geotools.gce.imagemosaic.ImageMosaicReader; import org.geotools.gce.imagemosaic.ImageMosaicReader;
import org.geotools.geometry.Envelope2D;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.geometry.jts.LiteShape2; import org.geotools.geometry.jts.LiteShape2;
import org.geotools.geometry.jts.ReferencedEnvelope; import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.image.test.ImageAssert; import org.geotools.image.test.ImageAssert;
Expand Down Expand Up @@ -113,6 +118,7 @@
import org.opengis.parameter.GeneralParameterValue; import org.opengis.parameter.GeneralParameterValue;
import org.opengis.referencing.FactoryException; import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException; import org.opengis.referencing.operation.TransformException;
import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpServletResponse;


Expand Down Expand Up @@ -510,6 +516,102 @@ public void testAdvancedProjectionWithoutDensification() throws Exception {
assertEquals(2, drawnShape.getGeometry().getCoordinates().length); assertEquals(2, drawnShape.getGeometry().getCoordinates().length);
} }


@Test
public void testDisableGutter() throws Exception {
setDisableGutter(true);
WMS wms = getWMS();
WMSInfo info = wms.getServiceInfo();
info.getMetadata().put(WMS.ADVANCED_PROJECTION_KEY, false);
getGeoServer().save(info);
Catalog catalog = getCatalog();
CoverageInfo ci =
catalog.getCoverageByName(
SystemTestData.WORLD.getPrefix(), SystemTestData.WORLD.getLocalPart());

GetMapRequest request = new GetMapRequest();
CoordinateReferenceSystem crs = CRS.decode("EPSG:3857");
CoordinateReferenceSystem wgs84 = DefaultGeographicCRS.WGS84;
GeneralEnvelope env =
GeneralEnvelope.toGeneralEnvelope(new Envelope2D(wgs84, -40, 0, 40, 80));
MathTransform transform = CRS.findMathTransform(wgs84, crs);
env = CRS.transform(transform, env);
ReferencedEnvelope bbox =
new ReferencedEnvelope(
env.getMinimum(0),
env.getMaximum(0),
env.getMinimum(1),
env.getMaximum(1),
crs);
request.setBbox(bbox);
request.setInterpolations(
Collections.singletonList(
Interpolation.getInstance(Interpolation.INTERP_BILINEAR)));
request.setSRS("EPSG:3857");
request.setFormat("image/png");

final WMSMapContent map = new WMSMapContent(request);
final int width = 300;
final int height = 300;
map.setMapWidth(width);
map.setMapHeight(height);
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();
RenderedImage warp[] = new RenderedImage[1];
lookForOp("Warp", image, warp);
// No Gutter has been done
assertEquals(width, image.getWidth());
assertEquals(height, image.getHeight());

imageMap.dispose();
setDisableGutter(false);
wms = getWMS();
info = wms.getServiceInfo();
info.getMetadata().put(WMS.ADVANCED_PROJECTION_KEY, true);
getGeoServer().save(info);
}

private void lookForOp(String opName, RenderedImage image, RenderedImage[] returnedOp) {
if (image instanceof RenderedOp) {
RenderedOp op = (RenderedOp) image;
String operationName = op.getOperationName();
if (opName.equalsIgnoreCase(operationName)) {
returnedOp[0] = op;
return;
} else {
Vector sources = op.getSources();
if (sources != null && !sources.isEmpty()) {
Iterator iterator = sources.iterator();
while (iterator.hasNext() && returnedOp[0] == null) {
Object next = iterator.next();
if (next instanceof RenderedImage) {
lookForOp(opName, (RenderedImage) next, returnedOp);
}
}
}
}
}
}

private void setDisableGutter(boolean value)
throws NoSuchFieldException, SecurityException, IllegalArgumentException,
IllegalAccessException {
Field field = RenderedImageMapOutputFormat.class.getDeclaredField("DISABLE_GUTTER");
field.setAccessible(true);
field.set(null, value);
}

/** /**
* Test to make sure the "direct" raster path and the "nondirect" raster path produce matching * Test to make sure the "direct" raster path and the "nondirect" raster path produce matching
* results. This test was originally created after fixes to GEOS-7270 where there were issues * results. This test was originally created after fixes to GEOS-7270 where there were issues
Expand Down

0 comments on commit 15a569a

Please sign in to comment.