Source Code Cross Referenced for DefaultRasterMapProducerTest.java in  » GIS » GeoServer » org » vfny » geoserver » wms » responses » 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.wms.responses 
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.wms.responses;
006:
007:        import java.awt.Color;
008:        import java.awt.image.BufferedImage;
009:        import java.awt.image.RenderedImage;
010:        import java.io.IOException;
011:        import java.io.OutputStream;
012:        import java.util.logging.Logger;
013:
014:        import org.geotools.data.DataStore;
015:        import org.geotools.data.FeatureSource;
016:        import org.geotools.filter.FilterFactory;
017:        import org.geotools.filter.FilterFactoryFinder;
018:        import org.geotools.filter.IllegalFilterException;
019:        import org.geotools.styling.Style;
020:        import org.geotools.styling.StyleFactory;
021:        import org.geotools.styling.StyleFactoryFinder;
022:        import org.vfny.geoserver.testdata.AbstractCiteDataTest;
023:        import org.vfny.geoserver.wms.WMSMapContext;
024:        import org.vfny.geoserver.wms.WmsException;
025:        import org.vfny.geoserver.wms.requests.GetMapRequest;
026:
027:        import com.vividsolutions.jts.geom.Envelope;
028:
029:        /**
030:         * Tests that DefaultRasterMapProducerTest, which is based on LiteRenderer,
031:         * correctly generates a raster map.
032:         * 
033:         * @author Gabriel Roldan, Axios Engineering
034:         * @version $Id: DefaultRasterMapProducerTest.java 6797 2007-05-16 10:23:50Z
035:         *          aaime $
036:         */
037:        public class DefaultRasterMapProducerTest extends AbstractCiteDataTest {
038:            /** DOCUMENT ME! */
039:            private static final Logger LOGGER = org.geotools.util.logging.Logging
040:                    .getLogger(DefaultRasterMapProducerTest.class.getPackage()
041:                            .getName());
042:
043:            /** DOCUMENT ME! */
044:            private static final FilterFactory filterFactory = FilterFactoryFinder
045:                    .createFilterFactory();
046:
047:            /** DOCUMENT ME! */
048:            private static final StyleFactory sFac = StyleFactoryFinder
049:                    .createStyleFactory();
050:
051:            /** DOCUMENT ME! */
052:            private static final Color BG_COLOR = Color.white;
053:
054:            /** DOCUMENT ME! */
055:            private DefaultRasterMapProducer rasterMapProducer;
056:
057:            /**
058:             * 
059:             */
060:            public DefaultRasterMapProducerTest() {
061:                super ();
062:            }
063:
064:            /**
065:             * DOCUMENT ME!
066:             * 
067:             * @throws Exception
068:             *             DOCUMENT ME!
069:             */
070:            public void setUp() throws Exception {
071:                this .rasterMapProducer = getProducerInstance();
072:                super .setUp();
073:            }
074:
075:            /**
076:             * DOCUMENT ME!
077:             * 
078:             * @return DOCUMENT ME!
079:             */
080:            protected DefaultRasterMapProducer getProducerInstance() {
081:                return new DummyRasterMapProducer();
082:            }
083:
084:            /**
085:             * DOCUMENT ME!
086:             * 
087:             * @throws Exception
088:             *             DOCUMENT ME!
089:             */
090:            public void tearDown() throws Exception {
091:                this .rasterMapProducer = null;
092:                super .tearDown();
093:            }
094:
095:            /**
096:             * DOCUMENT ME!
097:             * 
098:             * @throws Exception
099:             *             DOCUMENT ME!
100:             */
101:            public void testSimpleGetMapQuery() throws Exception {
102:                final String mapFormat = "image/gif";
103:
104:                final DataStore ds = getCiteDataStore();
105:                final FeatureSource basicPolygons = ds
106:                        .getFeatureSource(BASIC_POLYGONS_TYPE);
107:                final Envelope env = basicPolygons.getBounds();
108:
109:                LOGGER
110:                        .info("about to create map ctx for BasicPolygons with bounds "
111:                                + env);
112:
113:                final WMSMapContext map = new WMSMapContext();
114:                map.setAreaOfInterest(env);
115:                map.setMapWidth(300);
116:                map.setMapHeight(300);
117:                map.setBgColor(Color.red);
118:                map.setTransparent(false);
119:                map.setRequest(new GetMapRequest(null));
120:
121:                Style basicStyle = getStyle("default.sld");
122:                map.addLayer(basicPolygons, basicStyle);
123:
124:                this .rasterMapProducer.setOutputFormat(mapFormat);
125:                this .rasterMapProducer.setMapContext(map);
126:                this .rasterMapProducer.produceMap();
127:
128:                assertNotBlank("testSimpleGetMapQuery", this .rasterMapProducer);
129:            }
130:
131:            /**
132:             * DOCUMENT ME!
133:             * 
134:             * @throws Exception
135:             *             DOCUMENT ME!
136:             */
137:            public void testDefaultStyle() throws Exception {
138:                final DataStore ds = getCiteDataStore();
139:                final String[] typeNames = ds.getTypeNames();
140:
141:                FeatureSource fSource;
142:
143:                for (int i = 0; i < typeNames.length; i++) {
144:                    fSource = ds.getFeatureSource(typeNames[i]);
145:                    testDefaultStyle(fSource);
146:                }
147:            }
148:
149:            /**
150:             * DOCUMENT ME!
151:             * 
152:             * @throws IOException
153:             *             DOCUMENT ME!
154:             * @throws IllegalFilterException
155:             *             DOCUMENT ME!
156:             * @throws IOException
157:             *             DOCUMENT ME!
158:             */
159:            public void testBlueLake() throws IOException,
160:                    IllegalFilterException, Exception {
161:                final DataStore ds = getCiteDataStore();
162:                Envelope env = getBlueLakeBounds();
163:                double shift = env.getWidth() / 6;
164:
165:                env = new Envelope(env.getMinX() - shift,
166:                        env.getMaxX() + shift, env.getMinY() - shift, env
167:                                .getMaxY()
168:                                + shift);
169:
170:                final WMSMapContext map = new WMSMapContext();
171:                int w = 400;
172:                int h = (int) Math
173:                        .round((env.getHeight() * w) / env.getWidth());
174:                map.setMapWidth(w);
175:                map.setMapHeight(h);
176:                map.setBgColor(BG_COLOR);
177:                map.setTransparent(true);
178:                map.setRequest(new GetMapRequest(null));
179:
180:                map.addLayer(ds.getFeatureSource(FORESTS_TYPE),
181:                        getDefaultStyle(FORESTS_TYPE));
182:                map.addLayer(ds.getFeatureSource(LAKES_TYPE),
183:                        getDefaultStyle(LAKES_TYPE));
184:                map.addLayer(ds.getFeatureSource(STREAMS_TYPE),
185:                        getDefaultStyle(STREAMS_TYPE));
186:                map.addLayer(ds.getFeatureSource(NAMED_PLACES_TYPE),
187:                        getDefaultStyle(NAMED_PLACES_TYPE));
188:                map.addLayer(ds.getFeatureSource(ROAD_SEGMENTS_TYPE),
189:                        getDefaultStyle(ROAD_SEGMENTS_TYPE));
190:                map.addLayer(ds.getFeatureSource(PONDS_TYPE),
191:                        getDefaultStyle(PONDS_TYPE));
192:                map.addLayer(ds.getFeatureSource(BUILDINGS_TYPE),
193:                        getDefaultStyle(BUILDINGS_TYPE));
194:
195:                map.addLayer(ds.getFeatureSource(DIVIDED_ROUTES_TYPE),
196:                        getDefaultStyle(DIVIDED_ROUTES_TYPE));
197:                map.addLayer(ds.getFeatureSource(BRIDGES_TYPE),
198:                        getDefaultStyle(BRIDGES_TYPE));
199:
200:                map.addLayer(ds.getFeatureSource(MAP_NEATLINE_TYPE),
201:                        getDefaultStyle(MAP_NEATLINE_TYPE));
202:
203:                map.setAreaOfInterest(env);
204:
205:                this .rasterMapProducer.setOutputFormat("image/gif");
206:                this .rasterMapProducer.setMapContext(map);
207:                this .rasterMapProducer.produceMap();
208:
209:                assertNotBlank("testBlueLake", this .rasterMapProducer);
210:            }
211:
212:            /**
213:             * Checks that the image generated by the map producer is not blank.
214:             * 
215:             * @param testName
216:             * @param producer
217:             */
218:            protected void assertNotBlank(String testName,
219:                    DefaultRasterMapProducer producer) {
220:                BufferedImage image = (BufferedImage) producer.getImage();
221:                assertNotBlank(testName, image, BG_COLOR);
222:                showImage(testName, image);
223:            }
224:
225:            /**
226:             * DOCUMENT ME!
227:             * 
228:             * @param fSource
229:             *            DOCUMENT ME!
230:             * 
231:             * @throws Exception
232:             *             DOCUMENT ME!
233:             */
234:            private void testDefaultStyle(FeatureSource fSource)
235:                    throws Exception {
236:                Style style = getStyle("default.sld");
237:
238:                Envelope env = getBlueLakeBounds();
239:                env.expandToInclude(fSource.getBounds());
240:
241:                int w = 400;
242:                int h = (int) Math
243:                        .round((env.getHeight() * w) / env.getWidth());
244:
245:                double shift = env.getWidth() / 6;
246:
247:                env = new Envelope(env.getMinX() - shift,
248:                        env.getMaxX() + shift, env.getMinY() - shift, env
249:                                .getMaxY()
250:                                + shift);
251:
252:                WMSMapContext map = new WMSMapContext();
253:                map.setRequest(new GetMapRequest(null));
254:                map.addLayer(fSource, style);
255:                map.setAreaOfInterest(env);
256:                map.setMapWidth(w);
257:                map.setMapHeight(h);
258:                map.setBgColor(BG_COLOR);
259:                map.setTransparent(false);
260:
261:                this .rasterMapProducer.setOutputFormat("image/gif");
262:                this .rasterMapProducer.setMapContext(map);
263:                this .rasterMapProducer.produceMap();
264:
265:                RenderedImage image = this .rasterMapProducer.getImage();
266:
267:                String typeName = fSource.getSchema().getTypeName();
268:                assertNotBlank("testDefaultStyle " + typeName,
269:                        this .rasterMapProducer);
270:            }
271:
272:            /**
273:             * Returns the bounds of the entire Blue Lake fictional location, given by
274:             * the bounds of the MapNeatline feature source.
275:             * 
276:             * @return
277:             * 
278:             * @throws IOException
279:             *             DOCUMENT ME!
280:             */
281:            protected Envelope getBlueLakeBounds() throws IOException {
282:                return getCiteDataStore().getFeatureSource(MAP_NEATLINE_TYPE)
283:                        .getBounds();
284:            }
285:
286:            /**
287:             * This dummy producer adds no functionality to DefaultRasterMapProducer,
288:             * just implements a void formatImageOutputStream to have a concrete class
289:             * over which test that DefaultRasterMapProducer correctly generates the
290:             * BufferedImage.
291:             * 
292:             * @author Gabriel Roldan, Axios Engineering
293:             * @version $Id: DefaultRasterMapProducerTest.java 6797 2007-05-16 10:23:50Z
294:             *          aaime $
295:             */
296:            private static class DummyRasterMapProducer extends
297:                    DefaultRasterMapProducer {
298:                /**
299:                 * DOCUMENT ME!
300:                 * 
301:                 * @param image
302:                 *            not used.
303:                 * @param outStream
304:                 *            not used.
305:                 * 
306:                 * @throws WmsException
307:                 *             never.
308:                 * @throws IOException
309:                 *             never.
310:                 */
311:                public void formatImageOutputStream(RenderedImage image,
312:                        OutputStream outStream) throws WmsException,
313:                        IOException {
314:                    /*
315:                     * Intentionally left blank, since this class is used just to ensure
316:                     * the abstract raster producer correctly generates a BufferedImage.
317:                     */
318:                }
319:
320:                protected BufferedImage prepareImage(int width, int height) {
321:                    // final int size = width * height;
322:                    // final byte pixels[] = new byte[size];
323:                    // Arrays.fill(pixels, (byte) 255);
324:                    //
325:                    // // Create a data buffer using the byte buffer of pixel data.
326:                    // // The pixel data is not copied; the data buffer uses the byte
327:                    // buffer
328:                    // // array.
329:                    // final DataBuffer dbuf = new DataBufferByte(pixels, width *
330:                    // height,
331:                    // 0);
332:                    //
333:                    // // Prepare a sample model suitable for the default palette
334:                    // final SampleModel sampleModel = DEFAULT_PALETTE
335:                    // .createCompatibleSampleModel(width, height);
336:                    //
337:                    // // Create a raster using the sample model and data buffer
338:                    // final WritableRaster raster =
339:                    // Raster.createWritableRaster(sampleModel,
340:                    // dbuf, null);
341:                    //
342:                    // // Combine the color model and raster into a buffered image
343:                    // return new BufferedImage(DEFAULT_PALETTE, raster, false, null);
344:                    return new BufferedImage(width, height,
345:                            BufferedImage.TYPE_4BYTE_ABGR);
346:                }
347:
348:                public String getContentDisposition() {
349:                    // can be null
350:                    return null;
351:                }
352:            }
353:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.