Revision 37383

View differences:

tags/v2_0_0_Build_2041/libraries/libJCRS/src/es/idr/teledeteccion/connection/EpsgConnection.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
34
 *   Campus Universitario s/n
35
 *   02071 Alabacete
36
 *   Spain
37
 *
38
 *   +34 967 599 200
39
 */
40

  
41
package es.idr.teledeteccion.connection;
42

  
43
import java.io.BufferedReader;
44
import java.io.File;
45
import java.io.IOException;
46
import java.io.InputStreamReader;
47
import java.sql.Connection;
48
import java.sql.ResultSet;
49
import java.sql.SQLException;
50
import java.sql.Statement;
51
import java.util.logging.Logger;
52

  
53
import org.geotools.referencing.factory.epsg.HSQLDataSource;
54
import org.geotools.referencing.factory.iau2000.FactoryUsingHSQL;
55
import org.hsqldb.jdbc.jdbcDataSource;
56

  
57
/**
58
 * Clase para la conexi?n con la base de datos de hsqldb.
59
 * Establece el driver necesario, as? como la cadena de
60
 * conexi?n a la base de datos de la EPSG y la IAU2000
61
 * 
62
 * @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
63
 *
64
 */
65

  
66
public class EpsgConnection extends jdbcDataSource {
67
	
68
	Connection connect;
69

  
70
	public EpsgConnection() {	
71
	/*	try {
72
			Class.forName("org.hsqldb.jdbcDriver");
73
		} catch (ClassNotFoundException e) {
74
			e.printStackTrace();
75
		}*/
76
	}
77
	
78
	public void setConnectionEPSG() {
79
		HSQLDataSource ds = new HSQLDataSource();
80
				
81
		try {
82
			connect = ds.getConnection();
83
		} catch (SQLException e) {
84
			// TODO Auto-generated catch block
85
			e.printStackTrace();
86
		}
87
	}
88
	
89
	/**
90
	 * Establece la conexi?n con la base de datos de la IAU2000
91
	 *
92
	 */
93
	public void setConnectionIAU2000() {
94
		setDatabase("jdbc:hsqldb:file:gvSIG/extensiones/org.gvsig.crs.extension/iau2000");
95
		setUser("sa");
96
		try {
97
			connect = super.getConnection();
98
		} catch (SQLException e) {
99
			// TODO Auto-generated catch block
100
			e.printStackTrace();
101
		}
102
	}
103
	
104
	/**
105
	 * Establece la conexi?n con la base de datos de ESRI
106
	 *
107
	 */
108
	public void setConnectionEsri() {
109
		setDatabase("jdbc:hsqldb:file:gvSIG/extensiones/org.gvsig.crs.extension/esri");
110
		setUser("sa");
111
		try {
112
			connect = super.getConnection();
113
		} catch (SQLException e) {
114
			// TODO Auto-generated catch block
115
			e.printStackTrace();
116
		}
117
	}
118
	
119
	/**
120
	 * Establece la conexi?n con la base de datos de USR
121
	 *
122
	 */
123
	public void setConnectionUsr() {
124
		setDatabase("jdbc:hsqldb:file:gvSIG/extensiones/org.gvsig.crs.extension/usr");
125
		setUser("sa");
126
		try {
127
			connect = super.getConnection();
128
		} catch (SQLException e) {
129
			// TODO Auto-generated catch block
130
			e.printStackTrace();
131
		}
132
	}
133
	
134
	public Connection getConnection(){
135
		return connect;
136
	}
137
	
138
	public void shutdown() throws SQLException {
139

  
140
        Statement st = connect.createStatement();
141

  
142
        // db writes out to files and performs clean shuts down
143
        // otherwise there will be an unclean shutdown
144
        // when program ends
145
        st.execute("SHUTDOWN");
146
        connect.close();    // if there are no other open connection
147
    }
148
	
149
	public synchronized void update(String expression) throws SQLException {
150

  
151
        Statement st = null;
152

  
153
        st = connect.createStatement();    // statements
154

  
155
        int i = st.executeUpdate(expression);    // run the query
156

  
157
        if (i == -1) {
158
            System.out.println("db error : " + expression);
159
        }
160

  
161
        st.close();
162
    }
163
	/*
164
	*//**
165
	 * Establece la conexi?n con la base de datos de la EPSG
166
	 *
167
	 *//*
168
	public void setConnectionEPSG() {
169
		try {			
170
			connect =  DriverManager.getConnection("jdbc:hsqldb:file:gvSIG/extensiones/org.gvsig.crs.extension/db_epsg", "sa", "");
171
		} catch (SQLException e1) {
172
			e1.printStackTrace();
173
		}
174
	}
175
	
176
	*//**
177
	 * Establece la conexi?n con la base de datos de la IAU2000
178
	 *
179
	 *//*
180
	public void setConnectionIAU2000() {
181
		try {			
182
			connect =  DriverManager.getConnection("jdbc:hsqldb:file:gvSIG/extensiones/org.gvsig.crs.extension/db_iau2000", "sa", "");			
183
		} catch (SQLException e1) {
184
			e1.printStackTrace();
185
		}
186
	}
187
	
188
	*//**
189
	 * Establece la conexi?n con la base de datos de ESRI
190
	 *
191
	 *//*
192
	public void setConnectionEsri() {
193
		try {			
194
			connect =  DriverManager.getConnection("jdbc:hsqldb:file:/home/jlgomez/gvSIGF2/_fwAndami/gvSIG/extensiones/org.gvsig.crs.extension/db_esri", "sa", "");			
195
		} catch (SQLException e1) {
196
			e1.printStackTrace();
197
		}
198
	}
199
	
200
	*//**
201
	 * Establece la conexi?n con la base de datos de USR
202
	 *
203
	 *//*
204
	public void setConnectionUsr() {
205
		try {			
206
			connect =  DriverManager.getConnection("jdbc:hsqldb:file:gvSIG/extensiones/org.gvsig.crs.extension/db_usr", "sa", "");			
207
		} catch (SQLException e1) {
208
			e1.printStackTrace();
209
		}
210
	}
211
	
212
	public Connection getConnection(){
213
		return connect;
214
	}
215
	
216
	public void shutdown() throws SQLException {
217

  
218
        Statement st = connect.createStatement();
219

  
220
        // db writes out to files and performs clean shuts down
221
        // otherwise there will be an unclean shutdown
222
        // when program ends
223
        st.execute("SHUTDOWN");
224
        connect.close();    // if there are no other open connection
225
    }*/
226
	
227
	 /**
228
     * Returns {@code true} if the database contains data. This method returns {@code false}
229
     * if an empty EPSG database has been automatically created by HSQL and not yet populated.
230
     */
231
    private static boolean dataExists(final Connection connection) throws SQLException {
232
        final ResultSet tables = connection.getMetaData().getTables(
233
                null, null, "IAU2000_%", new String[] {"TABLE"});
234
        final boolean exists = tables.next();
235
        tables.close();
236
        return exists;
237
    }
238
}
0 239

  
tags/v2_0_0_Build_2041/libraries/libJCRS/src/es/idr/teledeteccion/connection/Query.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
34
 *   Campus Universitario s/n
