Revision 1889

View differences:

org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/distribution/distribution.xml
1
<assembly>
2
	<id>distribution</id>
3
	<formats>
4
		<format>dir</format>
5
	</formats>
6
	<fileSets>
7
		<!-- Estructure for the extension -->
8
		<fileSet>
9
			<directory>src/main/resources</directory>
10
			<outputDirectory>${extension.install.dir.name}
11
			</outputDirectory>
12
		</fileSet>
13
	</fileSets>
14
	<files>
15
	    <file>
16
            <source>package.info</source>
17
            <outputDirectory>${extension.install.dir.name}</outputDirectory>
18
        </file>
19
    </files>
20
	<dependencySets>
21
		<dependencySet>
22
			<outputDirectory>${extension.install.dir.name}/${library-dir}
23
			</outputDirectory>
24
			<includes>
25
				<include>org.gvsig:org.gvsig.raster.tools.app.reproject:jar</include>
26
				<!-- 
27
				Ojo! no incluir estos ya que los pone app.basic
28
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.base:jar</include>
29
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.reproject:jar</include>
30
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.api:jar</include>
31
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.impl:jar</include>
32
				-->
33
			</includes>
34
		</dependencySet>
35
	</dependencySets>
36
</assembly>
0 37

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Wed May 15 12:24:42 CEST 2013
3
buildNumber=12
0 4

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/src/main/resources/text.properties
1
reproject_layer=Reproyectar
2
reprojection=Reproyecci?n
3
wrong_size=Tama?o incorrecto en la imagen de salida
4
wrong_projection=Proyecci?n incorrecta
5
error_creating_algorithm=Error construyendo el objeto algoritmo
6
directory_does_not_exists=El directorio de destino no existe
7
file_name_not_valid=Nombre de fichero no v?lido
8
file_exists=El fichero de salida existe
9
overwrite=Quieres sobreescribirlo?
10
valid_characters=Caracteres validos
0 11

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/src/main/resources/text_en.properties
1
reproject_layer=Reproject
2
reprojection=Reprojection
3
wrong_size=Wrong size in output image
4
wrong_projection=Wrong projection
5
error_creating_algorithm=Error building the algorithm object
6
directory_does_not_exists=The destination directory does not exists
7
file_name_not_valid=File name not valid
8
file_exists=The output file exists
9
overwrite=Do you want overwrite it?
10
valid_characters=Valid characters
0 11

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/src/main/resources/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<depends plugin-name="org.gvsig.raster.tools.app.basic" />
4
	<resourceBundle name="text"/>
5
	<libraries library-dir="lib"/>
6
	<extensions>
7
		<extension class-name="org.gvsig.raster.tools.app.reproject.ReprojectExtension"
8
			description="Reproject plugin" 
9
			active="true" 
10
			priority="1">
11
			
12
			<menu text="Layer/reproject_layer"
13
				position="0" 
14
				action-command="Reproject" 
15
				icon="tools-raster-reproject"/>
16
				
17
		</extension>	
18
	</extensions>
19
</plugin-config>
0 20

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/src/main/java/org/gvsig/raster/tools/app/reproject/ReprojectListener.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.app.reproject;
23

  
24
import java.awt.Component;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27
import java.io.File;
28
import java.util.HashMap;
29

  
30
import javax.swing.JOptionPane;
31

  
32
import org.cresques.cts.IProjection;
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.andami.ui.mdiManager.IWindow;
35
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.FLayers;
38
import org.gvsig.i18n.Messages;
39
import org.gvsig.raster.fmap.layers.FLyrRaster;
40
import org.gvsig.raster.tools.algorithm.base.RasterBaseAlgorithmLibrary;
41
import org.gvsig.raster.tools.algorithm.base.process.IProcessActions;
42
import org.gvsig.raster.tools.algorithm.base.process.ProcessException;
43
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess;
44
import org.gvsig.raster.tools.algorithm.reproject.ReprojectProcess;
45
import org.gvsig.raster.tools.algorithm.swing.reproject.RasterReprojectPanel;
46
import org.gvsig.raster.tools.algorithm.swing.reproject.ReprojectPanelDataModel;
47
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
48
import org.gvsig.raster.tools.app.basic.raster.bean.endinfo.EndInfoDialog;
49
import org.gvsig.raster.util.RasterNotLoadException;
50

  
51

  
52
/**
53
 * Actions for the reprojection panel
54
 * 
55
 * @author Nacho Brodin (nachobrodin@gmail.com)
56
 */
