Source Code Cross Referenced for CoverageInfo.java in  » GIS » GeoServer » org » vfny » geoserver » global » 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 » GeoServer » org.vfny.geoserver.global 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org.  All rights reserved.
002:         * This code is licensed under the GPL 2.0 license, availible at the root
003:         * application directory.
004:         */
005:        package org.vfny.geoserver.global;
006:
007:        import org.geotools.coverage.grid.GridCoverage2D;
008:        import org.geotools.factory.Hints;
009:        import org.geotools.geometry.GeneralEnvelope;
010:        import org.geotools.resources.CRSUtilities;
011:        import org.geotools.styling.Style;
012:        import org.opengis.coverage.grid.GridCoverage;
013:        import org.opengis.coverage.grid.GridCoverageReader;
014:        import org.opengis.coverage.grid.GridGeometry;
015:        import org.opengis.parameter.InvalidParameterValueException;
016:        import org.opengis.parameter.ParameterNotFoundException;
017:        import org.opengis.referencing.FactoryException;
018:        import org.opengis.referencing.crs.CoordinateReferenceSystem;
019:        import org.opengis.referencing.operation.MathTransform;
020:        import org.opengis.referencing.operation.TransformException;
021:        import org.opengis.util.InternationalString;
022:        import org.vfny.geoserver.global.dto.CoverageInfoDTO;
023:        import org.vfny.geoserver.util.CoverageStoreUtils;
024:        import org.vfny.geoserver.util.CoverageUtils;
025:        import java.awt.Rectangle;
026:        import java.io.IOException;
027:        import java.net.MalformedURLException;
028:        import java.util.ArrayList;
029:        import java.util.Iterator;
030:        import java.util.List;
031:        import java.util.Map;
032:        import java.util.logging.Level;
033:
034:        /**
035:         * DOCUMENT ME!
036:         *
037:         * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
038:         *         modification)
039:         * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
040:         *         modification)
041:         */
042:        public final class CoverageInfo extends GlobalLayerSupertype {
043:            /**
044:             *
045:             */
046:            private String formatId;
047:
048:            /**
049:             *
050:             */
051:            private String name;
052:
053:            /**
054:             *
055:             */
056:            private String wmsPath;
057:
058:            /**
059:             *
060:             */
061:            private String label;
062:
063:            /**
064:             *
065:             */
066:            private String description;
067:
068:            /**
069:             *
070:             */
071:            private MetaDataLink metadataLink;
072:
073:            /**
074:             *
075:             */
076:            private String dirName;
077:
078:            /**
079:             *
080:             */
081:            private List keywords;
082:
083:            /**
084:             *
085:             */
086:            private GeneralEnvelope envelope;
087:
088:            /**
089:             *
090:             */
091:            private GeneralEnvelope lonLatWGS84Envelope;
092:
093:            /**
094:             *
095:             */
096:            private GridGeometry grid;
097:
098:            /**
099:             *
100:             */
101:            private CoverageDimension[] dimensions;
102:
103:            /**
104:             *
105:             */
106:            private InternationalString[] dimensionNames;
107:
108:            /**
109:             *
110:             */
111:            private List requestCRSs;
112:
113:            /**
114:             *
115:             */
116:            private List responseCRSs;
117:
118:            /**
119:             *
120:             */
121:            private String nativeFormat;
122:
123:            /**
124:             *
125:             */
126:            private List supportedFormats;
127:
128:            /**
129:             *
130:             */
131:            private String defaultInterpolationMethod;
132:
133:            /**
134:             *
135:             */
136:            private List interpolationMethods;
137:
138:            /**
139:             *
140:             */
141:            private Data data;
142:
143:            /**
144:             *
145:             */
146:            private Map meta;
147:
148:            /**
149:             *
150:             */
151:            private String srsName;
152:
153:            /**
154:             *
155:             */
156:            private String srsWKT;
157:
158:            /**
159:             *
160:             */
161:            private CoordinateReferenceSystem crs;
162:
163:            /**
164:             * Default style used to render this Coverage with WMS
165:             */
166:            private String defaultStyle;
167:
168:            /**
169:             * Other WMS Styles
170:             */
171:            private ArrayList styles;
172:
173:            /**
174:             * String representation of connection parameter values
175:             */
176:            private Map parameters;
177:
178:            public CoverageInfo(CoverageInfoDTO dto, Data data)
179:                    throws ConfigurationException {
180:                this .data = data;
181:                formatId = dto.getFormatId();
182:                name = dto.getName();
183:                wmsPath = dto.getWmsPath();
184:                label = dto.getLabel();
185:                description = dto.getDescription();
186:                metadataLink = dto.getMetadataLink();
187:                dirName = dto.getDirName();
188:                keywords = dto.getKeywords();
189:                crs = dto.getCrs();
190:                srsName = dto.getSrsName();
191:                srsWKT = dto.getSrsWKT();
192:                envelope = dto.getEnvelope();
193:                lonLatWGS84Envelope = dto.getLonLatWGS84Envelope();
194:                grid = dto.getGrid();
195:                dimensions = dto.getDimensions();
196:                dimensionNames = dto.getDimensionNames();
197:                requestCRSs = dto.getRequestCRSs();
198:                responseCRSs = dto.getResponseCRSs();
199:                nativeFormat = dto.getNativeFormat();
200:                supportedFormats = dto.getSupportedFormats();
201:                defaultInterpolationMethod = dto
202:                        .getDefaultInterpolationMethod();
203:                interpolationMethods = dto.getInterpolationMethods();
204:                defaultStyle = dto.getDefaultStyle();
205:                styles = dto.getStyles();
206:                parameters = dto.getParameters();
207:            }
208:
209:            Object toDTO() {
210:                CoverageInfoDTO dto = new CoverageInfoDTO();
211:
212:                dto.setFormatId(formatId);
213:                dto.setName(name);
214:                dto.setWmsPath(wmsPath);
215:                dto.setLabel(label);
216:                dto.setDescription(description);
217:                dto.setMetadataLink(metadataLink);
218:                dto.setDirName(dirName);
219:                dto.setKeywords(keywords);
220:                dto.setCrs(crs);
221:                dto.setSrsName(srsName);
222:                dto.setSrsWKT(srsWKT);
223:                dto.setEnvelope(envelope);
224:                dto.setLonLatWGS84Envelope(lonLatWGS84Envelope);
225:                dto.setGrid(grid);
226:                dto.setDimensions(dimensions);
227:                dto.setDimensionNames(dimensionNames);
228:                dto.setRequestCRSs(requestCRSs);
229:                dto.setResponseCRSs(responseCRSs);
230:                dto.setNativeFormat(nativeFormat);
231:                dto.setSupportedFormats(supportedFormats);
232:                dto.setDefaultInterpolationMethod(defaultInterpolationMethod);
233:                dto.setInterpolationMethods(interpolationMethods);
234:                dto.setDefaultStyle(defaultStyle);
235:                dto.setStyles(styles);
236:                dto.setParameters(parameters);
237:
238:                return dto;
239:            }
240:
241:            public CoverageStoreInfo getFormatInfo() {
242:                return data.getFormatInfo(formatId);
243:            }
244:
245:            public boolean isEnabled() {
246:                return (getFormatInfo() != null)
247:                        && (getFormatInfo().isEnabled());
248:            }
249:
250:            public CoverageStoreInfo getFormatMetaData() {
251:                return data.getFormatInfo(formatId);
252:            }
253:
254:            public boolean containsMetaData(String key) {
255:                return meta.containsKey(key);
256:            }
257:
258:            public void putMetaData(String key, Object value) {
259:                meta.put(key, value);
260:            }
261:
262:            public Object getMetaData(String key) {
263:                return meta.get(key);
264:            }
265:
266:            /**
267:             * @return Returns the data.
268:             */
269:            public Data getData() {
270:                return data;
271:            }
272:
273:            /**
274:             * @return Returns the defaultInterpolationMethod.
275:             */
276:            public String getDefaultInterpolationMethod() {
277:                return defaultInterpolationMethod;
278:            }
279:
280:            /**
281:             * @return Returns the description.
282:             */
283:            public String getDescription() {
284:                return description;
285:            }
286:
287:            /**
288:             * @return Returns the dirName.
289:             */
290:            public String getDirName() {
291:                return dirName;
292:            }
293:
294:            /**
295:             * @return Returns the envelope.
296:             */
297:            public GeneralEnvelope getEnvelope() {
298:                return envelope;
299:            }
300:
301:            /**
302:             * @return Returns the formatId.
303:             */
304:            public String getFormatId() {
305:                return formatId;
306:            }
307:
308:            /**
309:             * @return Returns the interpolationMethods.
310:             */
311:            public List getInterpolationMethods() {
312:                return interpolationMethods;
313:            }
314:
315:            /**
316:             * @return Returns the keywords.
317:             */
318:            public List getKeywords() {
319:                return keywords;
320:            }
321:
322:            /**
323:             * @return Returns the label.
324:             */
325:            public String getLabel() {
326:                return label;
327:            }
328:
329:            /**
330:             * @return Returns the meta.
331:             */
332:            public Map getMeta() {
333:                return meta;
334:            }
335:
336:            /**
337:             * @return Returns the metadataLink.
338:             */
339:            public MetaDataLink getMetadataLink() {
340:                return metadataLink;
341:            }
342:
343:            /**
344:             * @return String the namespace prefix.
345:             */
346:            public String getPrefix() {
347:                CoverageStoreInfo info = getFormatInfo();
348:
349:                if (info != null) {
350:                    return info.getNameSpace().getPrefix();
351:                }
352:
353:                return null;
354:            }
355:
356:            /**
357:             * @return NameSpaceInfo the namespace specified for the specified
358:             *         CoverageStoreInfo (by ID)
359:             *
360:             * @throws IllegalStateException
361:             *             Thrown when disabled.
362:             */
363:            public NameSpaceInfo getNameSpace() {
364:                if (!isEnabled()) {
365:                    throw new IllegalStateException("This coverage is not "
366:                            + "enabled");
367:                }
368:
369:                return getFormatInfo().getNameSpace();
370:            }
371:
372:            /**
373:             * @return Returns the name.
374:             */
375:            public String getName() {
376:                return getPrefix() + ":" + name;
377:            }
378:
379:            /**
380:             * @return Returns the nativeFormat.
381:             */
382:            public String getNativeFormat() {
383:                return nativeFormat;
384:            }
385:
386:            /**
387:             * @return Returns the requestCRSs.
388:             */
389:            public List getRequestCRSs() {
390:                return requestCRSs;
391:            }
392:
393:            /**
394:             * @return Returns the responseCRSs.
395:             */
396:            public List getResponseCRSs() {
397:                return responseCRSs;
398:            }
399:
400:            /**
401:             * @return Returns the srsName.
402:             */
403:            public String getSrsName() {
404:                return srsName;
405:            }
406:
407:            /**
408:             * @return Returns the supportedFormats.
409:             */
410:            public List getSupportedFormats() {
411:                return supportedFormats;
412:            }
413:
414:            /**
415:             * By now just return the default style to be able to declare it in WMS
416:             * capabilities, but all this stuff needs to be revisited since it seems
417:             * currently there is no way of retrieving all the styles declared for a
418:             * given Coverage.
419:             *
420:             * @return the default Style for the Coverage
421:             */
422:            public Style getDefaultStyle() {
423:                return data.getStyle(defaultStyle);
424:            }
425:
426:            public ArrayList getStyles() {
427:                final ArrayList realStyles = new ArrayList();
428:                Iterator s_IT = styles.iterator();
429:
430:                while (s_IT.hasNext())
431:                    realStyles.add(data.getStyle((String) s_IT.next()));
432:
433:                return realStyles;
434:            }
435:
436:            /**
437:             *
438:             */
439:            public CoordinateReferenceSystem getCrs() {
440:                return crs;
441:            }
442:
443:            /**
444:             *
445:             */
446:            public GridGeometry getGrid() {
447:                return grid;
448:            }
449:
450:            /**
451:             *
452:             */
453:            public InternationalString[] getDimensionNames() {
454:                return dimensionNames;
455:            }
456:
457:            /**
458:             * @return Returns the dimensions.
459:             */
460:            public CoverageDimension[] getDimensions() {
461:                return dimensions;
462:            }
463:
464:            public String getSrsWKT() {
465:                return srsWKT;
466:            }
467:
468:            public GeneralEnvelope getWGS84LonLatEnvelope() {
469:                if (this .lonLatWGS84Envelope == null) {
470:                    try {
471:                        this .lonLatWGS84Envelope = CoverageStoreUtils
472:                                .getWGS84LonLatEnvelope(this .envelope);
473:                    } catch (IndexOutOfBoundsException e) {
474:                        return null;
475:                    } catch (FactoryException e) {
476:                        return null;
477:                    } catch (TransformException e) {
478:                        return null;
479:                    }
480:                }
481:
482:                return this .lonLatWGS84Envelope;
483:            }
484:
485:            public String getWmsPath() {
486:                return wmsPath;
487:            }
488:
489:            public void setWmsPath(String wmsPath) {
490:                this .wmsPath = wmsPath;
491:            }
492:
493:            public GridCoverageReader getReader() {
494:                // /////////////////////////////////////////////////////////
495:                //
496:                // Getting coverage config and then reader
497:                //
498:                // /////////////////////////////////////////////////////////
499:                return data.getFormatInfo(formatId).getReader();
500:            }
501:
502:            public GridCoverageReader createReader(Hints hints) {
503:                // /////////////////////////////////////////////////////////
504:                //
505:                // Getting coverage config and then reader
506:                //
507:                // /////////////////////////////////////////////////////////
508:                return data.getFormatInfo(formatId).createReader(hints);
509:            }
510:
511:            public Map getParameters() {
512:                return parameters;
513:            }
514:
515:            public GridCoverage getCoverage() {
516:                return getCoverage(null, null);
517:            }
518:
519:            public GridCoverage getCoverage(GeneralEnvelope envelope,
520:                    Rectangle dim) {
521:                GridCoverage gc = null;
522:
523:                try {
524:                    if (envelope == null) {
525:                        envelope = this .envelope;
526:                    }
527:
528:                    // /////////////////////////////////////////////////////////
529:                    //
530:                    // Do we need to proceed?
531:                    // I need to check the requested envelope in order to see if the
532:                    // coverage we ask intersect it otherwise it is pointless to load it
533:                    // since its reader might return null;
534:                    // /////////////////////////////////////////////////////////
535:                    final CoordinateReferenceSystem sourceCRS = envelope
536:                            .getCoordinateReferenceSystem();
537:                    final CoordinateReferenceSystem destCRS = crs;
538:
539:                    if (!CRSUtilities.equalsIgnoreMetadata(sourceCRS, destCRS)) {
540:                        // get a math transform
541:                        final MathTransform transform = CoverageUtils
542:                                .getMathTransform(sourceCRS, destCRS);
543:
544:                        // transform the envelope
545:                        if (!transform.isIdentity()) {
546:                            envelope = CRSUtilities.transform(transform,
547:                                    envelope);
548:                        }
549:                    }
550:
551:                    // just do the intersection since
552:                    envelope.intersect(this .envelope);
553:
554:                    if (envelope.isEmpty()) {
555:                        return null;
556:                    }
557:
558:                    envelope.setCoordinateReferenceSystem(destCRS);
559:
560:                    // /////////////////////////////////////////////////////////
561:                    //
562:                    // get a reader
563:                    //
564:                    // /////////////////////////////////////////////////////////
565:                    final GridCoverageReader reader = getReader();
566:
567:                    if (reader == null) {
568:                        return null;
569:                    }
570:
571:                    // /////////////////////////////////////////////////////////
572:                    //
573:                    // Reading the coverage
574:                    //
575:                    // /////////////////////////////////////////////////////////
576:                    gc = reader.read(CoverageUtils.getParameters(getReader()
577:                            .getFormat().getReadParameters(), getParameters()));
578:
579:                    if ((gc == null) || !(gc instanceof  GridCoverage2D)) {
580:                        throw new IOException(
581:                                "The requested coverage could not be found.");
582:                    }
583:                } catch (InvalidParameterValueException e) {
584:                    LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
585:                } catch (ParameterNotFoundException e) {
586:                    LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
587:                } catch (MalformedURLException e) {
588:                    LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
589:                } catch (IllegalArgumentException e) {
590:                    LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
591:                } catch (SecurityException e) {
592:                    LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
593:                } catch (IOException e) {
594:                    LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
595:                } catch (TransformException e) {
596:                    LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
597:                }
598:
599:                return gc;
600:            }
601:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.