Revision 130

View differences:

trunk/libraries/libCq CMS for java.old/src/org/cresques/io/TifGeoRefFile.java
72 72
		return this;
73 73
	}
74 74

  
75
	public int getWidth() { return geoRasterFile.getWidth(); }
76
	public int getHeight() { return geoRasterFile.getHeight(); }
77

  
75 78
	/* (non-Javadoc)
76 79
	 * @see org.cresques.io.GeoRasterFile#setView(org.cresques.px.Extent)
77 80
	 */
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/EcwFile.java
7 7
import java.awt.image.BufferedImage;
8 8

  
9 9
import com.ermapper.ecw.JNCSFile;
10
import com.ermapper.ecw.JNCSProgressiveUpdate;
10 11
import com.ermapper.util.JNCSDatasetPoint;
11 12

  
12 13
import org.cresques.cts.ICoordTrans;
......
72 73
/**
73 74
 * Soporte para los ficheros .ecw de ErMapper
74 75
 * 
76
 * NOTA: El SDK que ermapper ha puesto a disposici?n del p?blico en java
77
 * es una versi?n 2.45, de 19/11/2001. Est? implementada usando JNI que
78
 * se apoya en tres librer?as din?micas (dll), y presenta deficiencias
79
 * muy graves a la hora de acceder a la informaci?n. Hasta el momento
80
 * hemos detectado 3 de ellas:
81
 *     1?.- No soporta ampliaciones superiores a 1:1. si se intenta acceder
82
 * a un ecw con un zoom mayor da una excepci?n del tipo
83
 * com.ermapper.ecw.JNCSInvalidSetViewException, que de no ser tenida encuenta
84
 * acaba tirando abajo la m?quina virtual de java.
85
 *     2?.- La longitud m?xima de l?nea que adminte el m?todo readLineRGBA es
86
 * de unos 2500 pixeles, lo que hace el uso para la impresi?n en formatos
87
 * superiorea a A4 a 300 ppp o m?s inviable.
88
 *     3?.- La actualizaci?n progresiva usando el interface JNCSProgressiveUpdate
89
 * con el JNCSFile hace que el equipo genere un error severo y se apague. Este
90
 * error imposibilita esta t?cnica de acceso a ECW.
91
 *  
75 92
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
76 93
 */
