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


0001:        /*
0002:         *    GeoTools - OpenSource mapping toolkit
0003:         *    http://geotools.org
0004:         *    (C) 2003-2006, Geotools Project Managment Committee (PMC)
0005:         *
0006:         *    This library is free software; you can redistribute it and/or
0007:         *    modify it under the terms of the GNU Lesser General Public
0008:         *    License as published by the Free Software Foundation; either
0009:         *    version 2.1 of the License, or (at your option) any later version.
0010:         *
0011:         *    This library is distributed in the hope that it will be useful,
0012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014:         *    Lesser General Public License for more details.
0015:         *
0016:         *    Created on April 12, 2002, 1:18 PM
0017:         */
0018:        package org.geotools.renderer.lite;
0019:
0020:        import java.awt.Graphics2D;
0021:        import java.awt.Rectangle;
0022:        import java.awt.image.BufferedImage;
0023:        import java.io.IOException;
0024:        import java.net.URL;
0025:        import java.util.HashMap;
0026:        import java.util.Map;
0027:        import java.util.logging.Logger;
0028:
0029:        import junit.framework.TestCase;
0030:
0031:        import org.geotools.data.DataUtilities;
0032:        import org.geotools.data.memory.MemoryDataStore;
0033:        import org.geotools.feature.AttributeType;
0034:        import org.geotools.feature.AttributeTypeFactory;
0035:        import org.geotools.feature.DefaultFeatureCollection;
0036:        import org.geotools.feature.Feature;
0037:        import org.geotools.feature.FeatureCollection;
0038:        import org.geotools.feature.FeatureCollections;
0039:        import org.geotools.feature.FeatureType;
0040:        import org.geotools.feature.FeatureTypes;
0041:        import org.geotools.feature.IllegalAttributeException;
0042:        import org.geotools.feature.SchemaException;
0043:        import org.geotools.filter.FilterFactory;
0044:        import org.geotools.filter.FilterFactoryFinder;
0045:        import org.geotools.filter.IllegalFilterException;
0046:        import org.geotools.geometry.jts.JTS;
0047:        import org.geotools.geometry.jts.ReferencedEnvelope;
0048:        import org.geotools.map.DefaultMapContext;
0049:        import org.geotools.map.MapContext;
0050:        import org.geotools.referencing.CRS;
0051:        import org.geotools.referencing.crs.DefaultGeographicCRS;
0052:        import org.geotools.renderer.RenderListener;
0053:        import org.geotools.test.TestData;
0054:        import org.geotools.styling.FeatureTypeStyle;
0055:        import org.geotools.styling.Fill;
0056:        import org.geotools.styling.LineSymbolizer;
0057:        import org.geotools.styling.PointSymbolizer;
0058:        import org.geotools.styling.PolygonSymbolizer;
0059:        import org.geotools.styling.Rule;
0060:        import org.geotools.styling.SLDParser;
0061:        import org.geotools.styling.Stroke;
0062:        import org.geotools.styling.Style;
0063:        import org.geotools.styling.StyleBuilder;
0064:        import org.geotools.styling.StyleFactory;
0065:        import org.geotools.styling.StyleFactoryFinder;
0066:        import org.geotools.styling.StyledLayerDescriptor;
0067:        import org.geotools.styling.Symbolizer;
0068:        import org.geotools.styling.UserLayer;
0069:        import org.opengis.referencing.crs.CoordinateReferenceSystem;
0070:        import org.opengis.referencing.operation.MathTransform;
0071:
0072:        import com.vividsolutions.jts.geom.Coordinate;
0073:        import com.vividsolutions.jts.geom.Envelope;
0074:        import com.vividsolutions.jts.geom.Geometry;
0075:        import com.vividsolutions.jts.geom.GeometryCollection;
0076:        import com.vividsolutions.jts.geom.GeometryFactory;
0077:        import com.vividsolutions.jts.geom.LineString;
0078:        import com.vividsolutions.jts.geom.LinearRing;
0079:        import com.vividsolutions.jts.geom.MultiLineString;
0080:        import com.vividsolutions.jts.geom.MultiPolygon;
0081:        import com.vividsolutions.jts.geom.Point;
0082:        import com.vividsolutions.jts.geom.Polygon;
0083:        import com.vividsolutions.jts.geom.TopologyException;
0084:        import com.vividsolutions.jts.geom.impl.PackedCoordinateSequenceFactory;
0085:
0086:        /**
0087:         * @author jamesm
0088:         * @source $URL:
0089:         *         http://svn.geotools.org/geotools/trunk/gt/module/render/test/org/geotools/renderer/lite/Rendering2DTest.java $
0090:         */
0091:        public class Rendering2DTest extends TestCase {
0092:
0093:            /**
0094:             * The logger for the rendering module.
0095:             */
0096:            private static final Logger LOGGER = org.geotools.util.logging.Logging
0097:                    .getLogger("org.geotools.rendering");
0098:
0099:            private final int xCenter = -74, yCenter = 41;
0100:
0101:            static final String LINE = "linefeature";
0102:
0103:            static final String POLYGON = "polygonfeature";
0104:
0105:            static final String POINT = "pointfeature";
0106:
0107:            static final String RING = "ringfeature";
0108:
0109:            static final String COLLECTION = "collfeature";
0110:
0111:            protected static final Map rendererHints = new HashMap();
0112:
0113:            protected static final FilterFactory filterFactory = FilterFactoryFinder
0114:                    .createFilterFactory();
0115:
0116:            {
0117:                rendererHints.put("optimizedDataLoadingEnabled", new Boolean(
0118:                        true));
0119:            }
0120:
0121:            public Rendering2DTest(java.lang.String testName) {
0122:                super (testName);
0123:            }
0124:
0125:            Style loadTestStyle() throws IOException {
0126:                StyleFactory factory = StyleFactoryFinder.createStyleFactory();
0127:
0128:                URL surl = TestData.getResource(this , "test-sld.xml");
0129:                SLDParser stylereader = new SLDParser(factory, surl);
0130:                StyledLayerDescriptor sld = stylereader.parseSLD();
0131:                UserLayer layer = (UserLayer) sld.getStyledLayers()[0];
0132:                return layer.getUserStyles()[0];
0133:            }
0134:
0135:            Style createTestStyle() throws IllegalFilterException {
0136:                StyleFactory sFac = StyleFactoryFinder.createStyleFactory();
0137:                // The following is complex, and should be built from
0138:                // an SLD document and not by hand
0139:                PointSymbolizer pointsym = sFac.createPointSymbolizer();
0140:                pointsym.setGraphic(sFac.getDefaultGraphic());
0141:
0142:                Rule rule = sFac.createRule();
0143:                rule.setSymbolizers(new Symbolizer[] { polysym(sFac) });
0144:                FeatureTypeStyle fts = sFac
0145:                        .createFeatureTypeStyle(new Rule[] { rule });
0146:                fts.setFeatureTypeName("polygonfeature");
0147:
0148:                Rule rule1 = sFac.createRule();
0149:                rule.setSymbolizers(new Symbolizer[] { polysym(sFac) });
0150:                FeatureTypeStyle fts1 = sFac
0151:                        .createFeatureTypeStyle(new Rule[] { rule1 });
0152:                fts1.setFeatureTypeName("polygonfeature");
0153:
0154:                Rule rule2 = sFac.createRule();
0155:                rule2.setSymbolizers(new Symbolizer[] { linesym(sFac) });
0156:                FeatureTypeStyle fts2 = sFac.createFeatureTypeStyle();
0157:                fts2.setRules(new Rule[] { rule2 });
0158:                fts2.setFeatureTypeName("linefeature");
0159:
0160:                Rule rule3 = sFac.createRule();
0161:                rule3.setSymbolizers(new Symbolizer[] { pointsym });
0162:                FeatureTypeStyle fts3 = sFac.createFeatureTypeStyle();
0163:                fts3.setRules(new Rule[] { rule3 });
0164:                fts3.setFeatureTypeName("pointfeature");
0165:
0166:                Rule rule4 = sFac.createRule();
0167:                rule4.setSymbolizers(new Symbolizer[] { polysym(sFac),
0168:                        linesym(sFac) });
0169:                FeatureTypeStyle fts4 = sFac.createFeatureTypeStyle();
0170:                fts4.setRules(new Rule[] { rule4 });
0171:                fts4.setFeatureTypeName("collFeature");
0172:
0173:                Rule rule5 = sFac.createRule();
0174:                rule5.setSymbolizers(new Symbolizer[] { linesym(sFac) });
0175:                FeatureTypeStyle fts5 = sFac.createFeatureTypeStyle();
0176:                fts5.setRules(new Rule[] { rule5 });
0177:                fts5.setFeatureTypeName("ringFeature");
0178:
0179:                Style style = sFac.createStyle();
0180:                style.setFeatureTypeStyles(new FeatureTypeStyle[] { fts1, fts,
0181:                        fts2, fts3, fts4, fts5 });
0182:                return style;
0183:            }
0184:
0185:            private LineSymbolizer linesym(StyleFactory sFac)
0186:                    throws IllegalFilterException {
0187:                LineSymbolizer linesym = sFac.createLineSymbolizer();
0188:                Stroke myStroke = sFac.getDefaultStroke();
0189:                myStroke.setColor(filterFactory
0190:                        .createLiteralExpression("#0000ff"));
0191:                myStroke.setWidth(filterFactory
0192:                        .createLiteralExpression(new Integer(5)));
0193:                LOGGER.fine("got new Stroke " + myStroke);
0194:                linesym.setStroke(myStroke);
0195:                return linesym;
0196:            }
0197:
0198:            private PolygonSymbolizer polysym(StyleFactory sFac)
0199:                    throws IllegalFilterException {
0200:                Stroke myStroke;
0201:                PolygonSymbolizer polysym = sFac.createPolygonSymbolizer();
0202:                Fill myFill = sFac.getDefaultFill();
0203:                myFill.setColor(filterFactory
0204:                        .createLiteralExpression("#ff0000"));
0205:                polysym.setFill(myFill);
0206:                myStroke = sFac.getDefaultStroke();
0207:                myStroke.setColor(filterFactory
0208:                        .createLiteralExpression("#0000ff"));
0209:                myStroke.setWidth(filterFactory
0210:                        .createLiteralExpression(new Integer(2)));
0211:                polysym.setStroke(myStroke);
0212:                return polysym;
0213:            }
0214:
0215:            private PolygonSymbolizer polysym1(StyleFactory sFac)
0216:                    throws IllegalFilterException {
0217:                Stroke myStroke;
0218:                PolygonSymbolizer polysym = sFac.createPolygonSymbolizer();
0219:                Fill myFill = sFac.getDefaultFill();
0220:                myFill.setColor(filterFactory
0221:                        .createLiteralExpression("#00ff00"));
0222:                polysym.setFill(myFill);
0223:                myStroke = sFac.getDefaultStroke();
0224:                myStroke.setColor(filterFactory
0225:                        .createLiteralExpression("#00ff00"));
0226:                myStroke.setWidth(filterFactory
0227:                        .createLiteralExpression(new Integer(2)));
0228:                polysym.setStroke(myStroke);
0229:                return polysym;
0230:            }
0231:
0232:            FeatureCollection createTestFeatureCollection(
0233:                    CoordinateReferenceSystem crs, String typeName)
0234:                    throws Exception {
0235:                GeometryFactory geomFac = new GeometryFactory();
0236:                return createTestFeatureCollection(crs, geomFac, typeName);
0237:            }
0238:
0239:            FeatureCollection createTestFeatureCollection(
0240:                    CoordinateReferenceSystem crs, GeometryFactory geomFac,
0241:                    String typeName) throws Exception {
0242:
0243:                AttributeType[] types = new AttributeType[2];
0244:
0245:                LineString line = makeSampleLineString(geomFac);
0246:                if (crs != null)
0247:                    types[0] = AttributeTypeFactory.newAttributeType(
0248:                            "collection", line.getClass(), false, 0, null, crs);
0249:                else
0250:                    types[0] = AttributeTypeFactory.newAttributeType(
0251:                            "centerline", line.getClass());
0252:                types[1] = AttributeTypeFactory.newAttributeType("name",
0253:                        String.class);
0254:                FeatureType lineType = FeatureTypes.newFeatureType(types, LINE);
0255:                Feature lineFeature = lineType.create(new Object[] { line,
0256:                        "centerline" });
0257:
0258:                Polygon polygon = makeSamplePolygon(geomFac);
0259:
0260:                if (crs != null)
0261:                    types[0] = AttributeTypeFactory.newAttributeType(
0262:                            "collection", polygon.getClass(), false, 0, null,
0263:                            crs);
0264:                else
0265:                    types[0] = AttributeTypeFactory.newAttributeType("edge",
0266:                            polygon.getClass());
0267:                types[1] = AttributeTypeFactory.newAttributeType("name",
0268:                        String.class);
0269:                FeatureType polygonType = FeatureTypes.newFeatureType(types,
0270:                        POLYGON);
0271:
0272:                Feature polygonFeature = polygonType.create(new Object[] {
0273:                        polygon, "edge" });
0274:
0275:                Point point = makeSamplePoint(geomFac);
0276:                if (crs != null)
0277:                    types[0] = AttributeTypeFactory
0278:                            .newAttributeType("collection", point.getClass(),
0279:                                    false, 0, null, crs);
0280:                else
0281:                    types[0] = AttributeTypeFactory.newAttributeType("centre",
0282:                            point.getClass());
0283:                types[1] = AttributeTypeFactory.newAttributeType("name",
0284:                        String.class);
0285:                FeatureType pointType = FeatureTypes.newFeatureType(types,
0286:                        POINT);
0287:
0288:                Feature pointFeature = pointType.create(new Object[] { point,
0289:                        "centre" });
0290:
0291:                LinearRing ring = makeSampleLinearRing(geomFac);
0292:                if (crs != null)
0293:                    types[0] = AttributeTypeFactory.newAttributeType(
0294:                            "collection", line.getClass(), false, 0, null, crs);
0295:                else
0296:                    types[0] = AttributeTypeFactory.newAttributeType(
0297:                            "centerline", line.getClass());
0298:                types[1] = AttributeTypeFactory.newAttributeType("name",
0299:                        String.class);
0300:                FeatureType lrType = FeatureTypes.newFeatureType(types, RING);
0301:                Feature ringFeature = lrType.create(new Object[] { ring,
0302:                        "centerline" });
0303:
0304:                GeometryCollection coll = makeSampleGeometryCollection(geomFac);
0305:                if (crs != null)
0306:                    types[0] = AttributeTypeFactory.newAttributeType(
0307:                            "collection", coll.getClass(), false, 0, null, crs);
0308:                else
0309:                    types[0] = AttributeTypeFactory.newAttributeType(
0310:                            "collection", coll.getClass());
0311:                types[1] = AttributeTypeFactory.newAttributeType("name",
0312:                        String.class);
0313:                FeatureType collType = FeatureTypes.newFeatureType(types,
0314:                        COLLECTION);
0315:                Feature collFeature = collType.create(new Object[] { coll,
0316:                        "collection" });
0317:
0318:                MemoryDataStore data = new MemoryDataStore();
0319:                data.addFeature(lineFeature);
0320:                data.addFeature(polygonFeature);
0321:                data.addFeature(pointFeature);
0322:                data.addFeature(ringFeature);
0323:                data.addFeature(collFeature);
0324:
0325:                return data.getFeatureSource(typeName).getFeatures();
0326:            }
0327:
0328:            public void testSimplePolygonRender() throws Exception {
0329:
0330:                LOGGER.finer("starting rendering2DTest");
0331:
0332:                // ////////////////////////////////////////////////////////////////////
0333:                //
0334:                // CREATING FEATURES
0335:                //
0336:                // ////////////////////////////////////////////////////////////////////
0337:                final FeatureCollection ft = createTestFeatureCollection(
0338:                        DefaultGeographicCRS.WGS84, POLYGON);
0339:
0340:                // ////////////////////////////////////////////////////////////////////
0341:                //
0342:                // CREATING STYLE
0343:                //
0344:                // ////////////////////////////////////////////////////////////////////
0345:                final Style style = createTestStyle();
0346:
0347:                // ////////////////////////////////////////////////////////////////////
0348:                //
0349:                // CREATING MAP CONTEXT
0350:                //
0351:                // ////////////////////////////////////////////////////////////////////
0352:                final MapContext map = new DefaultMapContext(
0353:                        DefaultGeographicCRS.WGS84);
0354:                map.addLayer(ft, style);
0355:                map.setAreaOfInterest(map.getLayerBounds());
0356:
0357:                // ////////////////////////////////////////////////////////////////////
0358:                //
0359:                // CREATING STREAMING RENDERER
0360:                //
0361:                // ////////////////////////////////////////////////////////////////////
0362:                final StreamingRenderer renderer = new StreamingRenderer();
0363:                renderer.setContext(map);
0364:                renderer.setRendererHints(rendererHints);
0365:
0366:                // ////////////////////////////////////////////////////////////////////
0367:                //
0368:                // SHOWING RENDERER
0369:                //
0370:                // ////////////////////////////////////////////////////////////////////
0371:                RendererBaseTest.showRender("testSimplePolygonRender",
0372:                        renderer, 1000, map.getLayerBounds());
0373:
0374:            }
0375:
0376:            // public void testRenderLoadedStyle() throws Exception {
0377:            //
0378:            // // same as the datasource test, load in some features into a table
0379:            // System.err.println("starting RenderLoadedStyle");
0380:            //
0381:            // FeatureCollection ft = createTestFeatureCollection(null, POLYGON);
0382:            // Style style = loadTestStyle();
0383:            //
0384:            // MapContext map = new DefaultMapContext();
0385:            // map.addLayer(ft, style);
0386:            // LiteRenderer2 renderer = new LiteRenderer2(map);
0387:            // Envelope env = map.getLayerBounds();
0388:            // env = new Envelope(env.getMinX() - 20, env.getMaxX() + 20, env.getMinY()
0389:            // - 20, env
0390:            // .getMaxY() + 20);
0391:            // showRender("RenderLoadedStyle", renderer, 5000, env);
0392:            //
0393:            // }
0394:
0395:            public void testSimpleLineRender() throws Exception {
0396:
0397:                // ////////////////////////////////////////////////////////////////////
0398:                //
0399:                // CREATING FEATURES
0400:                //
0401:                // ////////////////////////////////////////////////////////////////////
0402:                final FeatureCollection ft = createTestFeatureCollection(
0403:                        DefaultGeographicCRS.WGS84, LINE);
0404:
0405:                // ////////////////////////////////////////////////////////////////////
0406:                //
0407:                // CREATING STYLE
0408:                //
0409:                // ////////////////////////////////////////////////////////////////////
0410:                final Style style = createTestStyle();
0411:
0412:                // ////////////////////////////////////////////////////////////////////
0413:                //
0414:                // CREATING MAP CONTEXT
0415:                //
0416:                // ////////////////////////////////////////////////////////////////////
0417:                final MapContext map = new DefaultMapContext(
0418:                        DefaultGeographicCRS.WGS84);
0419:                map.addLayer(ft, style);
0420:                map.setAreaOfInterest(map.getLayerBounds());
0421:
0422:                // ////////////////////////////////////////////////////////////////////
0423:                //
0424:                // CREATING STREAMING RENDERER
0425:                //
0426:                // ////////////////////////////////////////////////////////////////////
0427:                final StreamingRenderer renderer = new StreamingRenderer();
0428:                renderer.setContext(map);
0429:                renderer.setRendererHints(rendererHints);
0430:
0431:                // ////////////////////////////////////////////////////////////////////
0432:                //
0433:                // SHOWING RENDERER
0434:                //
0435:                // ////////////////////////////////////////////////////////////////////
0436:                ReferencedEnvelope env = map.getLayerBounds();
0437:                env = new ReferencedEnvelope(env.getMinX() - 20,
0438:                        env.getMaxX() + 20, env.getMinY() - 20,
0439:                        env.getMaxY() + 20, map.getCoordinateReferenceSystem());
0440:                RendererBaseTest.showRender("testSimpleLineRender", renderer,
0441:                        1000, env);
0442:
0443:            }
0444:
0445:            public void testSimplePointRender() throws Exception {
0446:
0447:                // ////////////////////////////////////////////////////////////////////
0448:                //
0449:                // CREATING FEATURES
0450:                //
0451:                // ////////////////////////////////////////////////////////////////////
0452:                final FeatureCollection ft = createTestFeatureCollection(
0453:                        DefaultGeographicCRS.WGS84, POINT);
0454:
0455:                // ////////////////////////////////////////////////////////////////////
0456:                //
0457:                // CREATING STYLE
0458:                //
0459:                // ////////////////////////////////////////////////////////////////////
0460:                final Style style = createTestStyle();
0461:
0462:                // ////////////////////////////////////////////////////////////////////
0463:                //
0464:                // CREATING MAP CONTEXT
0465:                //
0466:                // ////////////////////////////////////////////////////////////////////
0467:                final MapContext map = new DefaultMapContext(
0468:                        DefaultGeographicCRS.WGS84);
0469:                map.addLayer(ft, style);
0470:                map.setAreaOfInterest(map.getLayerBounds());
0471:
0472:                // ////////////////////////////////////////////////////////////////////
0473:                //
0474:                // CREATING STREAMING RENDERER
0475:                //
0476:                // ////////////////////////////////////////////////////////////////////
0477:                final StreamingRenderer renderer = new StreamingRenderer();
0478:                renderer.setContext(map);
0479:                renderer.setRendererHints(rendererHints);
0480:
0481:                // ////////////////////////////////////////////////////////////////////
0482:                //
0483:                // SHOWING RENDERER
0484:                //
0485:                // ////////////////////////////////////////////////////////////////////
0486:                ReferencedEnvelope env = map.getLayerBounds();
0487:                env = new ReferencedEnvelope(env.getMinX() - 20,
0488:                        env.getMaxX() + 20, env.getMinY() - 20,
0489:                        env.getMaxY() + 20, map.getCoordinateReferenceSystem());
0490:                RendererBaseTest.showRender("testSimplePointRender", renderer,
0491:                        1000, env);
0492:
0493:            }
0494:
0495:            public void testReprojectionWithPackedCoordinateSequence()
0496:                    throws Exception {
0497:
0498:                // same as the datasource test, load in some features into a table
0499:                StringBuffer stringBuffer = new StringBuffer();
0500:                stringBuffer.append("starting testLiteRender2").append("\n");
0501:
0502:                // //
0503:                //
0504:                // Create test features
0505:                //
0506:                // //
0507:                GeometryFactory geomFac = new GeometryFactory(
0508:                        PackedCoordinateSequenceFactory.DOUBLE_FACTORY);
0509:                FeatureCollection ft = createTestFeatureCollection(
0510:                        DefaultGeographicCRS.WGS84, geomFac, POLYGON);
0511:                Style style = createTestStyle();
0512:
0513:                // //
0514:                //
0515:                // Create the map context
0516:                //
0517:                // //
0518:                MapContext map = new DefaultMapContext();
0519:                map.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
0520:                map.addLayer(ft, style);
0521:                map.setAreaOfInterest(map.getLayerBounds());
0522:
0523:                // //
0524:                //
0525:                // Create the streaming renderer
0526:                //
0527:                // //
0528:                StreamingRenderer renderer = new StreamingRenderer();
0529:                renderer.setContext(map);
0530:                renderer.setRendererHints(rendererHints);
0531:
0532:                // //
0533:                //
0534:                // Transform the area of interest
0535:                //
0536:                // //
0537:                final CoordinateReferenceSystem crs = CRS
0538:                        .parseWKT("PROJCS[\"NAD83 / BC"
0539:                                + "Albers\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS"
0540:                                + "1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],"
0541:                                + "TOWGS84[0,0,0],AUTHORITY[\"EPSG\",\"6269\"]],"
0542:                                + "PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],"
0543:                                + "UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],"
0544:                                + "AUTHORITY[\"EPSG\",\"4269\"]],"
0545:                                + "PROJECTION[\"Albers_Conic_Equal_Area\"],"
0546:                                + "PARAMETER[\"standard_parallel_1\",50],"
0547:                                + "PARAMETER[\"standard_parallel_2\",58.5],"
0548:                                + "PARAMETER[\"latitude_of_center\",45],"
0549:                                + "PARAMETER[\"longitude_of_center\",-126],"
0550:                                + "PARAMETER[\"false_easting\",1000000],"
0551:                                + "PARAMETER[\"false_northing\",0],"
0552:                                + "UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],"
0553:                                + "AUTHORITY[\"EPSG\",\"3005\"]]");
0554:                final MathTransform t = CRS.findMathTransform(
0555:                        DefaultGeographicCRS.WGS84, crs, true);
0556:
0557:                // //
0558:                //
0559:                // Set the new AOI
0560:                //
0561:                // //
0562:                final ReferencedEnvelope env = (ReferencedEnvelope) map
0563:                        .getLayerBounds();
0564:                final ReferencedEnvelope bounds = new ReferencedEnvelope(JTS
0565:                        .transform(env, null, t, 10), crs);
0566:
0567:                RendererBaseTest.showRender("testReprojection", renderer, 1000,
0568:                        bounds);
0569:
0570:                LOGGER.finer(stringBuffer.toString());
0571:
0572:            }
0573:
0574:            public void testLineReprojection() throws Exception {
0575:                // ///////////////////////////////////////////////////////////////////
0576:                //
0577:                // LOAD FEATURES
0578:                //
0579:                //
0580:                // /////////////////////////////////////////////////////////////////
0581:                LOGGER.finer("starting testLiteRender2");
0582:                final GeometryFactory geomFac = new GeometryFactory(
0583:                        PackedCoordinateSequenceFactory.DOUBLE_FACTORY);
0584:                final FeatureCollection ft = createTestFeatureCollection(
0585:                        DefaultGeographicCRS.WGS84, geomFac, LINE);
0586:                final Style style = createTestStyle();
0587:
0588:                //
0589:                // ///////////////////////////////////////////////////////////////////
0590:                //
0591:                // CREATE MAP CONTEXT AND RENDERER
0592:                //
0593:                //
0594:                // /////////////////////////////////////////////////////////////////
0595:                final MapContext map = new DefaultMapContext(
0596:                        DefaultGeographicCRS.WGS84);
0597:                map.addLayer(ft, style);
0598:
0599:                // ///////////////////////////////////////////////////////////////////
0600:                //
0601:                // CREATE A PROJECTED AOI
0602:                //
0603:                //
0604:                // /////////////////////////////////////////////////////////////////
0605:                final CoordinateReferenceSystem crs = CRS
0606:                        .parseWKT("PROJCS[\"NAD83 / BC"
0607:                                + "Albers\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS"
0608:                                + "1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],"
0609:                                + "TOWGS84[0,0,0],AUTHORITY[\"EPSG\",\"6269\"]],"
0610:                                + "PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],"
0611:                                + "UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],"
0612:                                + "AUTHORITY[\"EPSG\",\"4269\"]],"
0613:                                + "PROJECTION[\"Albers_Conic_Equal_Area\"],"
0614:                                + "PARAMETER[\"standard_parallel_1\",50],"
0615:                                + "PARAMETER[\"standard_parallel_2\",58.5],"
0616:                                + "PARAMETER[\"latitude_of_center\",45],"
0617:                                + "PARAMETER[\"longitude_of_center\",-126],"
0618:                                + "PARAMETER[\"false_easting\",1000000],"
0619:                                + "PARAMETER[\"false_northing\",0],"
0620:                                + "UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],"
0621:                                + "AUTHORITY[\"EPSG\",\"3005\"]]");
0622:
0623:                // /////////////////////////////////////////////////////////////////
0624:                //
0625:                // CREATE MAP CONTEXT AND RENDERER
0626:                //
0627:                //
0628:                // /////////////////////////////////////////////////////////////////
0629:                final StreamingRenderer renderer = new StreamingRenderer();
0630:                renderer.setRendererHints(rendererHints);
0631:                renderer.setContext(map);
0632:
0633:                ReferencedEnvelope env = map.getLayerBounds();
0634:                env = new ReferencedEnvelope(env.getMinX() - 20,
0635:                        env.getMaxX() + 20, env.getMinY() - 20,
0636:                        env.getMaxY() + 20, DefaultGeographicCRS.WGS84);
0637:                final ReferencedEnvelope newbounds = env.transform(crs, true);
0638:                RendererBaseTest.showRender("testLineReprojection", renderer,
0639:                        1000, newbounds);
0640:
0641:            }
0642:
0643:            public void testPointReprojection() throws Exception {
0644:
0645:                // ///////////////////////////////////////////////////////////////////
0646:                //
0647:                // LOAD FEATURES
0648:                //
0649:                //
0650:                // /////////////////////////////////////////////////////////////////
0651:                LOGGER.finer("starting testLiteRender2");
0652:                final GeometryFactory geomFac = new GeometryFactory(
0653:                        PackedCoordinateSequenceFactory.DOUBLE_FACTORY);
0654:                final FeatureCollection ft = createTestFeatureCollection(
0655:                        DefaultGeographicCRS.WGS84, geomFac, POINT);
0656:                final Style style = createTestStyle();
0657:
0658:                //
0659:                // ///////////////////////////////////////////////////////////////////
0660:                //
0661:                // CREATE MAP CONTEXT AND RENDERER
0662:                //
0663:                //
0664:                // /////////////////////////////////////////////////////////////////
0665:                final MapContext map = new DefaultMapContext(
0666:                        DefaultGeographicCRS.WGS84);
0667:                map.addLayer(ft, style);
0668:
0669:                // ///////////////////////////////////////////////////////////////////
0670:                //
0671:                // CREATE A PROJECTED AOI
0672:                //
0673:                //
0674:                // /////////////////////////////////////////////////////////////////
0675:                // //
0676:                //
0677:                // Transform the area of interest
0678:                //
0679:                // //
0680:                final CoordinateReferenceSystem crs = CRS
0681:                        .parseWKT("PROJCS[\"NAD83 / BC"
0682:                                + "Albers\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS"
0683:                                + "1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],"
0684:                                + "TOWGS84[0,0,0],AUTHORITY[\"EPSG\",\"6269\"]],"
0685:                                + "PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],"
0686:                                + "UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],"
0687:                                + "AUTHORITY[\"EPSG\",\"4269\"]],"
0688:                                + "PROJECTION[\"Albers_Conic_Equal_Area\"],"
0689:                                + "PARAMETER[\"standard_parallel_1\",50],"
0690:                                + "PARAMETER[\"standard_parallel_2\",58.5],"
0691:                                + "PARAMETER[\"latitude_of_center\",45],"
0692:                                + "PARAMETER[\"longitude_of_center\",-126],"
0693:                                + "PARAMETER[\"false_easting\",1000000],"
0694:                                + "PARAMETER[\"false_northing\",0],"
0695:                                + "UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],"
0696:                                + "AUTHORITY[\"EPSG\",\"3005\"]]");
0697:
0698:                // /////////////////////////////////////////////////////////////////
0699:                //
0700:                // CREATE MAP CONTEXT AND RENDERER
0701:                //
0702:                //
0703:                // /////////////////////////////////////////////////////////////////
0704:                final StreamingRenderer renderer = new StreamingRenderer();
0705:                renderer.setRendererHints(rendererHints);
0706:                renderer.setContext(map);
0707:
0708:                ReferencedEnvelope env = map.getLayerBounds();
0709:                env = new ReferencedEnvelope(env.getMinX() - 20,
0710:                        env.getMaxX() + 20, env.getMinY() - 20,
0711:                        env.getMaxY() + 20, DefaultGeographicCRS.WGS84);
0712:                final ReferencedEnvelope newbounds = env.transform(crs, true);
0713:                RendererBaseTest.showRender("testPointReprojection", renderer,
0714:                        1000, newbounds);
0715:
0716:            }
0717:
0718:            /**
0719:             * Tests the layer definition query behavior as implemented by
0720:             * StreamingRenderer.
0721:             * <p>
0722:             * This method relies on the features created on
0723:             * createTestFeatureCollection()
0724:             * </p>
0725:             * 
0726:             * @throws Exception
0727:             */
0728:            public void testDefinitionQueryProcessing() throws Exception {
0729:
0730:                // LOGGER.info("starting definition query test");
0731:                // final FeatureCollection ft = createTestDefQueryFeatureCollection();
0732:                // final Style style = createDefQueryTestStyle();
0733:                // FeatureResults results;
0734:                // Envelope envelope = ft.getBounds();
0735:                //
0736:                // // we'll use this as the definition query for the layer
0737:                // Query layerQuery;
0738:                //
0739:                // MapLayer layer = new DefaultMapLayer(ft, style);
0740:                // MapContext map = new DefaultMapContext(new MapLayer[] { layer });
0741:                // map.setAreaOfInterest(envelope, ft.getFeatureType()
0742:                // .getDefaultGeometry().getCoordinateSystem());
0743:                // StreamingRenderer renderer = new StreamingRenderer();
0744:                // renderer.setContext(map);
0745:                // renderer.setRendererHints(rendererHints);
0746:                //
0747:                // // this is the reader that StreamingRenderer obtains after applying
0748:                // // the mixed filter to a given layer.
0749:                // Filter filter = Filter.INCLUDE;
0750:                // FilterFactory ffac = FilterFactoryFinder.createFilterFactory();
0751:                //
0752:                // // test maxFeatures, render just the first 2 features
0753:                // layerQuery = new DefaultQuery("querytest", filter, 2, null,
0754:                // "handle");
0755:                // layer.setQuery(layerQuery);
0756:                //
0757:                // results = renderer.queryLayer(layer,layer.getFeatureSource() ,
0758:                // layer.getFeatureSource() .getSchema(), null, envelope,
0759:                // DefaultGeographicCRS.WGS84, map.getCoordinateReferenceSystem(), null,
0760:                // null);
0761:                // assertEquals(2, results.getCount());
0762:                // // just the 3 geometric atts should get be loaded
0763:                // assertEquals(4, results.getSchema().getAttributeCount());
0764:                //
0765:                // RendererBaseTest.showRender("testDefinitionQuery1", renderer, 1000,
0766:                // null);
0767:                //
0768:                // // test attribute based filter
0769:                // FeatureType schema = ft.features().next().getFeatureType();
0770:                // filter = ffac.createCompareFilter(AbstractFilter.COMPARE_EQUALS);
0771:                // ((CompareFilter) filter).addLeftValue(ffac.createAttributeExpression(
0772:                // schema, "id"));
0773:                // ((CompareFilter) filter).addRightValue(ffac
0774:                // .createLiteralExpression("ft1"));
0775:                //
0776:                // // note we include the "id" field in the layer query. Bad practice,
0777:                // // since it goes
0778:                // // against
0779:                // // the performance gain of
0780:                // // renderer.setOptimizedDataLoadingEnabled(true),
0781:                // // but we should test it anyway
0782:                // layerQuery = new DefaultQuery("querytest", filter, Integer.MAX_VALUE,
0783:                // new String[] { "id" }, "handle");
0784:                // layer.setQuery(layerQuery);
0785:                //
0786:                // results = renderer.queryLayer(layer, null, envelope,
0787:                // DefaultGeographicCRS.WGS84);
0788:                // assertEquals(1, results.getCount());
0789:                // // the 4 atts should be loaded since the definition query includes
0790:                // "id"
0791:                // assertEquals(4, results.getSchema().getAttributeCount());
0792:                // // we can check this since we explicitly requested the "id"
0793:                // attribute.
0794:                // // If we not,
0795:                // // it would be not loaded
0796:                // String val = (String) results.reader().next().getAttribute("id");
0797:                // assertEquals("ft1", val);
0798:                //
0799:                // RendererBaseTest.showRender("testDefinitionQuery2", renderer, 1000,
0800:                // null);
0801:                //
0802:                // // try a bbox filter as definition query for the layer
0803:                // filter = null;
0804:                // GeometryFilter gfilter;
0805:                // // contains the first 2 features
0806:                // Envelope env = new Envelope(20, 130, 20, 130);
0807:                // gfilter = ffac.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX);
0808:                // gfilter
0809:                // .addLeftGeometry(ffac
0810:                // .createAttributeExpression(schema, "point"));
0811:                // gfilter.addRightGeometry(ffac.createBBoxExpression(env));
0812:                // filter = gfilter;
0813:                //
0814:                // gfilter = ffac.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX);
0815:                // gfilter.addLeftGeometry(ffac.createAttributeExpression(schema,
0816:                // "line"));
0817:                // gfilter.addRightGeometry(ffac.createBBoxExpression(env));
0818:                // filter = filter.or(gfilter);
0819:                //
0820:                // gfilter = ffac.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX);
0821:                // gfilter.addLeftGeometry(ffac.createAttributeExpression(schema,
0822:                // "polygon"));
0823:                // gfilter.addRightGeometry(ffac.createBBoxExpression(env));
0824:                // filter = filter.or(gfilter);
0825:                //
0826:                // System.err.println("trying with filter: " + filter);
0827:                //
0828:                // layerQuery = new DefaultQuery("querytest", filter, Integer.MAX_VALUE,
0829:                // null, "handle");
0830:                // layer.setQuery(layerQuery);
0831:                //
0832:                // results = renderer.queryLayer(layer, null, envelope,
0833:                // DefaultGeographicCRS.WGS84);
0834:                // assertEquals(2, results.getCount());
0835:                // // the 4 atts should be loaded since the definition query includes
0836:                // "id"
0837:                // assertEquals(4, results.getSchema().getAttributeCount());
0838:                //
0839:                // RendererBaseTest.showRender("testDefinitionQuery3", renderer, 1000,
0840:                // null);
0841:
0842:            }
0843:
0844:            public void testDefinitionQuerySLDProcessing() throws Exception {
0845:                // final FeatureCollection ft = createTestDefQueryFeatureCollection();
0846:                // final Style style = createDefQueryTestStyle();
0847:                // FeatureResults results;
0848:                // Envelope envelope = ft.getBounds();
0849:                //
0850:                // // we'll use this as the definition query for the layer
0851:                // Query layerQuery;
0852:                //
0853:                // MapLayer layer = new DefaultMapLayer(ft, style);
0854:                // MapContext map = new DefaultMapContext(new MapLayer[] { layer });
0855:                // map.setAreaOfInterest(envelope);
0856:                // StreamingRenderer renderer = new StreamingRenderer();
0857:                // renderer.setContext(map);
0858:                // renderer.setRendererHints(rendererHints);
0859:                //
0860:                // // this is the reader that StreamingRenderer obtains after applying
0861:                // // the mixed filter to a given layer.
0862:                // FeatureReader reader;
0863:                // Filter filter = Filter.INCLUDE;
0864:                // FilterFactory ffac = FilterFactoryFinder.createFilterFactory();
0865:                //
0866:                // // test maxFeatures, render just the first 2 features
0867:                // layerQuery = new DefaultQuery("querytest", filter);
0868:                // layer.setQuery(layerQuery);
0869:                //
0870:                // ArrayList rules = new ArrayList();
0871:                // ArrayList elseRules = new ArrayList();
0872:                // StyleBuilder builder = new StyleBuilder();
0873:                // Rule rule = builder.createRule(builder.createLineSymbolizer());
0874:                // rules.add(rule);
0875:                // rule.setFilter(
0876:                // // JD: remove this null parameter
0877:                // new AbstractFilterImpl(null) {
0878:                // int i = 0;
0879:                //
0880:                // public boolean evaluate(Feature feature) {
0881:                // i++;
0882:                // return i < 3;
0883:                // }
0884:                //
0885:                // // public void accept(FilterVisitor visitor) {
0886:                // // visitor.visit(this);
0887:                // // }
0888:                // public Object accept(
0889:                // org.opengis.filter.FilterVisitor visitor,
0890:                // Object extraData) {
0891:                // return extraData;
0892:                // }
0893:                // });
0894:                // LiteFeatureTypeStyle fts = new LiteFeatureTypeStyle(null, rules,
0895:                // elseRules);
0896:                //
0897:                // results = renderer.queryLayer(layer,
0898:                // new LiteFeatureTypeStyle[] { fts }, envelope,
0899:                // DefaultGeographicCRS.WGS84);
0900:                // assertEquals(2, results.getCount());
0901:                //
0902:                // elseRules.add(rule);
0903:                //
0904:                // fts = new LiteFeatureTypeStyle(null, rules, elseRules);
0905:                // results = renderer.queryLayer(layer,
0906:                // new LiteFeatureTypeStyle[] { fts }, envelope,
0907:                // DefaultGeographicCRS.WGS84);
0908:                // assertEquals(3, results.getCount());
0909:
0910:            }
0911:
0912:            private FeatureCollection createTestDefQueryFeatureCollection()
0913:                    throws Exception {
0914:                MemoryDataStore data = new MemoryDataStore();
0915:                AttributeType[] types = new AttributeType[4];
0916:
0917:                types[0] = AttributeTypeFactory.newAttributeType("id",
0918:                        String.class);
0919:                types[1] = AttributeTypeFactory.newAttributeType("point",
0920:                        Point.class);
0921:                types[2] = AttributeTypeFactory.newAttributeType("line",
0922:                        LineString.class);
0923:                types[3] = AttributeTypeFactory.newAttributeType("polygon",
0924:                        Polygon.class);
0925:
0926:                FeatureType type = FeatureTypes.newFeatureType(types,
0927:                        "querytest");
0928:
0929:                GeometryFactory gf = new GeometryFactory();
0930:                Feature f;
0931:                LineString l;
0932:                Polygon p;
0933:
0934:                l = line(gf, new int[] { 20, 20, 100, 20, 100, 100 });
0935:                p = (Polygon) l.convexHull();
0936:                f = type.create(
0937:                        new Object[] { "ft1", point(gf, 20, 20), l, p },
0938:                        "test.1");
0939:                data.addFeature(f);
0940:
0941:                l = line(gf,
0942:                        new int[] { 130, 130, 110, 110, 110, 130, 30, 130 });
0943:                p = (Polygon) l.convexHull();
0944:                f = type.create(
0945:                        new Object[] { "ft2", point(gf, 130, 130), l, p },
0946:                        "test.2");
0947:                data.addFeature(f);
0948:
0949:                l = line(gf, new int[] { 150, 150, 190, 140, 190, 190 });
0950:                p = (Polygon) l.convexHull();
0951:                f = type.create(
0952:                        new Object[] { "ft3", point(gf, 150, 150), l, p },
0953:                        "test.3");
0954:                data.addFeature(f);
0955:
0956:                String typeName = type.getTypeName();
0957:                return data.getFeatureSource(typeName).getFeatures();
0958:            }
0959:
0960:            private Style createDefQueryTestStyle()
0961:                    throws IllegalFilterException {
0962:                StyleFactory sFac = StyleFactoryFinder.createStyleFactory();
0963:
0964:                PointSymbolizer pointsym = sFac.createPointSymbolizer();
0965:                pointsym.setGraphic(sFac.getDefaultGraphic());
0966:                pointsym.setGeometryPropertyName("point");
0967:
0968:                Rule rulep = sFac.createRule();
0969:                rulep.setSymbolizers(new Symbolizer[] { pointsym });
0970:                FeatureTypeStyle ftsP = sFac.createFeatureTypeStyle();
0971:                ftsP.setRules(new Rule[] { rulep });
0972:                ftsP.setFeatureTypeName("querytest");
0973:
0974:                LineSymbolizer linesym = sFac.createLineSymbolizer();
0975:                linesym.setGeometryPropertyName("line");
0976:
0977:                Stroke myStroke = sFac.getDefaultStroke();
0978:                myStroke.setColor(filterFactory
0979:                        .createLiteralExpression("#0000ff"));
0980:                myStroke.setWidth(filterFactory
0981:                        .createLiteralExpression(new Integer(3)));
0982:                LOGGER.info("got new Stroke " + myStroke);
0983:                linesym.setStroke(myStroke);
0984:
0985:                Rule rule2 = sFac.createRule();
0986:                rule2.setSymbolizers(new Symbolizer[] { linesym });
0987:                FeatureTypeStyle ftsL = sFac.createFeatureTypeStyle();
0988:                ftsL.setRules(new Rule[] { rule2 });
0989:                ftsL.setFeatureTypeName("querytest");
0990:
0991:                PolygonSymbolizer polysym = sFac.createPolygonSymbolizer();
0992:                polysym.setGeometryPropertyName("polygon");
0993:                Fill myFill = sFac.getDefaultFill();
0994:                myFill.setColor(filterFactory
0995:                        .createLiteralExpression("#ff0000"));
0996:                polysym.setFill(myFill);
0997:                polysym.setStroke(sFac.getDefaultStroke());
0998:                Rule rule = sFac.createRule();
0999:                rule.setSymbolizers(new Symbolizer[] { polysym });
1000:                FeatureTypeStyle ftsPoly = sFac
1001:                        .createFeatureTypeStyle(new Rule[] { rule });
1002:                // ftsPoly.setRules(new Rule[]{rule});
1003:                ftsPoly.setFeatureTypeName("querytest");
1004:
1005:                Style style = sFac.createStyle();
1006:                style.setFeatureTypeStyles(new FeatureTypeStyle[] { ftsPoly,
1007:                        ftsL, ftsP });
1008:
1009:                return style;
1010:            }
1011:
1012:            public LineString line(final GeometryFactory gf, int[] xy) {
1013:                Coordinate[] coords = new Coordinate[xy.length / 2];
1014:
1015:                for (int i = 0; i < xy.length; i += 2) {
1016:                    coords[i / 2] = new Coordinate(xy[i], xy[i + 1]);
1017:                }
1018:
1019:                return gf.createLineString(coords);
1020:            }
1021:
1022:            public Point point(final GeometryFactory gf, int x, int y) {
1023:                Coordinate coord = new Coordinate(x, y);
1024:                return gf.createPoint(coord);
1025:            }
1026:
1027:            private Point makeSamplePoint(final GeometryFactory geomFac) {
1028:                Coordinate c = new Coordinate(xCenter - 14.0d, yCenter - 14.0d);
1029:                Point point = geomFac.createPoint(c);
1030:                return point;
1031:            }
1032:
1033:            private LineString makeSampleLineString(
1034:                    final GeometryFactory geomFac) {
1035:                Coordinate[] linestringCoordinates = new Coordinate[7];
1036:                linestringCoordinates[0] = new Coordinate(xCenter - 5.0d,
1037:                        yCenter - 5.0d);
1038:                linestringCoordinates[1] = new Coordinate(xCenter - 6.0d,
1039:                        yCenter - 5.0d);
1040:                linestringCoordinates[2] = new Coordinate(xCenter - 6.0d,
1041:                        yCenter - 6.0d);
1042:                linestringCoordinates[3] = new Coordinate(xCenter - 7.0d,
1043:                        yCenter - 6.0d);
1044:                linestringCoordinates[4] = new Coordinate(xCenter - 7.0d,
1045:                        yCenter - 7.0d);
1046:                linestringCoordinates[5] = new Coordinate(xCenter - 8.0d,
1047:                        yCenter - 7.0d);
1048:                linestringCoordinates[6] = new Coordinate(xCenter - 8.0d,
1049:                        yCenter - 8.0d);
1050:                LineString line = geomFac
1051:                        .createLineString(linestringCoordinates);
1052:
1053:                return line;
1054:            }
1055:
1056:            private Polygon makeSamplePolygon(final GeometryFactory geomFac) {
1057:                Coordinate[] polygonCoordinates = new Coordinate[10];
1058:                polygonCoordinates[0] = new Coordinate(xCenter - 7, yCenter - 7);
1059:                polygonCoordinates[1] = new Coordinate(xCenter - 6, yCenter - 9);
1060:                polygonCoordinates[2] = new Coordinate(xCenter - 6,
1061:                        yCenter - 11);
1062:                polygonCoordinates[3] = new Coordinate(xCenter - 7,
1063:                        yCenter - 12);
1064:                polygonCoordinates[4] = new Coordinate(xCenter - 9,
1065:                        yCenter - 11);
1066:                polygonCoordinates[5] = new Coordinate(xCenter - 11,
1067:                        yCenter - 12);
1068:                polygonCoordinates[6] = new Coordinate(xCenter - 13,
1069:                        yCenter - 11);
1070:                polygonCoordinates[7] = new Coordinate(xCenter - 13,
1071:                        yCenter - 9);
1072:                polygonCoordinates[8] = new Coordinate(xCenter - 11,
1073:                        yCenter - 7);
1074:                polygonCoordinates[9] = new Coordinate(xCenter - 7, yCenter - 7);
1075:                try {
1076:                    LinearRing ring = geomFac
1077:                            .createLinearRing(polygonCoordinates);
1078:                    Polygon polyg = geomFac.createPolygon(ring, null);
1079:                    return polyg;
1080:                } catch (TopologyException te) {
1081:                    fail("Error creating sample polygon for testing " + te);
1082:                }
1083:                return null;
1084:            }
1085:
1086:            private GeometryCollection makeSampleGeometryCollection(
1087:                    final GeometryFactory geomFac) {
1088:                try {
1089:                    Geometry polyg = buildShiftedGeometry(
1090:                            makeSamplePolygon(geomFac), 50, 50);
1091:                    Geometry lineString = buildShiftedGeometry(
1092:                            makeSampleLineString(geomFac), 50, 50);
1093:                    return geomFac.createGeometryCollection(new Geometry[] {
1094:                            polyg, lineString });
1095:                } catch (TopologyException te) {
1096:                    fail("Error creating sample polygon for testing " + te);
1097:                }
1098:                return null;
1099:            }
1100:
1101:            private LinearRing makeSampleLinearRing(
1102:                    final GeometryFactory geomFac) {
1103:                try {
1104:                    Polygon polyg = (Polygon) buildShiftedGeometry(
1105:                            makeSamplePolygon(geomFac), 0, 100);
1106:                    return (LinearRing) polyg.getExteriorRing();
1107:                } catch (TopologyException te) {
1108:                    fail("Error creating sample polygon for testing " + te);
1109:                }
1110:                return null;
1111:            }
1112:
1113:            private Geometry buildShiftedGeometry(Geometry g, double shiftX,
1114:                    double shiftY) {
1115:                Geometry clone = (Geometry) g.clone();
1116:                Coordinate[] coords = clone.getCoordinates();
1117:                final int length = coords.length;
1118:                for (int i = 0; i < length; i++) {
1119:                    Coordinate coord = coords[i];
1120:                    coord.x += shiftX;
1121:                    coord.y += shiftY;
1122:                }
1123:
1124:                return clone;
1125:            }
1126:
1127:            /**
1128:             * I am not sure this is really correct. We should check it with more care.
1129:             * 
1130:             * @throws Exception
1131:             */
1132:            public void testScaleCalc() throws Exception {
1133:
1134:                // 1388422.8746916912, 639551.3924667436
1135:                // 1407342.5139777814, 650162.7155794351
1136:                // 655,368
1137:                // some location in bc albers
1138:                CoordinateReferenceSystem crs = CRS
1139:                        .parseWKT("PROJCS[\"NAD83 / BC"
1140:                                + "Albers\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS"
1141:                                + "1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],"
1142:                                + "TOWGS84[0,0,0],AUTHORITY[\"EPSG\",\"6269\"]],"
1143:                                + "PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],"
1144:                                + "UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],"
1145:                                + "AUTHORITY[\"EPSG\",\"4269\"]],"
1146:                                + "PROJECTION[\"Albers_Conic_Equal_Area\"],"
1147:                                + "PARAMETER[\"standard_parallel_1\",50],"
1148:                                + "PARAMETER[\"standard_parallel_2\",58.5],"
1149:                                + "PARAMETER[\"latitude_of_center\",45],"
1150:                                + "PARAMETER[\"longitude_of_center\",-126],"
1151:                                + "PARAMETER[\"false_easting\",1000000],"
1152:                                + "PARAMETER[\"false_northing\",0],"
1153:                                + "UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],"
1154:                                + "AUTHORITY[\"EPSG\",\"3005\"]]");
1155:                ReferencedEnvelope envelope = new ReferencedEnvelope(
1156:                        1388422.8746916912, 1407342.5139777814,
1157:                        639551.3924667438, 650162.715579435, crs);
1158:
1159:                double s = RendererUtilities.calculateScale(envelope, 655, 368,
1160:                        90.0);
1161:
1162:                LOGGER.info(Double.toString(s));
1163:                // assertTrue(Math.abs(102355 - s) < 10); // 102355.1639202933
1164:            }
1165:
1166:            public void testRenderEmptyLine() throws SchemaException,
1167:                    IllegalAttributeException {
1168:                GeometryFactory gf = new GeometryFactory();
1169:                StyleBuilder sb = new StyleBuilder();
1170:                FeatureType pointType = DataUtilities.createType("emptyLines",
1171:                        "geom:LineString,name:String");
1172:                Feature f = pointType.create(new Object[] {
1173:                        gf.createLineString((Coordinate[]) null), "name" });
1174:                Style style = sb.createStyle(sb.createLineSymbolizer());
1175:
1176:                renderEmptyGeometry(f, style);
1177:            }
1178:
1179:            public void testRenderEmptyCollection() throws SchemaException,
1180:                    IllegalAttributeException {
1181:                GeometryFactory gf = new GeometryFactory();
1182:                StyleBuilder sb = new StyleBuilder();
1183:                FeatureType pointType = DataUtilities.createType(
1184:                        "emptyPolygon", "geom:MultiPolygon,name:String");
1185:                Feature f = pointType.create(new Object[] {
1186:                        gf.createMultiPolygon((Polygon[]) null), "name" });
1187:                Style style = sb.createStyle(sb.createPolygonSymbolizer());
1188:
1189:                renderEmptyGeometry(f, style);
1190:            }
1191:
1192:            public void testRenderCollectionWithEmptyItems()
1193:                    throws SchemaException, IllegalAttributeException {
1194:                GeometryFactory gf = new GeometryFactory();
1195:                StyleBuilder sb = new StyleBuilder();
1196:                FeatureType pointType = DataUtilities.createType(
1197:                        "emptyPolygon", "geom:MultiPolygon,name:String");
1198:                Polygon p1 = gf.createPolygon(gf
1199:                        .createLinearRing((Coordinate[]) null), null);
1200:                Polygon p2 = gf.createPolygon(gf
1201:                        .createLinearRing(new Coordinate[] {
1202:                                new Coordinate(0, 0), new Coordinate(1, 1),
1203:                                new Coordinate(1, 0), new Coordinate(0, 0) }),
1204:                        null);
1205:                MultiPolygon mp = gf
1206:                        .createMultiPolygon(new Polygon[] { p1, p2 });
1207:                Feature f = pointType.create(new Object[] { mp, "name" });
1208:                Style style = sb.createStyle(sb.createPolygonSymbolizer());
1209:
1210:                renderEmptyGeometry(f, style);
1211:            }
1212:
1213:            public void testRenderPolygonEmptyRings() throws SchemaException,
1214:                    IllegalAttributeException {
1215:                GeometryFactory gf = new GeometryFactory();
1216:                StyleBuilder sb = new StyleBuilder();
1217:                FeatureType pointType = DataUtilities.createType("emptyRings",
1218:                        "geom:MultiPolygon,name:String");
1219:                LinearRing emptyRing = gf.createLinearRing((Coordinate[]) null);
1220:                LinearRing realRing = gf.createLinearRing(new Coordinate[] {
1221:                        new Coordinate(0, 0), new Coordinate(1, 1),
1222:                        new Coordinate(1, 0), new Coordinate(0, 0) });
1223:                Polygon p1 = gf.createPolygon(realRing,
1224:                        new LinearRing[] { emptyRing });
1225:                Polygon p2 = gf.createPolygon(emptyRing,
1226:                        new LinearRing[] { emptyRing });
1227:                MultiPolygon mp = gf
1228:                        .createMultiPolygon(new Polygon[] { p1, p2 });
1229:                Feature f = pointType.create(new Object[] { mp, "name" });
1230:                Style style = sb.createStyle(sb.createPolygonSymbolizer());
1231:
1232:                renderEmptyGeometry(f, style);
1233:            }
1234:
1235:            public void testMixedEmptyMultiLine() throws SchemaException,
1236:                    IllegalAttributeException {
1237:                GeometryFactory gf = new GeometryFactory();
1238:                StyleBuilder sb = new StyleBuilder();
1239:                FeatureType pointType = DataUtilities.createType("emptyRings",
1240:                        "geom:MultiLineString,name:String");
1241:                LineString emptyLine = gf.createLineString((Coordinate[]) null);
1242:                LineString realLine = gf.createLineString(new Coordinate[] {
1243:                        new Coordinate(0, 0), new Coordinate(1, 1) });
1244:                MultiLineString mls = gf
1245:                        .createMultiLineString(new LineString[] { emptyLine,
1246:                                realLine });
1247:                Feature f = pointType.create(new Object[] { mls, "name" });
1248:                Style style = sb.createStyle(sb.createPolygonSymbolizer());
1249:
1250:                renderEmptyGeometry(f, style);
1251:            }
1252:
1253:            private void renderEmptyGeometry(Feature f, Style style) {
1254:                FeatureCollection fc = DataUtilities.collection(f);
1255:                MapContext mc = new DefaultMapContext();
1256:                mc.addLayer(fc, style);
1257:                StreamingRenderer sr = new StreamingRenderer();
1258:                sr.setContext(mc);
1259:                BufferedImage bi = new BufferedImage(640, 480,
1260:                        BufferedImage.TYPE_4BYTE_ABGR);
1261:                sr.addRenderListener(new RenderListener() {
1262:
1263:                    public void featureRenderer(Feature feature) {
1264:                    }
1265:
1266:                    public void errorOccurred(Exception e) {
1267:                        e.printStackTrace();
1268:                        fail("Got an exception during rendering, this should not happen, "
1269:                                + "not even with emtpy geometries");
1270:                    }
1271:
1272:                });
1273:                sr.paint((Graphics2D) bi.getGraphics(),
1274:                        new Rectangle(640, 480), new ReferencedEnvelope(
1275:                                new Envelope(0, 10, 0, 10),
1276:                                DefaultGeographicCRS.WGS84));
1277:            }
1278:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.