Source Code Cross Referenced for WMSReader.java in  » GIS » GeoTools-2.4.1 » org » geotools » data » wms » gce » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.data.wms.gce 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2004-2006, Geotools Project Managment Committee (PMC)
005:         *    
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation; either
009:         *    version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.data.wms.gce;
017:
018:        import java.awt.image.BufferedImage;
019:        import java.io.IOException;
020:        import java.util.List;
021:        import java.util.NoSuchElementException;
022:
023:        import javax.imageio.ImageIO;
024:
025:        import org.geotools.coverage.FactoryFinder;
026:        import org.geotools.coverage.grid.GridCoverageFactory;
027:        import org.geotools.data.wms.WebMapServer;
028:        import org.geotools.data.wms.request.GetMapRequest;
029:        import org.geotools.data.wms.response.GetMapResponse;
030:        import org.geotools.geometry.GeneralEnvelope;
031:        import org.geotools.parameter.Parameter;
032:        import org.geotools.parameter.ParameterGroup;
033:        import org.geotools.referencing.CRS;
034:        import org.geotools.referencing.crs.DefaultGeographicCRS;
035:        import org.opengis.coverage.MetadataNameNotFoundException;
036:        import org.opengis.coverage.grid.Format;
037:        import org.opengis.coverage.grid.GridCoverage;
038:        import org.opengis.coverage.grid.GridCoverageReader;
039:        import org.opengis.parameter.GeneralParameterValue;
040:        import org.opengis.parameter.ParameterValue;
041:        import org.opengis.referencing.FactoryException;
042:        import org.opengis.referencing.crs.CoordinateReferenceSystem;
043:        import org.opengis.referencing.operation.OperationNotFoundException;
044:        import org.opengis.geometry.Envelope;
045:        import org.xml.sax.SAXException;
046:
047:        /**
048:         *
049:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wms/src/main/java/org/geotools/data/wms/gce/WMSReader.java $
050:         */
051:        public class WMSReader implements  GridCoverageReader {
052:            private Object source;
053:            private boolean hasNext = true;
054:            private WMSFormat format;
055:            private WebMapServer wms;
056:
057:            /**
058:             * Source must be a WebMapServer object
059:             *
060:             * @param source
061:             * @throws IOException 
062:             *
063:             * @throws RuntimeException DOCUMENT ME!
064:             */
065:            public WMSReader(Object source) throws IOException {
066:                this .source = source;
067:
068:                if (source instanceof  WebMapServer) {
069:                    wms = (WebMapServer) source;
070:                } else {
071:                    throw new RuntimeException(
072:                            "source is not of type WebMapServer");
073:                }
074:
075:                this .format = new WMSFormat(wms.getCapabilities());
076:            }
077:
078:            public Object getSource() {
079:                return source;
080:            }
081:
082:            public String[] getMetadataNames() throws IOException {
083:                // TODO Auto-generated method stub
084:                return null;
085:            }
086:
087:            public String getMetadataValue(String arg0) throws IOException,
088:                    MetadataNameNotFoundException {
089:                // TODO Auto-generated method stub
090:                return null;
091:            }
092:
093:            public String[] listSubNames() throws IOException {
094:                // TODO Auto-generated method stub
095:                return null;
096:            }
097:
098:            public String getCurrentSubname() throws IOException {
099:                // TODO Auto-generated method stub
100:                return null;
101:            }
102:
103:            public boolean hasMoreGridCoverages() throws IOException {
104:                return hasNext;
105:            }
106:
107:            public void skip() throws IOException {
108:                hasNext = false;
109:            }
110:
111:            public void dispose() throws IOException {
112:                hasNext = false;
113:            }
114:
115:            public void setFormat(WMSFormat format) {
116:                this .format = format;
117:            }
118:
119:            /* (non-Javadoc)
120:             * @see org.opengis.coverage.grid.GridCoverageReader#getFormat()
121:             */
122:            public Format getFormat() {
123:                return format;
124:            }
125:
126:            /* (non-Javadoc)
127:             * @see org.opengis.coverage.grid.GridCoverageReader#read(org.opengis.parameter.GeneralParameterValue[])
128:             */
129:            public GridCoverage read(GeneralParameterValue[] parameters)
130:                    throws IllegalArgumentException, IOException {
131:                GetMapRequest request = wms.createGetMapRequest();
132:                double minx = 0;
133:                double miny = 0;
134:                double maxx = 0;
135:                double maxy = 0;
136:
137:                CoordinateReferenceSystem crs = null;
138:
139:                for (int i = 0; i < parameters.length; i++) {
140:                    GeneralParameterValue generalValue = parameters[i];
141:
142:                    String paramName = generalValue.getDescriptor().getName()
143:                            .getCode();
144:
145:                    if ((generalValue == null)) {
146:                        continue;
147:                    }
148:
149:                    if (paramName.equals("LAYERS")) {
150:                        ParameterGroup groupValue = (ParameterGroup) generalValue;
151:                        String layers = "";
152:                        String styles = "";
153:
154:                        List layerList = (List) groupValue.values();
155:
156:                        for (int j = 0; j < layerList.size(); j++) {
157:                            Parameter parameter = (Parameter) layerList.get(j);
158:
159:                            layers = layers
160:                                    + parameter.getDescriptor().getName()
161:                                            .getCode();
162:                            styles = styles + (String) parameter.getValue();
163:
164:                            if (j < (layerList.size() - 1)) {
165:                                layers = layers + ",";
166:                                styles = styles + ",";
167:                            }
168:                        }
169:
170:                        request.setProperty("LAYERS", layers);
171:                        request.setProperty("STYLES", styles);
172:
173:                        continue;
174:                    }
175:
176:                    ParameterValue value = (ParameterValue) generalValue;
177:
178:                    if (paramName.equals("BBOX_MINX")) {
179:                        minx = ((Double) value.getValue()).doubleValue();
180:
181:                        continue;
182:                    }
183:
184:                    if (paramName.equals("BBOX_MINY")) {
185:                        miny = ((Double) value.getValue()).doubleValue();
186:
187:                        continue;
188:                    }
189:
190:                    if (paramName.equals("BBOX_MAXX")) {
191:                        maxx = ((Double) value.getValue()).doubleValue();
192:
193:                        continue;
194:                    }
195:
196:                    if (paramName.equals("BBOX_MAXY")) {
197:                        maxy = ((Double) value.getValue()).doubleValue();
198:
199:                        continue;
200:                    }
201:
202:                    if (paramName.equals("HEIGHT")) {
203:                        request.setProperty("HEIGHT", ((Integer) value
204:                                .getValue()).toString());
205:
206:                        continue;
207:                    }
208:
209:                    if (paramName.equals("WIDTH")) {
210:                        request.setProperty("WIDTH", ((Integer) value
211:                                .getValue()).toString());
212:
213:                        continue;
214:                    }
215:
216:                    if (paramName.equals("TRANSPARENT")) {
217:                        if (value.booleanValue()) {
218:                            request.setProperty("TRANSPARENT", "TRUE");
219:                        } else {
220:                            request.setProperty("TRANSPARENT", "FALSE");
221:                        }
222:
223:                        continue;
224:                    }
225:
226:                    if (value.getValue() == null) {
227:                        continue;
228:                    }
229:
230:                    if (paramName.equals("SRS")) {
231:                        String srs = value.stringValue();
232:
233:                        try {
234:                            crs = CRS.decode(srs);
235:                        } catch (FactoryException e1) {
236:                            // TODO Auto-generated catch block
237:                            e1.printStackTrace();
238:                        }
239:                    }
240:
241:                    request.setProperty(value.getDescriptor().getName()
242:                            .getCode(), value.stringValue());
243:                }
244:
245:                String bbox = minx + "," + miny + "," + maxx + "," + maxy;
246:                request.setProperty("BBOX", bbox);
247:
248:                GetMapResponse response;
249:                try {
250:                    response = (GetMapResponse) wms.issueRequest(request);
251:                } catch (SAXException e) {
252:                    e.printStackTrace();
253:                    throw new IOException(e.getLocalizedMessage());
254:                }
255:                BufferedImage image = ImageIO.read(response.getInputStream());
256:
257:                if (image == null) {
258:                    throw new IOException("Image cannot be read from:"
259:                            + response);
260:                }
261:
262:                if (crs == null) {
263:                    crs = DefaultGeographicCRS.WGS84;
264:                }
265:
266:                GeneralEnvelope envelope = new GeneralEnvelope(new double[] {
267:                        minx, miny }, new double[] { maxx, maxy });
268:                envelope.setCoordinateReferenceSystem(crs);
269:
270:                hasNext = false;
271:
272:                GridCoverageFactory factory = FactoryFinder
273:                        .getGridCoverageFactory(null);
274:                GridCoverage coverage = factory.create("wmsMap", image,
275:                        envelope);
276:
277:                return coverage;
278:            }
279:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.