57
public class ReprojectListener implements ActionListener, IProcessActions {
58
	private RasterReprojectPanel            reprojectPanel   = null;
59
	private FLayer                          lyr              = null;
60
	private ReprojectPanelDataModel         dataModel        = null;
61
	private ReprojectWindow                 window           = null;
62

  
63
	public ReprojectListener(FLayer lyr, ReprojectPanelDataModel dataModel, ReprojectWindow window, RasterReprojectPanel reprojectPanel) {
64
		this.lyr = lyr;
65
		this.dataModel = dataModel;
66
		this.window = window;
67
		this.reprojectPanel = reprojectPanel;
68
	}
69

  
70
	public void actionPerformed(ActionEvent e) {
71
		if(reprojectPanel.getObjectSelected(e.getSource()) == RasterReprojectPanel.BUTTON_ACCEPT) {
72
			double cellsize = dataModel.getCellSize();
73
			int w = dataModel.getSize()[0];
74
			int h = dataModel.getSize()[1];
75
			IProjection srcPrj = dataModel.getSrcProjection();
76
			IProjection dstPrj = dataModel.getDstProjection();
77
			
78
			if(cellsize <= 0 || w <= 0 || h <= 0) {
79
				messageBoxError("wrong_size");
80
				return;
81
			}
82
			
83
			if(srcPrj == null || dstPrj == null) {
84
				messageBoxError("wrong_projection");
85
				return;
86
			}
87
			
88
			RasterProcess process;
89
			try {
90
				process = RasterBaseAlgorithmLibrary.getManager().createRasterTask("RasterReprojectionProcess");
91
			} catch (ProcessException e1) {
92
				messageBoxError("error_creating_algorithm");
93
				return;
94
			}
95
			
96
			String path = getPath();
97
			if(path == null)
98
				return;
99
			
100
			process.setActions(this);
101
			process.addParam(ReprojectProcess.RASTER_STORE, ((FLyrRaster)lyr).getDataStore());
102
			process.addParam(ReprojectProcess.SIZEX, w);
103
			process.addParam(ReprojectProcess.SIZEY, h);
104
			process.addParam(ReprojectProcess.PATH, path);
105
			process.addParam(ReprojectProcess.SRC_PROJECTION, dataModel.getSrcProjection());
106
			process.addParam(ReprojectProcess.DST_PROJECTION, dataModel.getDstProjection());
107
			process.addParam(ReprojectProcess.CELLSIZE, dataModel.getCellSize());
108
			process.addParam(ReprojectProcess.INTERPOLATION, dataModel.getInterpolationMethodSelected());
109
			process.start();
110
			
111
		}
112
		if(reprojectPanel.getObjectSelected(e.getSource()) == RasterReprojectPanel.BUTTON_CANCEL) {
113
			if(window != null) {
114
				PluginServices.getMDIManager().closeWindow(window);
115
				window = null;
116
			}
117
		}
118
	}
119
	
120
	/**
121
	 * Gets the path to the file
122
	 * @return
123
	 */
124
	private String getPath() {
125
		String file = reprojectPanel.getFileSelected();
126
		if(file == null || file.equals("") || !file.matches("[a-zA-Z0-9_]*")) {
127
			messageBoxError(
128
					Messages.getText("file_name_not_valid") + 
129
					"\n" + file + "\n " + 
130
					Messages.getText("valid_characters") + 
131
					" a-zA-Z0-9_");
132
			return null;
133
		}
134
		
135
		if(!file.endsWith(".tif"))
136
			file += ".tif";
137
		String dir = reprojectPanel.getDirectorySelected();
138
		if(!new File(dir).exists()) {
139
			messageBoxError("directory_does_not_exists");
140
			return null;
141
		}
142
		
143
		if(new File(dir + File.separator + file).exists()) {
144
			if(!RasterToolsUtil.messageBoxYesOrNot(
145
					Messages.getText("file_exists") + 
146
					"\n " + (dir + File.separator + file) + "\n " + 
147
					Messages.getText("overwrite"), null))
148
			return null;
149
		}
150
		return (dir + File.separator + file);
151
	}
152
	
153
	/**
154
	 * Shows an error dialog with a text and a accept button 
155
	 * @param msg Message to show in the dialog
156
	 * @param parentWindow Parent window
157
	 */
158
	public static void messageBoxError(String msg) {
159
		String string = Messages.getText("accept");
160
		Object[] options = {string};
161
		JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
162
					"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "</html>",
163
					Messages.getText("confirmacion"),
164
					JOptionPane.OK_OPTION,
165
					JOptionPane.ERROR_MESSAGE,
166
					null,
167
					options,
168
					string);
169
	}