77 94

  
78
public class EcwFile extends GeoRasterFile {
79
	JNCSFile file = null;
80
	boolean bErrorOnOpen = false;
81
	String errorMessage = null;
95
public class EcwFile extends GeoRasterFile  implements JNCSProgressiveUpdate {
96
	private JNCSFile file = null;
97
	private boolean bErrorOnOpen = false;
98
	private String errorMessage = null;
82 99

  
83
	Extent v = null;
84
	boolean doTransparency = false;
85
	PixelFilter tFilter = null;
100
	private Extent v = null;
101
	private boolean doTransparency = false;
102
	private PixelFilter tFilter = null;
86 103
	
104
	// Ultimo porcentaje de refresco. Se carga en el update y se
105
	// actualiza en el refreshUpdate
106
	private int lastRefreshPercent = 0;
107
	
87 108
	public EcwFile(IProjection proj, String fName) {
88 109
		super(proj, null);
89 110
		fName = DataSource.normalize(fName);
......
91 112
		extent = new Extent();
92 113
		try {
93 114
			System.err.println("Abriendo "+fName);
94
			file = new JNCSFile(fName, false);
115
			file = new JNCSFile(fName, true);
116
		    file.addProgressiveUpdateListener(this);
117

  
95 118
			load();
96 119
		} catch(Exception e) {
97 120
		  bErrorOnOpen = true;
......
137 160
		file.close(true);
138 161
		file = null;
139 162
	}
163
	
164
	public int getWidth() { return file.width; }
165
	public int getHeight() { return file.height; }
140 166

  
141 167
	/**
142 168
	 * Obtiene un trozo de imagen (determinado por la vista y los par?metros.
......
145 171
	 * @param height
146 172
	 */
147 173
	
148
	public Image updateImage(int width, int height, ICoordTrans rp) {
149
		// TODO reproyectar
174
	public synchronized Image updateImage(int width, int height, ICoordTrans rp) {
175
		// TODO reproyectar para devolver el trozo de imagen pedida sobre ...
176
		// la proyecci?n de destino.
150 177
		BufferedImage ecwImage = null;
151
		if (file != null) {
152
		  try {
178
		if (file == null) return ecwImage;
179
		try {
153 180
			double dFileAspect, dWindowAspect;
154 181
			//double dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY;
155 182
			int bandlist[];
......
182 209
			JNCSDatasetPoint ptMax = file.convertWorldToDataset(v.maxX(), v.maxY());
183 210
			System.out.println("Dataset coords Width = "+(ptMax.x-ptMin.x)+", px width ="+width);
184 211
			// Set the view
185
			try {
186
				file.setView(file.numBands, bandlist, 
187
					v.minX(), v.maxY(), v.maxX(), v.minY(),
188
					width, height);
189
			} catch (com.ermapper.ecw.JNCSInvalidSetViewException e) {
190
				System.err.println(errorMessage);
191
				e.printStackTrace();
192
			}
212
			file.setView(file.numBands, bandlist, 
213
				v.minX(), v.maxY(), v.maxX(), v.minY(),
214
				width, height);
193 215

  
194 216
			// Read the scan lines
195 217
			for (line=0; line < height; line++) {
196
			  file.readLineRGBA(pRGBArray);
197
			  // Prueba de sustituci?n de color transparente
198
			  if (doTransparency) {
218
				file.readLineRGBA(pRGBArray);
219
				// Prueba de sustituci?n de color transparente
220
				if (doTransparency) {
199 221
					if (line == 0) tFilter.debug = true;
200 222
			  		tFilter.filterLine(pRGBArray);
201 223
					tFilter.debug = false; 
202
					
203
			  }
204
			  ecwImage.setRGB(0, line, width, 1, pRGBArray, 0, width);
224
				}
225
				ecwImage.setRGB(0, line, width, 1, pRGBArray, 0, width);
205 226
			}
206 227
			updateImage(width, height);
207
		  } catch(Exception e) {
228
		/*
229
		 * La excepci?n atrapada es la de 'zoom > 1:1 no valido'
230
		} catch (com.ermapper.ecw.JNCSInvalidSetViewException e) {
231
			System.err.println(errorMessage);
232
			e.printStackTrace(); */
233
		} catch(Exception e) {
208 234
			bErrorOnOpen = true;
209 235
			errorMessage = e.getMessage();
210 236
//			g.drawString(errorMessage, 0, 50);
211 237
			System.err.println(errorMessage);
212 238
			e.printStackTrace();
213
		  }
214 239
		}
240
		lastRefreshPercent = file.getPercentComplete();
215 241
		return ecwImage;
216 242
	}
217 243
	
218 244
	private void updateImage(int width, int height) {
219
		
220 245
	}
221

  
222 246
	
223 247
	/**
224
	 * Cambia el raster de proyecci?n.
248
	 * Reproyecta el raster.
225 249
	 */
226
	
227 250
	public void reProject(ICoordTrans rp) {
228 251
		// TODO metodo reProject pendiente de implementar
229 252
	}
230 253

  
254

  
255
	/**
256
	 * Soporte para actualizaci?n de la imagen
257
	 * @see com.ermapper.ecw.JNCSProgressiveUpdate#refreshUpdate(int, int, double, double, double, double)
258
	 */
259
	public void refreshUpdate(int nWidth, int nHeight, double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY) {
260
		int completado = file.getPercentComplete();
261
		System.out.println("EcwFile: se actualiza 1: "+completado+" % completado");
262
		if ((updatable != null) && (lastRefreshPercent < 100)) {
263
			if ((completado-lastRefreshPercent > 25) || completado == 100) {
264
				lastRefreshPercent = file.getPercentComplete();
265
				updatable.repaint();
266
			}
267
		}
268
	}
269

  
270
	public void refreshUpdate(int nWidth, int nHeight, int dDatasetTLX, int dDatasetTLY, int dDatasetBRX, int dDatasetBRY) {
271
		System.out.println("EcwFile: se actualiza 2");
272
	}
231 273
}
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/GeoTiffFile.java
80 80
		return this;
81 81
	}
82 82
	
83
	public int getWidth() { return geoRasterFile.getWidth(); }
84
	public int getHeight() { return geoRasterFile.getHeight(); }
85

  
83 86
	/* (non-Javadoc)
84 87
	 * @see org.cresques.geo.Projected#reProject(org.cresques.geo.ReProjection)
85 88
	 */
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/GeoRasterFile.java
5 5
 */
6 6
package org.cresques.io;
7 7

  
8
import java.awt.Component;
8 9
import java.awt.Image;
9 10

  
10 11
import org.cresques.cts.ICoordTrans;
......
21 22
 */
22 23

  
23 24
public abstract class GeoRasterFile extends GeoFile {
25
	protected Component updatable = null;
24 26
	/**
25 27
	 * Factoria para abrir distintos tipos de raster
26 28
	 * @param fName
......
69 71
		PxContour contour = null;
70 72
		return contour;
71 73
	}
74
	
75
	abstract public int getWidth();
76
	abstract public int getHeight();
72 77

  
73 78
	abstract public void reProject(ICoordTrans rp);
74 79

  
......
79 84
	
80 85
	abstract public void setTransparency(boolean t);
81 86
	
87
	public void setUpdatable(Component c) { updatable = c; }
88
	
82 89
	abstract public Image updateImage(int width, int height, ICoordTrans rp);
83 90
	
84 91
	public IObjList getObjects() {
trunk/libraries/libCq CMS for java.old/src/org/cresques/px/gml/Feature.java
7 7
import java.util.Hashtable;
8 8

  
9 9
import org.cresques.geo.ViewPortData;
10
import org.cresques.px.Drawable;
10 11
import org.cresques.px.Extent;
11 12

  
12 13
/**
......
14 15
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
15 16
 */
16 17

  
17
public class Feature implements Extent.Has {
18
public class Feature implements Extent.Has, Drawable {
18 19
	Hashtable property = null;
19 20
	Geometry geometry = null;
20 21
	public Feature() {
trunk/libraries/libCq CMS for java.old/src/org/cresques/px/PxRaster.java
7 7
import java.awt.geom.Point2D;
8 8

  
9 9
import java.awt.Color;
10
import java.awt.Component;
10 11
import java.awt.Graphics2D;
11 12
import java.awt.Image;
12 13

  
......
46 47
		
47 48
	public PxRaster(IProjection proj, String fname, ImageObserver component) {
48 49
		geoFile = GeoRasterFile.openFile(proj, fname);//loadECW(fname);
50
		geoFile.setUpdatable((Component) component);
49 51
		this.proj = proj;
50 52
		this.component = component;
51 53
		setExtent(geoFile.getExtent());
......
72 74
		extentOrig = extent;
73 75
	}
74 76

  
77
	public String getFName() {
78
		return geoFile.getName();
79
	}
80
	
81
	/**
82
	 * Devuelve la anchura total del fichero, en pixeles.
83
	 * @return ancho en pixeles
84
	 */
85
	public int getFWidth() {
86
		return geoFile.getWidth();
87
	}
88
	
89
	/**
90
	 * Devuelve la altura total del fichero, en pixeles.
91
	 * @return alto en pixeles
92
	 */
93
	public int getFHeight() {
94
		return geoFile.getHeight();
95
	}
96
	
75 97
	public void setTransparency(boolean t) {geoFile.setTransparency(t);}
76 98
	
77 99
	public void setExtent(Extent e) {
trunk/libraries/libCq CMS for java.old/src/org/cresques/ui/cmd/CmdPLine.java
1
/*
2
 * 20-sep-2004
3
 */
4
package org.cresques.ui.cmd;
5

  
6
import java.awt.event.MouseEvent;
7
import java.awt.geom.Point2D;
8
import java.util.Vector;
9

  
10
import org.cresques.px.PxLine;
11
import org.cresques.px.dxf.DxfPolyline;
12
import org.cresques.px.gml.Feature;
13
import org.cresques.px.gml.LineString;
14
import org.cresques.ui.CQCursor;
15
import org.cresques.ui.CQMapCanvas;
16

  
17
/**
18
 * Comando pline.
19
 * A?ade al canvas la capacidad de crear polilineas.
20
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
21
 */
22
public class CmdPLine extends Cmd {
23
	private Point2D ptIni = null;
24
	private Vector pts = new Vector();
25
	private Feature pLine = null;
26
	
27
	/**
28
	 * Construye un nuevo CmdPan para el Canvas.
29
	 * @param canvas
30
	 */
31
	public CmdPLine(CQMapCanvas canvas) {
32
		super(canvas);
33
		eventsWanted = LEFT | RIGHT | PRESS | RELEASE;
34
		cursor = CQCursor.getCursor(CQCursor.SELECT_CURSOR);
35
	}
36

  
37
	/**
38
	 * Recibe los eventos del rat?n.
39
	 */
40
	public void cmd(Point2D pt, int bt, int mouseEvent) {
41
		if (mouseEvent == Cmd.RELEASE) 
42
			if (bt == MouseEvent.BUTTON1) {
43
				pts.add(pt);
44
				pline();
45
			} else {
46
				pts = new Vector();
47
			}
48
	}
49
	
50
	/**
51
	 * Realiza un desplazamiento de la vista.
52
	 * @param ptIni Punto inicial.
53
	 * @param ptFin Punto final.
54
	 */
55
	private void pline() {
56
		if (pts.size() > 2) {
57
			pLine.getGeometry().add((Point2D) pts.lastElement());
58
		} else if (pts.size() == 2) {
59
			pLine = new Feature();
60
			pLine.setGeometry(new LineString());
61
			pLine.getGeometry().add((Point2D) pts.get(0));
62
			pLine.getGeometry().add((Point2D) pts.get(1));
63
			canvas.getApp().getCurrentLayer().add(pLine);
64
		} 
65
		canvas.repaint();
66
	}
67
}
0 68

  
trunk/libraries/libCq CMS for java.old/src/org/cresques/ui/CQApp.java
22 22

  
23 23
	public PxLayer getLayerByName(String lName);
24 24
	public void setCurrentLayer(PxLayer layer);
25
	public PxLayer getCurrentLayer();
25 26
	public PxLayer createLayer(String name, IProjection proj);
26 27

  
27 28
	public void loadFile(String fName, IProjection proj);

Also available in: Unified diff