35
 *   02071 Alabacete
36
 *   Spain
37
 *
38
 *   +34 967 599 200
39
 */
40

  
41
package es.idr.teledeteccion.connection;
42

  
43
import java.io.Serializable;
44
import java.sql.Connection;
45
import java.sql.ResultSet;
46
import java.sql.ResultSetMetaData;
47
import java.sql.SQLException;
48
import java.sql.Statement;
49

  
50
/**
51
 * Clase para realizar las consultas a las bases de datos utilizadas
52
 * 
53
 * @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
54
 *
55
 */
56
public class Query implements Serializable{
57
	
58
	/**
59
	 * 
60
	 */
61
	private static final long serialVersionUID = 1L;
62

  
63
	/**
64
	 * Acepta la sentencia y la conexi?n a la base de datos actual,
65
	 * realiza una selecci?n y devuelve los datos en un ResultSet
66
	 * @param sentence
67
	 * @param conn
68
	 * @return
69
	 */
70
	public static synchronized ResultSet select(String sentence, Connection conn){
71
		Statement st = null;
72
		ResultSet rs = null;
73
				
74
		try {
75
			st = conn.createStatement();
76
			rs = st.executeQuery(sentence);
77
			st.close();
78
		} catch (SQLException e) {
79
			e.printStackTrace();
80
		}		
81
		return rs;
82
	}	
83
}
84

  
0 85

  
tags/v2_0_0_Build_2041/libraries/libJCRS/src/org/gvsig/crs/CrsException.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
34
 *   Campus Universitario s/n
35
 *   02071 Alabacete
36
 *   Spain
37
 *
38
 *   +34 967 599 200
39
 */
40

  
41
package org.gvsig.crs;
42

  
43
/**
44
 * Clase que captura las excepciones cuando se definen los CRS
45
 * 
46
 * @author Miguel Garc?a Jim?nez (garciajimenez.miguel@gmail.com)
47
 *
48
 */
49
public class CrsException extends Exception {
50
	/**
51
	 * 
52
	 */
53
	private static final long serialVersionUID = 1L;
54

  
55
	public CrsException(Exception e) {
56
		super(e);
57
	}
58
}
0 59

  
tags/v2_0_0_Build_2041/libraries/libJCRS/src/org/gvsig/crs/JCRSLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program 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
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.crs;
23

  
24
import java.io.File;
25
import java.util.Arrays;
26
import java.util.Iterator;
27

  
28
import org.cresques.ProjectionLibrary;
29

  
30
import org.geotools.factory.FactoryRegistry;
31
import org.geotools.referencing.operation.MathTransformProvider;
32
import org.gvsig.andami.messages.NotificationManager;
33
import org.gvsig.fmap.crs.CRSFactory;
34
import org.gvsig.tools.library.AbstractLibrary;
35
import org.gvsig.tools.library.LibraryException;
36

  
37

  
38
/**
39
 * @author gvSIG Team
40
 * @version $Id$
41
 *
42
 */
