Statistics
| Revision:

root / org.gvsig.projection.jcrs / trunk / org.gvsig.projection.jcrs / org.gvsig.projection.jcrs.lib / src / main / java / org / gvsig / crs / repository / EsriRepository.java @ 229

History | View | Annotate | Download (3.51 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
package org.gvsig.crs.repository;
41

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

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

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

    
51
import org.gvsig.crs.Crs;
52
import org.gvsig.crs.CrsException;
53
import org.gvsig.crs.ICrs;
54
import org.gvsig.crs.ogr.Esri2wkt;
55
import org.gvsig.tools.dispose.Disposable;
56

    
57

    
58
/**
59
 * Repositorio de CRSs de EPSG
60
 * 
61
 * @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
62
 *
63
 */
64

    
65
public class EsriRepository implements ICrsRepository, Disposable {
66
    private static final Logger logger =
67
        LoggerFactory.getLogger(EsriRepository.class);
68
    
69
        EpsgConnection connection = null;
70
        
71
        public EsriRepository() {
72
                connection = new EpsgConnection();
73
                connection.setConnectionEsri();                
74
        }
75

    
76
        public ICrs getCrs(String code) {
77
                String cadWKT = "";
78
                Crs crs = null;
79
                
80
                String sentence = "SELECT esri_code, esri_wkt, esri_proj, esri_geog, esri_datum " +                                                         
81
                                                  "FROM ESRI " +                                      
82
                          "WHERE esri_code = " + code;
83
                
84
                ResultSet result = Query.select(sentence,connection.getConnection());        
85
                /*try {
86
                        connection.shutdown();
87
                } catch (SQLException e) {
88
                        // TODO Auto-generated catch block
89
                        logger...
90
                }*/
91
                try {
92
                        if (!result.next())
93
                                return null;        
94
                        cadWKT = result.getString("esri_wkt");                        
95
                } catch (SQLException e1) {
96
                    logger.info("Error executing the SQL", e1);
97
                    return null;
98
                }                
99
                cadWKT = cadWKT.substring(0, cadWKT.length()-1) + ", AUTHORITY[\"ESRI\","+ Integer.parseInt(code)+"]]";
100
                if (cadWKT.charAt(0) == 'P'){
101
                        Esri2wkt wk = new Esri2wkt(cadWKT);
102
                        cadWKT = wk.getWkt();
103
                }
104
                
105
                try {
106
                        crs = new Crs(Integer.parseInt(code),cadWKT);
107
                } catch (CrsException e) {
108
                    logger.info("Impossible to parse the CRS", e);
109
                    return null;
110
                }
111
                
112
                return crs;
113

    
114
        }
115

    
116

    
117
        public void dispose() {
118
            try {
119
                this.connection.shutdown();
120
                this.connection = null;
121
            } catch (SQLException ex) {
122
                logger.warn("Con't shutdown the connection.",ex);
123
            }
124
        }
125
}