170

  
171
	/*
172
	 * (non-Javadoc)
173
	 * @see org.gvsig.raster.tools.algorithm.base.process.IProcessActions#end(java.lang.Object)
174
	 */
175
	@SuppressWarnings("unchecked")
176
	public void end(Object params) {
177
		if(window != null) {
178
			PluginServices.getMDIManager().closeWindow(window);
179
			window = null;
180
		}
181
		if(params instanceof HashMap<?, ?>) {
182
			HashMap<String, Object>  map = (HashMap<String, Object>) params;
183
			String fName = (String)map.get(ReprojectProcess.FILENAME);
184
			long milis = (Long)map.get(ReprojectProcess.TIME);
185
			processFinalize(fName, milis);
186
			EndInfoDialog.show(fName, milis);
187
		}
188

  
189
	}
190
	
191
	/**
192
	 * Acciones que se realizan al finalizar de crear los recortes de imagen.
193
	 * Este m?todo es llamado por el thread TailRasterProcess al finalizar.
194
	 */
195
	private void processFinalize(String fileName, long milis) {
196
		if (!new File(fileName).exists())
197
			return;
198

  
199
		String viewName = getViewName();
200
		if(viewName != null) {
201
			if (RasterToolsUtil.messageBoxYesOrNot("cargar_toc", this)) {
202
				try {
203
					RasterToolsUtil.loadLayer(viewName, fileName, null);
204
				} catch (RasterNotLoadException e) {
205
					messageBoxError("error_load_layer");
206
				}
207
			}
208
		}
209
	}
210
	
211
	/**
212
	 * Gets the view 
213
	 * @return
214
	 */
215
	private String getViewName() {
216
		IWindow[] w = PluginServices.getMDIManager().getAllWindows();
217
		for (int i = 0; i < w.length; i++) {
218
			if(w[i] instanceof AbstractViewPanel) {
219
				FLayers lyrs = ((AbstractViewPanel)w[i]).getMapControl().getMapContext().getLayers();
220
				for (int j = 0; j < lyrs.getLayersCount(); j++) {
221
					FLayer lyr = lyrs.getLayer(j);
222
					if(this.lyr == lyr) {
223
						return PluginServices.getMDIManager().getWindowInfo((AbstractViewPanel) w[i]).getTitle();
224
					}
225
				}
226
			}
227
		}
228
		return null;
229
	}
230

  
231
	public void interrupted() {
232
	}
233
}
0 234

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/src/main/java/org/gvsig/raster/tools/app/reproject/ReprojectWindow.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2011-2012 Prodevelop S.L
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 */
21
package org.gvsig.raster.tools.app.reproject;
22

  
23
import java.awt.BorderLayout;
24

  
25
import javax.swing.JComponent;
26
import javax.swing.JPanel;
27

  
28
import org.gvsig.andami.ui.mdiManager.IWindow;
29
import org.gvsig.andami.ui.mdiManager.WindowInfo;
30

  
31

  
32
/**
33
 * @author Nacho Brodin (nachobrodin@gmail.com)
34
 */
35
public class ReprojectWindow extends JPanel implements IWindow {
36
    
37
    private static final long serialVersionUID = -4401123724140025094L;
38

  
39
    private WindowInfo info;
40

  
41
    private Object profile = WindowInfo.EDITOR_PROFILE;
42

  
43
    public ReprojectWindow(JComponent panel, String title, int w, int h) {
44
        this.setLayout(new BorderLayout());
45
        add(panel, BorderLayout.CENTER);
46

  
47
        info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE);
48
        info.setTitle(title);
49
        info.setWidth(w);
50
        info.setHeight(h);
51
    }
52

  
53
    public WindowInfo getWindowInfo() {
54
        return info;
55
    }
56

  
57
    public Object getWindowProfile() {
58
        return profile;
59
    }