43
public class JCRSLibrary extends AbstractLibrary {
44
    
45
    @Override
46
    public void doRegistration() {
47
        registerAsImplementationOf(ProjectionLibrary.class, 10);
48
    }
49

  
50
    @Override
51
    protected void doInitialize() throws LibraryException {
52
//    	cleanGeotoolsDatabase();
53
    	initializeGeotoolsProviders();
54
        CRSFactory.cp = new CrsFactory();
55
    }
56

  
57
    @Override
58
    protected void doPostInitialize() throws LibraryException {
59
        // nothing to do 
60
    }
61

  
62
    //Hemos cambiado el jar de epsg-hsql y tal vez esto ya no sea necesario
63
//	private void cleanGeotoolsDatabase(){
64
//        
65
//		// Parche para limpiar los archivos temporales de la base de datos cacheada de EPSG cuando ha podido quedar corrupta 
66
//		String tempFolder =  System.getProperty("java.io.tmpdir") ;
67
//        String pathSeparator = System.getProperty("file.separator") ;
68
//        String cachedDatabasesDir = tempFolder+pathSeparator+"Geotools"+pathSeparator+"Cached databases";
69
//        
70
//        File fileProperties = new File(cachedDatabasesDir+pathSeparator+"EPSG.properties");
71
//        File fileScript = new File(cachedDatabasesDir+pathSeparator+"EPSG.script");
72
//        File fileData = new File(cachedDatabasesDir+pathSeparator+"EPSG.data");
73
//        
74
//        boolean canDelete = true;
75
//        if ((fileProperties.exists() || fileScript.exists()) && !fileData.exists()){
76
//        	File cachedDatabasesDirFile = new File(cachedDatabasesDir);
77
//        	String[] fileNames = cachedDatabasesDirFile.list();
78
//        	for (int i = 0; i < fileNames.length; i++) {
79
//				File file = new File(cachedDatabasesDir+pathSeparator+fileNames[i]);
80
//				canDelete &= file.delete();
81
//			}
82
//        	if (!canDelete){
83
//        		NotificationManager.showMessageWarning("La base de datos de EPSG ha quedado corrupta, por favor salga de la aplicaci?n y borre manualmente el directorio "+cachedDatabasesDir, null);
84
//        	}
85
//        }
86
//        // Fin del parche
87
//        
88
//        /* Parche para prevenir una posible corrupci?n de la base de datos de EPSG que se
89
//         * produce en windows al tener m?s de una instancia de gvSIG abierta. 
90
//         */
91
//        if (fileProperties.exists()){
92
//        	if (!fileProperties.delete()){
93
//        		NotificationManager.showMessageWarning("La base de datos de EPSG ha podido quedar corrupta, por favor salga de la aplicaci?n y borre manualmente el directorio "+cachedDatabasesDir, null);
94
//        	}
95
//        }
96
//        // Fin del parche
97
//            
98
//
99
//	}
100
	
101
	private void initializeGeotoolsProviders(){
102
		/*
103
		 * Se eliminan del registro de geotools las proyecciones que aporta libJCrs para asegurar que
104
		 * son estas ?ltimas las que se utilizan.
105
		 */
106
		final Class[] categories = {org.geotools.referencing.operation.MathTransformProvider.class};
107
		FactoryRegistry registry = new FactoryRegistry(Arrays.asList(categories));
108
		Iterator providers = registry.getServiceProviders(MathTransformProvider.class);
109
		Iterator providers2 = null;
110
		MathTransformProvider provider = null;
111
		MathTransformProvider provider2 = null;
112

  
113
		while (providers.hasNext()){
114
			provider = (MathTransformProvider) providers.next();
115
			if(provider.nameMatches("IDR")){
116
				providers2 = registry.getServiceProviders(MathTransformProvider.class);
117
				while (providers2.hasNext()){
118
					provider2 = (MathTransformProvider) providers2.next();
119
					if(provider2.nameMatches(provider.getName().toString()) && !provider2.nameMatches("IDR")) {
120
						registry.deregisterServiceProvider(provider2, categories[0]);
121
					}
122
				}
123
			}
124
		}
125

  
126
		//TODO: Solo para depurar: BORRAR
127
		providers = registry.getServiceProviders(MathTransformProvider.class);
128
		while (providers.hasNext()) {
129
            provider = (MathTransformProvider) providers.next();
130
            System.out.println(provider.toString());
131
		}
132
		/*
133
		 *
134
		 */
135
	}
136

  
137
}
tags/v2_0_0_Build_2041/libraries/libJCRS/src/org/gvsig/crs/Crs.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
34
 *   Campus Universitario s/n
35
 *   02071 Alabacete
36
 *   Spain
37
 *
38
 *   +34 967 599 200
39
 */
40

  
41
package org.gvsig.crs;
42

  
43
import java.awt.Color;
44
import java.awt.Graphics2D;
45
import java.awt.geom.Point2D;
46
import java.awt.geom.Rectangle2D;
47

  
48
import org.cresques.cts.ICoordTrans;
49
import org.cresques.cts.IDatum;
50
import org.cresques.cts.IProjection;
51
import org.cresques.geo.ViewPortData;
52
import org.gvsig.crs.proj.CrsProj;
53
import org.gvsig.crs.proj.JNIBaseCrs;
54
import org.gvsig.crs.proj.OperationCrsException;
55
import org.gvsig.fmap.crs.CRSFactory;
56

  
57
/**
58
 * Clase que construye el CRS a partir de la cadena WKT
59
 * @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
60
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
61
 * @author Miguel Garc?a Jim?nez (garciajimenez.miguel@gmail.com)
62
 *
63
 */
