01: package org.geotools.util;
02:
03: import com.vividsolutions.jts.geom.Coordinate;
04: import com.vividsolutions.jts.geom.Envelope;
05: import com.vividsolutions.jts.geom.Geometry;
06: import com.vividsolutions.jts.geom.GeometryFactory;
07: import com.vividsolutions.jts.geom.LinearRing;
08:
09: import junit.framework.TestCase;
10:
11: public class GeometryConverterFactoryTest extends TestCase {
12:
13: GeometryConverterFactory factory;
14:
15: protected void setUp() throws Exception {
16: factory = new GeometryConverterFactory();
17: }
18:
19: public void testEnvelopeToGeometry() throws Exception {
20: Geometry geometry = (Geometry) factory.createConverter(
21: Envelope.class, Geometry.class, null)
22: .convert(
23: new Envelope(new Coordinate(0, 0),
24: new Coordinate(1, 1)), Geometry.class);
25: assertNotNull(geometry);
26: assertTrue(new GeometryFactory().createPolygon(
27: new GeometryFactory()
28: .createLinearRing(new Coordinate[] {
29: new Coordinate(0, 0),
30: new Coordinate(1, 0),
31: new Coordinate(1, 1),
32: new Coordinate(0, 1),
33: new Coordinate(0, 0) }), null).equals(
34: geometry));
35:
36: }
37:
38: public void testGeometryToEnvelope() throws Exception {
39: Envelope envelope = (Envelope) factory.createConverter(
40: Geometry.class, Envelope.class, null).convert(
41: new GeometryFactory().createPolygon(
42: new GeometryFactory()
43: .createLinearRing(new Coordinate[] {
44: new Coordinate(0, 0),
45: new Coordinate(1, 0),
46: new Coordinate(1, 1),
47: new Coordinate(0, 1),
48: new Coordinate(0, 0) }), null),
49: Envelope.class);
50:
51: assertEquals(new Envelope(new Coordinate(0, 0), new Coordinate(
52: 1, 1)), envelope);
53: }
54:
55: public void testStringToGeometry() throws Exception {
56: Geometry geometry = (Geometry) factory.createConverter(
57: String.class, Geometry.class, null).convert(
58: "POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", Geometry.class);
59: assertNotNull(geometry);
60: assertTrue(new GeometryFactory().createPolygon(
61: new GeometryFactory()
62: .createLinearRing(new Coordinate[] {
63: new Coordinate(0, 0),
64: new Coordinate(1, 0),
65: new Coordinate(1, 1),
66: new Coordinate(0, 1),
67: new Coordinate(0, 0) }), null).equals(
68: geometry));
69: }
70:
71: public void testGeometryToString() throws Exception {
72: String wkt = (String) factory.createConverter(Geometry.class,
73: String.class, null).convert(
74: new GeometryFactory().createPolygon(
75: new GeometryFactory()
76: .createLinearRing(new Coordinate[] {
77: new Coordinate(0, 0),
78: new Coordinate(1, 0),
79: new Coordinate(1, 1),
80: new Coordinate(0, 1),
81: new Coordinate(0, 0) }), null),
82: String.class);
83:
84: assertEquals("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", wkt);
85: }
86: }
|