01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.vfny.geoserver.wms.responses.map;
06:
07: import com.vividsolutions.jts.geom.Coordinate;
08: import com.vividsolutions.jts.geom.Envelope;
09: import com.vividsolutions.jts.geom.Geometry;
10: import com.vividsolutions.jts.geom.GeometryFactory;
11: import com.vividsolutions.jts.geom.LineString;
12: import com.vividsolutions.jts.geom.Point;
13: import com.vividsolutions.jts.geom.Polygon;
14: import org.geotools.data.FeatureSource;
15: import org.geotools.data.memory.MemoryDataStore;
16: import org.geotools.feature.AttributeTypeFactory;
17: import org.geotools.feature.Feature;
18: import org.geotools.feature.FeatureType;
19: import org.geotools.feature.FeatureTypeFactory;
20: import org.geotools.styling.Style;
21: import org.vfny.geoserver.testdata.AbstractCiteDataTest;
22: import org.vfny.geoserver.wms.WMSMapContext;
23: import org.vfny.geoserver.wms.responses.map.svg.SVGMapProducer;
24: import java.awt.Color;
25: import java.io.ByteArrayOutputStream;
26:
27: public class SVGMapProducerTest extends AbstractCiteDataTest {
28: public void testHeterogeneousGeometry() throws Exception {
29: GeometryFactory gf = new GeometryFactory();
30: Point point = gf.createPoint(new Coordinate(10, 10));
31: LineString line = gf.createLineString(new Coordinate[] {
32: new Coordinate(50, 50), new Coordinate(100, 100) });
33: Polygon polygon = gf
34: .createPolygon(
35: gf.createLinearRing(new Coordinate[] {
36: new Coordinate(0, 0),
37: new Coordinate(0, 200),
38: new Coordinate(200, 200),
39: new Coordinate(200, 0),
40: new Coordinate(0, 0) }), null);
41:
42: AttributeTypeFactory atf = AttributeTypeFactory
43: .defaultInstance();
44: FeatureTypeFactory ff = FeatureTypeFactory.newInstance("test");
45:
46: ff.addType(atf.newAttributeType("geom", Geometry.class));
47:
48: FeatureType type = ff.getFeatureType();
49:
50: Feature f1 = type.create(new Object[] { point });
51: Feature f2 = type.create(new Object[] { line });
52: Feature f3 = type.create(new Object[] { polygon });
53:
54: MemoryDataStore ds = new MemoryDataStore();
55: ds.createSchema(type);
56: ds.addFeatures(new Feature[] { f1, f2, f3 });
57:
58: FeatureSource fs = ds.getFeatureSource("test");
59:
60: final WMSMapContext map = new WMSMapContext();
61: map.setAreaOfInterest(new Envelope(-250, 250, -250, 250));
62: map.setMapWidth(300);
63: map.setMapHeight(300);
64: map.setBgColor(Color.red);
65: map.setTransparent(false);
66:
67: // FilterFactory f = FilterFactory.createFilterFactory();
68: // GeometryFilter filter =
69: // f.createGeometryFilter(GeometryFilter.GEOMETRY_BBOX);
70: //
71: // filter.addLeftGeometry(f.createAttributeExpression(type,"geom"));
72: // filter.addRightGeometry(f.createBBoxExpression(new
73: // Envelope(-100,100,-100,100)));
74: Style basicStyle = getStyle("default.sld");
75: map.addLayer(fs, basicStyle);
76:
77: SVGMapProducer producer = new SVGMapProducer();
78: producer.setMapContext(map);
79: producer.produceMap();
80:
81: ByteArrayOutputStream out = new ByteArrayOutputStream();
82: producer.writeTo(out);
83: }
84: }
|