64
public class Crs implements ICrs {
65
	private static final Color basicGridColor = new Color(64, 64, 64, 128);
66
	private Proj4 proj4;
67
	private String proj4String;
68
	private String trans;
69
	//private String transOrigin = "";
70
	private String abrev;
71
	private String name = "";
72
	private CrsProj crsProj;
73
	private CrsProj crsBase = null;
74
	private CrsWkt crsWkt;
75
	private int epsg_code = 23030;
76
	String sourceTrParams = null;
77
	String targetTrParams = null;
78
	String wkt = null;
79
	Color gridColor = basicGridColor;
80
	CRSDatum datum = null;	
81

  
82
	public Crs(int epsgCode, int aut) throws CrsException
83
	{
84
		String strEpsgCode = "";
85
		if (aut == 1) {
86
			strEpsgCode="EPSG:"+epsgCode;			
87
		} else if (aut == 2){
88
			strEpsgCode="ESRI:"+epsgCode;
89
		} else if (aut == 3){
90
			strEpsgCode="IAU2000:"+epsgCode;
91
		} else if (aut == 4) {
92
			strEpsgCode="USR:"+epsgCode;
93
		} else System.out.println("Error, autorithy err?neo");
94
		crsWkt=new CrsWkt(strEpsgCode);
95
		setWKT(crsWkt.getWkt());
96
	}
97
	
98
	
99
	/**
100
	 * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
101
	 * 
102
	 * @param code
103
	 * @throws CrsException
104
	 */
105
	public Crs(String code) throws CrsException {
106
		String fullCode;
107
		setWKT(code);
108
		if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
109
			fullCode = code;
110
		else fullCode = "EPSG:"+code;
111
		String cod = "";
112
		if(code.length() < 15 ) {
113
			code = code.substring(code.indexOf(":")+1);
114
			try {
115
				//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
116
				crsWkt = new CrsWkt(fullCode);				
117
				setName(fullCode);
118
				setAbrev(fullCode);
119
				
120
			} catch (NumberFormatException e) {
121
				// TODO Auto-generated catch block
122
				e.printStackTrace();
123
			}
124
		}else {
125
			String aux;
126
			String code2 = "";
127
			for(int i = 0; i < code.length(); i++) {
128
				aux = ""+code.charAt(i);
129
				if(!aux.equals(" ")) {
130
					code2+=aux;
131
				}else {
132
					code2 += "";
133
				}
134
			}
135
			crsWkt = new CrsWkt(code2);
136
	    	    		
137
    		setName(fullCode);
138
    		//setAbrev(crsWkt.getName());
139
    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);	    	
140
	    	
141
    	}
142
		//	Asignar el datum y el crs base (en el caso de ser projectado):
143
		if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){
144
			double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
145
			double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
146
			datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
147
			
148
			//crs base (en el caso de ser projectado):
149
			/*if(this.isProjected()){
150
				String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
151
				crsBase = new CrsProj(proj4Base);
152
			}*/
153
		}
154
	}	
155
	
156
	/**
157
	 *Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
158
	 * 
159
	 * @param epsg_cod
160
	 * @param code
161
	 * @throws CrsException
162
	 */
163
	public Crs(int epsg_cod, String code) throws CrsException {
164
		String fullCode;
165
		setWKT(code);
166
		setCode(epsg_cod);
167
		if(code != null || code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
168
			fullCode = code;
169
		else fullCode = "EPSG:"+code;
170
		String cod = "";
171
		if(code.length() < 15 ) {
172
			code = code.substring(code.indexOf(":")+1);
173
			try {
174
				//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
175
				crsWkt = new CrsWkt(fullCode);				
176
				setName(fullCode);
177
				setAbrev(fullCode);
178
				
179
			} catch (NumberFormatException e) {
180
				// TODO Auto-generated catch block
181
				e.printStackTrace();
182
			}
183
		}else {
184
			String aux;
185
			String code2 = "";
186
			for(int i = 0; i < code.length(); i++) {
187
				aux = ""+code.charAt(i);
188
				if(!aux.equals(" ")) {
189
					code2+=aux;
190
				}else {
191
					code2 += "";
192
				}
193
			}
194
			crsWkt = new CrsWkt(code2);
195
			/*
196
			 * Arreglo temporal para ver si funcionan de la iau2000 las proyecciones
197
			 * cilindrica equidistante y oblicua cilindrica equidistante
198
			 * que no estan en gdal, por lo que asignaremos directamente su cadena
199
			 * en proj4 para trabajar con ellas
200
			 */
201
			if (!crsWkt.getProjection().equals("Equidistant_Cylindrical") && !crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){		    		    		
202
	    		setName(fullCode);
203
	    		//setAbrev(crsWkt.getName());
204
	    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);		    	 
205
			}
206
			else if (crsWkt.getProjection().equals("Equidistant_Cylindrical")){
207
				String spheroid1 = crsWkt.getSpheroid()[1];
208
				String spheroid2 = crsWkt.getSpheroid()[2];
209
				String centralMeridian = "";
210
				String falseNorthing = "";
211
				String falseEasting = "";
212
				String standardParallel1 = "0.0";
213
				for (int i=0; i<crsWkt.getParam_name().length;i++){
214
					if (crsWkt.getParam_name()[i].equals("Central_Meridian"))
215
						centralMeridian = crsWkt.getParam_value()[i];	
216
					if (crsWkt.getParam_name()[i].equals("False_Easting"))
217
						falseEasting = crsWkt.getParam_value()[i];					
218
					if(crsWkt.getParam_name()[i].equals("False_Northing"))
219
						falseNorthing = crsWkt.getParam_value()[i];					
220
					if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1"))
221
						standardParallel1 = crsWkt.getParam_value()[i];					
222
				}
223
				if (spheroid2.equals("0.0")){
224
					proj4String = "+proj=eqc +a=" + spheroid1 +
225
					" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
226
					" +lat_ts="+standardParallel1;
227
				} else {
228
					proj4String = "+proj=eqc +a="+ spheroid1 +" +rf=" + spheroid2 +
229
					" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
230
					" +lat_ts="+standardParallel1;
231
				}				
232
				setName(fullCode);
233
	    		//setAbrev(crsWkt.getName());
234
	    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
235
				
236
			}
237
			else if (crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){
238
				String spheroid1 = crsWkt.getSpheroid()[1];
239
				String spheroid2 = crsWkt.getSpheroid()[2];
240
				String centralMeridian = "";
241
				String falseNorthing = "";
242
				String falseEasting = "";
243
				String standardParallel1 = "";
244
				String standardParallel2 = "0.0";
245
				for (int i=0; i<crsWkt.getParam_name().length;i++){					
246
					if (crsWkt.getParam_name()[i].equals("Central_Meridian"))
247
						centralMeridian = crsWkt.getParam_value()[i];	
248
					if (crsWkt.getParam_name()[i].equals("False_Easting"))
249
						falseEasting = crsWkt.getParam_value()[i];					
250
					if(crsWkt.getParam_name()[i].equals("False_Northing"))
251
						falseNorthing = crsWkt.getParam_value()[i];					
252
					if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1"))
253
						standardParallel1 = crsWkt.getParam_value()[i];
254
					if (crsWkt.getParam_name()[i].equals("Standard_Parallel_2"))
255
						standardParallel2 = crsWkt.getParam_value()[i];		
256
				}
257
				if (spheroid2.equals("0.0")){
258
					proj4String = "+proj=ocea +a="+ spheroid1  +
259
					" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
260
					" +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" +
261
					" +lon_2=long_2 +no_defs";
262
				} else {
263
					proj4String = "+proj=ocea +a="+ spheroid1 + " +rf=" + spheroid2 +
264
					" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
265
					" +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" +
266
					" +lon_2=long_2 +no_defs";
267
				}				
268
				setName(fullCode);
269
	    		//setAbrev(crsWkt.getName());
270
	    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
271
			}
272
		}
273
		//	Asignar el datum:
274
		if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){
275
			double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
276
			double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
277
			datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
278
			
279
			// Crs base (en el caso de ser projectado):
280
			/*if(this.isProjected()){
281
				String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
282
				crsBase = new CrsProj(proj4Base);
283
			}*/
284
		}
