Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extPublish / src / org / gvsig / publish / infoproject / datasources / RasterInfo.java @ 19900

History | View | Annotate | Download (4.51 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004-2006 IVER T.I. 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 Iba?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
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.publish.infoproject.datasources;
42

    
43
import java.awt.geom.Rectangle2D;
44
import java.io.File;
45

    
46
import org.cresques.cts.ICoordTrans;
47
import org.cresques.cts.IProjection;
48
import org.gvsig.publish.infoproject.IDataSourceInfo;
49

    
50
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
51
import com.iver.cit.gvsig.fmap.drivers.raster.CmsRasterDriver;
52
import com.iver.utiles.FileUtils;
53

    
54

    
55
public class RasterInfo implements IRasterDSInfo, IFileInfo, IDataSourceInfo {
56
        private CmsRasterDriver driver = null;
57
        private Rectangle2D extent = null;
58

    
59
        public RasterInfo(CmsRasterDriver driver) {
60
                this.driver = driver;
61
                this.extent = driver.getFullExtent();
62
        }
63

    
64
        public String getAbsolutePath() {
65

    
66
                return driver.getFile().getAbsolutePath();
67
        }
68

    
69
        public String getFileName() {
70
                return  driver.getFile().getName();                
71
        }
72

    
73
        public int getNumBands() {
74

    
75
                return driver.getNumBands();
76
        }
77

    
78
        public Rectangle2D getNativeBBox() {
79
                return extent;
80
        }
81
        /**
82
         * Can be null!!
83
         */
84
        public String getEPSG() {
85
                IProjection proj = driver.getProjection();
86
                if (proj !=null){
87
                        return proj.getAbrev();
88
                }
89
                return null;
90
        }
91
        /**
92
         * @see http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html
93
         * @return BYTE, INT16, UINT16, INT32, UINT32, FLOAT32, FLOAT64 or null if I don't know the data type
94
         * TODO: complex types CInt16/CInt32/CFloat32/CFloat64
95
         *  
96
         */
97
        public String getDataType() {
98
                int datatype = driver.getRasterDataType();
99
                switch(datatype){
100
                case java.awt.image.DataBuffer.TYPE_BYTE:
101
                        return IDataSourceInfo.BYTE;
102
                case java.awt.image.DataBuffer.TYPE_USHORT:
103
                        return IDataSourceInfo.UINT16;
104
                case java.awt.image.DataBuffer.TYPE_SHORT:
105
                        return IDataSourceInfo.INT16;
106
                case java.awt.image.DataBuffer.TYPE_INT:
107
                        return IDataSourceInfo.INT32;
108
                case java.awt.image.DataBuffer.TYPE_FLOAT:
109
                        return IDataSourceInfo.FLOAT32;
110
                case java.awt.image.DataBuffer.TYPE_DOUBLE:
111
                        return IDataSourceInfo.FLOAT64;                                
112
                case java.awt.image.DataBuffer.TYPE_UNDEFINED:
113
                        return null;
114
                }
115
                return null;
116
        }
117
        /**
118
         * @return type of datasource, that is RASTER 
119
         */
120
        public String getType() {
121
                return IDataSourceInfo.RASTER_TYPE;
122
//                String extension = FileUtils.getFileExtension(driver.getFile());                                        
123
//                return extension;
124
        }
125

    
126
        public int getTransparency() {                
127
                return this.driver.getTransparency();
128
        }
129

    
130
        public String getExtension() {                
131
                return FileUtils.getFileExtension(driver.getFile());
132
        }
133

    
134

    
135
        /**
136
         * 
137
         * @see org.gvsig.publish.infoproject.IDataSourceInfo#getLatLonBBox()
138
         */
139
        public Rectangle2D getLatLonBBox() {
140
                IProjection proj_source = CRSFactory.getCRS(getEPSG());
141
                IProjection proj_dest = CRSFactory.getCRS("EPSG:4326");
142
                ICoordTrans trans = proj_source.getCT(proj_dest);                
143
                return trans.convert(getNativeBBox());
144
        }
145
        /**
146
         * the datastore is the file itself
147
         * @return file name
148
         * @see org.gvsig.publish.infoproject.IDataSourceInfo#getDatastoreName()
149
         */
150
        public String getDatastoreName() {
151
                return getFileName();
152
        }
153
        /*
154
         * (non-Javadoc)
155
         * @see org.gvsig.publish.infoproject.datasources.IFileInfo#getFile()
156
         */
157
        public File getFile() {                
158
                return driver.getFile();
159
        }
160
        /*
161
         * (non-Javadoc)
162
         * @see org.gvsig.publish.infoproject.datasources.IFileInfo#getFilenameWithoutExtension()
163
         */
164
        public String getFilenameWithoutExtension() {
165
                String[] aux = getFileName().split(".");
166
                if (aux.length > 0){
167
                        return aux[1];
168
                }else{
169
                        return null;
170
                }
171
        }
172
}