001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.referencing.factory.epsg;
017:
018: // J2SE dependencies
019: import java.util.Collection;
020:
021: // OpenGIS dependencies
022: import org.opengis.referencing.FactoryException;
023: import org.opengis.referencing.crs.ProjectedCRS;
024: import org.opengis.referencing.crs.GeographicCRS;
025: import org.opengis.referencing.crs.CoordinateReferenceSystem;
026: import org.opengis.referencing.crs.CRSAuthorityFactory;
027:
028: // Geotools dependencies
029: import org.geotools.referencing.CRS;
030: import org.geotools.referencing.NamedIdentifier;
031: import org.geotools.referencing.crs.DefaultGeographicCRS;
032: import org.geotools.metadata.iso.citation.Citations;
033:
034: // JUnit dependencies
035: import junit.framework.Test;
036: import junit.framework.TestCase;
037: import junit.framework.TestSuite;
038:
039: /**
040: * Tests {@link FactoryUsingWKT} as a fallback after {@link DefaultFactory}.
041: * This method performs the tests through the {@link CRS#decode} method.
042: *
043: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/epsg-extension/src/test/java/org/geotools/referencing/factory/epsg/EpsgFallbackTest.java $
044: * @version $Id: EpsgFallbackTest.java 25668 2007-05-29 13:44:16Z desruisseaux $
045: * @author Jody Garnett
046: * @author Martin Desruisseaux
047: */
048: public class EpsgFallbackTest extends TestCase {
049: /**
050: * Returns the test suite.
051: */
052: public static Test suite() {
053: return new TestSuite(EpsgFallbackTest.class);
054: }
055:
056: /**
057: * Run the test from the command line.
058: * Options: {@code -verbose}.
059: *
060: * @param args the command line arguments.
061: */
062: public static void main(final String[] args) {
063: junit.textui.TestRunner.run(suite());
064: }
065:
066: /**
067: * Creates a test case with the specified name.
068: */
069: public EpsgFallbackTest(final String name) {
070: super (name);
071: }
072:
073: /**
074: * A random CRS for fun.
075: * This CRS is defined in the {@linkplain DefaultFactory default EPSG authority factory}.
076: */
077: public void test26910() throws FactoryException {
078: final String code = "EPSG:26910";
079: final CoordinateReferenceSystem crs = CRS.decode(code);
080: assertNotNull(crs);
081: assertTrue(crs instanceof ProjectedCRS);
082: assertFalse(CRS.equalsIgnoreMetadata(crs, CRS
083: .decode(code, true)));
084: }
085:
086: /**
087: * UDIG requires this to work.
088: * This CRS is defined in the {@linkplain DefaultFactory default EPSG authority factory}.
089: */
090: public void test4326() throws FactoryException {
091: final String code = "EPSG:4326";
092: final CoordinateReferenceSystem crs = CRS.decode(code);
093: assertNotNull(crs);
094: assertTrue(crs instanceof GeographicCRS);
095: assertFalse(CRS.equalsIgnoreMetadata(crs, CRS
096: .decode(code, true)));
097: }
098:
099: /**
100: * UDIG requires this to work.
101: * This CRS is defined in the {@linkplain DefaultFactory default EPSG authority factory}.
102: */
103: public void test4269() throws FactoryException {
104: final String code = "EPSG:4269";
105: final CoordinateReferenceSystem crs = CRS.decode(code);
106: assertNotNull(crs);
107: assertTrue(crs instanceof GeographicCRS);
108: assertFalse(CRS.equalsIgnoreMetadata(crs, CRS
109: .decode(code, true)));
110: }
111:
112: /**
113: * UDIG requires this to work.
114: * This CRS is defined in {@code unnamed.properties}.
115: */
116: public void test42102() throws FactoryException {
117: final String code = "EPSG:42102";
118: final CoordinateReferenceSystem crs = CRS.decode(code);
119: assertNotNull(crs);
120: assertTrue(crs instanceof ProjectedCRS);
121: assertSame(crs, CRS.decode(code, true));
122:
123: // Checks identifier
124: final Collection identifiers = crs.getIdentifiers();
125: assertNotNull(identifiers);
126: assertFalse(identifiers.isEmpty());
127: NamedIdentifier expected = new NamedIdentifier(Citations.EPSG,
128: "42102");
129: assertTrue(identifiers.contains(expected));
130: }
131:
132: /**
133: * A random CRS for fun.
134: * This CRS is defined in the {@linkplain DefaultFactory default EPSG authority factory}.
135: */
136: public void test26910Lower() throws FactoryException {
137: final String code = "epsg:26910";
138: final CoordinateReferenceSystem crs = CRS.decode(code);
139: assertNotNull(crs);
140: assertTrue(crs instanceof ProjectedCRS);
141: assertFalse(CRS.equalsIgnoreMetadata(crs, CRS
142: .decode(code, true)));
143: }
144:
145: /**
146: * A random CRS for fun.
147: * This CRS is defined in the {@linkplain DefaultFactory default EPSG authority factory}.
148: */
149: public void test26986Lower() throws FactoryException {
150: final String code = "epsg:26986";
151: final CoordinateReferenceSystem crs = CRS.decode(code);
152: assertNotNull(crs);
153: assertTrue(crs instanceof ProjectedCRS);
154: assertFalse(CRS.equalsIgnoreMetadata(crs, CRS
155: .decode(code, true)));
156: }
157:
158: /**
159: * WFS requires this to work.
160: * This CRS is defined in the {@linkplain DefaultFactory default EPSG authority factory}.
161: */
162: public void test4326Lower() throws FactoryException {
163: final String code = "epsg:4326";
164: final CoordinateReferenceSystem crs = CRS.decode(code);
165: assertNotNull(crs);
166: assertTrue(crs instanceof GeographicCRS);
167: assertFalse(CRS.equalsIgnoreMetadata(crs, CRS
168: .decode(code, true)));
169: }
170:
171: /**
172: * WFS requires this to work.
173: * This CRS is defined in the {@linkplain DefaultFactory default EPSG authority factory}.
174: */
175: public void test26742Lower() throws FactoryException {
176: final String code = "epsg:26742";
177: final CoordinateReferenceSystem crs = CRS.decode(code);
178: assertNotNull(crs);
179: assertTrue(crs instanceof ProjectedCRS);
180: assertFalse(CRS.equalsIgnoreMetadata(crs, CRS
181: .decode(code, true)));
182: }
183:
184: /**
185: * WFS requires this to work.
186: * This CRS is defined in the {@linkplain DefaultFactory default EPSG authority factory}.
187: */
188: public void test4269Lower() throws FactoryException {
189: final String code = "epsg:4269";
190: final CoordinateReferenceSystem crs = CRS.decode(code);
191: assertNotNull(crs);
192: assertTrue(crs instanceof GeographicCRS);
193: assertFalse(CRS.equalsIgnoreMetadata(crs, CRS
194: .decode(code, true)));
195: }
196:
197: /**
198: * WFS requires this to work.
199: * This CRS is defined in {@code unnamed.properties}.
200: */
201: public void test42304Lower() throws FactoryException {
202: final String code = "epsg:42304";
203: final CoordinateReferenceSystem crs = CRS.decode(code);
204: assertNotNull(crs);
205: assertSame(crs, CRS.decode(code, true));
206: }
207:
208: /**
209: * WFS requires this to work.
210: * This CRS is defined in {@code unnamed.properties}.
211: */
212: public void test42102Lower() throws FactoryException {
213: final String code = "epsg:42102";
214: final CoordinateReferenceSystem crs = CRS.decode(code);
215: assertNotNull(crs);
216: assertSame(crs, CRS.decode(code, true));
217:
218: // Checks identifier
219: final Collection identifiers = crs.getIdentifiers();
220: assertNotNull(identifiers);
221: assertFalse(identifiers.isEmpty());
222: NamedIdentifier expected = new NamedIdentifier(Citations.EPSG,
223: "42102");
224: assertTrue(identifiers.contains(expected));
225: }
226:
227: /**
228: * This CRS is defined in {@code esri.properties}.
229: */
230: public void test54004() throws FactoryException {
231: final CRSAuthorityFactory factory = CRS
232: .getAuthorityFactory(false);
233: final String code = "EPSG:54004";
234: final CoordinateReferenceSystem crs = factory
235: .createCoordinateReferenceSystem(code);
236: assertNotNull(crs);
237: assertSame(crs, CRS.decode(code, true));
238: assertEquals("World_Mercator", String.valueOf(factory
239: .getDescriptionText(code)));
240:
241: // Equivalent standard ESPG
242: final CoordinateReferenceSystem standard = factory
243: .createCoordinateReferenceSystem("EPSG:3395");
244: assertEquals("WGS 84 / World Mercator", String.valueOf(factory
245: .getDescriptionText("EPSG:3395")));
246: // TODO: enable if we implement more intelligent 'equalsIgnoreMetadata'
247: //assertTrue(CRS.equalsIgnoreMetadata(crs, standard));
248: }
249:
250: /**
251: * Tests the obtention of various codes.
252: */
253: public void testCodes() throws FactoryException {
254: final CRSAuthorityFactory factory = CRS
255: .getAuthorityFactory(false);
256: final Collection codes = factory
257: .getAuthorityCodes(ProjectedCRS.class);
258: assertTrue(codes.contains("EPSG:3395")); // Defined in EPSG database
259: assertTrue(codes.contains("EPSG:54004")); // Defined in ESRI database
260: assertFalse(codes.contains("ESRI:54004"));
261: assertTrue(codes.contains("EPSG:42304")); // Defined in unnamed database
262: assertTrue(codes.contains("EPSG:26742")); // Defined in EPSG database
263: assertTrue(codes.contains("EPSG:42102")); // Defined in unnamed database
264: assertFalse(codes.contains("EPSG:4326")); // This is a GeographicCRS, not a ProjectedCRS
265: assertTrue(codes.contains("EPSG:100002")); // Defined in unnamed database
266: assertFalse(codes.contains("EPSG:100001")); // This is a GeographicCRS, not a ProjectedCRS
267: }
268: }
|