285
	}
286
	
287
	/**
288
	 * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
289
	 * En el caso de WKT le a?ade a la cadena proj4 el string params.
290
	 * 
291
	 * @param epsg_cod
292
	 * @param code
293
	 * @param params
294
	 * @throws CrsException
295
	 */
296
	public Crs(int epsg_cod, String code,String params) throws CrsException {
297
		String fullCode;
298
		setCode(epsg_cod);
299
		setWKT(code);
300
		if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
301
			fullCode = code;
302
		else fullCode = "EPSG:"+code;
303
		String cod = "";
304
		if(code.length() < 15 ) {
305
			code = code.substring(code.indexOf(":")+1);
306
			try {
307
				//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
308
				crsWkt = new CrsWkt(fullCode);
309
				
310
				setName(fullCode);
311
				setAbrev(fullCode);
312
				
313
			} catch (NumberFormatException e) {
314
				// TODO Auto-generated catch block
315
				e.printStackTrace();
316
			}
317
		}else {
318
			String aux;
319
			String code2 = "";
320
			for(int i = 0; i < code.length(); i++) {
321
				aux = ""+code.charAt(i);
322
				if(!aux.equals(" ")) {
323
					code2+=aux;
324
				}else {
325
					code2 += "";
326
				}
327
			}
328
			crsWkt = new CrsWkt(code2);
329
	    	
330
    		setName(fullCode);
331
    		//setAbrev(crsWkt.getName());
332
    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
333
	    	
334
		}
335
		//	Asignar el datum:
336
		if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){
337
			double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
338
			double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
339
			datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
340
			
341
			// Crs base (en el caso de ser projectado):
342
			/*if(this.isProjected()){
343
				String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
344
				crsBase = new CrsProj(proj4Base);
345
			}*/
346
		}
347
	}
348
		
349
/*	public Crs(CrsEpsg source) throws CrsException {
350
		crsProj4 = source;
351
	}*/
352
	
353
	/**
354
	 * @param code 
355
	 */
356
	public void setTrans(String code) {
357
		trans = code;
358
		changeTrans(trans);
359
	}
360
	
361
	/**
362
	 * 
363
	 * @param code
364
	 */
365
	public void changeTrans(String code) {
366
		getCrsProj().changeStrCrs(code);
367
	}
368
	
369
	/**
370
	 * 
371
	 */
372
	public String getAbrev() {
373
		return abrev;
374
	}
375
	
376
	/**
377
	 * 
378
	 * @param code
379
	 */
380
	protected void setAbrev(String code) {
381
		abrev = code;
382
	}
383
	
384
	/**
385
	 * 
386
	 * @param nom
387
	 */
388
	public void setName(String nom) {
389
		name = nom;
390
	}
391
	
392
	/**
393
	 * @return
394
	 */
395
	public IDatum getDatum() {
396
		
397
		return datum;
398
	}
399
	
400
	/**
401
	 * @return
402
	 */
403
	public CrsWkt getCrsWkt() {
404
		return crsWkt;
405
	}
406
	
407
	/**
408
	 * 
409
	 * @param wkt
410
	 */