60
}
0 61

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/src/main/java/org/gvsig/raster/tools/app/reproject/ReprojectExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.app.reproject;
23

  
24
import org.gvsig.andami.IconThemeHelper;
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.andami.ui.mdiManager.IWindow;
28
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
29
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
30
import org.gvsig.fmap.mapcontext.layers.FLayer;
31
import org.gvsig.fmap.mapcontext.layers.FLayers;
32
import org.gvsig.raster.fmap.layers.FLyrRaster;
33
import org.gvsig.raster.fmap.layers.ILayerState;
34
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.extensionpoint.ExtensionBuilder;
37
import org.gvsig.tools.extensionpoint.ExtensionPoint;
38
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
39

  
40
/**
41
 * Extension for adding grid netcdf support to gvSIG.
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 */
44
public class ReprojectExtension extends Extension {
45
	private ExtensionPoint      genericToolBarMenuExtensionPoint  = null;
46
	private static String       action                            = "Reproject";
47

  
48
	public void initialize() {
49
		IconThemeHelper.registerIcon("action", "tools-raster-reproject", this);
50
		
51
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
52
		ExtensionPoint point = extensionPoints.add("GenericToolBarMenu");
53
		point.append(action, "", ReprojectTocMenuEntry.getSingleton());
54
	}
55

  
56
	public void execute(String actionCommand) {
57
		//Las entradas en GenericToolBarModule est?n registradas con la misma etiqueta que la del actionCommand
58
		//De esta forma pueden recuperarse los TocMenuEntry del punto de extensi?n y ejecutar la acci?n a
59
		//trav?s de este.
60
		ExtensionBuilder ext = getGenericToolBarMenuExtensionPoint().get(actionCommand).getBuilder();
61
		if(ext != null && ext instanceof AbstractTocContextMenuAction) {
62
			IWindow w = PluginServices.getMDIManager().getActiveWindow();
63
			if(w instanceof AbstractViewPanel) {
64
				FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers();
65
				FLayer[] actives = lyrs.getActives();
66
				((AbstractTocContextMenuAction)ext).execute(null, actives);
67
			}
68
		}
69
	}
70

  
71
	public boolean isEnabled() {
72
		IWindow w = PluginServices.getMDIManager().getActiveWindow();
73
		if(w instanceof AbstractViewPanel) {
74
			FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers();
75
			FLayer[] actives = lyrs.getActives();
76
			if(actives != null && actives.length > 0) {
77
				for (int i = 0; i < actives.length; i++) {
78
					if(actives[i] instanceof FLyrRaster && ((ILayerState)actives[i]).isOpen()) {
79
						return true;
80
					}
81
				}
82
			}
83
		}
84
		return false;
85
	}
86

  
87
	public boolean isVisible() {
88
		IWindow w = PluginServices.getMDIManager().getActiveWindow();
89
		if(w instanceof AbstractViewPanel) {
90
			FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers();
91
			FLayer[] actives = lyrs.getActives();
92
			if(actives != null && actives.length > 0) {
93
				for (int i = 0; i < actives.length; i++) {
94
					if(actives[i] instanceof FLyrRaster && 
95
						((IRasterLayerActions)actives[i]).isActionEnabled(IRasterLayerActions.REPROJECT)) {
96
						return true;
97
					}
98
				}
99
			}
100
		}
101
		return false;
102
	}
103
	
104
	public ExtensionPoint getGenericToolBarMenuExtensionPoint() {
105
		if(genericToolBarMenuExtensionPoint == null) {
106
			ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
107
			genericToolBarMenuExtensionPoint = extensionPoints.get("GenericToolBarMenu");
108
		}
109
		return genericToolBarMenuExtensionPoint;
110
	}
111
}
0 112

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/src/main/java/org/gvsig/raster/tools/app/reproject/ReprojectPanelDataModelImpl.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.app.reproject;
23

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

  
28
import org.cresques.cts.ICoordTrans;
29
import org.cresques.cts.IProjection;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
33
import org.gvsig.fmap.crs.CRSFactory;
34
import org.gvsig.fmap.dal.coverage.RasterLocator;
35
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
36
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
37
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
38
import org.gvsig.fmap.mapcontext.MapContext;
39
import org.gvsig.fmap.mapcontext.layers.FLayers;
40
import org.gvsig.raster.fmap.layers.FLyrRaster;
41
import org.gvsig.raster.tools.algorithm.reproject.ReprojectProcess;
42
import org.gvsig.raster.tools.algorithm.swing.reproject.ReprojectPanelDataModel;
43

  
44
/**
45
 * Data model for the panel of reprojection
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class ReprojectPanelDataModelImpl implements ReprojectPanelDataModel {
49
	private double               cellSize                 = 0;
50
	private IProjection          dstProjection            = null;
51
	private IProjection          srcProjection            = null;
52
	private List<String>         interpolationMethodList  = null;
53
	private int                  interpolationMethod      = 0;
54
	private String               layerName                = null;
55
	private int[]                size                     = new int[]{0, 0};
56
	private FLyrRaster           lyr                      = null;
57
	private Extent               newBbox                  = null;
58
	
59
	public ReprojectPanelDataModelImpl(FLyrRaster lyr) {
60
		this.lyr = lyr;
61
		cellSize = lyr.getDataStore().getCellSize();
62
		try {
63
			srcProjection = lyr.readProjection();
64
		} catch (RasterDriverException e) {
65
			srcProjection = getViewProjection(lyr);
66
		}
67
		if (srcProjection == null) 
68
			srcProjection = getViewProjection(lyr);
69
		if (srcProjection == null)
70
			srcProjection = CRSFactory.getCRS("EPSG:23030");
71

  
72
		dstProjection = srcProjection;
73
		
74
		layerName = lyr.getName();
75
		size = new int[]{(int)lyr.getDataStore().getWidth(), 
76
						 (int)lyr.getDataStore().getHeight()};
77
		
78
		interpolationMethod = -1;
79
		interpolationMethodList = new ArrayList<String>();
80
		for (int i = 0; i < ReprojectProcess.INTERP_METHODS.length; i++) {
81
			interpolationMethodList.add(ReprojectProcess.INTERP_METHODS[i]);
82
		}
83
		//updateValues(lyr.getDataStore());
84
	}
85
	
86
	/**
87
	 * Gets the projection of the view
88
	 * @param lyr
89
	 * @return
90
	 */
