Revision 1252

View differences:

org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject/src/main/java/org/gvsig/raster/tools/app/reproject/ReprojectPanelDataModelImpl.java
21 21
*/
22 22
package org.gvsig.raster.tools.app.reproject;
23 23

  
24
import java.awt.geom.Point2D;
24 25
import java.util.ArrayList;
25 26
import java.util.List;
26 27

  
28
import org.cresques.cts.ICoordTrans;
27 29
import org.cresques.cts.IProjection;
28 30
import org.gvsig.andami.PluginServices;
29 31
import org.gvsig.andami.ui.mdiManager.IWindow;
30 32
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
31 33
import org.gvsig.fmap.crs.CRSFactory;
34
import org.gvsig.fmap.dal.coverage.RasterLocator;
35
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
32 36
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
37
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
33 38
import org.gvsig.fmap.mapcontext.MapContext;
34 39
import org.gvsig.fmap.mapcontext.layers.FLayers;
35 40
import org.gvsig.raster.fmap.layers.FLyrRaster;
......
47 52
	private int                  interpolationMethod      = 0;
48 53
	private String               layerName                = null;
49 54
	private int[]                size                     = new int[]{0, 0};
55
	private FLyrRaster           lyr                      = null;
56
	private Extent               newBbox                  = null;
50 57
	