411
	public void setWKT(String wkt){
412
		this.wkt = wkt;
413
	}
414
	
415
	/**
416
	 * @return
417
	 */
418
	public String getWKT(){
419
		return this.wkt;
420
	}
421
	
422
	/**
423
	 * 
424
	 * @param params
425
	 */
426
	public void setTransformationParams(String sourceParams, String targetParams){
427
		this.sourceTrParams = sourceParams;
428
		this.targetTrParams = targetParams;
429
	}
430
	
431
	/**
432
	 * Devuelve los parametros de la transformacion del crs fuente
433
	 * @return
434
	 */
435
	public String getSourceTransformationParams() {
436
		return this.sourceTrParams;
437
	}
438
	
439
	/**
440
	 * Devuelve los parametros de la transformacion del crs destino
441
	 * @return
442
	 */
443
	public String getTargetTransformationParams() {
444
		return this.targetTrParams;
445
	}
446
	
447
	/**
448
	 * @return
449
	 */
450
	public String getTransformationParams(){
451
		return this.sourceTrParams;
452
	}
453
		
454
	/**
455
	 * 
456
	 * @return
457
	 */
458
	public CrsProj getCrsProj() {
459
		if (crsProj == null)
460
			try {
461
				crsProj = new CrsProj(getProj4String());
462
			} catch (CrsException e) {
463
				// TODO Auto-generated catch block
464
				e.printStackTrace();
465
			} 
466
		return crsProj;
467
	}
468

  
469
	/**
470
	 * @param x
471
	 * @param y
472
	 * @return
473
	 */
474
	public Point2D createPoint(double x, double y) {
475
		return new Point2D.Double(x,y);
476
	}
477

  
478
	/**
479
	 * @param g
480
	 * @param vp
481
	 */
482
	public void drawGrid(Graphics2D g, ViewPortData vp) {
483
		// TODO Auto-generated method stub
484
		
485
	}
486

  
487
	/**
488
	 * @param c
489
	 */
490
	public void setGridColor(Color c) {
491
		gridColor = c;
492
	}
493

  
494
	/**
495
	 * @return
496
	 */
497
	public Color getGridColor() {
498
		return gridColor;
499
	}
500

  
501
	/**
502
	 * @param dest
503
	 * @return
504
	 */
505
	public ICoordTrans getCT(IProjection dest) {
506
		
507
		
508
		try {
509
			if (dest == this)
510
				return null;
511
			COperation operation = null;
512
			if(((ICrs)dest).getSourceTransformationParams() != null || ((ICrs)dest).getTargetTransformationParams() != null) 
513
				operation = new COperation(this, (ICrs)dest,((ICrs)dest).getTargetTransformationParams(),((ICrs)dest).getSourceTransformationParams());
514
			else
515
				operation = new COperation(this, (ICrs)dest,sourceTrParams,targetTrParams);
516
			return operation;
517
		}catch (CrsException e) {
518
			// TODO Auto-generated catch block
519
			e.printStackTrace();
520
			return null;
521
		}
522
		
523
		/*
524
		try {
525
			operation = new COperation(this, (ICrs)dest);
526
		} catch (CrsException e) {
527
			// TODO Auto-generated catch block
528
			e.printStackTrace();
529
		}
530
		
531
		if (getTransformationParams()!=null){
532
			if (isTargetParams())
533
				operation.setParamsCrsProj(new CrsProj(crsDest.getProj4String()+getTransformationParams()), true);
534
			else
535
				operation.setParamsCrsProj(new CrsProj(getProj4String()+getTransformationParams()), false);
536
			
537
			return operation;
538
		}
539
		
540
		return operation;	*/	
541
	}
542
	
543
	/**
544
	 * @param pt
545
	 * @return
546
	 */
547
	public Point2D toGeo(Point2D pt) {
548
		if (isProjected()){
549
			double x[] = {pt.getX()};
550
			double y[] = {pt.getY()};
551
			double z[] = {0D};
552
			try {
553
				JNIBaseCrs.operate( x , y, z,
554
						getCrsProj(),crsBase);
555
			} catch (OperationCrsException e) {
556
				// TODO Auto-generated catch block
557
				e.printStackTrace();
558
			}
559
			return new Point2D.Double(x[0],y[0]);
560
		}
561
		else
562
			return pt;
563
	}
564

  
565
	/**
566
	 * @param gPt
567
	 * @param mPt
568
	 * @return
569
	 */
570
	public Point2D fromGeo(Point2D gPt, Point2D mPt) {
571
		// TODO Auto-generated method stub
572
		return null;
573
	}
574

  
575
	/**
576
	 * @return
577
	 */
578
	public boolean isProjected() {
579
		return !getCrsProj().isLatlong();		
580
	}
581

  
582
	/**
583
	 * @param minX
584
	 * @param maxX
585
	 * @param width
586
	 * @param dpi
587
	 * @return
588
	 */
589
	public double getScale(double minX, double maxX, double width, double dpi) {
590
		double scale = 0D;
591
		//Esto ahora se hace fuera
592
//        if (!isProjected()) { // Es geogr?fico; calcula la escala.
593
//            scale = ((maxX - minX) * // grados
594
//
595
//            // 1852.0 metros x minuto de meridiano
596
//            (dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro
597
//                    width; // pixels
598
//        }
599
//        else{
600
        	 scale = ((maxX - minX) * // metros
601
                    (dpi / 2.54 * 100.0)) / // px / metro
602
                    width; // pixels
603
//        }
604
        return scale;
605
	}
