Statistics
| Revision:

root / org.gvsig.jcrs / trunk / libJCRS / src / org / gvsig / crs / repository / Iau2000Repository.java @ 76

History | View | Annotate | Download (3.3 KB)

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.repository;
42

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

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

    
49
import org.slf4j.Logger;
50
import org.slf4j.LoggerFactory;
51

    
52
import org.gvsig.crs.Crs;
53
import org.gvsig.crs.CrsException;
54
import org.gvsig.crs.ICrs;
55
import org.gvsig.crs.ogr.Iau2wkt;
56

    
57
/**
58
 * Repositorio de CRSs de IAU2000
59
 * 
60
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
61
 *
62
 */
63
public class Iau2000Repository implements ICrsRepository {
64
    private static final Logger LOG =
65
        LoggerFactory.getLogger(Iau2000Repository.class);
66
    
67
        EpsgConnection connection = null;
68
        
69
        public Iau2000Repository() {
70
                connection = new EpsgConnection();        
71
        }
72

    
73
        /**
74
         * Obtiene un CRS a partir de su c?digo IAU2000.
75
         * 
76
         * @param code Codigo IAU2000 del CRS. 
77
         * @return ICrs 
78
         */
79
        public ICrs getCrs(String code) {
80
                String cadWKT = "";
81
                Crs crs = null;
82
                
83
                String sentence = "SELECT iau_code, iau_wkt, iau_proj, iau_geog, iau_datum " +                                                         
84
                                                  "FROM IAU2000 " +                                      
85
                          "WHERE iau_code = " + code;
86
                
87
                connection.setConnectionIAU2000();
88
                ResultSet result = Query.select(sentence,connection.getConnection());        
89
                try {
90
                        connection.shutdown();
91
                } catch (SQLException e) {
92
                    LOG.info("Error while shutting down the connection", e);
93
                }
94
                try {
95
                        if (!result.next())
96
                                return null;                        
97
                        cadWKT = result.getString("iau_wkt");                        
98
                } catch (SQLException e1) {
99
                    LOG.info("Error executing the SQL", e1);
100
                    return null;
101
                }                
102
                cadWKT = cadWKT.substring(0, cadWKT.length()-1) + ", AUTHORITY[\"IAU2000\","+ Integer.parseInt(code)+"]]";
103
                if (cadWKT.charAt(0) == 'P'){
104
                        Iau2wkt wk = new Iau2wkt(cadWKT);
105
                        cadWKT = wk.getWkt();
106
                }
107
                
108
                try {
109
                        crs = new Crs(Integer.parseInt(code),cadWKT);
110
                } catch (CrsException e) {
111
                    LOG.info("Impossible to parse the CRS", e);
112
                }
113
                
114
                return crs;
115
        }
116
}