Source Code Cross Referenced for ImagePyramidReaderTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » gce » imagepyramid » 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.gce.imagepyramid 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Geotools 2 - OpenSource mapping toolkit
003:         * (C) 2006, Geotools Project Managment Committee (PMC)
004:         *
005:         *    This library is free software; you can redistribute it and/or
006:         *    modify it under the terms of the GNU Lesser General Public
007:         *    License as published by the Free Software Foundation; either
008:         *    version 2.1 of the License, or (at your option) any later version.
009:         *
010:         *    This library is distributed in the hope that it will be useful,
011:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         *    Lesser General Public License for more details.
014:         *
015:         *    You should have received a copy of the GNU Lesser General Public
016:         *    License along with this library; if not, write to the Free Software
017:         *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         */
019:        package org.geotools.gce.imagepyramid;
020:
021:        import java.awt.Color;
022:        import java.awt.Rectangle;
023:        import java.io.File;
024:        import java.io.FileInputStream;
025:        import java.io.IOException;
026:        import java.net.URL;
027:
028:        import javax.imageio.ImageIO;
029:        import javax.media.jai.JAI;
030:
031:        import junit.framework.TestCase;
032:        import junit.textui.TestRunner;
033:
034:        import org.geotools.coverage.grid.GeneralGridRange;
035:        import org.geotools.coverage.grid.GridCoverage2D;
036:        import org.geotools.coverage.grid.GridGeometry2D;
037:        import org.geotools.coverage.grid.io.AbstractGridFormat;
038:        import org.geotools.data.DataSourceException;
039:        import org.geotools.factory.Hints;
040:        import org.geotools.gce.imagemosaic.ImageMosaicFormat;
041:        import org.geotools.geometry.GeneralEnvelope;
042:        import org.geotools.referencing.crs.DefaultGeographicCRS;
043:        import org.geotools.resources.TestData;
044:        import org.opengis.parameter.GeneralParameterValue;
045:        import org.opengis.parameter.ParameterValue;
046:        import org.opengis.referencing.NoSuchAuthorityCodeException;
047:        import org.opengis.geometry.MismatchedDimensionException;
048:
049:        /**
050:         * Testing {@link ImagePyramidReader}.
051:         * 
052:         * @author Simone Giannecchini
053:         * @since 2.3
054:         * 
055:         */
056:        public class ImagePyramidReaderTest extends TestCase {
057:
058:            /**
059:             * File to be used for testing purposes.
060:             */
061:            private final static String TEST_FILE = "pyramid.properties";
062:
063:            /**
064:             * Default constructor.
065:             */
066:            public ImagePyramidReaderTest() {
067:
068:            }
069:
070:            public void testDefaultParameterValue() throws IOException,
071:                    MismatchedDimensionException, NoSuchAuthorityCodeException {
072:                //
073:                // /////////////////////////////////////////////////////////////////
074:                //
075:                // Get the resource.
076:                //
077:                //
078:                // /////////////////////////////////////////////////////////////////
079:                final URL testFile = TestData.getResource(this , TEST_FILE);//
080:                assertNotNull(testFile);
081:
082:                //
083:                // /////////////////////////////////////////////////////////////////
084:                //
085:                // Get a reader
086:                //
087:                //
088:                // /////////////////////////////////////////////////////////////////
089:                final AbstractGridFormat format = new ImagePyramidFormat();
090:                assertTrue(format.accepts(testFile));
091:                final ImagePyramidReader reader = (ImagePyramidReader) format
092:                        .getReader(testFile);
093:                assertNotNull(reader);
094:
095:                //
096:                // /////////////////////////////////////////////////////////////////
097:                //
098:                // Show the coverage
099:                //
100:                //
101:                // /////////////////////////////////////////////////////////////////
102:                final GridCoverage2D coverage = (GridCoverage2D) reader
103:                        .read(null);
104:                assertNotNull("Null value returned instead of a coverage",
105:                        coverage);
106:                assertTrue(
107:                        "coverage dimensions different from what we expected",
108:                        coverage.getGridGeometry().getGridRange().getLength(0) == 250
109:                                && coverage.getGridGeometry().getGridRange()
110:                                        .getLength(1) == 250);
111:                if (TestData.isInteractiveTest())
112:                    coverage.show("testDefaultParameterValue");
113:                else
114:                    ((GridCoverage2D) coverage).getRenderedImage().getData();
115:
116:            }
117:
118:            public void testDefaultParameterValueFile() throws IOException,
119:                    MismatchedDimensionException, NoSuchAuthorityCodeException {
120:                //
121:                // /////////////////////////////////////////////////////////////////
122:                //
123:                // Get the resource.
124:                //
125:                //
126:                // /////////////////////////////////////////////////////////////////
127:                final File testFile = TestData.file(this , TEST_FILE);//
128:                assertNotNull(testFile);
129:
130:                //
131:                // /////////////////////////////////////////////////////////////////
132:                //
133:                // Get a reader
134:                //
135:                //
136:                // /////////////////////////////////////////////////////////////////
137:                final AbstractGridFormat format = new ImagePyramidFormat();
138:                assertTrue(format.accepts(testFile));
139:                final ImagePyramidReader reader = (ImagePyramidReader) format
140:                        .getReader(testFile);
141:                assertNotNull(reader);
142:
143:                //
144:                // /////////////////////////////////////////////////////////////////
145:                //
146:                // Show the coverage
147:                //
148:                //
149:                // /////////////////////////////////////////////////////////////////
150:                final GridCoverage2D coverage = (GridCoverage2D) reader
151:                        .read(null);
152:                assertNotNull("Null value returned instead of a coverage",
153:                        coverage);
154:                assertTrue(
155:                        "coverage dimensions different from what we expected",
156:                        coverage.getGridGeometry().getGridRange().getLength(0) == 250
157:                                && coverage.getGridGeometry().getGridRange()
158:                                        .getLength(1) == 250);
159:                if (TestData.isInteractiveTest())
160:                    coverage.show("testDefaultParameterValueFile");
161:                else
162:                    ((GridCoverage2D) coverage).getRenderedImage().getData();
163:
164:            }
165:
166:            public void testDefaultParameterValueString() throws IOException,
167:                    MismatchedDimensionException, NoSuchAuthorityCodeException {
168:                //
169:                // /////////////////////////////////////////////////////////////////
170:                //
171:                // Get the resource.
172:                //
173:                //
174:                // /////////////////////////////////////////////////////////////////
175:                final String testFile = TestData.file(this , TEST_FILE)
176:                        .getCanonicalPath();//
177:                assertNotNull(testFile);
178:
179:                //
180:                // /////////////////////////////////////////////////////////////////
181:                //
182:                // Get a reader
183:                //
184:                //
185:                // /////////////////////////////////////////////////////////////////
186:                final AbstractGridFormat format = new ImagePyramidFormat();
187:                assertTrue(format.accepts(testFile));
188:                final ImagePyramidReader reader = (ImagePyramidReader) format
189:                        .getReader(testFile);
190:                assertNotNull(reader);
191:
192:                //
193:                // /////////////////////////////////////////////////////////////////
194:                //
195:                // Show the coverage
196:                //
197:                //
198:                // /////////////////////////////////////////////////////////////////
199:                final GridCoverage2D coverage = (GridCoverage2D) reader
200:                        .read(null);
201:                assertNotNull("Null value returned instead of a coverage",
202:                        coverage);
203:                assertTrue(
204:                        "coverage dimensions different from what we expected",
205:                        coverage.getGridGeometry().getGridRange().getLength(0) == 250
206:                                && coverage.getGridGeometry().getGridRange()
207:                                        .getLength(1) == 250);
208:                if (TestData.isInteractiveTest())
209:                    coverage.show("testDefaultParameterValueString");
210:                else
211:                    ((GridCoverage2D) coverage).getRenderedImage().getData();
212:
213:            }
214:
215:            public void testForErrors() throws IOException,
216:                    MismatchedDimensionException, NoSuchAuthorityCodeException {
217:                //
218:                // /////////////////////////////////////////////////////////////////
219:                //
220:                // Get the resource.
221:                //
222:                //
223:                // /////////////////////////////////////////////////////////////////
224:                final File testFile = TestData.file(this , TEST_FILE);//
225:                assertNotNull(testFile);
226:
227:                // /////////////////////////////////////////////////////////////////
228:                //
229:                // Null argument
230:                //
231:                //
232:                // /////////////////////////////////////////////////////////////////
233:                ImagePyramidReader reader = null;
234:                try {
235:                    reader = new ImagePyramidReader(null, new Hints(
236:                            Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER,
237:                            Boolean.FALSE));
238:                } catch (DataSourceException e) {
239:
240:                }
241:                assertNull(reader);
242:
243:                // /////////////////////////////////////////////////////////////////
244:                //
245:                // Illegal arguments
246:                //
247:                //
248:                // /////////////////////////////////////////////////////////////////
249:                try {
250:                    reader = new ImagePyramidReader(new FileInputStream(
251:                            testFile), new Hints(
252:                            Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER,
253:                            Boolean.FALSE));
254:                } catch (IllegalArgumentException e) {
255:
256:                }
257:                assertNull(reader);
258:                try {
259:                    reader = new ImagePyramidReader(ImageIO
260:                            .createImageInputStream(testFile), new Hints(
261:                            Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER,
262:                            Boolean.FALSE));
263:                } catch (IllegalArgumentException e) {
264:
265:                }
266:                assertNull(reader);
267:
268:                // /////////////////////////////////////////////////////////////////
269:                //
270:                // Unsopported operations
271:                //
272:                //
273:                // /////////////////////////////////////////////////////////////////
274:                reader = new ImagePyramidReader(testFile, new Hints(
275:                        Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.FALSE));
276:
277:                try {
278:                    reader.getCurrentSubname();
279:
280:                } catch (UnsupportedOperationException e) {
281:                    try {
282:                        reader.getMetadataNames();
283:                        ;
284:
285:                    } catch (UnsupportedOperationException e1) {
286:                        try {
287:                            reader.getMetadataValue("");
288:                        } catch (UnsupportedOperationException e2) {
289:                            return;
290:                        }
291:                    }
292:                }
293:                assertTrue(
294:                        "Some of the unsopported methdo did not send an exception",
295:                        false);
296:
297:            }
298:
299:            public void testComplete() throws IOException,
300:                    MismatchedDimensionException, NoSuchAuthorityCodeException {
301:
302:                //
303:                // /////////////////////////////////////////////////////////////////
304:                //
305:                // Get the resource.
306:                //
307:                //
308:                // /////////////////////////////////////////////////////////////////
309:                final URL testFile = TestData.getResource(this , TEST_FILE);
310:                assertNotNull(testFile);
311:
312:                //
313:                // /////////////////////////////////////////////////////////////////
314:                //
315:                // Get a reader
316:                //
317:                //
318:                // /////////////////////////////////////////////////////////////////
319:                final ImagePyramidReader reader = new ImagePyramidReader(
320:                        testFile, new Hints(
321:                                Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER,
322:                                Boolean.FALSE));
323:                assertNotNull(reader);
324:
325:                //
326:                // /////////////////////////////////////////////////////////////////
327:                //
328:                // alpha on output
329:                //
330:                //
331:                // /////////////////////////////////////////////////////////////////
332:                final ParameterValue threshold = (ParameterValue) ImageMosaicFormat.INPUT_IMAGE_THRESHOLD_VALUE
333:                        .createValue();
334:                threshold.setValue(100);
335:                final ParameterValue transp = (ParameterValue) ImageMosaicFormat.INPUT_TRANSPARENT_COLOR
336:                        .createValue();
337:                transp.setValue(Color.black);
338:
339:                // /////////////////////////////////////////////////////////////////
340:                //
341:                // Show the coverage
342:                //
343:                //
344:                // /////////////////////////////////////////////////////////////////
345:                GridCoverage2D coverage = (GridCoverage2D) reader
346:                        .read(new GeneralParameterValue[] { threshold, transp });
347:                assertNotNull(coverage);
348:                assertTrue(
349:                        "coverage dimensions different from what we expected",
350:                        coverage.getGridGeometry().getGridRange().getLength(0) == 250
351:                                && coverage.getGridGeometry().getGridRange()
352:                                        .getLength(1) == 250);
353:                if (TestData.isInteractiveTest())
354:                    coverage.show("testComplete");
355:                else
356:                    ((GridCoverage2D) coverage).getRenderedImage().getData();
357:
358:            }
359:
360:            /**
361:             * Testing {@link ImagePyramidReader} by cropping requesting a the best
362:             * possible dimension.
363:             * 
364:             * <p>
365:             * The underlying pyramid i made by 4 levels on the same area, more or less
366:             * italy, with resolution decreasing as a power of 2.
367:             * 
368:             * <p>
369:             * Size of the original mosaic is 250,250.
370:             * 
371:             * @throws IOException
372:             * @throws MismatchedDimensionException
373:             * @throws NoSuchAuthorityCodeException
374:             */
375:            public void testCropHighestLevel() throws IOException,
376:                    MismatchedDimensionException, NoSuchAuthorityCodeException {
377:
378:                // /////////////////////////////////////////////////////////////////
379:                //
380:                // Get the resource.
381:                //
382:                //
383:                // /////////////////////////////////////////////////////////////////
384:                final URL testFile = TestData.getResource(this , TEST_FILE);
385:
386:                //
387:                // /////////////////////////////////////////////////////////////////
388:                //
389:                // Get a reader
390:                //
391:                //
392:                // /////////////////////////////////////////////////////////////////
393:                final AbstractGridFormat format = new ImagePyramidFormat();
394:                final ImagePyramidReader reader = (ImagePyramidReader) format
395:                        .getReader(testFile);
396:
397:                // /////////////////////////////////////////////////////////////////
398:                //
399:                // crop
400:                //
401:                //
402:                // /////////////////////////////////////////////////////////////////
403:                final ParameterValue gg = (ParameterValue) ImageMosaicFormat.READ_GRIDGEOMETRY2D
404:                        .createValue();
405:                final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope();
406:                final GeneralEnvelope cropEnvelope = new GeneralEnvelope(
407:                        new double[] {
408:                                oldEnvelop.getLowerCorner().getOrdinate(0),
409:                                oldEnvelop.getLowerCorner().getOrdinate(1) },
410:                        new double[] {
411:                                oldEnvelop.getLowerCorner().getOrdinate(0)
412:                                        + oldEnvelop.getLength(0) / 2,
413:                                oldEnvelop.getLowerCorner().getOrdinate(1)
414:                                        + oldEnvelop.getLength(1) / 2 });
415:                cropEnvelope
416:                        .setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
417:                gg.setValue(new GridGeometry2D(new GeneralGridRange(
418:                        new Rectangle(0, 0, 250, 250)), cropEnvelope));
419:
420:                //
421:                // /////////////////////////////////////////////////////////////////
422:                //
423:                // Show the coverage
424:                //
425:                //
426:                // /////////////////////////////////////////////////////////////////
427:                GridCoverage2D coverage = ((GridCoverage2D) reader
428:                        .read(new GeneralParameterValue[] { gg }));
429:                assertNotNull("Null value returned instead of a coverage",
430:                        coverage);
431:                assertTrue(
432:                        "coverage dimensions different from what we expected",
433:                        coverage.getGridGeometry().getGridRange().getLength(0) == 125
434:                                && coverage.getGridGeometry().getGridRange()
435:                                        .getLength(1) == 125);
436:                if (TestData.isInteractiveTest())
437:                    coverage.show("testCropHighestLevel");
438:                else
439:                    coverage.getRenderedImage().getData();
440:
441:            }
442:
443:            /**
444:             * Testing {@link ImagePyramidReader} by cropping requesting a the second
445:             * better avialble resolution.
446:             * 
447:             * <p>
448:             * The underlying pyramid i made by 4 levels on the same area, more or less
449:             * italy, with resolution decreasing as a power of 2.
450:             * 
451:             * <p>
452:             * Size of the original mosaic is 250,250.
453:             * 
454:             * @throws IOException
455:             * @throws MismatchedDimensionException
456:             * @throws NoSuchAuthorityCodeException
457:             */
458:            public void testCropLevel1() throws IOException,
459:                    MismatchedDimensionException, NoSuchAuthorityCodeException {
460:
461:                // /////////////////////////////////////////////////////////////////
462:                //
463:                // Get the resource.
464:                //
465:                //
466:                // /////////////////////////////////////////////////////////////////
467:                final URL testFile = TestData.getResource(this , TEST_FILE);
468:
469:                //
470:                // /////////////////////////////////////////////////////////////////
471:                //
472:                // Get a reader
473:                //
474:                //
475:                // /////////////////////////////////////////////////////////////////
476:                final AbstractGridFormat format = new ImagePyramidFormat();
477:                final ImagePyramidReader reader = (ImagePyramidReader) format
478:                        .getReader(testFile);
479:
480:                // /////////////////////////////////////////////////////////////////
481:                //
482:                // crop
483:                //
484:                //
485:                // /////////////////////////////////////////////////////////////////
486:                final ParameterValue gg = (ParameterValue) ImageMosaicFormat.READ_GRIDGEOMETRY2D
487:                        .createValue();
488:                final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope();
489:                final GeneralEnvelope cropEnvelope = new GeneralEnvelope(
490:                        new double[] {
491:                                oldEnvelop.getLowerCorner().getOrdinate(0),
492:                                oldEnvelop.getLowerCorner().getOrdinate(1) },
493:                        new double[] {
494:                                oldEnvelop.getLowerCorner().getOrdinate(0)
495:                                        + oldEnvelop.getLength(0) / 2,
496:                                oldEnvelop.getLowerCorner().getOrdinate(1)
497:                                        + oldEnvelop.getLength(1) / 2 });
498:                cropEnvelope
499:                        .setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
500:                gg.setValue(new GridGeometry2D(new GeneralGridRange(
501:                        new Rectangle(0, 0, 125, 125)), cropEnvelope));
502:
503:                //
504:                // /////////////////////////////////////////////////////////////////
505:                //
506:                // Show the coverage
507:                //
508:                //
509:                // /////////////////////////////////////////////////////////////////
510:                GridCoverage2D coverage = ((GridCoverage2D) reader
511:                        .read(new GeneralParameterValue[] { gg }));
512:                assertNotNull("Null value returned instead of a coverage",
513:                        coverage);
514:                // assertTrue("coverage dimensions different from what we expected",
515:                // coverage.getGridGeometry().getGridRange().getLength(0) == 63
516:                // && coverage.getGridGeometry().getGridRange().getLength(
517:                // 1) == 62);
518:                if (TestData.isInteractiveTest())
519:                    coverage.show("testCropLevel1");
520:                else
521:                    coverage.getRenderedImage().getData();
522:
523:            }
524:
525:            /**
526:             * Testing {@link ImagePyramidReader} by cropping requesting a the third
527:             * better avialble resolution.
528:             * 
529:             * <p>
530:             * The underlying pyramid i made by 4 levels on the same area, more or less
531:             * italy, with resolution decreasing as a power of 2.
532:             * 
533:             * <p>
534:             * Size of the original mosaic is 250,250.
535:             * 
536:             * @throws IOException
537:             * @throws MismatchedDimensionException
538:             * @throws NoSuchAuthorityCodeException
539:             */
540:            public void testCropLevel2() throws IOException,
541:                    MismatchedDimensionException, NoSuchAuthorityCodeException {
542:
543:                // /////////////////////////////////////////////////////////////////
544:                //
545:                // Get the resource.
546:                //
547:                //
548:                // /////////////////////////////////////////////////////////////////
549:                final URL testFile = TestData.getResource(this , TEST_FILE);
550:
551:                //
552:                // /////////////////////////////////////////////////////////////////
553:                //
554:                // Get a reader
555:                //
556:                //
557:                // /////////////////////////////////////////////////////////////////
558:                final AbstractGridFormat format = new ImagePyramidFormat();
559:                final ImagePyramidReader reader = (ImagePyramidReader) format
560:                        .getReader(testFile);
561:
562:                // /////////////////////////////////////////////////////////////////
563:                //
564:                // crop
565:                //
566:                //
567:                // /////////////////////////////////////////////////////////////////
568:                final ParameterValue gg = (ParameterValue) ImageMosaicFormat.READ_GRIDGEOMETRY2D
569:                        .createValue();
570:                final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope();
571:                final GeneralEnvelope cropEnvelope = new GeneralEnvelope(
572:                        new double[] {
573:                                oldEnvelop.getLowerCorner().getOrdinate(0),
574:                                oldEnvelop.getLowerCorner().getOrdinate(1) },
575:                        new double[] {
576:                                oldEnvelop.getLowerCorner().getOrdinate(0)
577:                                        + oldEnvelop.getLength(0) / 2,
578:                                oldEnvelop.getLowerCorner().getOrdinate(1)
579:                                        + oldEnvelop.getLength(1) / 2 });
580:                cropEnvelope
581:                        .setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
582:                gg.setValue(new GridGeometry2D(new GeneralGridRange(
583:                        new Rectangle(0, 0, 62, 62)), cropEnvelope));
584:
585:                //
586:                // /////////////////////////////////////////////////////////////////
587:                //
588:                // Show the coverage
589:                //
590:                //
591:                // /////////////////////////////////////////////////////////////////
592:                GridCoverage2D coverage = ((GridCoverage2D) reader
593:                        .read(new GeneralParameterValue[] { gg }));
594:                assertNotNull("Null value returned instead of a coverage",
595:                        coverage);
596:                // assertTrue("coverage dimensions different from what we expected",
597:                // coverage.getGridGeometry().getGridRange().getLength(0) == 31
598:                // && coverage.getGridGeometry().getGridRange().getLength(
599:                // 1) == 31);
600:                if (TestData.isInteractiveTest())
601:                    coverage.show("testCropLevel1");
602:                else
603:                    coverage.getRenderedImage().getData();
604:
605:            }
606:
607:            /**
608:             * Testing {@link ImagePyramidReader} by cropping requesting a the worst
609:             * availaible resolution.
610:             * 
611:             * <p>
612:             * The underlying pyramid i made by 4 levels on the same area, more or less
613:             * italy, with resolution decreasing as a power of 2.
614:             * 
615:             * <p>
616:             * Size of the original mosaic is 250,250.
617:             * 
618:             * @throws IOException
619:             * @throws MismatchedDimensionException
620:             * @throws NoSuchAuthorityCodeException
621:             */
622:            public void testCropLevel3() throws IOException,
623:                    MismatchedDimensionException, NoSuchAuthorityCodeException {
624:
625:                // /////////////////////////////////////////////////////////////////
626:                //
627:                // Get the resource.
628:                //
629:                //
630:                // /////////////////////////////////////////////////////////////////
631:                final URL testFile = TestData.getResource(this , TEST_FILE);
632:
633:                //
634:                // /////////////////////////////////////////////////////////////////
635:                //
636:                // Get a reader
637:                //
638:                //
639:                // /////////////////////////////////////////////////////////////////
640:                final AbstractGridFormat format = new ImagePyramidFormat();
641:                final ImagePyramidReader reader = (ImagePyramidReader) format
642:                        .getReader(testFile);
643:
644:                // /////////////////////////////////////////////////////////////////
645:                //
646:                // crop
647:                //
648:                //
649:                // /////////////////////////////////////////////////////////////////
650:                final ParameterValue gg = (ParameterValue) ImageMosaicFormat.READ_GRIDGEOMETRY2D
651:                        .createValue();
652:                final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope();
653:                final GeneralEnvelope cropEnvelope = new GeneralEnvelope(
654:                        new double[] {
655:                                oldEnvelop.getLowerCorner().getOrdinate(0),
656:                                oldEnvelop.getLowerCorner().getOrdinate(1) },
657:                        new double[] {
658:                                oldEnvelop.getLowerCorner().getOrdinate(0)
659:                                        + oldEnvelop.getLength(0) / 2,
660:                                oldEnvelop.getLowerCorner().getOrdinate(1)
661:                                        + oldEnvelop.getLength(1) / 2 });
662:                cropEnvelope
663:                        .setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
664:                gg.setValue(new GridGeometry2D(new GeneralGridRange(
665:                        new Rectangle(0, 0, 25, 25)), cropEnvelope));
666:
667:                //
668:                // /////////////////////////////////////////////////////////////////
669:                //
670:                // Show the coverage
671:                //
672:                //
673:                // /////////////////////////////////////////////////////////////////
674:                GridCoverage2D coverage = ((GridCoverage2D) reader
675:                        .read(new GeneralParameterValue[] { gg }));
676:                assertNotNull("Null value returned instead of a coverage",
677:                        coverage);
678:                // assertTrue("coverage dimensions different from what we expected",
679:                // coverage.getGridGeometry().getGridRange().getLength(0) == 15
680:                // && coverage.getGridGeometry().getGridRange().getLength(
681:                // 1) == 15);
682:                if (TestData.isInteractiveTest())
683:                    coverage.show("testCropLevel1");
684:                else
685:                    coverage.getRenderedImage().getData();
686:
687:            }
688:
689:            /**
690:             * @param args
691:             */
692:            public static void main(String[] args) {
693:                TestRunner.run(ImagePyramidReaderTest.class);
694:
695:            }
696:
697:            protected void setUp() throws Exception {
698:
699:                JAI.getDefaultInstance().getTileCache().setMemoryCapacity(
700:                        64 * 1024 * 1024);
701:                JAI.getDefaultInstance().getTileScheduler().setParallelism(50);
702:                JAI.getDefaultInstance().getTileScheduler().setPriority(6);
703:                JAI.getDefaultInstance().getTileScheduler()
704:                        .setPrefetchParallelism(50);
705:                JAI.getDefaultInstance().getTileScheduler()
706:                        .setPrefetchPriority(6);
707:
708:                super.setUp();
709:            }
710:
711:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.