13 |
13 |
|
14 |
14 |
import org.cresques.cts.ICoordTrans;
|
15 |
15 |
import org.cresques.cts.IProjection;
|
|
16 |
import org.cresques.geo.ViewPortData;
|
16 |
17 |
import org.cresques.io.GeoRasterFile;
|
|
18 |
import org.cresques.px.Extent;
|
|
19 |
import org.cresques.px.PxRaster;
|
17 |
20 |
|
18 |
21 |
import com.iver.cit.gvsig.fmap.ViewPort;
|
19 |
22 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
|
... | ... | |
26 |
29 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
27 |
30 |
*/
|
28 |
31 |
public class CmsRasterDriver implements GeorreferencedRasterDriver {
|
29 |
|
private File rasterFile = null;
|
|
32 |
private File file = null;
|
30 |
33 |
private IProjection proj = null;
|
31 |
|
private GeoRasterFile grFile = null;
|
|
34 |
private GeoRasterFile rasterFile = null;
|
|
35 |
private PxRaster raster = null;
|
|
36 |
|
|
37 |
/* (non-Javadoc)
|
|
38 |
* @see com.hardcode.driverManager.Driver#getName()
|
|
39 |
*/
|
|
40 |
public String getName() {
|
|
41 |
return "gvSIG Image Driver";
|
|
42 |
}
|
|
43 |
|
32 |
44 |
/**
|
33 |
45 |
* @see com.iver.cit.gvsig.fmap.drivers.RasterDriver#open(java.io.File)
|
34 |
46 |
*/
|
35 |
47 |
public void open(File f) throws IOException {
|
36 |
|
rasterFile = f;
|
|
48 |
file = f;
|
37 |
49 |
}
|
38 |
50 |
|
39 |
51 |
/* (non-Javadoc)
|
... | ... | |
47 |
59 |
* @see com.iver.cit.gvsig.fmap.drivers.RasterDriver#initialize()
|
48 |
60 |
*/
|
49 |
61 |
public void initialize() throws IOException {
|
50 |
|
// TODO Auto-generated method stub
|
|
62 |
if (proj != null){
|
|
63 |
rasterFile = GeoRasterFile.openFile(proj, file.getAbsolutePath());
|
|
64 |
rasterFile.load();
|
|
65 |
|
|
66 |
createPxRaster();
|
|
67 |
} else
|
|
68 |
throw new IOException("Proyecci?n no asignada");
|
|
69 |
System.out.println(getName()+": Inicializado (con PxRaster)");
|
51 |
70 |
}
|
52 |
71 |
|
53 |
72 |
/**
|
... | ... | |
55 |
74 |
*/
|
56 |
75 |
public void initialize(IProjection proj) throws IOException {
|
57 |
76 |
this.proj = proj;
|
58 |
|
grFile = GeoRasterFile.openFile(proj, rasterFile.getAbsolutePath());
|
|
77 |
rasterFile = GeoRasterFile.openFile(proj, file.getAbsolutePath());
|
|
78 |
rasterFile.load();
|
|
79 |
|
|
80 |
createPxRaster();
|
59 |
81 |
}
|
|
82 |
|
|
83 |
private void createPxRaster() {
|
|
84 |
raster = new PxRaster(rasterFile, null, rasterFile.getExtent());
|
|
85 |
raster.setTransparency(false);
|
|
86 |
}
|
60 |
87 |
|
61 |
|
/**
|
|
88 |
/*
|
|
89 |
* @see com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver#getFullExtent()
|
|
90 |
*/
|
|
91 |
public Rectangle2D getFullExtent() {
|
|
92 |
return rasterFile.getExtent().toRectangle2D();
|
|
93 |
}
|
|
94 |
|
|
95 |
/* (non-Javadoc)
|
|
96 |
* @see com.iver.cit.gvsig.fmap.drivers.RasterDriver#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
|
97 |
*/
|
|
98 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp) throws DriverIOException {
|
|
99 |
Extent e = new Extent(vp.getExtent());
|
|
100 |
Dimension imgSz = vp.getImageSize();
|
|
101 |
ViewPortData vp2 = new ViewPortData(vp.getProjection(), e, imgSz );
|
|
102 |
vp2.setMat(vp.getAffineTransform());
|
|
103 |
raster.draw(g, vp2);
|
|
104 |
}
|
|
105 |
|
|
106 |
/*
|
62 |
107 |
* @see com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver#getProjection()
|
63 |
108 |
*/
|
64 |
109 |
public IProjection getProjection() {
|
65 |
110 |
return proj;
|
66 |
111 |
}
|
67 |
112 |
|
68 |
|
/**
|
69 |
|
* @see com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver#getFullExtent()
|
|
113 |
/* (non-Javadoc)
|
|
114 |
* @see com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver#setProjection(org.cresques.cts.IProjection)
|
70 |
115 |
*/
|
71 |
|
public Rectangle2D getFullExtent() {
|
72 |
|
return grFile.getExtent().toRectangle2D();
|
|
116 |
public void setProjection(IProjection proj) {
|
|
117 |
this.proj = proj;
|
73 |
118 |
}
|
74 |
119 |
|
75 |
|
/**
|
|
120 |
/*
|
76 |
121 |
* @see com.iver.cit.gvsig.fmap.drivers.RasterDriver#getNumBands()
|
77 |
122 |
*/
|
78 |
123 |
public int getNumBands() {
|
79 |
|
return grFile.getBandCount();
|
|
124 |
return rasterFile.getBandCount();
|
80 |
125 |
}
|
81 |
126 |
|
82 |
127 |
/* (non-Javadoc)
|
... | ... | |
108 |
153 |
*/
|
109 |
154 |
public Object getData(int x, int y, int band) {
|
110 |
155 |
// TODO Auto-generated method stub
|
111 |
|
return grFile.getData(x, y, band);
|
|
156 |
return null;
|
112 |
157 |
}
|
113 |
158 |
|
114 |
159 |
/* (non-Javadoc)
|
... | ... | |
142 |
187 |
// TODO Auto-generated method stub
|
143 |
188 |
return 0;
|
144 |
189 |
}
|
145 |
|
/* (non-Javadoc)
|
146 |
|
* @see com.hardcode.driverManager.Driver#getName()
|
147 |
|
*/
|
148 |
|
public String getName() {
|
149 |
|
return "gvSIG Image Driver";
|
150 |
|
}
|
151 |
190 |
|
152 |
191 |
/* (non-Javadoc)
|
153 |
|
* @see com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver#setProjection(org.cresques.cts.IProjection)
|
154 |
|
*/
|
155 |
|
public void setProjection(IProjection proj) {
|
156 |
|
// TODO Auto-generated method stub
|
157 |
|
|
158 |
|
}
|
159 |
|
|
160 |
|
/* (non-Javadoc)
|
161 |
192 |
* @see com.iver.cit.gvsig.fmap.drivers.RasterDriver#fileAccepted(java.io.File)
|
162 |
193 |
*/
|
163 |
|
public boolean fileAccepted(File fName) {
|
164 |
|
// TODO Auto-generated method stub
|
165 |
|
return false;
|
|
194 |
public boolean fileAccepted(File file) {
|
|
195 |
return GeoRasterFile.fileIsSupported(file.getName());
|
166 |
196 |
}
|
167 |
197 |
|
168 |
198 |
/* (non-Javadoc)
|
... | ... | |
172 |
202 |
// TODO Auto-generated method stub
|
173 |
203 |
return null;
|
174 |
204 |
}
|
175 |
|
|
176 |
|
/* (non-Javadoc)
|
177 |
|
* @see com.iver.cit.gvsig.fmap.drivers.RasterDriver#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
178 |
|
*/
|
179 |
|
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort) throws DriverIOException {
|
180 |
|
// TODO Auto-generated method stub
|
181 |
|
|
182 |
|
}
|
183 |
205 |
}
|