01: /*
02: * Geotools2 - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package org.geotools.data.shapefile.shp;
18:
19: import java.awt.Rectangle;
20: import java.awt.geom.AffineTransform;
21: import java.net.URL;
22:
23: import junit.framework.TestCase;
24:
25: import org.geotools.TestData;
26: import org.geotools.data.Query;
27: import org.geotools.data.shapefile.Lock;
28: import org.geotools.data.shapefile.ShapefileDataStore;
29: import org.geotools.data.shapefile.ShapefileDataStoreFactory;
30: import org.geotools.data.shapefile.ShapefileRendererUtil;
31: import org.geotools.referencing.CRS;
32: import org.geotools.referencing.ReferencingFactoryFinder;
33: import org.geotools.referencing.crs.DefaultGeographicCRS;
34: import org.geotools.referencing.operation.matrix.GeneralMatrix;
35: import org.geotools.renderer.lite.RendererUtilities;
36: import org.geotools.renderer.shape.SimpleGeometry;
37: import org.opengis.referencing.crs.CoordinateReferenceSystem;
38: import org.opengis.referencing.operation.MathTransform;
39:
40: import com.vividsolutions.jts.geom.Envelope;
41:
42: /**
43: * @TODO class description
44: *
45: * @author jeichar
46: * @since 2.1.x
47: * @source $URL:
48: * http://svn.geotools.org/geotools/branches/2.2.x/ext/shaperenderer/test/org/geotools/data/shapefile/shp/PointHandlerTest.java $
49: */
50: public class SimplePointHandlerTest extends TestCase {
51:
52: public void testRead() throws Exception {
53: URL url = TestData.url("shapes/pointtest.shp");
54: ShapefileDataStore ds = (ShapefileDataStore) new ShapefileDataStoreFactory()
55: .createDataStore(url);
56:
57: Envelope env = ds.getFeatureSource().getBounds();
58: CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
59: MathTransform mt = CRS.findMathTransform(crs,
60: DefaultGeographicCRS.WGS84);
61:
62: Rectangle rectangle = new Rectangle(300, 0, 300, 300);
63: AffineTransform transform = RendererUtilities
64: .worldToScreenTransform(env, rectangle);
65: GeneralMatrix matrix = new GeneralMatrix(transform);
66: MathTransform at = ReferencingFactoryFinder
67: .getMathTransformFactory(null).createAffineTransform(
68: matrix);
69: mt = ReferencingFactoryFinder.getMathTransformFactory(null)
70: .createConcatenatedTransform(mt, at);
71:
72: ShapefileReader reader = new ShapefileReader(
73: ShapefileRendererUtil.getShpReadChannel(ds), new Lock());
74: reader
75: .setHandler(new org.geotools.renderer.shape.shapehandler.simple.PointHandler(
76: reader.getHeader().getShapeType(), env,
77: rectangle, mt, false));
78:
79: Object shape = reader.nextRecord().shape();
80: assertNotNull(shape);
81: assertTrue(shape instanceof SimpleGeometry);
82: int i = 0;
83: while (reader.hasNext()) {
84: i++;
85: shape = reader.nextRecord().shape();
86: assertNotNull(shape);
87: assertTrue(shape instanceof SimpleGeometry);
88: }
89: assertEquals(ds.getFeatureSource().getCount(Query.ALL) - 1, i);
90: }
91:
92: }
|