606
	
607
	public double getScale(double minX, double maxX, double minY, double maxY, double width, double dpi) {
608
		
609
		double scale = 0D;
610
		double incX = (maxX-minX);
611
		
612
		if (!isProjected()) {
613
			double a = getDatum().getESemiMajorAxis();
614
			double invF = getDatum().getEIFlattening();
615
			double meanY = (minY+maxY)/2.0;
616
			double radius = 0.0;
617
			
618
			
619
			if (invF == Double.POSITIVE_INFINITY){
620
				radius = a;
621
			}
622
			else{
623
				double e2 = 2.0/invF-Math.pow(1.0/invF,2.0);
624
				radius = a/Math.sqrt(1.0-e2*Math.pow(Math.sin(meanY*Math.PI/180.0),2.0))*Math.cos(meanY*Math.PI/180.0);
625
			}
626
			incX *= Math.PI/180.0*radius;
627
		}
628
			
629
		scale = (incX * // metros
630
				(dpi / 2.54 * 100.0)) / // px / metro
631
					width; // pixels
632
		
633
        return scale;
634
	}
635
	
636
	/**
637
	 * 
638
	 * @param epsg_cod
639
	 */
640
	public void setCode(int epsg_cod){
641
		epsg_code = epsg_cod;
642
	}
643

  
644
	/**
645
	 * @return
646
	 */
647
	public int getCode() {
648
		// TODO Auto-generated method stub
649
		return epsg_code;
650
	}
651

  
652
	public String getFullCode() {
653
		if (this.sourceTrParams == null && this.targetTrParams == null)
654
			return getAbrev();
655
		String sourceParams = "";
656
		String targetParams = "";
657
		if (sourceTrParams != null)
658
			sourceParams = sourceTrParams;
659
		if (targetTrParams != null)
660
			targetParams = targetTrParams;
661
		
662
		return getAbrev()+":proj@"+sourceParams+"@"+targetParams;
663
	}
664

  
665

  
666
    public Rectangle2D getExtent(Rectangle2D extent,double scale,double wImage,double hImage,double mapUnits,double distanceUnits,double dpi) {
667
    	double w =0;
668
		double h =0;
669
		double wExtent =0;
670
		double hExtent =0;
671
//    	if (isProjected()) {
672
			w = ((wImage / dpi) * 2.54);
673
			h = ((hImage / dpi) * 2.54);
674
			wExtent =w * scale*distanceUnits/ mapUnits;
675
			hExtent =h * scale*distanceUnits/ mapUnits;
676

  
677
			//En las no proyectadas, ahora viene el calculo hecho
678
			//al haber incluido los grados en el array DISTANCETRANS2METER del MapContext
679
//		}else {
680
//			w = ((wImage / dpi) * 2.54);
681
//			h = ((hImage / dpi) * 2.54);
682
//			wExtent =(w*scale*distanceUnits)/ (mapUnits*1852.0*60.0);
683
//			hExtent =(h*scale*distanceUnits)/ (mapUnits*1852.0*60.0);
684
//		}
685
    	double xExtent = extent.getCenterX() - wExtent/2;
686
		double yExtent = extent.getCenterY() - hExtent/2;
687
		Rectangle2D rec=new Rectangle2D.Double(xExtent,yExtent,wExtent,hExtent);
688
    	return  rec;
689
    }
690
   
691
	private Proj4 getProj4() {
692
		if (proj4 == null)
693
			try {
694
				proj4 = new Proj4();
695
			} catch (CrsException e) {
696
				// TODO Auto-generated catch block
697
				e.printStackTrace();
698
			}
699
		return proj4;
700
	}
701
	
702
	/** 
703
	 * 
704
	 * @return Cadena proj4 Correspondiente al CRS.
705
	 * @throws CrsException 
706
	 */
707
	public String getProj4String() throws CrsException {
708
		if (proj4String == null)
709
			proj4String = getProj4().exportToProj4(this);			
710
		return proj4String;
711
	}
712
	
713
	public Object clone() throws CloneNotSupportedException {
714
	       return CRSFactory.getCRS( this.getFullCode() );
715
	    }
716

  
717
}
0 718

  
tags/v2_0_0_Build_2041/libraries/libJCRS/src/org/gvsig/crs/ogr/CrsEPSG.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
34
 *   Campus Universitario s/n
35
 *   02071 Alabacete
36
 *   Spain
37
 *
38
 *   +34 967 599 200
39
 */
40

  
41
package org.gvsig.crs.ogr;
42

  
43
import java.sql.ResultSet;
44
import java.sql.SQLException;
45

  
46

  
47
import es.idr.teledeteccion.connection.EpsgConnection;
48
import es.idr.teledeteccion.connection.Query;
49

  
50
/**
51
 * Clase que consigue los par?metros necesarios de la base de
52
 * datos de la EPSG una vez escogido un CRS, y que ser?n
53
 * los que se utilicen para la generaci?n de la cadena wkt
54
 * correcta para generar el CRS.
55
 * 
56
 * @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
57
 *
58
 */
