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.opengis.referencing.crs.CoordinateReferenceSystem;
37: import org.opengis.referencing.operation.MathTransform;
38:
39: import com.vividsolutions.jts.geom.Coordinate;
40: import com.vividsolutions.jts.geom.Envelope;
41: import com.vividsolutions.jts.geom.Geometry;
42:
43: /**
44: * @TODO class description
45: *
46: * @author jeichar
47: * @since 2.1.x
48: * @source $URL:
49: * http://svn.geotools.org/geotools/branches/2.2.x/ext/shaperenderer/test/org/geotools/data/shapefile/shp/PointHandlerTest.java $
50: */
51: public class JTSPointHandlerTest extends TestCase {
52:
53: public void testRead() throws Exception {
54: URL url = TestData.url("shapes/pointtest.shp");
55: ShapefileDataStore ds = (ShapefileDataStore) new ShapefileDataStoreFactory()
56: .createDataStore(url);
57:
58: Envelope env = ds.getFeatureSource().getBounds();
59: CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
60: MathTransform mt = CRS.findMathTransform(crs,
61: DefaultGeographicCRS.WGS84);
62:
63: Rectangle rectangle = new Rectangle(300, 0, 300, 300);
64: AffineTransform transform = RendererUtilities
65: .worldToScreenTransform(env, rectangle);
66: GeneralMatrix matrix = new GeneralMatrix(transform);
67: MathTransform at = ReferencingFactoryFinder
68: .getMathTransformFactory(null).createAffineTransform(
69: matrix);
70: mt = ReferencingFactoryFinder.getMathTransformFactory(null)
71: .createConcatenatedTransform(mt, at);
72:
73: ShapefileReader reader = new ShapefileReader(
74: ShapefileRendererUtil.getShpReadChannel(ds), new Lock());
75: reader
76: .setHandler(new org.geotools.renderer.shape.shapehandler.jts.PointHandler(
77: reader.getHeader().getShapeType(), env,
78: rectangle, mt, false));
79:
80: Object shape = reader.nextRecord().shape();
81: assertNotNull(shape);
82: assertTrue(shape instanceof Geometry);
83: Coordinate[] coords = ((Geometry) shape).getCoordinates();
84: for (int i = 0; i < coords.length; i++) {
85: Coordinate coordinate = coords[i];
86: assertNotNull(coordinate);
87: }
88:
89: int i = 0;
90: while (reader.hasNext()) {
91: i++;
92: shape = reader.nextRecord().shape();
93: assertNotNull(shape);
94: assertTrue(shape instanceof Geometry);
95: }
96: assertEquals(ds.getFeatureSource().getCount(Query.ALL) - 1, i);
97: }
98:
99: }
|