91
	private IProjection getViewProjection(FLyrRaster lyr) {
92
		IWindow[] w = PluginServices.getMDIManager().getAllWindows();
93
		for (int i = 0; i < w.length; i++) {
94
			if(w[i] instanceof AbstractViewPanel) {
95
				MapContext mapContext = ((AbstractViewPanel)w[i]).getMapControl().getMapContext();
96
				FLayers lyrs = mapContext.getLayers();
97
				for (int j = 0; j < lyrs.getLayersCount(); j++) {
98
					if(lyrs.getLayer(j) == lyr) {
99
						return ((AbstractViewPanel)w[i]).getProjection();
100
					}
101
				}
102
			}
103
		}
104
		return null;
105
	}
106
	
107
	private void updateValues(RasterDataStore store) {
108
		//      d1x                 d2x
109
		//   ---------           ---------
110
		//   |  p1x  |           |  p2x  |
111
		//d1y|p1y    |        d2y|p2y    |
112
		//   |       |           |       |
113
		//   ---------           ---------
114
		
115
		ICoordTrans transf = srcProjection.getCT(dstProjection);
116
		Extent bbox = store.getExtent();
117
		Point2D ul = new Point2D.Double(bbox.getULX(), bbox.getULY());
118
		Point2D lr = new Point2D.Double(bbox.getLRX(), bbox.getLRY());
119
		if(transf == null)
120
			return;
121
		ul = transf.convert(ul, ul);
122
		lr = transf.convert(lr, lr);
123
		newBbox = RasterLocator.getManager().getDataStructFactory().createExtent(ul, lr);
124
		
125
		//System.out.println("Old BBox: " + bbox.toString());
126
		//System.out.println("New BBox: " + newBbox.toString());
127
		//System.out.println("Old Pixel Size: " + store.getCellSize());
128
		
129
		//double p1x = store.getWidth();
130
		//double p1y = store.getHeight();
131
		//System.out.println("Old WxH: " + p1x + " " + p1y + " --- " + (p1x / p1y) + "  " + (p1y / p1x));
132
		
133
		//long nPixels = (long)(store.getWidth() * store.getHeight());
134
		double sumSideOldBBox = bbox.width() + bbox.height();
135
		double sumSideNewBBox = newBbox.width() + newBbox.height();
136
		double d1x = (bbox.width() * 100) / sumSideOldBBox; 
137
		double d1y = (bbox.height() * 100) / sumSideOldBBox;
138
		double d2x = (newBbox.width() * 100) / sumSideNewBBox;
139
		double d2y = (newBbox.height() * 100) / sumSideNewBBox;
140
		//System.out.println("Old nPixels: " + nPixels);
141
		//System.out.println("d1x: " + d1x + " d1y: " + d1y + " d2x: " + d2x + " d2y: " + d2y);
142
		double p2y = (store.getHeight() * d2y) / d1y;
143
		double p2x = (store.getWidth() * d2x) / d1x;
144
		//long newNPixels = (long)(p2x * p2y);
145
		//System.out.println("New nPixels: " + newNPixels);
146
		//System.out.println("New WxH: " + p2x + " " + p2y + " --- " + (p2x / p2y) + "  " + (p2y / p2x));
147
		double newCellSize = newBbox.width() / p2x;
148
		
149
		size[0] = (int)Math.round(p2x);
150
		size[1] = (int)Math.round(p2y);
151
		cellSize = newCellSize;
152
		//double newCellSizeY = newBbox.height() / p2y;
153
		//System.out.println("New Pixel Size: " + newCellSize + " " + newCellSizeY);
154
	}
155
	
156
	public double getCellSize() {
157
		return cellSize;
158
	}
159

  
160
	public IProjection getDstProjection() {
161
		return dstProjection;
162
	}
163

  
164
	public List<String> getInterpolationMethodList() {
165
		return interpolationMethodList;
166
	}
167

  
168
	public int getInterpolationMethodSelected() {
169
		return interpolationMethod;
170
	}
171

  
172
	public String getLayerName() {
173
		return layerName;
174
	}
175

  
176
	public int[] getSize() {
177
		return size;
178
	}
179

  
180
	public IProjection getSrcProjection() {
181
		return srcProjection;
182
	}
183

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

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

  
200
	public void setInterpolationMethodList(List<String> list) {
201
		this.interpolationMethodList = list;
202
	}
203

  
204
	public void setInterpolationMethodSelected(int method) {
205
		this.interpolationMethod = method;
206
	}
207

  
208
	public void setLayerName(String layerName) {
209
		this.layerName = layerName;
210
	}
211

  
212
	public void setSize(int w, int h) {
213
		this.size = new int[]{w, h};
214
	}
215
}
0 216

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/src/main/java/org/gvsig/raster/tools/app/reproject/ReprojectTocMenuEntry.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.app.reproject;
23

  
24
import javax.swing.Icon;
25

  
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
29
import org.gvsig.app.project.documents.view.toc.ITocItem;
30
import org.gvsig.fmap.mapcontext.layers.FLayer;
31
import org.gvsig.i18n.Messages;
32
import org.gvsig.raster.fmap.layers.FLyrRaster;
33
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
34
import org.gvsig.raster.swing.newlayer.FileNameManagement;
35
import org.gvsig.raster.tools.algorithm.swing.AlgorithmSwingLocator;
36
import org.gvsig.raster.tools.algorithm.swing.reproject.RasterReprojectPanel;
37
import org.gvsig.raster.tools.algorithm.swing.reproject.ReprojectPanelDataModel;
38
import org.gvsig.raster.tools.app.basic.raster.gui.IGenericToolBarMenuItem;
39

  
40

  
41
/**
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 */
44
public class ReprojectTocMenuEntry extends AbstractTocContextMenuAction 
45
	implements IGenericToolBarMenuItem {
46
	static private ReprojectTocMenuEntry    singleton        = null;
47
	private ReprojectListener               listener         = null;
48

  
49
	/*
50
	 *  (non-Javadoc)
51
	 * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getGroup()
52
	 */
53
	public String getGroup() {
54
		return "GeoRaster";
55
	}
56

  
57
	/*
58
	 *  (non-Javadoc)
59
	 * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getGroupOrder()
60
	 */
61
	public int getGroupOrder() {
62
		return 10;
63
	}
64

  
65
	/*
66
	 *  (non-Javadoc)
67
	 * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getOrder()
68
	 */
69
	public int getOrder() {
70
		return 10;
71
	}
72

  
73
	/*
74
	 *  (non-Javadoc)
75
	 * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
76
	 */
77
	public String getText() {
78
		return Messages.getText("toc_reproject");
79
	}
80
	
81
	/**
82
	 * Devuelve un objeto unico a dicha clase
83
	 * @return
84
	 */
85
	static public ReprojectTocMenuEntry getSingleton() {
86
		if (singleton == null)
87
			singleton = new ReprojectTocMenuEntry();
88
		return singleton;
89
	}
90

  
91
	/*
92
	 *  (non-Javadoc)
93
	 * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
94
	 */
95
	public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
96
		return true;
97
	}
98

  
99
	/*
100
	 *  (non-Javadoc)
101
	 * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
102
	 */
103
	public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
104
		if ((selectedItems == null) || (selectedItems.length != 1))
105
			return false;
106

  
107
		if (!(selectedItems[0] instanceof IRasterLayerActions))
108
			return false;
109

  
110
		return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.REPROJECT);
111
	}
112

  
113
	/**
114
	 * M?todo que se ejecuta cuando se pulsa la entrada en el men? contextual del TOC 
115
	 * correspondiente a "Zoom a la resoluci?n del raster". Aqu? se crear? el mapTool si 
116
	 * no se ha hecho antes y se cargar?.
117
	 */
118
	public void execute(ITocItem item, FLayer[] selectedItems) {
119
		if (selectedItems.length == 1) {
120
			FLayer lyr = selectedItems[0];
121
			if (lyr instanceof FLyrRaster) {
122
				FileNameManagement fileNameManagement = new FileNameManagementImpl();
123
				ReprojectPanelDataModel dataModel = new ReprojectPanelDataModelImpl((FLyrRaster)lyr);
124
				RasterReprojectPanel reprojectPanel = AlgorithmSwingLocator.getSwingManager().createRasterReprojectPanel(fileNameManagement, dataModel);
125
				
126
				ReprojectWindow window = new ReprojectWindow(reprojectPanel.getComponent(), Messages.getText("reprojection"), 360, 460);
127
				listener = new ReprojectListener(lyr, dataModel, window, reprojectPanel);
128
				reprojectPanel.addButtonsListener(listener);
129
				PluginServices.getMDIManager().addCentredWindow(window);
130
			}
131
		}
132
	}
133
	
134
	/*
135
	 * (non-Javadoc)
136
	 * @see org.gvsig.rastertools.generictoolbar.IGenericToolBarMenuItem#getIcon()
137
	 */
138
	public Icon getIcon() {
139
		return IconThemeHelper.getImageIcon("tools-raster-reproject");
140
	}
141

  
142
	public void interrupted() {
143
		// TODO Auto-generated method stub
144
		
145
	}
146
}
0 147

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/src/main/java/org/gvsig/raster/tools/app/reproject/FileNameManagementImpl.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.app.reproject;
23

  
24
import java.util.ArrayList;
25
import java.util.List;
26

  
27
import org.gvsig.fmap.dal.coverage.RasterLocator;
28
import org.gvsig.fmap.dal.coverage.util.FileUtils;
29
import org.gvsig.raster.swing.newlayer.FileNameManagement;
30

  
31
/**
32
 * @author Nacho Brodin (nachobrodin@gmail.com)
33
 */
34
public class FileNameManagementImpl implements FileNameManagement {
35
	private FileUtils fileUtils = RasterLocator.getManager().getFileUtils();
36
	
37
	/*
38
	 * (non-Javadoc)
39
	 * @see org.gvsig.raster.swing.newlayer.FileNameManagement#getDefaultFilePath()
40
	 */
41
	public String getDefaultFilePath() {
42
		return System.getProperty("user.home");
43
	}
44

  
45
	/*
46
	 * (non-Javadoc)
47
	 * @see org.gvsig.raster.swing.newlayer.FileNameManagement#getPrefixSupported()
48
	 */
49
	public List<String> getPrefixSupported() {
50
		List<String> list = new ArrayList<String>();
51
		list.add("tif");
52
		return list;
53
	}
54

  
55
	/*
56
	 * (non-Javadoc)
57
	 * @see org.gvsig.raster.swing.newlayer.FileNameManagement#getUniqueLayerName()
58
	 */
59
	public String getUniqueLayerName() {
60
		return fileUtils.getOnlyLayerName();
61
	}
62

  
63
	/*
64
	 * (non-Javadoc)
65
	 * @see org.gvsig.raster.swing.newlayer.FileNameManagement#usesUniqueLayerName()
66
	 */
67
	public void usesUniqueLayerName() {
68
		fileUtils.usesOnlyLayerName();
69
	}
70

  
71
}
0 72

  
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject_deprecated/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.raster.tools.app.reproject</artifactId>
6
	<packaging>jar</packaging>
7
	<name>Tool: Raster reprojection support</name>
8
	<description>Raster reprojection support for gvSIG</description>
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.raster.tools.app</artifactId>
12
		<version>2.0.1-SNAPSHOT</version>
13
	</parent>
14
	<dependencies>
15
	    <dependency>
16
            <groupId>org.gvsig</groupId>
17
            <artifactId>org.gvsig.raster.lib.api</artifactId>
18
            <scope>compile</scope>
19
        </dependency>
20
		 <dependency>
21
            <groupId>org.gvsig</groupId>
22
            <artifactId>org.gvsig.ui</artifactId>
23
            <scope>compile</scope>
24
        </dependency>
25
		<dependency>
26
            <groupId>org.gvsig</groupId>
27
            <artifactId>org.gvsig.raster.tools.algorithm.base</artifactId>
28
        </dependency>
29
        <dependency>
30
            <groupId>org.gvsig</groupId>
31
            <artifactId>org.gvsig.raster.tools.algorithm.reproject</artifactId>
32
        </dependency>
33
        <dependency>
34
            <groupId>org.gvsig</groupId>
35
            <artifactId>org.gvsig.raster.tools.algorithm.swing.api</artifactId>
36
        </dependency>
37
        <dependency>
38
            <groupId>org.gvsig</groupId>
39
            <artifactId>org.gvsig.raster.tools.algorithm.swing.impl</artifactId>
40
        </dependency>
41
        <dependency>
42
			<groupId>org.gvsig</groupId>
43
			<artifactId>org.gvsig.raster.fmap</artifactId>
44
            <scope>compile</scope>
45
		</dependency>
46
		<dependency>
47
			<groupId>org.gvsig</groupId>
48
			<artifactId>org.gvsig.app</artifactId>
49
            <scope>compile</scope>
50
		</dependency>
51
		<dependency>
52
			<groupId>org.gvsig</groupId>
53
			<artifactId>org.gvsig.raster.tools.app.basic</artifactId>
54
            <scope>compile</scope>
55
		</dependency>
56
		<dependency>
57
            <groupId>org.gvsig</groupId>
58
            <artifactId>org.gvsig.fmap.dal</artifactId>
59
            <scope>compile</scope>
60
        </dependency>
61
        <dependency>
62
            <groupId>org.gvsig</groupId>
63
            <artifactId>org.gvsig.fmap.dal</artifactId>
64
            <classifier>spi</classifier>
65
            <scope>compile</scope>
66
        </dependency>
67
        <dependency>
68
            <groupId>org.gvsig</groupId>
69
            <artifactId>org.gvsig.fmap.mapcontext</artifactId>
70
            <scope>compile</scope>
71
        </dependency>
72
         <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.fmap.control</artifactId>
75
            <scope>compile</scope>
76
        </dependency>
77
        <dependency>
78
            <groupId>org.gvsig</groupId>
79
            <artifactId>org.gvsig.projection</artifactId>
80
            <scope>compile</scope>
81
        </dependency>
82
         <dependency>
83
            <groupId>org.gvsig</groupId>
84
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
85
            <scope>compile</scope>
86
        </dependency>
87
	</dependencies>
88
	<profiles>
89
		<profile>
90
			<id>gvsig-install</id>
91
			<activation>
92
				<activeByDefault>true</activeByDefault>
93
			</activation>
94
			<properties>
95
				<gvsig.install.dir>${basedir}/../../build/product</gvsig.install.dir>
96
				<package.info.baseDownloadURL>http://devel.gvsig.org/download/projects/Raster/pool/org.gvsig.raster.tools.app.reproject</package.info.baseDownloadURL>
97
        		<package.info.dependencies>required: org.gvsig.raster.tilecache.app -ge 2, required: org.gvsig.raster.tools.app.basic -ge 2</package.info.dependencies>
98
        		<package.info.categories>Raster</package.info.categories>
99
			</properties>
100
		</profile>
101
	</profiles>
102
</project>
0 103

  

Also available in: Unified diff