WMSCoverageReader extends AbstractGridCoverage2DReader { @Override public GridCoverage2D read(GeneralParameterValue[] parameters) throws IllegalArgumentException, IOException { Envelope requestedEnvelope = null; int width = -1; int height = -1; Color backgroundColor = null; if (parameters != null) { for (GeneralParameterValue param : parameters) { final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName())) { final GridGeometry2D gg = (GridGeometry2D) ((ParameterValue) param) .getValue(); requestedEnvelope = gg.getEnvelope(); width = gg.getGridRange().getHigh(0) + 1; height = gg.getGridRange().getHigh(1) + 1; } else if(name.equals(AbstractGridFormat.BACKGROUND_COLOR.getName())) { backgroundColor = (Color) ((ParameterValue) param).getValue(); } } } if (requestedEnvelope == null) { requestedEnvelope = getOriginalEnvelope(); width = 640; height = (int) Math.round(requestedEnvelope.getSpan(1) / requestedEnvelope.getSpan(0) * 640); } if (grid != null && grid.getGridGeometry().getGridRange2D().getWidth() == width && grid.getGridGeometry().getGridRange2D().getHeight() == height && grid.getEnvelope().equals(requestedEnvelope)) return grid; grid = getMap(reference(requestedEnvelope), width, height, backgroundColor); return grid; } WMSCoverageReader(WebMapServer wms, Layer layer); InputStream getFeatureInfo(DirectPosition2D pos, String infoFormat, int featureCount, GetMapRequest getmap); @Override GridCoverage2D read(GeneralParameterValue[] parameters); Format getFormat(); void updateBounds(); @Override String[] getMetadataNames(); @Override String getMetadataValue(String name); static final Logger LOGGER; }
@Test public void test4326wms13() throws Exception { WMSCoverageReader reader = getReader4326wms13(); CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326", true); ReferencedEnvelope worldEnvelope = new ReferencedEnvelope(-180, 180, -90, 90, wgs84); GridGeometry2D gg = new GridGeometry2D(new GridEnvelope2D(0, 0, 180, 90), worldEnvelope); final Parameter<GridGeometry2D> ggParam = (Parameter<GridGeometry2D>) AbstractGridFormat.READ_GRIDGEOMETRY2D .createValue(); ggParam.setValue(gg); GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { ggParam }); assertTrue(CRS.equalsIgnoreMetadata(wgs84, coverage.getCoordinateReferenceSystem())); assertEquals(worldEnvelope, new ReferencedEnvelope(coverage.getEnvelope())); }
@Test public void test4326wms13RequestFlipped() throws Exception { WMSCoverageReader reader = getReader4326wms13(); CoordinateReferenceSystem wgs84 = CRS.decode("urn:ogc:def:crs:EPSG::4326", true); ReferencedEnvelope worldEnvelope = new ReferencedEnvelope(-90, 90, -180, 180, wgs84); GridGeometry2D gg = new GridGeometry2D(new GridEnvelope2D(0, 0, 180, 90), worldEnvelope); final Parameter<GridGeometry2D> ggParam = (Parameter<GridGeometry2D>) AbstractGridFormat.READ_GRIDGEOMETRY2D .createValue(); ggParam.setValue(gg); GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { ggParam }); assertTrue(CRS.equalsIgnoreMetadata(wgs84, coverage.getCoordinateReferenceSystem())); assertEquals(worldEnvelope, new ReferencedEnvelope(coverage.getEnvelope())); }
@Test public void test4326wms13RequestFlippedStandardEPSG() throws Exception { System.clearProperty("org.geotools.referencing.forceXY"); Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING, ""); CRS.reset("all"); WMSCoverageReader reader = getReader4326wms13(); CoordinateReferenceSystem wgs84 = CRS.decode("urn:ogc:def:crs:EPSG::4326", true); ReferencedEnvelope worldEnvelope = new ReferencedEnvelope(-90, 90, -180, 180, wgs84); GridGeometry2D gg = new GridGeometry2D(new GridEnvelope2D(0, 0, 180, 90), worldEnvelope); final Parameter<GridGeometry2D> ggParam = (Parameter<GridGeometry2D>) AbstractGridFormat.READ_GRIDGEOMETRY2D .createValue(); ggParam.setValue(gg); GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { ggParam }); assertTrue(CRS.equalsIgnoreMetadata(wgs84, coverage.getCoordinateReferenceSystem())); assertEquals(worldEnvelope, new ReferencedEnvelope(coverage.getEnvelope())); }
@Test public void testGetMapNoContentType() throws Exception { System.clearProperty("org.geotools.referencing.forceXY"); Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING, ""); CRS.reset("all"); final AtomicBoolean disposeCalled = new AtomicBoolean(false); MockHttpClient client = new MockHttpClient() { public HTTPResponse get(URL url) throws IOException { if (url.getQuery().contains("GetCapabilities")) { URL caps130 = WMSCoverageReaderTest.class.getResource("caps130.xml"); return new MockHttpResponse(caps130, "text/xml"); } else if (url.getQuery().contains("GetMap") && url.getQuery().contains("world4326")) { Map<String, String> params = parseParams(url.getQuery()); assertEquals("1.3.0", params.get("VERSION")); assertEquals("-90.0,-180.0,90.0,180.0", params.get("BBOX")); assertEquals("EPSG:4326", params.get("CRS")); URL world = WMSCoverageReaderTest.class.getResource("world.png"); return new MockHttpResponse(world, null) { public void dispose() { disposeCalled.set(true); super.dispose(); }; }; } else { throw new IllegalArgumentException( "Don't know how to handle a get request over " + url.toExternalForm()); } } }; WebMapServer server = new WebMapServer(new URL("http: client); WMSCoverageReader reader = new WMSCoverageReader(server, getLayer(server, "world4326")); CoordinateReferenceSystem wgs84 = CRS.decode("urn:ogc:def:crs:EPSG::4326", true); ReferencedEnvelope worldEnvelope = new ReferencedEnvelope(-90, 90, -180, 180, wgs84); GridGeometry2D gg = new GridGeometry2D(new GridEnvelope2D(0, 0, 180, 90), worldEnvelope); final Parameter<GridGeometry2D> ggParam = (Parameter<GridGeometry2D>) AbstractGridFormat.READ_GRIDGEOMETRY2D .createValue(); ggParam.setValue(gg); try { reader.read(new GeneralParameterValue[] { ggParam }); fail("Should have thrown an exception, the GetMap content type was null"); } catch (Exception e) { } assertTrue(disposeCalled.get()); }
@Test public void test4326wms11() throws Exception { WMSCoverageReader reader = getReader4326wms11(); GeneralEnvelope original = reader.getOriginalEnvelope(); CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326", true); assertTrue(CRS.equalsIgnoreMetadata(wgs84, original.getCoordinateReferenceSystem())); ReferencedEnvelope worldEnvelope = new ReferencedEnvelope(-180, 180, -90, 90, wgs84); GridGeometry2D gg = new GridGeometry2D(new GridEnvelope2D(0, 0, 180, 90), worldEnvelope); final Parameter<GridGeometry2D> ggParam = (Parameter<GridGeometry2D>) AbstractGridFormat.READ_GRIDGEOMETRY2D .createValue(); ggParam.setValue(gg); GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { ggParam }); assertTrue(CRS.equalsIgnoreMetadata(wgs84, coverage.getCoordinateReferenceSystem())); assertEquals(worldEnvelope, new ReferencedEnvelope(coverage.getEnvelope())); }
@Test public void testCrs84wms13() throws Exception { MockHttpClient client = new MockHttpClient() { public HTTPResponse get(URL url) throws IOException { if (url.getQuery().contains("GetCapabilities")) { URL caps130 = WMSCoverageReaderTest.class.getResource("caps130_crs84.xml"); return new MockHttpResponse(caps130, "text/xml"); } else if (url.getQuery().contains("GetMap") && url.getQuery().contains("world84")) { Map<String, String> params = parseParams(url.getQuery()); assertEquals("1.3.0", params.get("VERSION")); assertEquals("CRS:84", params.get("CRS")); assertEquals("-180.0,-90.0,180.0,90.0", params.get("BBOX")); URL world = WMSCoverageReaderTest.class.getResource("world.png"); return new MockHttpResponse(world, "image/png"); } else { throw new IllegalArgumentException( "Don't know how to handle a get request over " + url.toExternalForm()); } } }; WebMapServer server = new WebMapServer(new URL("http: client); WMSCoverageReader reader = new WMSCoverageReader(server, getLayer(server, "world84")); CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326", true); ReferencedEnvelope worldEnvelope = new ReferencedEnvelope(-180, 180, -90, 90, wgs84); GridGeometry2D gg = new GridGeometry2D(new GridEnvelope2D(0, 0, 180, 90), worldEnvelope); final Parameter<GridGeometry2D> ggParam = (Parameter<GridGeometry2D>) AbstractGridFormat.READ_GRIDGEOMETRY2D .createValue(); ggParam.setValue(gg); GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { ggParam }); assertTrue(CRS.equalsIgnoreMetadata(wgs84, coverage.getCoordinateReferenceSystem())); assertEquals(worldEnvelope, new ReferencedEnvelope(coverage.getEnvelope())); }