51 58
	public ReprojectPanelDataModelImpl(FLyrRaster lyr) {
59
		this.lyr = lyr;
52 60
		cellSize = lyr.getDataStore().getCellSize();
53 61
		try {
54 62
			srcProjection = lyr.readProjection();
......
60 68
		if (srcProjection == null)
61 69
			srcProjection = CRSFactory.getCRS("EPSG:23030");
62 70

  
63
		dstProjection = srcProjection;
71
		//dstProjection = srcProjection;
72
		dstProjection = CRSFactory.getCRS("EPSG:4326");
64 73
		layerName = lyr.getName();
65 74
		size = new int[]{(int)lyr.getDataStore().getWidth(), 
66 75
						 (int)lyr.getDataStore().getHeight()};
......
70 79
		interpolationMethodList.add("Nearest");
71 80
		interpolationMethodList.add("Bilinear");
72 81
		interpolationMethodList.add("Bicubic");
82
		//updateValues(lyr.getDataStore());
73 83
	}
74 84
	
75 85
	/**
......
93 103
		return null;
94 104
	}
95 105
	
106
	private void updateValues(RasterDataStore store) {
107
		//      d1x                 d2x
108
		//   ---------           ---------
109
		//   |  p1x  |           |  p2x  |
110
		//d1y|p1y    |        d2y|p2y    |
111
		//   |       |           |       |
112
		//   ---------           ---------
113
		
114
		ICoordTrans transf = srcProjection.getCT(dstProjection);
115
		Extent bbox = store.getExtent();
116
		Point2D ul = new Point2D.Double(bbox.getULX(), bbox.getULY());
117
		Point2D lr = new Point2D.Double(bbox.getLRX(), bbox.getLRY());
118
		if(transf == null)
119
			return;
120
		ul = transf.convert(ul, ul);
121
		lr = transf.convert(lr, lr);
122
		newBbox = RasterLocator.getManager().getDataStructFactory().createExtent(ul, lr);
123
		
124
		//System.out.println("Old BBox: " + bbox.toString());
125
		//System.out.println("New BBox: " + newBbox.toString());
126
		//System.out.println("Old Pixel Size: " + store.getCellSize());
127
		
128
		//double p1x = store.getWidth();
129
		//double p1y = store.getHeight();
130
		//System.out.println("Old WxH: " + p1x + " " + p1y + " --- " + (p1x / p1y) + "  " + (p1y / p1x));
131
		
132
		//long nPixels = (long)(store.getWidth() * store.getHeight());
133
		double sumSideOldBBox = bbox.width() + bbox.height();
134
		double sumSideNewBBox = newBbox.width() + newBbox.height();
135
		double d1x = (bbox.width() * 100) / sumSideOldBBox; 
136
		double d1y = (bbox.height() * 100) / sumSideOldBBox;
137
		double d2x = (newBbox.width() * 100) / sumSideNewBBox;
138
		double d2y = (newBbox.height() * 100) / sumSideNewBBox;
139
		//System.out.println("Old nPixels: " + nPixels);
140
		//System.out.println("d1x: " + d1x + " d1y: " + d1y + " d2x: " + d2x + " d2y: " + d2y);
141
		double p2y = (store.getHeight() * d2y) / d1y;
142
		double p2x = (store.getWidth() * d2x) / d1x;
143
		//long newNPixels = (long)(p2x * p2y);
144
		//System.out.println("New nPixels: " + newNPixels);
145
		//System.out.println("New WxH: " + p2x + " " + p2y + " --- " + (p2x / p2y) + "  " + (p2y / p2x));
146
		double newCellSize = newBbox.width() / p2x;
147
		
148
		size[0] = (int)p2x;
149
		size[1] = (int)p2y;
150
		cellSize = newCellSize;
151
		//double newCellSizeY = newBbox.height() / p2y;
152
		//System.out.println("New Pixel Size: " + newCellSize + " " + newCellSizeY);
153
	}
154
	
96 155
	public double getCellSize() {
97 156
		return cellSize;
98 157
	}
......
123 182

  
124 183
	public void setCellSize(double cellSize) {
125 184
		this.cellSize = cellSize;
185
		size[0] = (int)(newBbox.width() / cellSize);
186
		size[1] = (int)(newBbox.height() / cellSize);
126 187
	}
127 188

  
128 189
	public void setDstProjection(IProjection dst) {
129 190
		this.dstProjection = dst;
191
		updateValues(lyr.getDataStore());
130 192
	}
193
	
194
	public void setSrcProjection(IProjection src) {
195
		this.srcProjection = src;
196
		updateValues(lyr.getDataStore());
197
	}
131 198

  
132 199
	public void setInterpolationMethodList(List<String> list) {
133 200
		this.interpolationMethodList = list;
......
144 211
	public void setSize(int w, int h) {
145 212
		this.size = new int[]{w, h};
146 213
	}
147

  
148
	public void setSrcProjection(IProjection src) {
149
		this.srcProjection = src;
150
	}
151 214
}
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject/pom.xml
5 5
	<modelVersion>4.0.0</modelVersion>
6 6
	<artifactId>org.gvsig.raster.tools.app.reproject</artifactId>
7 7
	<packaging>jar</packaging>
8
	<name>Raster reprojection support</name>
8
	<name>Tool: Raster reprojection support</name>
9 9
	<description>Raster reprojection support for gvSIG</description>
10 10
	<parent>
11 11
		<groupId>org.gvsig</groupId>
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.swing/org.gvsig.raster.tools.algorithm.swing.impl/src/main/java/org/gvsig/raster/tools/algorithm/swing/impl/reproject/RasterReprojectPanelImpl.java
213 213
	private CRSSelectPanel getProjectionSrcSelector() {
214 214
		if (projectionSrcSelector == null) {
215 215
			projectionSrcSelector = CRSSelectPanel.getPanel(dataModel.getSrcProjection());
216
			projectionSrcSelector.setCurProj(dataModel.getSrcProjection());
216 217
			projectionSrcSelector.setTransPanelActive(true);
217 218
			projectionSrcSelector.setPreferredSize(null);
218 219
			projectionSrcSelector.addActionListener(new ActionListener() {
219 220
				public void actionPerformed(ActionEvent e) {
220 221
					if (projectionSrcSelector.isOkPressed()) {
221 222
						dataModel.setSrcProjection(projectionSrcSelector.getCurProj());
223
						try {
224
							updateSize();
225
						} catch (Exception exc) {
226
						}
222 227
					}
223 228
				}
224 229
			});
......
234 239
	private CRSSelectPanel getProjectionDstSelector() {
235 240
		if (projectionDstSelector == null) {
236 241
			projectionDstSelector = CRSSelectPanel.getPanel(dataModel.getDstProjection());
242
			projectionDstSelector.setCurProj(dataModel.getDstProjection());
237 243
			projectionDstSelector.setTransPanelActive(true);
238 244
			projectionDstSelector.setPreferredSize(null);
239 245
			projectionDstSelector.addActionListener(new ActionListener() {
240 246
				public void actionPerformed(ActionEvent e) {
241 247
					if (projectionDstSelector.isOkPressed()) {
242 248
						dataModel.setDstProjection(projectionDstSelector.getCurProj());
249
						try {
250
							updateSize();
251
						} catch (Exception exc) {
252
						}
243 253
					}
244 254
				}
245 255
			});
......
257 267
		try {
258 268
			Double d = new Double(getLayerOptionsPanel().getTextFieldCellSize().getText());
259 269
			dataModel.setCellSize(d.doubleValue());
260
			getLayerOptionsPanel().getTextFieldSizeX().setText(dataModel.getSize()[0] + "");
261
			getLayerOptionsPanel().getTextFieldSizeY().setText(dataModel.getSize()[1] + "");
270
			updateSize();
262 271
		} catch (Exception exc) {
263 272
		}
264 273
	}
265 274

  
275
	private void updateSize() {
276
		getLayerOptionsPanel().getTextFieldSizeX().setText(dataModel.getSize()[0] + "");
277
		getLayerOptionsPanel().getTextFieldSizeY().setText(dataModel.getSize()[1] + "");
278
	}
279
	
266 280
	public void keyTyped(KeyEvent e) {
267 281
		
268 282
	}

Also available in: Unified diff