Statistics
| Revision:

root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / TifGeoRefFile.java @ 2249

History | View | Annotate | Download (5.79 KB)

1
/*
2
 * Created on 21-jun-2005
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package org.cresques.io;
48

    
49
import java.awt.Dimension;
50
import java.awt.Image;
51
import java.awt.Point;
52
import java.io.IOException;
53

    
54
import org.cresques.cts.ICoordTrans;
55
import org.cresques.cts.IProjection;
56
import org.cresques.geo.GeoPoint;
57
import org.cresques.geo.Geodetic;
58
import org.cresques.geo.ProjPoint;
59
import org.cresques.geo.Projection;
60
import org.cresques.px.Extent;
61

    
62
/**
63
 * Soporte para ficheros georeferenciados con World File (.tfw)
64
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
65
 * @author "Jos? Morell Rama" <morell_josram@gva.es>
66
 */
67
public class TifGeoRefFile extends GeoRasterFile {
68
        geo.raster.GeoRasterFile geoRasterFile = null;
69
        Extent v = null;
70

    
71
        /**
72
         * @param name
73
         */
74
        public TifGeoRefFile(IProjection proj, String fName) {
75
                super(proj, null); // TODO aqui van las proyecciones
76
                fName = DataSource.normalize(fName);
77
                super.setName(fName);
78
                System.out.println("jmGeoRaster: "+fName);
79

    
80
                geoRasterFile = geo.raster.GeoRasterFile.createFile(fName);
81

    
82
                load();
83
        }
84

    
85
        /* (non-Javadoc)
86
         * @see org.cresques.io.GeoRasterFile#load()
87
         */
88
        public GeoFile load() {
89
                try {
90
                        geoRasterFile.open();
91
                        if (!(proj instanceof Geodetic) && (proj instanceof Projection) &&
92
                                geoRasterFile.getOriginX() >= -180.0 && geoRasterFile.getOriginX() <= 180.0) {
93
                                GeoPoint gPt = new GeoPoint(geoRasterFile.getOriginX(), geoRasterFile.getOriginY());
94
                                ProjPoint pt = (ProjPoint) getProjection().createPoint(0.0, 0.0);
95
                                pt = (ProjPoint) ((Geodetic)getProjection()).fromGeo(gPt, pt);
96
                                GeoPoint gPt2 = new GeoPoint(geoRasterFile.getOriginX()+geoRasterFile.getCellIncrementX(), geoRasterFile.getOriginY()+geoRasterFile.getCellIncrementY());
97
                                ProjPoint pt2 = (ProjPoint) ((Geodetic)getProjection()).createPoint(0.0, 0.0);
98
                                pt2 = (ProjPoint) ((Geodetic)getProjection()).fromGeo(gPt2, pt2);
99
                                geoRasterFile.setOriginX(pt.getX());
100
                                geoRasterFile.setOriginY(pt.getY());
101
                                geoRasterFile.setCellIncrementX(pt2.getX()-pt.getX());
102
                                geoRasterFile.setCellIncrementY(pt2.getY()-pt.getY());
103
                                
104
                                //geoRasterFile.computeExtent();
105
                        }
106
                        extent = new Extent(geoRasterFile.getExtent());
107
                        System.out.println("jmGeoRaster: Extent="+extent);
108
                        geoRasterFile.setOriginRaster(new Point(0, 0));
109
                        geoRasterFile.setGraphics2Doffset(new Point(0, 0));
110

    
111
                } catch (IOException e) {
112
                        e.printStackTrace();
113
                        geoRasterFile = null;
114
                }
115
                return this;
116
        }
117

    
118
        public int getWidth() { return geoRasterFile.getWidth(); }
119
        public int getHeight() { return geoRasterFile.getHeight(); }
120

    
121
        /* (non-Javadoc)
122
         * @see org.cresques.io.GeoRasterFile#setView(org.cresques.px.Extent)
123
         */
124
        public void setView(Extent e) { v = new Extent(e); }
125
        public Extent getView() { return v; }
126

    
127
        /* (non-Javadoc)
128
         * @see org.cresques.io.GeoRasterFile#setTransparency(boolean)
129
         */
130
        public void setTransparency(boolean t) {
131
                //transparency = t;        
132
        }
133

    
134
        public void setTransparency(int t) {
135
                //transparency = t;        
136
        }
137
        /* (non-Javadoc)
138
         * @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.geo.ReProjection)
139
         */
140
        public Image updateImage(int width, int height, ICoordTrans rp) {
141
                double viewportScale = (double) width/v.width();
142
                Dimension sz = new Dimension(width, height);
143

    
144
                //return geoRasterFile.window(v.toRectangle2D(), viewportScale);
145
                return ((geo.raster.GeoRasterFile) geoRasterFile).updateImage(sz, v.toRectangle2D(), viewportScale);
146
        }
147

    
148

    
149
        /* (non-Javadoc)
150
         * @see org.cresques.io.GeoRasterFile#reProject(org.cresques.geo.ReProjection)
151
         */
152
        public void reProject(ICoordTrans rp) {
153
                // TODO Auto-generated method stub
154
                
155
        }
156

    
157
        /* (non-Javadoc)
158
         * @see org.cresques.io.GeoRasterFile#close()
159
         */
160
        public void close() {
161
        }
162

    
163
        /* (non-Javadoc)
164
         * @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int)
165
         */
166
        public Image updateImage(int width, int height, ICoordTrans rp, Image img, int flags) {
167
                // TODO Auto-generated method stub
168
                return null;
169
        }
170
        
171
        /* (non-Javadoc)
172
         * @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int)
173
         */
174
        public Image updateImage(int width, int height, ICoordTrans rp, Image img, int origBand, int destBand) {
175
                // TODO Auto-generated method stub
176
                return null;
177
        }
178
        /* (non-Javadoc)
179
         * @see org.cresques.io.GeoRasterFile#getData(int, int)
180
         */
181
        public Object getData(int x, int y, int band) {
182
                // TODO Auto-generated method stub
183
                return null;
184
        }
185
        
186
        public int getBlockSize(){
187
                return 0;
188
        }
189
        
190
        public byte[] getWindow(int ulX, int ulY, int sizeX, int sizeY, int band){
191
                return null;
192
        }
193
}