001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/graphics/OWSRasterLayer.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53177 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042: ---------------------------------------------------------------------------*/
043: package org.deegree.graphics;
044:
045: import java.awt.image.BufferedImage;
046: import java.io.IOException;
047: import java.net.URL;
048:
049: import org.deegree.framework.log.ILogger;
050: import org.deegree.framework.log.LoggerFactory;
051: import org.deegree.framework.util.ImageUtils;
052: import org.deegree.model.coverage.grid.GridCoverage;
053: import org.deegree.model.coverage.grid.ImageGridCoverage;
054: import org.deegree.model.crs.CoordinateSystem;
055: import org.deegree.model.spatialschema.Envelope;
056:
057: /**
058: *
059: *
060: *
061: * @version $Revision: 9340 $
062: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
063: * @author last edited by: $Author: apoth $
064: *
065: * @version $Revision: 9340 $, $Date: 2007-12-27 04:32:12 -0800 (Thu, 27 Dec 2007) $
066: */
067: public class OWSRasterLayer extends AbstractLayer {
068:
069: private ILogger LOG = LoggerFactory.getLogger(OWSRasterLayer.class);
070:
071: private URL baseURL;
072:
073: private Envelope envelope;
074:
075: /**
076: *
077: * @param name
078: * @param baseURL
079: * @throws Exception
080: */
081: public OWSRasterLayer(String name, URL baseURL) throws Exception {
082: super (name);
083: this .baseURL = baseURL;
084: }
085:
086: /**
087: * @param crs
088: * @throws Exception
089: *
090: */
091: public void setCoordinatesSystem(CoordinateSystem crs)
092: throws Exception {
093: // not supported yet
094: }
095:
096: /*
097: * (non-Javadoc)
098: *
099: * @see org.deegree.graphics.AbstractLayer#getBoundingBox()
100: */
101: @Override
102: public Envelope getBoundingBox() {
103: return envelope;
104: }
105:
106: /**
107: *
108: * @param envelope
109: * @param w
110: * width of image
111: * @param h
112: * height of image
113: * @return
114: * @throws IOException
115: */
116: public GridCoverage getRaster(Envelope envelope, double w, double h)
117: throws IOException {
118:
119: this .envelope = envelope;
120: StringBuffer sb = new StringBuffer(150);
121: sb.append(baseURL);
122: appendBoxParamtersToBuffer(sb, envelope, (int) w, (int) h);
123:
124: URL u = new URL(sb.toString());
125:
126: GridCoverage gc = null;
127: try {
128: BufferedImage img = ImageUtils.loadImage(u);
129:
130: gc = new ImageGridCoverage(null, envelope, img);
131:
132: } catch (Exception e) {
133: LOG
134: .logDebug("Error getting raster data: "
135: + e.getMessage());
136: }
137: return gc;
138: }
139:
140: private void appendBoxParamtersToBuffer(StringBuffer sb,
141: Envelope env, int w, int h) {
142:
143: sb.append("&BBOX=").append(env.getMin().getX()).append(",")
144: .append(env.getMin().getY()).append(",").append(
145: env.getMax().getX()).append(",").append(
146: env.getMax().getY()).append("&WIDTH=")
147: .append(w).append("&HEIGHT=").append(h);
148: }
149:
150: }
|