01: package org.geotools.renderer.lite;
02:
03: import java.util.HashMap;
04:
05: import junit.framework.TestCase;
06:
07: import org.geotools.geometry.jts.ReferencedEnvelope;
08: import org.geotools.referencing.CRS;
09: import org.geotools.referencing.crs.DefaultEngineeringCRS;
10: import org.geotools.referencing.crs.DefaultGeographicCRS;
11: import org.geotools.resources.XMath;
12: import org.opengis.referencing.crs.CoordinateReferenceSystem;
13:
14: import com.vividsolutions.jts.geom.Envelope;
15:
16: public class RenderUtilitiesTest extends TestCase {
17:
18: public void testScaleOutsideCrsDefinition() throws Exception {
19: CoordinateReferenceSystem utm1N = CRS.decode("EPSG:32601");
20: ReferencedEnvelope re = new ReferencedEnvelope(new Envelope(0,
21: 0, 100, 100), utm1N);
22: try {
23: RendererUtilities.calculateScale(re, 100, 100, 75);
24: fail("Should have failed, envelope outside of the source crs validity area");
25: } catch (IllegalArgumentException e) {
26: // ok
27: }
28: }
29:
30: public void testScaleProjected() throws Exception {
31: CoordinateReferenceSystem utm1N = CRS.decode("EPSG:32601");
32: // valid coords for utm nord 1 start from (200000, 0)
33: ReferencedEnvelope re = new ReferencedEnvelope(new Envelope(
34: 200000, 200100, 0, 100), utm1N);
35: double scale = RendererUtilities.calculateScale(re, 100, 100,
36: 2.54);
37: assertEquals(100.0, scale, 0.1); // account for projection deformation
38: }
39:
40: public void testScaleCartesian() throws Exception {
41: ReferencedEnvelope re = new ReferencedEnvelope(new Envelope(0,
42: 10, 0, 10), DefaultEngineeringCRS.CARTESIAN_2D);
43: double scale = RendererUtilities.calculateScale(re, 10 * 100,
44: 10 * 100, 2.54);
45: assertEquals(1.0, scale, 0.00001); // no projection deformation here!
46: }
47:
48: public void testScaleGeneric() throws Exception {
49: ReferencedEnvelope re = new ReferencedEnvelope(new Envelope(0,
50: 10, 0, 10), DefaultEngineeringCRS.GENERIC_2D);
51: double scale = RendererUtilities.calculateScale(re, 10 * 100,
52: 10 * 100, 2.54);
53: assertEquals(1.0, scale, 0.00001); // no projection deformation here!
54: }
55:
56: public void testOGCScaleProjected() throws Exception {
57: ReferencedEnvelope re = new ReferencedEnvelope(new Envelope(0,
58: 10, 0, 10), DefaultEngineeringCRS.CARTESIAN_2D);
59: int tenMetersPixels = (int) Math.round(10 / 0.00028);
60: double scale = RendererUtilities.calculateOGCScale(re,
61: tenMetersPixels, new HashMap());
62: assertEquals(1.0, scale, 0.0001);
63: }
64:
65: public void testOGCScaleGeographic() throws Exception {
66: // same example as page 29 in the SLD OGC spec, but with the expected scale corrected
67: // since the OGC document contains a very imprecise one
68: ReferencedEnvelope re = new ReferencedEnvelope(new Envelope(0,
69: 2, 0, 2), DefaultGeographicCRS.WGS84);
70: double scale = RendererUtilities.calculateOGCScale(re, 600,
71: new HashMap());
72: assertEquals(1325232.03, scale, 0.01);
73: }
74:
75: /**
76: * The following test is from the tile module where the behavior
77: * of RenderUtilities changed between 2.2. and 2.4.
78: */
79: public void testCenterTile() throws Exception {
80: Envelope centerTile = new Envelope(0, 36, -18, 18);
81: CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
82: double scale = RendererUtilities.calculateScale(centerTile,
83: crs, 512, 512, 72.0);
84: double groundDistance = XMath.hypot(36, 36) * (1852 * 60);
85: double pixelDistance = XMath.hypot(512, 512) * (0.0254 / 72);
86: double expected = groundDistance / pixelDistance;
87: assertEquals(expected, scale, expected * 0.05); // no projection deformation here!
88: }
89: }
|