59
public class CrsEPSG {
60
	
61
	int epsg_code;
62
	boolean crs_source;
63
	int source_code;
64
	int projection_code;	
65
	int coord_op_code;	
66
	
67
		
68
	int datum_code;
69
	int ellipsoid_code, prime_meridian_code;
70
	
71
	String PROJCS = null;
72
	String GEOGCS = null;
73
	String DATUM = null;
74
	String[] SPHEROID = null;
75
	String[] PRIMEM = null;
76
	String UNIT_A = "degree";
77
	String UNIT_B = "Meter";
78
	double unit_BValue = 1.0;
79
	String PROJECTION = null;
80
	//ArrayList PARAMETER = null;
81
	String[] param_name = null;
82
	String[] param_value = null;
83
	String[] AUTHORITY = null;
84
	EpsgConnection connect;
85
	private int coordSysCode;
86
	
87
	public CrsEPSG(){		
88
	}	
89
	
90
	public CrsEPSG(int code, boolean source_yn, int source_cod, int coord_op_cod, EpsgConnection conn){
91
		epsg_code = code;
92
		crs_source = source_yn;
93
		source_code = source_cod;		
94
		coord_op_code = coord_op_cod;
95
		connect = conn;
96
		SPHEROID = new String[3];
97
		PRIMEM = new String[2];
98
		AUTHORITY = new String[2];
99
		initialize();
100
	}
101
	
102
	public void initialize(){
103
		ResultSet result;
104
		ResultSet result2;
105
		/*
106
		 * Si es base solamente realizamos una consulta, y ya tenemos el Datum
107
		 * (ver en caso de ser fuente que PROJCS no tiene que estar definido)
108
		 */
109
		if (crs_source){
110
			String sentence = "SELECT coord_ref_sys_name, datum_code, coord_sys_code " +
111
							  "FROM epsg_coordinatereferencesystem " +	                              
112
							  "WHERE coord_ref_sys_code = " + epsg_code;
113
			result = Query.select(sentence,connect.getConnection());
114
			try {
115
				while (result.next()){
116
					GEOGCS = result.getString("coord_ref_sys_name");
117
					datum_code = Integer.parseInt(result.getString("datum_code"));
118
					coordSysCode = result.getInt("coord_sys_code");
119
				}
120
			} catch (SQLException e) {
121
				e.printStackTrace();
122
			}			
123
		}
124
		else{
125
			String sentence = "SELECT coord_ref_sys_name, coord_sys_code " +
126
							  "FROM epsg_coordinatereferencesystem " +	                              
127
							  "WHERE coord_ref_sys_code = " + epsg_code;
128
			result = Query.select(sentence,connect.getConnection());
129
			
130
			String sentence2 = "SELECT coord_ref_sys_name, datum_code " +
131
							  "FROM epsg_coordinatereferencesystem " +	                              
132
							  "WHERE coord_ref_sys_code = " + source_code;
133
			result2 = Query.select(sentence2,connect.getConnection());
134
			
135
			try {
136
				while (result.next()){
137
					PROJCS = result.getString("coord_ref_sys_name");
138
					coordSysCode = result.getInt("coord_sys_code");
139
				}
140
				while (result2.next()){
141
					datum_code = Integer.parseInt(result2.getString("datum_code"));
142
					GEOGCS = result2.getString("coord_ref_sys_name");
143
				}
144
			} catch (SQLException e) {
145
				e.printStackTrace();
146
			}
147
		}
148
		/*
149
		 * hasta aqui hemos rellenado projcs, geocs y tenemos el codigo de datum
150
		 * vamos a obtener los c?digos del elipsoide y el prime_meridian
151
		 */
152
		String sentence = "SELECT datum_name, ellipsoid_code, prime_meridian_code " +
153
						  "FROM epsg_datum " +	                              
154
						  "WHERE datum_code = " + datum_code;
155
		result = Query.select(sentence,connect.getConnection());
156
		try {
157
			while (result.next()){
158
				DATUM = result.getString("datum_name");
159
				ellipsoid_code = Integer.parseInt(result.getString("ellipsoid_code"));	
160
				prime_meridian_code = Integer.parseInt(result.getString("prime_meridian_code"));
161
			}			
162
		} catch (SQLException e) {
163
			e.printStackTrace();
164
		}
165
		
166
		/*
167
		 * Ahora vamos a coger varios campos del elipsoide y operaremos con ellos, si la
168
		 * informaci?n de los mismos no esta en las unidades de medida que utilizaremos.
169
		 */
170
		sentence = "SELECT ellipsoid_name, semi_major_axis, inv_flattening, uom_code, " +
171
					"semi_minor_axis, ellipsoid_shape " +
172
					  "FROM epsg_ellipsoid " +	                              
173
					  "WHERE ellipsoid_code = " + ellipsoid_code;
174
		result = Query.select(sentence,connect.getConnection());
175
		
176
		SPHEROID = getEllipsoid(result);
177
		
178
		sentence = "SELECT prime_meridian_name, greenwich_longitude, uom_code " +
179
					  "FROM epsg_primemeridian " +	                              
180
					  "WHERE prime_meridian_code = " + prime_meridian_code;
181
		result = Query.select(sentence,connect.getConnection());
182
		
183
		PRIMEM = getPrimeMeridian(result);
184
		AUTHORITY = getAuthority(epsg_code);
185
		/*
186
		 * si tiene proyecci?n porque es proyectado, la buscamos
187
		 */
188
		if (!crs_source){			
189
			sentence = "SELECT coord_op_method_code " +
190
						"FROM epsg_coordoperation " +
191
						"WHERE coord_op_code = " + coord_op_code;
192
			result = Query.select(sentence,connect.getConnection());
193
			try {
194
				while (result.next()){
195
					projection_code = result.getInt("coord_op_method_code");
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff