Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libGPE-GML / src / org / gvsig / gpe / gml / utils / GMLProjectionFactory.java @ 28113

History | View | Annotate | Download (3.97 KB)

1
package org.gvsig.gpe.gml.utils;
2

    
3
import org.gvsig.compat.CompatLocator;
4
import org.gvsig.gpe.GPELocator;
5
import org.gvsig.gpe.GPEManager;
6
import org.gvsig.gpe.gml.GmlProperties;
7
import org.gvsig.gpe.parser.GPEErrorHandler;
8
import org.gvsig.gpe.parser.IGPEErrorHandler;
9
import org.gvsig.gpe.warnings.SrsUnknownWarning;
10

    
11
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
12
 *
13
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
28
 *
29
 * For more information, contact:
30
 *
31
 *  Generalitat Valenciana
32
 *   Conselleria d'Infraestructures i Transport
33
 *   Av. Blasco Ib??ez, 50
34
 *   46010 VALENCIA
35
 *   SPAIN
36
 *
37
 *      +34 963862235
38
 *   gvsig@gva.es
39
 *      www.gvsig.gva.es
40
 *
41
 *    or
42
 *
43
 *   IVER T.I. S.A
44
 *   Salamanca 50
45
 *   46005 Valencia
46
 *   Spain
47
 *
48
 *   +34 963163400
49
 *   dac@iver.es
50
 */
51
/* CVS MESSAGES:
52
 *
53
 * $Id: GMLProjectionFactory.java 350 2008-01-09 12:53:07Z jpiera $
54
 * $Log$
55
 * Revision 1.4  2007/05/18 10:41:01  csanchez
56
 * Actualizaci?n libGPE-GML eliminaci?n de clases inecesarias
57
 *
58
 * Revision 1.3  2007/05/14 11:18:51  jorpiell
59
 * ProjectionFactory updated
60
 *
61
 * Revision 1.2  2007/04/12 17:06:44  jorpiell
62
 * First GML writing tests
63
 *
64
 * Revision 1.1  2007/04/12 10:23:41  jorpiell
65
 * Add some writers and the GPEXml parser
66
 *
67
 *
68
 */
69
/**
70
 * This class is used to convert a projection written 
71
 * using the EPSG projection to the GML projection
72
 * format
73
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
74
 */
75
public class GMLProjectionFactory {
76
        private static GPEManager gpeManager = GPELocator.getGPEManager();
77
        
78
        /**
79
         * This method is used to get the GML spatial reference
80
         * system (srs) calculated from a GPE srs.
81
         * @param srs
82
         * GPE srs
83
         * @param errorHandler
84
         * The error handler
85
         * @return
86
         * GML srs
87
         */
88
        public static String fromGPEToGML(String srs, GPEErrorHandler errorHandler){
89
                if (srs != null){
90
                        //If the SRS's are not based on XML the srs 
91
                        //will be the same
92
                        if (!gpeManager.getBooleanProperty(GmlProperties.SRS_BASED_ON_XML)){
93
                                return srs;
94
                        }
95
                        String[] parts = CompatLocator.getStringUtils().split(srs,":");
96
                        //String[] parts = org.gvsig.gpe.utils.StringUtils.splitString(srs,":");
97
                        //String[] parts = srs.split(":");
98
                        if (parts.length == 2){
99
                                if (parts[0].compareTo(GMLTags.SRS_EPSG_NAME) == 0){
100
                                        return GMLTags.SRS + GMLTags.SRS_EPSG + "#" + parts[1];
101
                                }
102
                        }else if(parts.length == 1){
103
                                //If the EPSG prefix is not found 
104
                                return GMLTags.SRS + GMLTags.SRS_EPSG + "#"  + parts[0];
105
                                
106
                        }
107
                }        
108
                errorHandler.addWarning(new SrsUnknownWarning(srs));
109
                return GMLTags.SRS_UNKNOWN;        
110
        }
111
        
112
        /**
113
         * This method is used to get the GPE spatial reference
114
         * system (srs) calculated from a GML srs.
115
         * @param srs
116
         * GML srs
117
         * @param errorHandler
118
         * The error handler
119
         * @return
120
         * GPE srs
121
         */
122
        public static String fromGMLToGPE(String srs,IGPEErrorHandler errorHandler){
123
                if (srs != null){
124
                        String[] parts = CompatLocator.getStringUtils().split(srs,"#");
125
                        //String[] parts = org.gvsig.gpe.utils.StringUtils.splitString(srs,"#");
126
                        //String[] parts = srs.split("#");
127
                        if (parts.length == 2){
128
                                if (parts[0].compareTo(GMLTags.SRS + GMLTags.SRS_EPSG) == 0){
129
                                        return GMLTags.SRS_EPSG_NAME + ":" + parts[1];
130
                                }
131
                        }
132
                }
133
                errorHandler.addWarning(new SrsUnknownWarning(srs));
134
                return GMLTags.SRS_UNKNOWN;        
135
        }
136
}