--
==
Meet us at GEO Business 2014! in London! Visit http://goo.gl/fES3aK
for more information.
==
Ing. Andrea Aime
@geowolf
Technical Lead
GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549
http://www.geo-solutions.it
http://twitter.com/geosolutions_it
-------------------------------------------------------
diff --git a/modules/library/render/pom.xml b/modules/library/render/pom.xml
index d2cb001..4390d64 100644
--- a/modules/library/render/pom.xml
+++ b/modules/library/render/pom.xml
@@ -169,6 +169,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.geotools</groupId>
+ <artifactId>gt-arcgrid</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
diff --git a/modules/library/render/src/main/java/org/geotools/renderer/lite/gridcoverage2d/GridCoverageRenderer.java b/modules/library/render/src/main/java/org/geotools/renderer/lite/gridcoverage2d/GridCoverageRenderer.java
index 8edee87..0ee464d 100644
--- a/modules/library/render/src/main/java/org/geotools/renderer/lite/gridcoverage2d/GridCoverageRenderer.java
+++ b/modules/library/render/src/main/java/org/geotools/renderer/lite/gridcoverage2d/GridCoverageRenderer.java
@@ -40,6 +40,8 @@ import javax.media.jai.Interpolation;
import javax.media.jai.InterpolationNearest;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
+import javax.media.jai.RenderedOp;
+import javax.media.jai.operator.AffineDescriptor;
import org.geotools.coverage.CoverageFactoryFinder;
import org.geotools.coverage.GridSampleDimension;
@@ -377,13 +379,6 @@ public final class GridCoverageRenderer {
// ///////////////////////////////////////////////////////////////////
final GridCoverage2D preSymbolizer= affine(afterReprojection,bkgValues);
-
-// final ParameterValueGroup param = (ParameterValueGroup) GridCoverageRendererUtilities.RESAMPLING_PARAMS.clone();
-// param.parameter("source").setValue(gridCoverage);
-// param.parameter("GridGeometry").setValue(new GridGeometry2D(new GridEnvelope2D(destinationSize), destinationEnvelope));
-// param.parameter("InterpolationType").setValue(interpolation);
-// final GridCoverage2D preSymbolizer =(GridCoverage2D) GridCoverageRendererUtilities.RESAMPLE_FACTORY.doOperation(param, hints);
-//
// ///////////////////////////////////////////////////////////////////
//
// RASTERSYMBOLIZER
@@ -552,47 +547,40 @@ public final class GridCoverageRenderer {
final AffineTransform finalRasterTransformation = (AffineTransform) finalWorldToGrid.clone();
finalRasterTransformation.concatenate(finalGCgridToWorld);
- //paranoiac check to avoid that JAI freaks out when computing its internal layouT on images that are too small
- Rectangle2D finalLayout= GridCoverageRendererUtilities.layoutHelper(
- finalImage,
- (float)finalRasterTransformation.getScaleX(),
- (float)finalRasterTransformation.getScaleY(),
- (float)finalRasterTransformation.getTranslateX(),
- (float)finalRasterTransformation.getTranslateY(),
- interpolation);
- if(finalLayout.isEmpty()){
- if(LOGGER.isLoggable(java.util.logging.Level.FINE))
- LOGGER.fine("Unable to create a granuleDescriptor "+this.toString()+ " due to jai scale bug");
+ // paranoiac check to avoid that JAI freaks out when computing its internal layouT on images
+ // that are too small
+ RenderedImage im = null;
+ try {
+ Rectangle2D finalLayout = GridCoverageRendererUtilities.layoutHelper(finalImage,
+ (float) finalRasterTransformation.getScaleX(),
+ (float) finalRasterTransformation.getScaleY(),
+ (float) finalRasterTransformation.getTranslateX(),
+ (float) finalRasterTransformation.getTranslateY(), interpolation);
+ if (finalLayout.isEmpty()) {
+ if (LOGGER.isLoggable(java.util.logging.Level.FINE))
+ LOGGER.fine("Unable to create a granuleDescriptor " + this.toString()
+ + " due to jai scale bug");
return null;
- }
-//
-// // final transformation
-// final ImageLayout2 layout = new ImageLayout2(finalImage);
-// if(tileDimension!=null){
-// layout.unsetImageBounds();
-// layout.unsetValid(ImageLayout.COLOR_MODEL_MASK&ImageLayout.SAMPLE_MODEL_MASK);
-// layout.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(tileDimension.height).setTileWidth(tileDimension.width);
-// }
-// final RenderingHints localHints = this.hints.clone();
-// localHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
-//
-// // === interpolation management
-// // others, make sure we don't force the colormodel if it is indexed with layout as it might lead to NO color expansion
-// if (!(interpolation instanceof InterpolationNearest)&& finalImage.getColorModel() instanceof IndexColorModel){
-// layout.unsetValid(ImageLayout2.COLOR_MODEL_MASK).unsetValid(ImageLayout2.SAMPLE_MODEL_MASK);
-// }
+ }
+
- RenderedImage im=null;
- try {
ImageWorker iw = new ImageWorker(finalImage);
iw.setRenderingHints(hints);
iw.affine(finalRasterTransformation, interpolation, bkgValues);
im = iw.getRenderedImage();
- } finally {
- if(DEBUG){
- writeRenderedImage(im, "postAffine");
- }
- }
+ // force the chain to run computation
+ im.getSampleModel().getNumBands();
+ } catch (Exception e) {
+ // if we get here, the single affine will fail too, we have to force two subsequent ones
+ RenderedOp step1 = AffineDescriptor.create(finalImage, finalWorldToGrid, interpolation,
+ bkgValues, hints);
+ im = AffineDescriptor
+ .create(step1, finalGCgridToWorld, interpolation, bkgValues, hints);
+ }
+ if (DEBUG) {
+ writeRenderedImage(im, "postAffine");
+ }
+
// recreate gridCoverage
int numBands = im.getSampleModel().getNumBands();
GridSampleDimension[] sd = new GridSampleDimension[numBands];
diff --git a/modules/library/render/src/test/java/org/geotools/renderer/lite/GridCoverageRendererTest.java b/modules/library/render/src/test/java/org/geotools/renderer/lite/GridCoverageRendererTest.java
index b73de3f..0379e24 100644
--- a/modules/library/render/src/test/java/org/geotools/renderer/lite/GridCoverageRendererTest.java
+++ b/modules/library/render/src/test/java/org/geotools/renderer/lite/GridCoverageRendererTest.java
@@ -17,6 +17,7 @@
package org.geotools.renderer.lite;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.awt.Color;
@@ -38,6 +39,8 @@ import org.geotools.coverage.GridSampleDimension;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.GridCoverageFactory;
import org.geotools.factory.GeoTools;
+import org.geotools.factory.Hints;
+import org.geotools.gce.arcgrid.ArcGridReader;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.gce.geotiff.GeoTiffWriter;
import org.geotools.geometry.GeneralEnvelope;
@@ -57,6 +60,7 @@ import org.geotools.referencing.operation.DefaultMathTransformFactory;
import org.geotools.styling.RasterSymbolizer;
import org.geotools.styling.Style;
import org.geotools.styling.StyleBuilder;
+import org.junit.Before;
import org.junit.Test;
import org.opengis.coverage.grid.GridCoverage;
import org.opengis.parameter.ParameterValueGroup;
@@ -81,6 +85,25 @@ public class GridCoverageRendererTest {
String FILENAME = "TestGridCoverage.jpg";
+ @Before
+ public void setup() throws Exception {
+ File file = TestData.copy(this, "arcgrid/arcgrid.zip");
+ assertTrue(file.exists());
+
+ // unzip it
+ TestData.unzipFile(this, "arcgrid/arcgrid.zip");
+
+ System.setProperty("org.geotools.referencing.forceXY", "true");
+ CRS.reset("all");
+ }
+
+ protected void tearDown() throws Exception {
+ System.clearProperty("org.geotools.referencing.forceXY");
+ Hints.removeSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER);
+ CRS.reset("all");
+ }
+
+
/**
* Returns a {@link GridCoverage} which may be used as a "real world"
* example.
@@ -326,5 +349,27 @@ public class GridCoverageRendererTest {
ImageAssert.assertEquals(new File("src/test/resources/org/geotools/renderer/lite/reprojectBuffer.png"), result, 0);
}
+ @Test
+ public void testReprojectStereoPolar() throws Exception {
+ final File testFile = TestData.file(this, "arcgrid/precip30min.asc");
+ Hints hints = new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM,
+ DefaultGeographicCRS.WGS84);
+ ArcGridReader reader = new ArcGridReader(testFile, hints);
+ Style style = RendererBaseTest.loadStyle(this, "rain.sld");
+ MapContent mc = new MapContent();
+
+ mc.addLayer(new GridReaderLayer(reader, style));
+ ReferencedEnvelope renderEnvelope = new ReferencedEnvelope(-20000000, 20000000, -20000000,
+ 20000000, CRS.decode("EPSG:3031", true));
+ // mc.getViewport().setBounds(renderEnvelope);
+ StreamingRenderer sr = new StreamingRenderer();
+ sr.setMapContent(mc);
+ BufferedImage result = RendererBaseTest.showRender("testGridCoverageBoundsReprojection",
+ sr, 1000, renderEnvelope);
+ ImageAssert.assertEquals(new File(
+ "src/test/resources/org/geotools/renderer/lite/reprojectStereoPolar.png"), result,
+ 0);
+ }
+
}
diff --git a/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/rain.sld b/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/rain.sld
new file mode 100644
index 0000000..cae1521
--- /dev/null
+++ b/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/rain.sld
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
+ xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
+ <NamedLayer>
+ <Name>rain</Name>
+ <UserStyle>
+ <Name>rain</Name>
+ <Title>Rain distribution</Title>
+ <FeatureTypeStyle>
+ <Rule>
+ <RasterSymbolizer>
+ <Opacity>1.0</Opacity>
+ <ColorMap>
+ <ColorMapEntry color="#FF0000" quantity="0" />
+ <ColorMapEntry color="#FFFFFF" quantity="100"/>
+ <ColorMapEntry color="#00FF00" quantity="2000"/>
+ <ColorMapEntry color="#0000FF" quantity="5000"/>
+ </ColorMap>
+ </RasterSymbolizer>
+ </Rule>
+ </FeatureTypeStyle>
+ </UserStyle>
+ </NamedLayer>
+</StyledLayerDescriptor>
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
GeoTools-Devel mailing list
GeoTools-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel