Author: jive Date: 2012-03-28 17:50:29 -0700 (Wed, 28 Mar 2012) New Revision: 38652 Removed: trunk/modules/unsupported/epsg-h2/pom.xml trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/DatabaseCreationScript.java trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/SqlScriptReader.java trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/ThreadedH2EpsgFactory.java trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.cs.CSAuthorityFactory trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.datum.DatumAuthorityFactory trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.operation.CoordinateOperationAuthorityFactory trunk/modules/unsupported/epsg-h2/src/main/resources/org/geotools/referencing/factory/epsg/EPSG.zip trunk/modules/unsupported/epsg-h2/src/main/resources/org/geotools/referencing/factory/epsg/EPSG_Indexes_H2.sql trunk/modules/unsupported/epsg-h2/src/main/resources/org/geotools/referencing/factory/epsg/README.txt trunk/modules/unsupported/epsg-h2/src/test/java/org/geotools/referencing/factory/OrderedAxisAuthorityFactoryTest.java trunk/modules/unsupported/epsg-h2/src/test/java/org/geotools/referencing/factory/URN_EPSG_Test.java trunk/modules/unsupported/epsg-h2/src/test/java/org/geotools/referencing/factory/epsg/DefaultFactoryTest.java trunk/modules/unsupported/epsg-h2/src/test/java/org/geotools/referencing/factory/epsg/OperationFactoryTest.java trunk/modules/unsupported/epsg-h2/src/test/java/org/geotools/referencing/factory/epsg/ThreadedH2EpsgFactoryTest.java trunk/modules/unsupported/epsg-h2/src/test/java/org/geotools/referencing/tools/LoadStresser.java trunk/modules/unsupported/epsg-h2/src/test/java/org/geotools/referencing/tools/Start.java trunk/modules/unsupported/epsg-h2/src/test/java/org/geotools/referencing/tools/ThreadedLoadStresser.java Modified: trunk/modules/unsupported/pom.xml Log: Remove gt-epsg-h2 as per GEOT-4095 Deleted: trunk/modules/unsupported/epsg-h2/pom.xml =================================================================== --- trunk/modules/unsupported/epsg-h2/pom.xml 2012-03-27 14:53:07 UTC (rev 38651) +++ trunk/modules/unsupported/epsg-h2/pom.xml 2012-03-29 00:50:29 UTC (rev 38652) @@ -1,110 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- ======================================================================= - Maven Project Configuration File - - The Geotools Project - http://www.geotools.org/ - - Version: $Id: pom.xml 33188 2009-05-30 19:48:33Z aaime $ - ======================================================================= --> - <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 - http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.geotools</groupId> - <artifactId>unsupported</artifactId> - <version>8-SNAPSHOT</version> - </parent> - - - <!-- =========================================================== --> - <!-- Module Description --> - <!-- =========================================================== --> - <groupId>org.geotools</groupId> - <artifactId>gt-epsg-h2</artifactId> - <packaging>jar</packaging> - <name>EPSG Authority Service using H2 database</name> - - - <scm> - <connection> - scm:svn:http://svn.osgeo.org/geotools/trunk/modules/plugin/epsg-hsql/ - </connection> - <url>http://svn.osgeo.org/geotools/trunk/modules/plugin/epsg-hsql/</url> - </scm> - - <description> - Connection to an embedded EPSG database in HSQL format. - This database is built from the SQL scripts delivered by EPSG. - </description> - - <licenses> - <license> - <name>Lesser General Public License (LGPL)</name> - <!-- url>http://www.gnu.org/copyleft/lesser.txt</url --> - <url>http://svn.osgeo.org/geotools/trunk/modules/plugin/epsg-hsql/LICENSE.html</url> - <distribution>repo</distribution> - </license> - <license> - <name>EPSG database distribution license</name> - <url>http://svn.osgeo.org/geotools/trunk/licenses/EPSG.html</url> - <distribution>repo</distribution> - <comments> - This Geotools module is bundled with a copy of the EPSG database. The - data may be copied and distributed subject to the EPSG conditions. - </comments> - </license> - <license> - <name>MPL 1.1</name> - <url>http://www.h2database.com/html/license.html</url> - <distribution>repo</distribution> - <comments> - This Geotools module requires the H2 database engine, which is bundled - with the binary distribution only (there is no H2 derived work in the - Java source code). - </comments> - </license> - </licenses> - - - <!-- =========================================================== --> - <!-- Developers and Contributors --> - <!-- =========================================================== --> - <developers> - <developer> - <name>Andrea Aime</name> - <id>aaime</id> - <email>aa...@us...</email> - <roles> - <role>Java Developer</role> - <role>Module Maintainer</role> - </roles> - </developer> - </developers> - - - <!-- =========================================================== --> - <!-- Dependency Management --> - <!-- =========================================================== --> - <dependencies> - <dependency> - <groupId>org.geotools</groupId> - <artifactId>gt-referencing</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.geotools</groupId> - <artifactId>gt-sample-data</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - </dependencies> - -</project> Deleted: trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/DatabaseCreationScript.java =================================================================== --- trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/DatabaseCreationScript.java 2012-03-27 14:53:07 UTC (rev 38651) +++ trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/DatabaseCreationScript.java 2012-03-29 00:50:29 UTC (rev 38652) @@ -1,165 +0,0 @@ -/* - * GeoTools - The Open Source Java GIS Toolkit - * http://geotools.org - * - * (C) 2005-2008, Open Source Geospatial Foundation (OSGeo) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - */ -package org.geotools.referencing.factory.epsg; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -import org.h2.jdbcx.JdbcDataSource; - -/** - * Utility used to create a HSQL zipped version of the official EPSG database - * - * - * - * - * @source $URL$ - */ -public class DatabaseCreationScript { - - public static void main(String[] args) throws Exception { - /** - * BEFORE USING THIS SCRIPT - * - make sure you've created modified .sql files following the instructions - * - update ThreadedH2EpsgFactory.VERSION - * - modify the "directory" variable below to point to the folder containing the SQL scripts - */ - String inputDirectory = "./src/main/resources/org/geotools/referencing/factory/epsg/"; - - /** - * The files we're interested into - */ - File directory = new File(inputDirectory); - File databaseFile = new File(directory, ThreadedH2EpsgFactory.DATABASE_NAME + ".data.db"); - File indexFile = new File(directory, ThreadedH2EpsgFactory.DATABASE_NAME + ".index.db"); - File lobDirectory = new File(directory, ThreadedH2EpsgFactory.DATABASE_NAME + ".lobs.db"); - File zipFile = new File(directory, ThreadedH2EpsgFactory.DATABASE_NAME + ".zip"); - - /** - * Preventive cleanup of the files should an old run was broken or stopped in the middle - */ - indexFile.delete(); - databaseFile.delete(); - zipFile.delete(); - - - /* - * Constructs the full path to the HSQL database. Note: we do not use - * File.toURI() because HSQL doesn't seem to expect an encoded URL - * (e.g. "%20" instead of spaces). - */ - final JdbcDataSource source = new JdbcDataSource(); - final StringBuilder url = new StringBuilder(ThreadedH2EpsgFactory.PREFIX); - final String path = directory.getAbsolutePath().replace(File.separatorChar, '/'); - if (path.length()==0 || path.charAt(0)!='/') { - url.append('/'); - } - url.append(path); - - if (url.charAt(url.length()-1) != '/') { - url.append('/'); - } - url.append(ThreadedH2EpsgFactory.DATABASE_NAME); - // no need for validation query, saves some work - url.append(";AUTO_RECONNECT=TRUE;CACHE_SIZE=131072;CACHE_TYPE=TQ"); - source.setURL((url.toString())); - source.setUser("sa"); - source.setPassword(""); - - Connection connection = source.getConnection(); - /* - * HSQL has created automatically an empty database. We need to populate it. Executes - * the SQL scripts bundled in the JAR. In theory, each line contains a full SQL - * statement. For this plugin however, we have compressed "INSERT INTO" statements using - * Compactor class in this package. - */ - System.out.println("Creating the EPSG database"); - final Statement statement = connection.createStatement(); - try { - // read and execute the scripts that make up the database - executeScript(new File(directory, "EPSG_Tables_PostgreSQL.sql"), statement); - executeScript(new File(directory, "EPSG_Data_PostgreSQL.sql"), statement); - // statement.execute("UPDATE EPSG_DATUM SET REALIZATION_EPOCH = NULL WHERE REALIZATION_EPOCH = ''"); - // statement.execute("ALTER TABLE EPSG_DATUM ALTER COLUMN REALIZATION_EPOCH INTEGER"); - executeScript(new File(directory, "EPSG_FKeys_PostgreSQL.sql"), statement); - executeScript(new File(directory, "EPSG_Indexes_H2.sql"), statement); - statement.execute("SHUTDOWN COMPACT"); - } catch (IOException exception) { - SQLException e = new SQLException("Error occurred while executing " - + "the EPSG database creation scripts"); - e.initCause(exception); - throw e; - } finally { - statement.close(); - connection.close(); - } - System.out.println("EPSG database created"); - - /* - * Zip the database - */ - System.out.println("Creating the zipped database"); - byte[] buf = new byte[1024]; - ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile)); - File[] files = new File[] {databaseFile, indexFile}; - for(File file : files) { - FileInputStream in = new FileInputStream(file); - - zos.putNextEntry(new ZipEntry(file.getName())); - int len; - while ((len = in.read(buf)) > 0) { - zos.write(buf, 0, len); - } - zos.closeEntry(); - in.close(); - } - zos.close(); - - /** - * Cleanup, delete the database files - */ - System.out.println("Cleaning up the unzipped database files"); - databaseFile.delete(); - indexFile.delete(); - - System.out.println("Done. The zipped database file is available at " + zipFile.getAbsolutePath()); - } - - static void executeScript(File scriptFile, Statement statement) throws IOException, SQLException { - System.out.println("Executing script " + scriptFile.getPath()); - SqlScriptReader reader = null; - try { - // first read in the tables - reader = new SqlScriptReader(new InputStreamReader(new FileInputStream(scriptFile), "ISO-8859-15")); - while(reader.hasNext()) { - statement.execute(reader.next()); - } - } finally { - if(reader != null) - reader.dispose(); - } - } - -} Deleted: trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/SqlScriptReader.java =================================================================== --- trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/SqlScriptReader.java 2012-03-27 14:53:07 UTC (rev 38651) +++ trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/SqlScriptReader.java 2012-03-29 00:50:29 UTC (rev 38652) @@ -1,84 +0,0 @@ -/* - * GeoTools - The Open Source Java GIS Toolkit - * http://geotools.org - * - * (C) 2005-2008, Open Source Geospatial Foundation (OSGeo) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - */ -package org.geotools.referencing.factory.epsg; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.Reader; - -/** - * Utility class extracting SQL statement out of a script file with multiline - * statements (works with EPSG distributed scripts) - * - * - * - * - * - * @source $URL$ - */ -public class SqlScriptReader { - boolean fetched = true; - StringBuilder builder = new StringBuilder(); - BufferedReader reader; - - public SqlScriptReader(Reader reader) { - this.reader = new BufferedReader(reader); - } - - public boolean hasNext() throws IOException { - // do we have an un-fetched command? - if(!fetched) { - return builder.length() > 0; - } - - builder.setLength(0); - String line = null; - while((line = reader.readLine()) != null) { - line = line.trim(); - if(!"".equals(line)) - builder.append(line).append("\n"); - if(line.endsWith(";")) { - fetched = false; - break; - } - } - - if(line == null && builder.length() > 0) { - throw new IOException("The file ends with a non ; terminated command"); - } - - return line != null; - } - - public String next() throws IOException { - if(fetched) - throw new IOException("hasNext was not called, or was called and it returned false"); - - fetched = true; - return builder.toString(); - } - - public void dispose() { - try { - reader.close(); - } catch(IOException e) { - // never mind - } - } - - -} Deleted: trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/ThreadedH2EpsgFactory.java =================================================================== --- trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/ThreadedH2EpsgFactory.java 2012-03-27 14:53:07 UTC (rev 38651) +++ trunk/modules/unsupported/epsg-h2/src/main/java/org/geotools/referencing/factory/epsg/ThreadedH2EpsgFactory.java 2012-03-29 00:50:29 UTC (rev 38652) @@ -1,417 +0,0 @@ -/* - * GeoTools - The Open Source Java GIS Toolkit - * http://geotools.org - * - * (C) 2005-2008, Open Source Geospatial Foundation (OSGeo) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - */ -package org.geotools.referencing.factory.epsg; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.nio.channels.OverlappingFileLockException; -import java.sql.SQLException; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import javax.sql.DataSource; - -import org.geotools.factory.Hints; -import org.geotools.referencing.factory.AbstractAuthorityFactory; -import org.geotools.resources.i18n.ErrorKeys; -import org.geotools.resources.i18n.Errors; -import org.geotools.resources.i18n.LoggingKeys; -import org.geotools.resources.i18n.Loggings; -import org.geotools.util.Version; -import org.geotools.util.logging.Logging; -import org.h2.jdbcx.JdbcDataSource; - - - -/** - * Connection to the EPSG database in H2 database engine format using JDBC. The EPSG - * database can be downloaded from <A HREF="http://www.epsg.org">http://www.epsg.org</A>. - * The SQL scripts (modified for the HSQL syntax as <A HREF="doc-files/HSQL.html">explained - * here</A>) are bundled into this plugin. The database version is given in the - * {@linkplain org.opengis.metadata.citation.Citation#getEdition edition attribute} - * of the {@linkplain org.opengis.referencing.AuthorityFactory#getAuthority authority}. - * The HSQL database is read only. - * <P> - * <H3>Implementation note</H3> - * The SQL scripts are executed the first time a connection is required. The database - * is then created as cached tables ({@code HSQL.properties} and {@code HSQL.data} files) - * in a temporary directory. Future connections to the EPSG database while reuse the cached - * tables, if available. Otherwise, the scripts will be executed again in order to recreate - * them. - * <p> - * If the EPSG database should be created in a different directory (or already exists in that - * directory), it may be specified as a {@linkplain System#getProperty(String) system property} - * nammed {@value #DIRECTORY_KEY}. - * - * @since 2.6 - * - * - * - * @source $URL$ - * @version $Id$ - * @author Martin Desruisseaux - * @author Didier Richard - * @author Andrea Aime - */ -public class ThreadedH2EpsgFactory extends ThreadedEpsgFactory { - /** - * Current version of EPSG-h2 plugin. This is usually the same version number than the - * one in the EPSG database bundled in this plugin. However this field may contains - * additional minor version number if there is some changes related to the EPSG-H2 - * plugin rather then the EPSG database itself (for example additional database index). - */ - public static final Version VERSION = new Version("7.5.0"); - - /** - * The name of the ZIP file to read in order to create the cached database. - */ - private static final String ZIP_FILE = "EPSG.zip"; - - /** - * The successful database creation marker - */ - static final String MARKER_FILE = "EPSG_creation_marker.txt"; - - /** - * The database creation lock file - */ - static final String LOCK_FILE = "EPSG_creation_lock.txt"; - - /** - * The key for fetching the database directory from {@linkplain System#getProperty(String) - * system properties}. - */ - public static final String DIRECTORY_KEY = "EPSG-H2.directory"; - - /** - * The database name. - */ - public static final String DATABASE_NAME = "EPSG"; - - /** - * The prefix to put in front of URL to the database. - */ - static final String PREFIX = "jdbc:h2:"; - - /** - * The logger name. - */ - private static final String LOGGER = "org.geotools.referencing.factory.epsg"; - - /** - * Creates a new instance of this factory. If the {@value #DIRECTORY_KEY} - * {@linkplain System#getProperty(String) system property} is defined and contains - * the name of a directory with a valid {@linkplain File#getParent parent}, then the - * {@value #DATABASE_NAME} database will be saved in that directory. Otherwise, a - * temporary directory will be used. - */ - public ThreadedH2EpsgFactory() { - this(null); - } - - /** - * Creates a new instance of this data source using the specified hints. The priority - * is set to a lower value than the {@linkplain FactoryOnAccess}'s one in order to give - * precedence to the Access-backed database, if presents. Priorities are set that way - * because: - * <ul> - * <li>The MS-Access format is the primary EPSG database format.</li> - * <li>If a user downloads the MS-Access database himself, he probably wants to use it.</li> - * </ul> - */ - public ThreadedH2EpsgFactory(final Hints hints) { - super(hints, PRIORITY + 1); - } - - /** - * Returns the default directory for the EPSG database. If the {@value #DIRECTORY_KEY} - * {@linkplain System#getProperty(String) system property} is defined and contains the - * name of a directory with a valid {@linkplain File#getParent parent}, then the - * {@value #DATABASE_NAME} database will be saved in that directory. Otherwise, - * a temporary directory will be used. - */ - private static File getDirectory() { - try { - final String property = System.getProperty(DIRECTORY_KEY); - if (property != null) { - final File directory = new File(property); - /* - * Creates the directory if needed (mkdir), but NOT the parent directories (mkdirs) - * because a missing parent directory may be a symptom of an installation problem. - * For example if 'directory' is a subdirectory in the temporary directory (~/tmp/), - * this temporary directory should already exists. If it doesn't, an administrator - * should probably looks at this problem. - */ - if (directory.isDirectory() || directory.mkdir()) { - return directory; - } - } - } catch (SecurityException e) { - /* - * Can't fetch the base directory from system properties. - * Fallback on the default temporary directory. - */ - } - return getTemporaryDirectory(); - } - /** - * Tests of the EPSG database is unpacked into the required directory. - * <p> - * This method exists to allow client applications to check if the EPSG - * database is unpacked and ready to go; or if more time shoudld be - * alloted to let the database be constructed. - * @return true if directory intended for h2 exists (assumed from a previous run) - */ - public static boolean isUnpacked(){ - try { - final String property = System.getProperty(DIRECTORY_KEY); - if (property != null) { - final File directory = new File(property); - if (directory.exists() && directory.isDirectory()) { - return true; - } - } - } catch (SecurityException e) { - } - File temp = new File(System.getProperty("java.io.tmpdir", "."), "Geotools"); - File directory = new File( temp, "Databases/EPSG-H2-" + VERSION + "/" ); - if (directory.exists() && directory.isDirectory()) { - return true; - } - return false; - } - /** - * Returns the directory to uses in the temporary directory folder. - */ - private static File getTemporaryDirectory() { - File directory = new File(System.getProperty("java.io.tmpdir", "."), "Geotools"); - if (directory.isDirectory() || directory.mkdir()) { - directory = new File(directory, "Databases/EPSG-H2-" + VERSION + "/"); - if (directory.isDirectory() || directory.mkdirs()) { - return directory; - } - } - return null; - } - - /** - * Extract the directory from the specified data source, or {@code null} if this - * information is not available. - */ - private static File getDirectory(final DataSource source) { - if (source instanceof JdbcDataSource) { - String path = ((JdbcDataSource) source).getURL(); - if (path!=null && PREFIX.regionMatches(true, 0, path, 0, PREFIX.length())) { - path = path.substring(PREFIX.length()); - if( path.indexOf(';') != -1 ){ - path = path.substring(0, path.indexOf(';')); - } - return new File(path).getParentFile(); - } - } - return null; - } - - /** - * Returns a data source for the HSQL database. - */ - protected DataSource createDataSource() throws SQLException { - DataSource candidate = super.createDataSource(); - if (candidate instanceof JdbcDataSource) { - return candidate; - } - final JdbcDataSource source = new JdbcDataSource(); - File directory = getDirectory(); - if (directory != null) { - /* - * Constructs the full path to the HSQL database. Note: we do not use - * File.toURI() because HSQL doesn't seem to expect an encoded URL - * (e.g. "%20" instead of spaces). - */ - final StringBuilder url = new StringBuilder(PREFIX); - final String path = directory.getAbsolutePath().replace(File.separatorChar, '/'); - if (path.length()==0 || path.charAt(0)!='/') { - url.append('/'); - } - url.append(path); - - if (url.charAt(url.length()-1) != '/') { - url.append('/'); - } - url.append(DATABASE_NAME); - // no need for validation query, saves some work - url.append(";AUTO_RECONNECT=TRUE;CACHE_SIZE=131072;CACHE_TYPE=TQ"); - source.setURL((url.toString())); - source.setUser("sa"); - source.setPassword(""); - assert directory.equals(getDirectory(source)) : url; - } - /* - * If the temporary directory do not exists or can't be created, lets the 'database' - * attribute unset. If the user do not set it explicitly (through JNDI or by overrding - * this method), an exception will be thrown when 'createBackingStore()' will be invoked. - */ - source.setUser("SA"); // System administrator. No password. - return source; - } - - /** - * Returns {@code true} if the database contains data. This method returns {@code false} - * if an empty EPSG database has been automatically created by HSQL and not yet populated. - */ - private static boolean dataExists(File directory) throws SQLException { - // check if the marker file is there, and all the other database files as well - // (as some windows cleanup tools delete the .data file only) - return new File(directory, MARKER_FILE).exists() && - new File(directory, DATABASE_NAME + ".data.db").exists() && - new File(directory, DATABASE_NAME + ".index.db").exists(); - } - - /** - * Returns the backing-store factory for HSQL syntax. If the cached tables are not available, - * they will be created now from the SQL scripts bundled in this plugin. - * - * @param hints A map of hints, including the low-level factories to use for CRS creation. - * @return The EPSG factory using HSQL syntax. - * @throws SQLException if connection to the database failed. - */ - protected AbstractAuthorityFactory createBackingStore(final Hints hints) throws SQLException { - final DataSource source = getDataSource(); - final File directory = getDirectory(source); - directory.mkdirs(); - if (!dataExists(directory)) { - FileLock lock = null; - try { - // get an exclusive lock - lock = acquireLock(directory); - - // if after getting the lock the database is still incomplete let's work on it - if(!dataExists(directory)) { - /* - * HSQL has created automatically an empty database. We need to populate it. - * Executes the SQL scripts bundled in the JAR. In theory, each line contains - * a full SQL statement. For this plugin however, we have compressed "INSERT - * INTO" statements using Compactor class in this package. - */ - final Logger logger = Logging.getLogger(LOGGER); - final LogRecord record = Loggings.format(Level.INFO, - LoggingKeys.CREATING_CACHED_EPSG_DATABASE_$1, VERSION); - record.setLoggerName(logger.getName()); - logger.log(record); - - ZipInputStream zin = new ZipInputStream(ThreadedH2EpsgFactory.class.getResourceAsStream(ZIP_FILE)); - ZipEntry ze = null; - byte[] buf = new byte[1024]; - int read = 0; - while ((ze = zin.getNextEntry()) != null) { - File file = new File(directory, ze.getName()); - if( file.exists() ){ - file.delete(); - } - FileOutputStream fout = new FileOutputStream(file); - while((read = zin.read(buf)) > 0) { - fout.write(buf, 0, read); - } - zin.closeEntry(); - fout.close(); - } - zin.close(); - - // mark the successful creation - File marker = new File(directory, MARKER_FILE); - if( marker.exists() ){ - marker.delete(); - } - marker.createNewFile(); - - setReadOnly(directory); - } - } catch (IOException exception) { - SQLException e = new SQLException(Errors.format(ErrorKeys.CANT_READ_$1, ZIP_FILE)); - e.initCause(exception); // TODO: inline cause when we will be allowed to target Java 6. - throw e; - } finally { - if(lock != null) { - try { - lock.release(); - lock.channel().close(); - new File(directory, LOCK_FILE).delete(); - } catch(IOException e) { - // does not matter, was just cleanup - } - } - } - - } - FactoryUsingAnsiSQL factory = new FactoryUsingAnsiSQL(hints, getDataSource().getConnection()); - factory.setValidationQuery("CALL NOW()"); - return factory; - } - - /** - * - * @param directory - * @return - * @throws IOException - */ - FileLock acquireLock(File directory) throws IOException { - // Get a file channel for the file - File file = new File(directory, LOCK_FILE); - FileChannel channel = new RandomAccessFile(file, "rw").getChannel(); - - // Use the file channel to create a lock on the file. - // This method blocks until it can retrieve the lock. - FileLock lock = channel.lock(); - - // Try acquiring the lock without blocking. This method returns - // null or throws an exception if the file is already locked. - while(!lock.isValid()) { - try { - lock = channel.tryLock(); - } catch (OverlappingFileLockException e) { - // File is already locked in this thread or virtual machine - } - // wait for the other process to unlock it, should take a couple of seconds - try { - Thread.sleep(500); - } catch(InterruptedException e) { - // someone waked us earlier, no problem - } - } - - return lock; - } - - private void setReadOnly(final File directory) { - if( directory == null ) return; - for (File file : directory.listFiles()) { - if(file.isDirectory()) { - setReadOnly(file); - } else if(file.getName().endsWith(".log.db")) - file.delete(); - else - file.setReadOnly(); - } - } -} Deleted: trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory =================================================================== --- trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory 2012-03-27 14:53:07 UTC (rev 38651) +++ trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory 2012-03-29 00:50:29 UTC (rev 38652) @@ -1 +0,0 @@ -org.geotools.referencing.factory.epsg.ThreadedH2EpsgFactory Deleted: trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.cs.CSAuthorityFactory =================================================================== --- trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.cs.CSAuthorityFactory 2012-03-27 14:53:07 UTC (rev 38651) +++ trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.cs.CSAuthorityFactory 2012-03-29 00:50:29 UTC (rev 38652) @@ -1 +0,0 @@ -org.geotools.referencing.factory.epsg.ThreadedH2EpsgFactory Deleted: trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.datum.DatumAuthorityFactory =================================================================== --- trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.datum.DatumAuthorityFactory 2012-03-27 14:53:07 UTC (rev 38651) +++ trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.datum.DatumAuthorityFactory 2012-03-29 00:50:29 UTC (rev 38652) @@ -1 +0,0 @@ -org.geotools.referencing.factory.epsg.ThreadedH2EpsgFactory Deleted: trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.operation.CoordinateOperationAuthorityFactory =================================================================== --- trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.operation.CoordinateOperationAuthorityFactory 2012-03-27 14:53:07 UTC (rev 38651) +++ trunk/modules/unsupported/epsg-h2/src/main/resources/META-INF/services/org.opengis.referencing.operation.CoordinateOperationAuthorityFactory 2012-03-29 00:50:29 UTC (rev 38652) @@ -1 +0,0 @@ -org.geotools.referencing.factory.epsg.ThreadedH2EpsgFactory Deleted: trunk/modules/unsupported/epsg-h2/src/main/resources/org/geotools/referencing/factory/epsg/EPSG.zip =================================================================== (Binary files differ) Deleted: trunk/modules/unsupported/epsg-h2/src/main/resources/org/geotools/referencing/factory/epsg/EPSG_Indexes_H2.sql =================================================================== --- trunk/modules/unsupported/epsg-h2/src/main/resources/org/geotools/referencing/factory/epsg/EPSG_Indexes_H2.sql 2012-03-27 14:53:07 UTC (rev 38651) +++ trunk/modules/unsupported/epsg-h2/src/main/resources/org/geotools/referencing/factory/epsg/EPSG_Indexes_H2.sql 2012-03-29 00:50:29 UTC (rev 38652) @@ -1,24 +0,0 @@ -CREATE INDEX ALIAS_OBJECT_CODE ON EPSG_ALIAS(OBJECT_CODE); -CREATE INDEX CRS_DATUM_CODE ON EPSG_COORDINATEREFERENCESYSTEM(DATUM_CODE); -CREATE INDEX CRS_PROJECTION_CODE ON EPSG_COORDINATEREFERENCESYSTEM(PROJECTION_CONV_CODE); -CREATE INDEX COORDINATE_AXIS_CODE ON EPSG_COORDINATEAXIS(COORD_AXIS_CODE); -CREATE INDEX COORDINATE_AXIS_SYS_CODE ON EPSG_COORDINATEAXIS(COORD_SYS_CODE); -CREATE INDEX COORDINATE_OPERATION_CRS ON EPSG_COORDOPERATION(SOURCE_CRS_CODE, TARGET_CRS_CODE); -CREATE INDEX COORDINATE_OPERATION_METHOD_CODE ON EPSG_COORDOPERATION(COORD_OP_METHOD_CODE); -CREATE INDEX PARAMETER_USAGE_METHOD_CODE ON EPSG_COORDOPERATIONPARAMUSAGE(COORD_OP_METHOD_CODE); -CREATE INDEX PARAMETER_VALUES ON EPSG_COORDOPERATIONPARAMVALUE(COORD_OP_CODE, COORD_OP_METHOD_CODE); -CREATE INDEX PARAMETER_VALUE_CODE ON EPSG_COORDOPERATIONPARAMVALUE(PARAMETER_CODE); -CREATE INDEX PATH_CONCAT_OPERATION_CODE ON EPSG_COORDOPERATIONPATH(CONCAT_OPERATION_CODE); -CREATE INDEX SUPERSESSION_OBJECT_CODE ON EPSG_SUPERSESSION(OBJECT_CODE); -CREATE INDEX NAME_CRS ON EPSG_COORDINATEREFERENCESYSTEM(COORD_REF_SYS_NAME); -CREATE INDEX NAME_CS ON EPSG_COORDINATESYSTEM(COORD_SYS_NAME); -CREATE INDEX NAME_AXIS ON EPSG_COORDINATEAXISNAME(COORD_AXIS_NAME); -CREATE INDEX NAME_DATUM ON EPSG_DATUM(DATUM_NAME); -CREATE INDEX NAME_ELLIPSOID ON EPSG_ELLIPSOID(ELLIPSOID_NAME); -CREATE INDEX NAME_PRIME_MERIDIAN ON EPSG_PRIMEMERIDIAN(PRIME_MERIDIAN_NAME); -CREATE INDEX NAME_COORD_OP ON EPSG_COORDOPERATION(COORD_OP_NAME); -CREATE INDEX NAME_METHOD ON EPSG_COORDOPERATIONMETHOD(COORD_OP_METHOD_NAME); -CREATE INDEX NAME_PARAMETER ON EPSG_COORDOPERATIONPARAM(PARAMETER_NAME); -CREATE INDEX NAME_UNIT ON EPSG_UNITOFMEASURE(UNIT_OF_MEAS_NAME); -ANALYZE; - Deleted: trunk/modules/unsupported/epsg-h2/src/main/resources/org/geotools/referencing/factory/epsg/README.txt =================================================================== --- trunk/modules/unsupported/epsg-h2/src/main/resources/org/geotools/referencing/factory/epsg/README.txt 2012-03-27 14:53:07 UTC (rev 38651) +++ trunk/modules/unsupported/epsg-h2/src/main/resources/org/geotools/referencing/factory/epsg/README.txt 2012-03-29 00:50:29 UTC (rev 38652) @@ -1,38 +0,0 @@ -Updating the EPSG database ---------------------------- - -The database in the zip file is a HSQL version of the official EPSG database. - -1) Download from www.epsg.org the "geodetic dataset" creation scripts for the PostgreSQL database -2) Unzip them in _this_ directory, you should get three files named EPSG_v<version>.mdb_Data_PostgreSQL.sql, - EPSG_v<version>.mdb_FKeys_PostgreSQL.sql and EPSG_v<version>.mdb_Tables_PostgreSQL.sql, where - <version> is the the version of the EPSG database ("7_1" at the time of writing) -3) Remove the _v<version.mdb part from all names, resulting in names like EPSG_Data_PostgreSQL.sql -5) Hand modify the EPSG_Tables_PostgreSQL.sql file and replace all TEXT types with VARCHAR(4096) -6) Update ThreadedH2EpsgFactory.VERSION to the current version -7) Run the DatabaseCreationScript.java -8) Check the EPSG.zip file has been updated -9) Run the build with extensive tests in the epsg-h2 module: - mvn clean install -Pextensive.tests - - This step might force you to amend tests or modify the referencing subsystem to handle new - axis direction definitions, new unit of measure and the like -10) Remove all the sql files in this directory, keeping only EPSG_Indexes_H2.sql (which was already - there when you started). Also remove an eventual EPSG.*.log.db file. -11) Commit the changes -12) Congratulations, you're done! - - -PostgreSQL notes ------------------------------- - -Sometimes it is handy to have the database loaded in PostgreSQL to run random queries -against it. In order to load it you'll have to change the psql encoding thought: -createdb epsg<version> -psql espg<version> -\encoding latin9 -\i EPSG_v<version>.mdb_Tables_PostgreSQL.sql -\i EPSG_v<version>.mdb_Data_PostgreSQL.sql -\i EPSG_v<version>.mdb_FKeys_PostgreSQL.sql - - \ No newline at end of file Deleted: trunk/modules/unsupported/epsg-h2/src/test/java/org/geotools/referencing/factory/OrderedAxisAuthorityFactoryTest.java =================================================================== --- trunk/modules/unsupported/epsg-h2/src/test/java/org/geotools/referencing/factory/OrderedAxisAuthorityFactoryTest.java 2012-03-27 14:53:07 UTC (rev 38651) +++ trunk/modules/unsupported/epsg-h2/src/test/java/org/geotools/referencing/factory/OrderedAxisAuthorityFactoryTest.java 2012-03-29 00:50:29 UTC (rev 38652) @@ -1,416 +0,0 @@ -/* - * GeoTools - The Open Source Java GIS Toolkit - * http://geotools.org - * - * (C) 2005-2008, Open Source Geospatial Foundation (OSGeo) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - */ -package org.geotools.referencing.factory; - -// J2SE dependencies -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; - -// JUnit dependencies -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -// OpenGIS dependencies -import org.opengis.referencing.IdentifiedObject; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.SingleCRS; -import org.opengis.referencing.crs.ProjectedCRS; -import org.opengis.referencing.crs.CRSAuthorityFactory; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.cs.CoordinateSystem; -import org.opengis.referencing.operation.CoordinateOperationFactory; -import org.opengis.referencing.operation.MathTransform; -import org.opengis.referencing.operation.Matrix; - -// Geotools dependencies -import org.geotools.factory.Hints; -import org.geotools.resources.Arguments; -import org.geotools.referencing.CRS; -import org.geotools.referencing.ReferencingFactoryFinder; -import org.geotools.referencing.crs.DefaultGeographicCRS; -import org.geotools.referencing.operation.LinearTransform; -import org.geotools.referencing.operation.matrix.GeneralMatrix; -import org.geotools.referencing.cs.DefaultCoordinateSystemAxis; -import org.geotools.referencing.factory.epsg.CartesianAuthorityFactory; -import org.geotools.referencing.factory.epsg.LongitudeFirstFactory; - - -/** - * Tests the usage of {@link OrderedAxisAuthorityFactory} with the help of the - * EPSG database. Any EPSG plugin should fit. However, this test live in the - * {@code plugin/epsg-hsql} module since the HSQL plugin is the only one which - * is garantee to work on any machine running Maven. - * - * - * - * - * @source $URL$ - * @version $Id$ - * @author Martin Desruisseaux (IRD) - * @author Jody Garnett - */ -public class OrderedAxisAuthorityFactoryTest extends TestCase { - /** - * {@code true} if metadata (especially identifiers) should be erased, or {@code false} if - * they should be kepts. The {@code true} value matches the pre GEOT-854 state, while the - * {@code false} value mathes the post GEOT-854 state. - * - * @see http://jira.codehaus.org/browse/GEOT-854 - */ - private static final boolean METADATA_ERASED = false; - - /** - * Small number for floating points comparaisons. - */ - private static final double EPS = 1E-8; - - /** - * Run the suite from the command line. If {@code "-log"} flag is specified on the - * command-line, then the logger will be set to {@link Level#CONFIG}. This is usefull - * for tracking down which data source is actually used. - */ - public static void main(final String[] args) { - final Arguments arguments = new Arguments(args); - final boolean log = arguments.getFlag("-log"); - arguments.getRemainingArguments(0); - org.geotools.util.logging.Logging.GEOTOOLS.forceMonolineConsoleOutput(log ? Level.CONFIG : null); - junit.textui.TestRunner.run(suite()); - } - - /** - * Returns the test suite. - */ - public static Test suite() { - return new TestSuite(OrderedAxisAuthorityFactoryTest.class); - } - - /** - * Constructs a test case with the given name. - */ - public OrderedAxisAuthorityFactoryTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - // this test does not work if there is more than one EPSG factory around - Set<CRSAuthorityFactory> factories = ReferencingFactoryFinder.getCRSAuthorityFactories(null); - for (CRSAuthorityFactory factory : factories) { - if(factory instanceof CartesianAuthorityFactory) { - ReferencingFactoryFinder.removeAuthorityFactory(factory); - } - } - } - - /** - * Returns the ordered axis factory for the specified set of hints. - */ - private static OrderedAxisAuthorityFactory getFactory(final Hints hints) { - CRSAuthorityFactory factory; - factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints); - - assertTrue(factory.getClass().toString(), factory instanceof LongitudeFirstFactory); - final LongitudeFirstFactory asLongitudeFirst = (LongitudeFirstFactory) factory; - final Map implementationHints = asLongitudeFirst.getImplementationHints(); - factory = (CRSAuthorityFactory) implementationHints.get(Hints.CRS_AUTHORITY_FACTORY); - - assertTrue(factory.getClass().toString(), factory instanceof OrderedAxisAuthorityFactory); - final OrderedAxisAuthorityFactory asOrdered = (OrderedAxisAuthorityFactory) factory; - assertFalse(asOrdered.isCodeMethodOverriden()); - - return asOrdered; - } - - /** - * Returns a positive number if the specified coordinate system is right-handed, - * or a negative number if it is left handed. - */ - private static double getAngle(final CoordinateReferenceSystem crs) { - final CoordinateSystem cs = crs.getCoordinateSystem(); - assertEquals(2, cs.getDimension()); - return DefaultCoordinateSystemAxis.getAngle(cs.getAxis(0).getDirection(), - cs.getAxis(1).getDirection()); - } - - /** - * Tests the registration of the various flavor of {@link OrderedAxisAuthorityFactoryTest} - * for the EPSG authority factory. - */ - public void testRegistration() { - final Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); - OrderedAxisAuthorityFactory factory; - factory = getFactory(hints); - assertFalse(factory.forceStandardDirections); - assertFalse(factory.forceStandardUnits); - - hints.put(Hints.FORCE_STANDARD_AXIS_DIRECTIONS, Boolean.FALSE); - assertSame(factory, getFactory(hints)); - assertFalse(factory.forceStandardDirections); - assertFalse(factory.forceStandardUnits); - - hints.put(Hints.FORCE_STANDARD_AXIS_UNITS, Boolean.FALSE); - assertSame(factory, getFactory(hints)); - assertFalse(factory.forceStandardDirections); - assertFalse(factory.forceStandardUnits); - - hints.put(Hints.FORCE_STANDARD_AXIS_UNITS, Boolean.TRUE); - assertNotSame(factory, factory = getFactory(hints)); - assertFalse (factory.forceStandardDirections); - assertTrue (factory.forceStandardUnits); - - hints.put(Hints.FORCE_STANDARD_AXIS_DIRECTIONS, Boolean.TRUE); - assertNotSame(factory, factory = getFactory(hints)); - assertTrue (factory.forceStandardDirections); - assertTrue (factory.forceStandardUnits); - - hints.put(Hints.FORCE_STANDARD_AXIS_UNITS, Boolean.FALSE); - assertNotSame(factory, factory = getFactory(hints)); - assertTrue (factory.forceStandardDirections); - assertFalse (factory.forceStandardUnits); - } - - /** - * Tests the axis reordering. - */ - public void testAxisReordering() throws FactoryException { - /* - * Tests the OrderedAxisAuthorityFactory creating using FactoryFinder. The following - * conditions are not tested directly, but are required in order to get the test to - * succeed: - * - * - EPSG factories must be provided for both "official" and "modified" axis order. - * - The "official" axis order must have precedence over the modified one. - * - The hints are correctly understood by FactoryFinder. - */ - final AbstractAuthorityFactory factory0, factory1; - final Hints hints = new Hints(Hints.CRS_AUTHORITY_FACTORY, AbstractAuthorityFactory.class); - factory0 = (AbstractAuthorityFactory) ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints); - assertFalse(factory0 instanceof OrderedAxisAuthorityFactory); - assertFalse(factory0 instanceof LongitudeFirstFactory); - hints.put(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); - hints.put(Hints.FORCE_STANDARD_AXIS_DIRECTIONS, Boolean.TRUE); - hints.put(Hints.FORCE_STANDARD_AXIS_UNITS, Boolean.TRUE); - factory1 = (AbstractAuthorityFactory) ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints); - assertTrue(factory1 instanceof LongitudeFirstFactory); - /* - * The local variables to be used for all remaining tests - * (usefull to setup in the debugger). - */ - String code; - CoordinateReferenceSystem crs0, crs1; - CoordinateOperationFactory opFactory = ReferencingFactoryFinder.getCoordinateOperationFactory(null); - MathTransform mt; - Matrix matrix; - /* - * Tests a WGS84 geographic CRS (2D) with (NORTH, EAST) axis directions. - * The factory should reorder the axis with no more operation than an axis swap. - */ - code = "4326"; - crs0 = factory0.createCoordinateReferenceSystem(code); - crs1 = factory1.createCoordinateReferenceSystem(code); - final CoordinateReferenceSystem cacheTest = crs1; - assertNotSame(crs0, crs1); - assertNotSame(crs0.getCoordinateSystem(), crs1.getCoordinateSystem()); - assertSame(((SingleCRS) crs0).getDatum(), ((SingleCRS) crs1).getDatum()); - assertEquals("Expected a left-handed CS.", -90, getAngle(crs0), EPS); - assertEquals("Expected a right-handed CS.", +90, getAngle(crs1), EPS); - assertFalse(crs0.getIdentifiers().isEmpty()); - if (METADATA_ERASED) { - assertTrue(crs1.getIdentifiers().isEmpty()); - } else { - assertEquals(crs0.getIdentifiers(), crs1.getIdentifiers()); - } - mt = opFactory.createOperation(crs0, crs1).getMathTransform(); - assertFalse(mt.isIdentity()); - assertTrue(mt instanceof LinearTransform); - matrix = ((LinearTransform) mt).getMatrix(); - assertEquals(new GeneralMatrix(new double[][] { - {0, 1, 0}, - {1, 0, 0}, - {0, 0, 1}}), new GeneralMatrix(matrix)); - /* - * Tests a WGS84 geographic CRS (3D) with (NORTH, EAST, UP) axis directions. - * Because this CRS uses sexagesimal units, conversions are not supported and - * will not be tested. - */ - code = "4329"; - crs0 = factory0.createCoordinateReferenceSystem(code); - crs1 = factory1.createCoordinateReferenceSystem(code); - assertNotSame(crs0, crs1); - assertNotSame(crs0.getCoordinateSystem(), crs1.getCoordinateSystem()); - assertSame(((SingleCRS) crs0).getDatum(), ((SingleCRS) crs1).getDatum()); - assertFalse(crs0.getIdentifiers().isEmpty()); - if (METADATA_ERASED) { - assertTrue(crs1.getIdentifiers().isEmpty()); - } else { - assertEquals(crs0.getIdentifiers(), crs1.getIdentifiers()); - } - /* - * Tests a WGS84 geographic CRS (3D) with (NORTH, EAST, UP) axis directions. - * The factory should reorder the axis with no more operation than an axis swap. - */ - code = "63266413"; - crs0 = factory0.createCoordinateReferenceSystem(code); - crs1 = factory1.createCoordinateReferenceSystem(code); - assertNotSame(crs0, crs1); - assertNotSame(crs0.getCoordinateSystem(), crs1.getCoordinateSystem()); - assertSame(((SingleCRS) crs0).getDatum(), ((SingleCRS) crs1).getDatum()); - assertFalse(crs0.getIdentifiers().isEmpty()); - if (METADATA_ERASED) { - assertTrue(crs1.getIdentifiers().isEmpty()); - } else { - assertEquals(crs0.getIdentifiers(), crs1.getIdentifiers()); - } - mt = opFactory.createOperation(crs0, crs1).getMathTransform(); - assertFalse(mt.isIdentity()); - assertTrue(mt instanceof LinearTransform); - matrix = ((LinearTransform) mt).getMatrix(); - assertEquals(new GeneralMatrix(new double[][] { - {0, 1, 0, 0}, - {1, 0, 0, 0}, - {0, 0, 1, 0}, - {0, 0, 0, 1}}), new GeneralMatrix(matrix)); - /* - * Tests a projected CRS with (EAST, NORTH) axis orientation. No axis reordering is needed, - * which means that their coordinate systems are identical and the math transform should be - * the identity one. Note that while no axis swap is needed, the base GeographicCRS are not - * the same since an axis reordering has been done there. - */ - code = "2027"; - crs0 = factory0.createCoordinateReferenceSystem(code); - crs1 = factory1.createCoordinateReferenceSystem(code); - assertNotSame(crs0, crs1); - assertSame(crs0.getCoordinateSystem(), crs1.getCoordinateSystem()); - assertSame(((SingleCRS) crs0).getDatum(), ((SingleCRS) crs1).getDatum()); - assertNotSame(((ProjectedCRS) crs0).getBaseCRS(), ((ProjectedCRS) crs1).getBaseCRS()); - assertFalse(crs0.getIdentifiers().isEmpty()); - if (METADATA_ERASED) { - assertTrue(crs1.getIdentifiers().isEmpty()); - } else { - assertEquals(crs0.getIdentifiers(), crs1.getIdentifiers()); - } - mt = opFactory.createOperation(crs0, crs1).getMathTransform(); - assertTrue(mt.isIdentity()); - /* - * Tests a projected CRS with (WEST, SOUTH) axis orientation. - * The factory should arrange the axis with no more operation than a direction change. - * While the end result is a matrix like the GeographicCRS case, the path that lead to - * this result is much more complex. - */ - code = "22275"; - crs0 = factory0.createCoordinateReferenceSystem(code); - crs1 = factory1.createCoordinateReferenceSystem(code); - assertNotSame(crs0, crs1); - assertNotSame(crs0.getCoordinateSystem(), crs1.getCoordinateSystem()); - assertSame(((SingleCRS) crs0).getDatum(), ((SingleCRS) crs1).getDatum()); - assertFalse(crs0.getIdentifiers().isEmpty()); - if (METADATA_ERASED) { - assertTrue(crs1.getIdentifiers().isEmpty()); - } else { - assertEquals(crs0.getIdentifiers(), crs1.getIdentifiers()); - } - mt = opFactory.createOperation(crs0, crs1).getMathTransform(); - assertFalse(mt.isIdentity()); - assertTrue(mt instanceof LinearTransform); - matrix = ((LinearTransform) mt).getMatrix(); - assertEquals(new GeneralMatrix(new double[][] { - {-1, 0, 0}, - { 0, -1, 0}, - { 0, 0, 1}}), new GeneralMatrix(matrix)); - /* - * Tests the cache. - */ - assertSame(cacheTest, factory1.createCoordinateReferenceSystem("4326")); - } - - /** - * Tests the creation of EPSG:4326 CRS with different axis order. - */ - public void testLongitudeFirst() throws FactoryException { - final CoordinateReferenceSystem standard = CRS.decode("EPSG:4326", false); - final CoordinateReferenceSystem modified = CRS.decode("EPSG:4326", true ); - assertEquals("Expected a left-handed CS.", -90, getAngle(standard), EPS); - assertEquals("Expected a right-handed CS.", +90, getAngle(modified), EPS); - final MathTransform transform = CRS.findMathTransform(standard, modified); - assertTrue(transform instanceof LinearTransform); - final Matrix matrix = ((LinearTransform) transform).getMatrix(); - assertEquals(new GeneralMatrix(new double[][] { - { 0, 1, 0}, - { 1, 0, 0}, - { 0, 0, 1}}), new GeneralMatrix(matrix)); - } - - /** - * Tests the {@link IdentifiedObjectFinder#find} method with axis order forced. - */ - public void testFind() throws FactoryException { - final CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory( - "EPSG", new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE)); - - assertTrue(factory instanceof AbstractAuthorityFactory); - AbstractAuthorityFactory findable = (AbstractAuthorityFactory) factory; - final IdentifiedObjectFinder finder = findable.getIdentifiedObjectFinder(CoordinateReferenceSystem.class); - - /* - * We tested in DefaultFactoryTest that WGS84 is not found when searching - * directly in DefaultFactory. Now we perform the same search through the - * ordered axis authority factory. - */ - finder.setFullScanAllowed(false); - assertNull("Should not find the CRS without a scan.", - finder.find(DefaultGeographicCRS.WGS84)); - - finder.setFullScanAllowed(true); - IdentifiedObject find = finder.find(DefaultGeographicCRS.WGS84); - assertNotNull("With scan allowed, should find the CRS.", find); - assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, find)); - assertEquals("Expected a right-handed CS.", +90, getAngle((CoordinateReferenceSystem) find), EPS); - /* - * Search a CRS using (latitude,longitude) axis order. The IdentifiedObjectFinder - * should be able to find it even if it is backed by... [truncated message content] |