Statistics
| Revision:

gvsig-raster / org.gvsig.raster.gdal / tags / pre-remove-jgdal / org.gvsig.raster.gdal / org.gvsig.raster.gdal.io / src / main / java / org / gvsig / jogr / OGRTools.java @ 3497

History | View | Annotate | Download (4.87 KB)

1
/**********************************************************************
2
 * $Id: OGRTools.java 7765 2006-10-03 07:05:18Z nacho $
3
 *
4
 * Name:     OGRTools.java
5
 * Project:  JGDAL. Interface java to gdal (Frank Warmerdam).
6
 * Purpose:   
7
 * Author:   Nacho Brodin, brodin_ign@gva.es
8
 *
9
 **********************************************************************/
10
/*Copyright (C) 2004  Nacho Brodin <brodin_ign@gva.es>
11

12
 This program is free software; you can redistribute it and/or
13
 modify it under the terms of the GNU General Public License
14
 as published by the Free Software Foundation; either version 2
15
 of the License, or (at your option) any later version.
16

17
 This program is distributed in the hope that it will be useful,
18
 but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 GNU General Public License for more details.
21

22
 You should have received a copy of the GNU General Public License
23
 along with this program; if not, write to the Free Software
24
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
 */
26

    
27
package org.gvsig.jogr;
28

    
29
import java.util.Arrays;
30
import java.util.Vector;
31

    
32
import org.gdal.ogr.ogrConstants;
33
import org.gdal.osr.CoordinateTransformation;
34

    
35

    
36

    
37
/** 
38
 * 
39
 * @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
40
 * @version 0.0
41
 * @link http://www.gvsig.gva.es
42
 */
43

    
44
public class OGRTools extends JNIBase{
45
        
46
//        private native static long OGRCreateCoordinateTransformationNat( long poSource, long poTarget);
47
        
48
        /**
49
         * 
50
         */
51
        
52
        public static OGRCoordinateTransformation OGRCreateCoordinateTransformation( OGRSpatialReference poSource,
53
                                                                                                                                            OGRSpatialReference poTarget )throws OGRException{
54
                if(poSource == null  || poTarget == null)
55
                        throw new OGRException("Error en OGRCreateCoordinateTransformation(). Los par?metros no tienen una referencia correcta.");
56
                
57
                CoordinateTransformation cct = org.gdal.osr.osr.CreateCoordinateTransformation(poSource, poTarget);
58
                
59
                if(cct == null || !(cct instanceof OGRCoordinateTransformation))
60
                        throw new OGRException("Error en OGRCreateCoordinateTransformation(). No se ha podido obtener una referencia valida al objeto OGRCoordinateTransformation.");
61
                
62
                return ((OGRCoordinateTransformation) cct);
63
                
64
        }
65
        
66
        public static int safeLongToInt(long l) {
67
            if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
68
                throw new IllegalArgumentException
69
                    (l + " cannot be cast to int without changing its value.");
70
            }
71
            return (int) l;
72
        }
73
        
74
        public static Vector safeStringToVector(String s) {
75
                Vector myVec = new Vector();
76

    
77
                //Convert the string to a char array and then just add each char to the vector
78
                char[] sChars = s.toCharArray();
79
                for(int i = 0; i < s.length(); ++i) {
80
                    myVec.add(sChars[i]);
81
                }
82
                
83
                return myVec;
84
        }
85
        
86
        public static Vector safeStringArrayToVector(String[] s) {
87
                return new Vector<String>(Arrays.asList(s));
88
        }
89

    
90
        public static int getTypeID(String gtype) throws OGRException {
91
                if(gtype!=null && (gtype.equals("wkbUnknown"))){
92
                        return ogrConstants.wkbUnknown;
93
                }else if(gtype!=null && (gtype.equals("wkbPoint"))){
94
                        return ogrConstants.wkbPoint;
95
                }else if(gtype!=null && (gtype.equals("wkbLineString"))){
96
                        return ogrConstants.wkbLineString;
97
                }else if(gtype!=null && (gtype.equals("wkbPolygon"))){
98
                        return ogrConstants.wkbPolygon;
99
                }else if(gtype!=null && (gtype.equals("wkbMultiPoint"))){
100
                        return ogrConstants.wkbMultiPoint;
101
                }else if(gtype!=null && (gtype.equals("wkbMultiLineString"))){
102
                        return ogrConstants.wkbMultiLineString;
103
                }else if(gtype!=null && (gtype.equals("wkbMultiPolygon"))){
104
                        return ogrConstants.wkbMultiPolygon;
105
                }else if(gtype!=null && (gtype.equals("wkbGeometryCollection"))){
106
                        return ogrConstants.wkbGeometryCollection;
107
                }else if(gtype!=null && (gtype.equals("wkbNone"))){
108
                        return ogrConstants.wkbNone;
109
                }else if(gtype!=null && (gtype.equals("wkbLinearRing"))){
110
                        return ogrConstants.wkbLinearRing;
111
                }else if(gtype!=null && (gtype.equals("wkbPoint25D"))){
112
                        return ogrConstants.wkbPoint25D;
113
                }else if(gtype!=null && (gtype.equals("wkbLineString25D"))){
114
                        return ogrConstants.wkbLineString25D;
115
                }else if(gtype!=null && (gtype.equals("wkbPolygon25D"))){
116
                        return ogrConstants.wkbPolygon25D;
117
                }else if(gtype!=null && (gtype.equals("wkbMultiPoint25D"))){
118
                        return ogrConstants.wkbMultiPoint25D;
119
                }else if(gtype!=null && (gtype.equals("wkbMultiLineString25D"))){
120
                        return ogrConstants.wkbLineString25D;
121
                }else if(gtype!=null && (gtype.equals("wkbMultiPolygon25D"))){
122
                        return ogrConstants.wkbLineString+ogrConstants.wkb25DBit;
123
                }else if(gtype!=null && (gtype.equals("wkbGeometryCollection25D"))){
124
                        return ogrConstants.wkbGeometryCollection25D;
125
                }
126
                
127
                throw new OGRException("Error en setGeomType(). Par?metro invalido");
128
        }
129

    
130
        public static String[] safeVectorToStringArray(Vector<String> res) {
131
                return res.toArray(new String[0]);
132
        }
133

    
134
}