Revision 2407

View differences:

org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/test/org/gvsig/raster/algorithm/reproject/TestReprojectPanel.java
1
package org.gvsig.raster.algorithm.reproject;
2

  
3

  
4
import java.util.ArrayList;
5
import java.util.List;
6

  
7
import javax.swing.JFrame;
8

  
9
import org.cresques.cts.IProjection;
10
import org.gvsig.raster.swing.newlayer.FileNameManagement;
11
import org.gvsig.raster.reproject.algorithm.swing.impl.reproject.RasterReprojectPanelImpl;
12
import org.gvsig.raster.reproject.algorithm.swing.reproject.ReprojectPanelDataModel;
13
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
14

  
15
public class TestReprojectPanel implements FileNameManagement, ReprojectPanelDataModel {
16
		private int                              w        = 360;
17
		private int                              h        = 600;
18
		private JFrame                           frame    = new JFrame();
19
		private RasterReprojectPanelImpl         ui       = null;
20
		private int[]                            size     = new int[]{1000, 1500};
21

  
22
		public TestReprojectPanel() {
23
			new DefaultLibrariesInitializer().fullInitialize(true);
24
			ui = new RasterReprojectPanelImpl(this, this);
25
			frame.getContentPane().add(ui);
26
			frame.setSize(w, h);
27
			frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
28
			frame.setVisible(true);
29
		}
30

  
31
		public static void main(String[] args) {
32
			new TestReprojectPanel();
33
		}
34

  
35
		public ArrayList<String> getPrefixSupported() {
36
			ArrayList<String> s = new ArrayList<String>();
37
			s.add("tif");
38
			s.add("ecw");
39
			return s;
40
		}
41

  
42
		public String getUniqueLayerName() {
43
			return "capa uno";
44
		}
45

  
46
		public void usesUniqueLayerName() {
47
			// TODO Auto-generated method stub
48
			
49
		}
50

  
51
		public String getDefaultFilePath() {
52
			return "/tmp/prueba.tif";
53
		}
54

  
55
		public double getCellSize() {
56
			return 0.5;
57
		}
58

  
59
		public IProjection getDstProjection() {
60
			// TODO Auto-generated method stub
61
			return null;
62
		}
63

  
64
		public List<String> getInterpolationMethodList() {
65
			ArrayList<String> s = new ArrayList<String>();
66
			s.add("interp1");
67
			s.add("interp2");
68
			return s;
69
		}
70

  
71
		public int getInterpolationMethodSelected() {
72
			return 1;
73
		}
74

  
75
		public String getLayerName() {
76
			return "My Layer";
77
		}
78

  
79
		public int[] getSize() {
80
			return size;
81
		}
82

  
83
		public IProjection getSrcProjection() {
84
			return null;
85
		}
86

  
87
		public void setCellSize(double cellSize) {
88
			setSize((int)(cellSize * 100), (int)(cellSize * 200));
89
		}
90

  
91
		public void setDstProjection(IProjection dst) {
92
			// TODO Auto-generated method stub
93
			
94
		}
95

  
96
		public void setInterpolationMethodList(List<String> list) {
97
			// TODO Auto-generated method stub
98
			
99
		}
100

  
101
		public void setInterpolationMethodSelected(int method) {
102
			// TODO Auto-generated method stub
103
			
104
		}
105

  
106
		public void setLayerName(String s) {
107
			// TODO Auto-generated method stub
108
			
109
		}
110

  
111
		public void setSize(int w, int h) {
112
			size[0] = w;
113
			size[1] = h;
114
		}
115

  
116
		public void setSrcProjection(IProjection src) {
117
			// TODO Auto-generated method stub
118
			
119
		}
120
	}
0 121

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.reproject.algorithm.RasterReprojectionAlgorithmLibrary
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/resources/org/gvsig/raster/reproject/algorithm/i18n/text.properties
1
reprojection
2
origen=Origen
3
dest_proj=CRS de destino
4
src_proj=CRS de origen
5
interpolation=Interpolaci?n
6
yes=Si
7
no=No
8
sizex=Ancho
9
sizey=Alto
10
cellsize=Tama?o de celda
11
output_options=Opciones
12
value=Valor
13
layer=Capa
0 14

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/resources/org/gvsig/raster/reproject/algorithm/i18n/text_en.properties
1
origen=Source
2
dest_proj=CRS of destination
3
src_proj=CRS source
4
interpolation=Interpolation
5
yes=Yes
6
no=No
7
sizex=Width
8
sizey=Height
9
cellsize=Cell size
10
output_options=Options
11
value=Value
12
layer=Layer
0 13

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/java/org/gvsig/raster/reproject/algorithm/swing/api/RasterReprojectionSwingManager.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.reproject.algorithm.swing.api;
23

  
24

  
25

  
26
/**
27
 * This class is responsible of the management of the library's swing user
28
 * interface. It is the swing library's main entry point, and provides all the
29
 * services to manage library swing components.
30
 * 
31
 * @see JValidationServicePanel
32
 * @author gvSIG team
33
 * @version $Id$
34
 */
35
public interface RasterReprojectionSwingManager {
36
	/**
37
	 * Creates a new panel to reproject a raster layer
38
	 * @param fileNameManagement
39
	 * @param dataModel
40
	 * @return
41
	 */
42
	public RasterReprojectionPanel createRasterReprojectPanel(
43
			ReprojectionPanelDataModel dataModel);
44
}
0 45

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/java/org/gvsig/raster/reproject/algorithm/swing/api/ReprojectionPanelDataModel.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.reproject.algorithm.swing.api;
23

  
24
import java.util.List;
25

  
26
import org.cresques.cts.IProjection;
27

  
28
/**
29
 * Data model for the reprojection panel
30
 * @author Nacho Brodin (nachobrodin@gmail.com)
31
 */
32
public interface ReprojectionPanelDataModel {
33
	public IProjection getSrcProjection();
34
	
35
	public IProjection getDstProjection();
36
	
37
	public void setSrcProjection(IProjection src);
38
	
39
	public void setDstProjection(IProjection dst);
40
	
41
	public double getCellSize();
42
	
43
	public void setCellSize(double cellSize);
44
	
45
	public void setSize(int w, int h);
46
	
47
	public int[] getSize();
48
	
49
	public List<String> getInterpolationMethodList();
50
	
51
	public void setInterpolationMethodList(List<String> list);
52
	
53
	public int getInterpolationMethodSelected();
54
	
55
	public void setInterpolationMethodSelected(int method);
56
	
57
	public String getLayerName();
58
	
59
	public void setLayerName(String layerName);
60
}
0 61

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/java/org/gvsig/raster/reproject/algorithm/swing/api/RasterReprojectionPanel.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.reproject.algorithm.swing.api;
23

  
24
import java.awt.event.ActionListener;
25

  
26
import javax.swing.JComponent;
27

  
28
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
29

  
30
/**
31
 * Panel to reproject raster layers.
32
 * 
33
 * @author Nacho Brodin (nachobrodin@gmail.com)
34
 */
35
public interface RasterReprojectionPanel {
36
	public static final int           BUTTON_ACCEPT   = ButtonsPanel.BUTTON_ACCEPT;
37
	public static final int           BUTTON_CANCEL   = ButtonsPanel.BUTTON_CANCEL;
38
	
39
	/**
40
	 * Adds listener to buttons
41
	 * @param listener
42
	 */
43
	public void addButtonsListener(ActionListener listener);
44
	
45
	/**
46
	 * Returns the ID of the object selected. The IDs are defined as constants
47
	 * in this interface
48
	 * @param obj
49
	 * @return
50
	 */
51
	public int getObjectSelected(Object obj);
52
	
53
	public String getFileSelected();
54
	
55
	public String getDirectorySelected();
56
	
57
	public JComponent getComponent();
58
}
0 59

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/java/org/gvsig/raster/reproject/algorithm/swing/impl/InterpolationPanel.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.reproject.algorithm.swing.impl;
23

  
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29

  
30
import javax.swing.BorderFactory;
31
import javax.swing.ButtonGroup;
32
import javax.swing.JComboBox;
33
import javax.swing.JPanel;
34
import javax.swing.JRadioButton;
35

  
36
import org.cresques.Messages;
37
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
38

  
39
/**
40
 * Panel para la reproyecci?n de capas cargadas.
41
 * 
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 */
44
public class InterpolationPanel extends JPanel implements ActionListener {
45
	private static final long      serialVersionUID      = 1;
46
	private ButtonGroup            group                 = null;
47
	private JRadioButton           radioNo               = null;
48
	private JRadioButton           radioYes              = null;
49
	private JComboBox              comboInterpMethods    = null;
50
	
51
	/**
52
	 * Constructor
53
	 * @throws RasterDriverException 
54
	 */
55
	public InterpolationPanel() {
56
		init();
57
	}
58
	
59
	/**
60
	 * Inicializaci?n de los componentes gr?ficos.
61
	 * @throws RasterDriverException 
62
	 */
63
	private void init() {
64
		group = new ButtonGroup();
65
		group.add(getRadioYes());
66
		group.add(getRadioNo());
67
		
68
		setBorder(BorderFactory.createTitledBorder(Messages.getText("interpolation")));
69
		
70
		GridBagConstraints gridBagConstraints;
71
		setLayout(new GridBagLayout());
72
		gridBagConstraints = new GridBagConstraints();
73
		gridBagConstraints.fill = GridBagConstraints.BOTH;
74
		gridBagConstraints.gridx = 0;
75
		gridBagConstraints.gridy = 0;
76
		gridBagConstraints.weightx = 1.0;
77
		gridBagConstraints.insets = new Insets(0, 5, 0, 5);
78
		
79
		add(getRadioNo(), gridBagConstraints);
80
		
81
		gridBagConstraints.gridy = 1;
82
		add(getRadioYes(), gridBagConstraints);
83
		
84
		gridBagConstraints.gridy = 2;
85
		gridBagConstraints.insets = new Insets(0, 25, 0, 5);
86
		add(getComboInterpolationMethod(), gridBagConstraints);
87
	}
88

  
89
	public JRadioButton getRadioYes() {
90
		if(radioYes == null) {
91
			radioYes = new JRadioButton(Messages.getText("yes"));
92
			radioYes.setSelected(false);
93
			radioYes.addActionListener(this);
94
		}
95
		return radioYes;
96
	}
97
	
98
	public JRadioButton getRadioNo() {
99
		if(radioNo == null) {
100
			radioNo = new JRadioButton(Messages.getText("no"));
101
			radioNo.setSelected(true);
102
			radioNo.addActionListener(this);
103
		}
104
		return radioNo;
105
	}
106
	
107
	public JComboBox getComboInterpolationMethod() {
108
		if(comboInterpMethods == null) {
109
			comboInterpMethods = new JComboBox();
110
			comboInterpMethods.setEnabled(false);
111
		}
112
		return comboInterpMethods;
113
	}
114

  
115
	public void actionPerformed(ActionEvent e) {
116
		if(e.getSource() == getRadioNo()) {
117
			getComboInterpolationMethod().setEnabled(false);
118
		}
119
		if(e.getSource() == getRadioYes()) {
120
			getComboInterpolationMethod().setEnabled(true);
121
		}
122
	}
123

  
124
}
0 125

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/java/org/gvsig/raster/reproject/algorithm/swing/impl/OutputLayerOptionsPanel.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.reproject.algorithm.swing.impl;
23

  
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27

  
28
import javax.swing.BorderFactory;
29
import javax.swing.JLabel;
30
import javax.swing.JPanel;
31
import javax.swing.JTextField;
32

  
33
import org.cresques.Messages;
34
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
35

  
36
/**
37
 * Panel para la reproyecci?n de capas cargadas.
38
 * 
39
 * @author Nacho Brodin (nachobrodin@gmail.com)
40
 */
41
public class OutputLayerOptionsPanel extends JPanel {
42
	private static final long      serialVersionUID     = 1;
43
	private JTextField             textFieldCellSize    = null;
44
	private JTextField             textFieldSizeX       = null;
45
	private JTextField             textFieldSizeY       = null;
46
	private JLabel                 labelSizeX           = null;
47
	private JLabel                 labelSizeY           = null;
48
	private JLabel                 labelCellSize        = null;
49
	
50
	/**
51
	 * Constructor
52
	 * @throws RasterDriverException 
53
	 */
54
	public OutputLayerOptionsPanel() {
55
		init();
56
	}
57
	
58
	/**
59
	 * Inicializaci?n de los componentes gr?ficos.
60
	 * @throws RasterDriverException 
61
	 */
62
	private void init() {
63
		setBorder(BorderFactory.createTitledBorder(Messages.getText("output_options")));
64
		
65
		GridBagConstraints gridBagConstraints;
66
		setLayout(new GridBagLayout());
67
		gridBagConstraints = new GridBagConstraints();
68
		gridBagConstraints.fill = GridBagConstraints.BOTH;
69
		gridBagConstraints.weightx = 1.0;
70
		gridBagConstraints.insets = new Insets(0, 5, 2, 5);
71
		
72
		//FILA 0
73
		gridBagConstraints.fill = GridBagConstraints.NONE;
74
		gridBagConstraints.weightx = 0;
75
		gridBagConstraints.gridx = 0;
76
		gridBagConstraints.gridy = 0;
77
		add(getLabelCellSize(), gridBagConstraints);
78
		
79
		gridBagConstraints.fill = GridBagConstraints.BOTH;
80
		gridBagConstraints.weightx = 1.0;
81
		gridBagConstraints.gridx = 1;
82
		gridBagConstraints.gridy = 0;
83
		gridBagConstraints.gridwidth = 3;
84
		add(getTextFieldCellSize(), gridBagConstraints);
85
		gridBagConstraints.gridwidth = 1;
86
		
87
		//FILA 1
88
		gridBagConstraints.fill = GridBagConstraints.NONE;
89
		gridBagConstraints.weightx = 0;
90
		gridBagConstraints.gridx = 0;
91
		gridBagConstraints.gridy = 1;
92
		add(getLabelSizeX(), gridBagConstraints);
93
		
94
		gridBagConstraints.fill = GridBagConstraints.BOTH;
95
		gridBagConstraints.weightx = 1.0;
96
		gridBagConstraints.gridx = 1;
97
		gridBagConstraints.gridy = 1;
98
		add(getTextFieldSizeX(), gridBagConstraints);
99
		
100
		gridBagConstraints.fill = GridBagConstraints.NONE;
101
		gridBagConstraints.weightx = 0;
102
		gridBagConstraints.gridx = 2;
103
		gridBagConstraints.gridy = 1;
104
		add(getLabelSizeY(), gridBagConstraints);
105
		
106
		gridBagConstraints.fill = GridBagConstraints.BOTH;
107
		gridBagConstraints.weightx = 1.0;
108
		gridBagConstraints.gridx = 3;
109
		gridBagConstraints.gridy = 1;
110
		add(getTextFieldSizeY(), gridBagConstraints);
111
	}
112
	
113
	public JTextField getTextFieldCellSize() {
114
		if(textFieldCellSize == null)
115
			textFieldCellSize = new JTextField();
116
		return textFieldCellSize;
117
	}
118

  
119
	public JTextField getTextFieldSizeX() {
120
		if(textFieldSizeX == null) {
121
			textFieldSizeX = new JTextField();
122
			textFieldSizeX.setEditable(false);
123
		}
124
		return textFieldSizeX;
125
	}
126

  
127
	public JTextField getTextFieldSizeY() {
128
		if(textFieldSizeY == null) {
129
			textFieldSizeY = new JTextField();
130
			textFieldSizeY.setEditable(false);
131
		}
132
		return textFieldSizeY;
133
	}
134

  
135
	public JLabel getLabelSizeX() {
136
		if(labelSizeX == null)
137
			labelSizeX = new JLabel(Messages.getText("sizex"));
138
		return labelSizeX;
139
	}
140

  
141
	public JLabel getLabelSizeY() {
142
		if(labelSizeY == null)
143
			labelSizeY = new JLabel(Messages.getText("sizey"));
144
		return labelSizeY;
145
	}
146

  
147
	public JLabel getLabelCellSize() {
148
		if(labelCellSize == null)
149
			labelCellSize = new JLabel(Messages.getText("cellsize"));
150
		return labelCellSize;
151
	}
152

  
153
}
0 154

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/java/org/gvsig/raster/reproject/algorithm/swing/impl/DefaultRasterReprojectionSwingManager.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.reproject.algorithm.swing.impl;
23

  
24
import org.gvsig.raster.reproject.algorithm.swing.api.RasterReprojectionPanel;
25
import org.gvsig.raster.reproject.algorithm.swing.api.RasterReprojectionSwingManager;
26
import org.gvsig.raster.reproject.algorithm.swing.api.ReprojectionPanelDataModel;
27

  
28
/**
29
 * Default implementation of the {@link RasterReprojectionSwingManager}.
30
 * 
31
 * @author gvSIG Team
32
 * @version $Id$
33
 */
34
public class DefaultRasterReprojectionSwingManager implements RasterReprojectionSwingManager {
35

  
36
	public RasterReprojectionPanel createRasterReprojectPanel(ReprojectionPanelDataModel dataModel) {
37
		return new RasterReprojectionPanelImpl(dataModel);
38
	}
39

  
40
}
0 41

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/java/org/gvsig/raster/reproject/algorithm/swing/impl/RasterReprojectionPanelImpl.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.reproject.algorithm.swing.impl;
23

  
24
import java.awt.BorderLayout;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.awt.event.KeyEvent;
31
import java.awt.event.KeyListener;
32
import java.util.List;
33

  
34
import javax.swing.BorderFactory;
35
import javax.swing.JComponent;
36
import javax.swing.JLabel;
37
import javax.swing.JPanel;
38

  
39
import org.gvsig.app.gui.panels.CRSSelectPanel;
40
import org.gvsig.app.gui.panels.CRSSelectPanelFactory;
41
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
42
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
43
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
44
import org.gvsig.i18n.Messages;
45
import org.gvsig.raster.reproject.algorithm.swing.api.RasterReprojectionPanel;
46
import org.gvsig.raster.reproject.algorithm.swing.api.ReprojectionPanelDataModel;
47
import org.gvsig.raster.swing.RasterSwingLocator;
48
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel;
49

  
50
/**
51
 * Panel para la reproyecci๏ฟฝn de capas cargadas.
52
 * 
53
 * @author Nacho Brodin (nachobrodin@gmail.com)
54
 */
55
public class RasterReprojectionPanelImpl extends DefaultButtonsPanel implements ActionListener, RasterReprojectionPanel, KeyListener {
56
	private static final long          serialVersionUID      = -1011688195806336071L;
57
	private CRSSelectPanel             projectionSrcSelector = null;
58
	private CRSSelectPanel             projectionDstSelector = null;
59
	private InterpolationPanel         interpolationPanel    = null;
60
	private OutputLayerOptionsPanel    layerOptions          = null;
61
	private CreateNewLayerPanel        newLayerPanel         = null;
62
	private ReprojectionPanelDataModel dataModel             = null;
63
	private JLabel                     layerName             = null;
64

  
65
	/**
66
	 * Constructor
67
	 * @throws RasterDriverException 
68
	 */
69
	public RasterReprojectionPanelImpl(
70
			ReprojectionPanelDataModel dataModel) {
71
		super(ButtonsPanel.BUTTONS_ACCEPTCANCEL);
72
		this.dataModel = dataModel;
73
		init();
74
		loadPanelFromDataModel();
75
		getInterpolationPanel().getComboInterpolationMethod().addActionListener(this);
76
		getInterpolationPanel().getRadioYes().addActionListener(this);
77
		getInterpolationPanel().getRadioNo().addActionListener(this);
78
	}
79
	
80
	private void loadPanelFromDataModel() {
81
		getLayerOptionsPanel().getTextFieldCellSize().setText(dataModel.getCellSize() + "");
82
		getLayerOptionsPanel().getTextFieldSizeX().setText(dataModel.getSize()[0] + "");
83
		getLayerOptionsPanel().getTextFieldSizeY().setText(dataModel.getSize()[1] + "");
84
		getLayerName().setText("<html><b>" + dataModel.getLayerName() + "</b></html>");
85
		List<String> list = dataModel.getInterpolationMethodList();
86
		for (int i = 0; i < list.size(); i++) {
87
			getInterpolationPanel().getComboInterpolationMethod().addItem(list.get(i));	
88
		}
89
		
90
		if(dataModel.getInterpolationMethodSelected() < 0) {
91
			getInterpolationPanel().getRadioYes().setSelected(false);
92
			getInterpolationPanel().getRadioNo().setSelected(true);
93
		} else {
94
			getInterpolationPanel().getRadioYes().setSelected(true);
95
			getInterpolationPanel().getRadioNo().setSelected(false);
96
			getInterpolationPanel().getComboInterpolationMethod().setEnabled(true);
97
		}
98
	}
99
	
100
	/**
101
	 * Inicializaci๏ฟฝn de los componentes gr๏ฟฝficos.
102
	 * @throws RasterDriverException 
103
	 */
104
	private void init() {
105
		GridBagConstraints gridBagConstraints;
106

  
107
		setLayout(new GridBagLayout());
108
		
109
		int posy = 0;
110
		
111
		gridBagConstraints = new GridBagConstraints();
112
		gridBagConstraints.fill = GridBagConstraints.BOTH;
113
		gridBagConstraints.gridx = 0;
114
		gridBagConstraints.gridy = posy;
115
		gridBagConstraints.weightx = 1.0;
116
		gridBagConstraints.insets = new Insets(2, 2, 2, 2);
117
		JPanel panelFile = new JPanel();
118
		panelFile.setLayout(new BorderLayout());
119
		panelFile.setBorder(BorderFactory.createTitledBorder(Messages.getText("origen")));
120
		panelFile.add(getLayerName(), BorderLayout.CENTER);
121
		add(panelFile, gridBagConstraints);
122
		
123
		posy++;
124
		gridBagConstraints = new GridBagConstraints();
125
		gridBagConstraints.fill = GridBagConstraints.BOTH;
126
		gridBagConstraints.gridx = 0;
127
		gridBagConstraints.gridy = posy;
128
		gridBagConstraints.weightx = 1.0;
129
		gridBagConstraints.insets = new Insets(2, 2, 2, 2);
130
		add(getProjectionSrcSelector(), gridBagConstraints);
131

  
132
		posy++;
133
		gridBagConstraints = new GridBagConstraints();
134
		gridBagConstraints.fill = GridBagConstraints.BOTH;
135
		gridBagConstraints.gridx = 0;
136
		gridBagConstraints.gridy = posy;
137
		gridBagConstraints.weightx = 1.0;
138
		gridBagConstraints.insets = new Insets(2, 2, 2, 2);
139
		add(getProjectionDstSelector(), gridBagConstraints);
140
		
141
		posy++;
142
		gridBagConstraints = new GridBagConstraints();
143
		gridBagConstraints.fill = GridBagConstraints.BOTH;
144
		gridBagConstraints.gridx = 0;
145
		gridBagConstraints.gridy = posy;
146
		gridBagConstraints.weightx = 1.0;
147
		gridBagConstraints.insets = new Insets(2, 2, 2, 2);
148
		add(getInterpolationPanel(), gridBagConstraints);
149
		
150
		posy++;
151
		gridBagConstraints = new GridBagConstraints();
152
		gridBagConstraints.fill = GridBagConstraints.BOTH;
153
		gridBagConstraints.gridx = 0;
154
		gridBagConstraints.gridy = posy;
155
		gridBagConstraints.weightx = 1.0;
156
		gridBagConstraints.insets = new Insets(2, 2, 2, 2);
157
		add(getLayerOptionsPanel(), gridBagConstraints);
158
		
159
		posy++;
160
		gridBagConstraints = new GridBagConstraints();
161
		gridBagConstraints.fill = GridBagConstraints.BOTH;
162
		gridBagConstraints.gridx = 0;
163
		gridBagConstraints.gridy = posy;
164
		gridBagConstraints.weightx = 1.0;
165
		gridBagConstraints.insets = new Insets(2, 2, 2, 2);
166
		add((JComponent)getCreateNewLayerPanel(), gridBagConstraints);
167

  
168
		// Insertamos un panel vacio
169
		posy++;
170
		gridBagConstraints = new GridBagConstraints();
171
		gridBagConstraints.gridx = 0;
172
		gridBagConstraints.gridy = posy;
173
		gridBagConstraints.weighty = 1.0;
174
		gridBagConstraints.insets = new Insets(0, 0, 0, 0);
175
		JPanel emptyPanel = new JPanel();
176
		add(emptyPanel, gridBagConstraints);
177
	}
178
	
179
	private JLabel getLayerName() {
180
		if(layerName == null)
181
			layerName = new JLabel();
182
		return layerName;
183
	}
184
	
185
	public CreateNewLayerPanel getCreateNewLayerPanel() {
186
		if(newLayerPanel == null) {
187
			newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel();
188
			//newLayerPanel = new CreateNewLayerPanelImpl(fileNameManagement);
189
		}
190
		return newLayerPanel;
191
	}
192
	
193
	public InterpolationPanel getInterpolationPanel() {
194
		if(interpolationPanel == null) {
195
			interpolationPanel = new InterpolationPanel();
196
		}
197
		return interpolationPanel;
198
	}
199
	
200
	public OutputLayerOptionsPanel getLayerOptionsPanel() {
201
		if(layerOptions == null) {
202
			layerOptions = new OutputLayerOptionsPanel();
203
			layerOptions.getTextFieldCellSize().addKeyListener(this);
204
		}
205
		return layerOptions;
206
	}
207

  
208
	/**
209
	 * Obtiene el bot๏ฟฝn que lanza el panel de selecci๏ฟฝn de proyecciones.
210
	 * @return
211
	 * @throws RasterDriverException 
212
	 */
213
	private CRSSelectPanel getProjectionSrcSelector() {
214
		if (projectionSrcSelector == null) {
215
			projectionSrcSelector = CRSSelectPanelFactory.getPanel(dataModel.getSrcProjection());
216
			projectionSrcSelector.setTransPanelActive(true);
217
			projectionSrcSelector.setPreferredSize(null);
218
			projectionSrcSelector.addActionListener(new ActionListener() {
219
				public void actionPerformed(ActionEvent e) {
220
					if (projectionSrcSelector.isOkPressed()) {
221
						dataModel.setSrcProjection(projectionSrcSelector.getCurProj());
222
						try {
223
							updateSize();
224
							getLayerOptionsPanel().getTextFieldCellSize().setText(dataModel.getCellSize() + "");
225
						} catch (Exception exc) {
226
						}
227
					}
228
				}
229
			});
230
			projectionSrcSelector.setBorder(BorderFactory.createTitledBorder(Messages.getText("src_proj")));
231
		}
232
		return projectionSrcSelector;
233
	}
234
	
235
	/**
236
	 * Obtiene el bot๏ฟฝn que lanza el panel de selecci๏ฟฝn de proyecciones.
237
	 * @return
238
	 */
239
	private CRSSelectPanel getProjectionDstSelector() {
240
		if (projectionDstSelector == null) {
241
			projectionDstSelector = CRSSelectPanel.getPanel(dataModel.getDstProjection());
242
			projectionDstSelector.setTransPanelActive(true);
243
			projectionDstSelector.setPreferredSize(null);
244
			projectionDstSelector.addActionListener(new ActionListener() {
245
				public void actionPerformed(ActionEvent e) {
246
					if (projectionDstSelector.isOkPressed()) {
247
						dataModel.setDstProjection(projectionDstSelector.getCurProj());
248
						try {
249
							updateSize();
250
							getLayerOptionsPanel().getTextFieldCellSize().setText(dataModel.getCellSize() + "");
251
						} catch (Exception exc) {
252
						}
253
					}
254
				}
255
			});
256
			projectionDstSelector.setBorder(BorderFactory.createTitledBorder(Messages.getText("dest_proj")));
257
		}
258
		return projectionDstSelector;
259
	}
260

  
261
	public void keyPressed(KeyEvent e) {
262
		
263
	}
264

  
265
	public void keyReleased(KeyEvent e) {
266
		try {
267
			Double d = new Double(getLayerOptionsPanel().getTextFieldCellSize().getText());
268
			dataModel.setCellSize(d.doubleValue());
269
			updateSize();
270
		} catch (Exception exc) {
271
		}
272
	}
273

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

  
283
	public void addButtonsListener(ActionListener listener) {
284
		getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).addActionListener(listener);
285
		getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).addActionListener(listener);
286
	}
287
	
288
	public int getObjectSelected(Object obj) {
289
		if(obj == getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT))
290
			return BUTTON_ACCEPT;
291
		if(obj == getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL))
292
			return BUTTON_CANCEL;
293
		return -1;
294
	}
295
	
296
	public JComponent getComponent() {
297
		return this;
298
	}
299

  
300
	public String getFileSelected() {
301
		return getCreateNewLayerPanel().getFileSelected();
302
	}
303
	
304
	public String getDirectorySelected() {
305
		return getCreateNewLayerPanel().getDirectorySelected();
306
	}
307

  
308
	public void actionPerformed(ActionEvent e) {
309
		if(e.getSource() == getInterpolationPanel().getComboInterpolationMethod()) {
310
			dataModel.setInterpolationMethodSelected(getInterpolationPanel().getComboInterpolationMethod().getSelectedIndex());
311
		}
312
		
313
		if(e.getSource() == getInterpolationPanel().getRadioYes()) {
314
			dataModel.setInterpolationMethodSelected(getInterpolationPanel().getComboInterpolationMethod().getSelectedIndex());
315
		}
316
		
317
		if(e.getSource() == getInterpolationPanel().getRadioNo()) {
318
			dataModel.setInterpolationMethodSelected(-1);
319
		}
320
	}
321
}
0 322

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/java/org/gvsig/raster/reproject/algorithm/ReprojectException.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.reproject.algorithm;
23

  
24

  
25
/**
26
 * This exception is thrown if happen problems processing data with this algorithm.
27
 * 
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 *
30
 */
31
public class ReprojectException extends Exception {
32
	private static final long serialVersionUID = -3022090543908771484L;
33
	
34
	public ReprojectException(String msg){
35
		super(msg);
36
	}
37
	
38
	public ReprojectException(String msg, Throwable e){
39
		super(msg, e);
40
	}
41
}
0 42

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/java/org/gvsig/raster/reproject/algorithm/ReprojectProcess.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.reproject.algorithm;
23

  
24
import org.cresques.cts.IProjection;
25
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
26
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
27
import org.gvsig.i18n.Messages;
28
import org.gvsig.raster.algorithm.process.DataProcess;
29

  
30
/**
31
 * Process to reproject layers. The size of the new image and the pixel size can
32
 * be passed by parameter. If some of these values are zero everyone are calculated
33
 * automatically
34
 *
35
 * 10/12/2007
36
 * @author Nacho Brodin nachobrodin@gmail.com
37
 */
38
public class ReprojectProcess extends DataProcess {
39
	public static String[]    INTERP_METHODS  = new String[]{"Nearest", "Bilinear", "InverseDistance"};
40
	
41
	public static String      RASTER_STORE    = "RasterStore";
42
	public static String      PATH            = "Path";
43
	public static String      DST_PROJECTION  = "DST_Projection";
44
	public static String      SRC_PROJECTION  = "SRC_Projection";
45
	public static String      SIZEX           = "SizeX";
46
	public static String      SIZEY           = "SizeY";
47
	public static String      CELLSIZE        = "CellSize";
48
	public static String      FILENAME        = "FileName";
49
	public static String      INTERPOLATION   = "Interpolation";
50
	
51
	private RasterDataStore   store          = null;
52
	private String            filename       = null;
53
	private IProjection       projdst        = null;
54
	private IProjection       projsrc        = null;
55
	private Reproject         reproject      = null;
56
	private int               w              = 0;
57
	private int               h              = 0;
58
	private double            cellSize       = 0;
59
	private int               interpolation  = 0;
60
	
61
	public static void registerParameters() {
62
		registerInputParameter(RASTER_STORE, RasterDataStore.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
63
		registerInputParameter(PATH, String.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
64
		registerInputParameter(DST_PROJECTION, IProjection.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
65
		registerInputParameter(SRC_PROJECTION, IProjection.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
66
		registerInputParameter(SIZEX, Integer.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
67
		registerInputParameter(SIZEY, Integer.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
68
		registerInputParameter(CELLSIZE, Double.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
69
		registerInputParameter(INTERPOLATION, Integer.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL); 
70
		
71
		registerOutputParameter(FILENAME, String.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
72
	}
73
	
74
	public void init() {
75
		store = getParam(RASTER_STORE) != null ? (RasterDataStore)getParam(RASTER_STORE) : null;
76
		filename = getStringParam(PATH);
77
		projdst = getParam(DST_PROJECTION) != null ? (IProjection) getParam(DST_PROJECTION) : null;
78
		projsrc = getParam(SRC_PROJECTION) != null ? (IProjection) getParam(SRC_PROJECTION) : null; 
79
		w = getIntParam(SIZEX);
80
		h = getIntParam(SIZEY);
81
		cellSize = getDoubleParam(CELLSIZE);
82
		interpolation = getIntParam(INTERPOLATION);
83
	}
84
	
85
	/**
86
	 * M?todo donde se ejecutar? el Thread, aqu? se reproyecta el raster.
87
	 */
88
	public void process() throws ProcessInterruptedException {
89
		insertLineLog(Messages.getText("reprojecting"));
90
		
91
		store = store.newNotTiledDataStore();
92
		
93
		reproject = new Reproject(store, filename, interpolation, this);
94
		try {
95
			int result = reproject.warp(projdst, projsrc, w, h, cellSize);
96
			if(result != 0) {
97
				if (incrementableTask != null) {
98
					incrementableTask.processFinalize();
99
					setProgressActive(false);
100
				}
101
				messageBoxError("transformation_not_possible", this);
102
				return;
103
			}
104

  
105
			addOutputValue(FILENAME, filename);
106
		} catch (ReprojectException e) {
107
			if (incrementableTask != null)
108
				incrementableTask.processFinalize();
109
			messageBoxError("error_reprojecting", this, e);
110
		}
111
	}
112
	
113
	public String getTitle() {
114
		return Messages.getText("reprojecting");
115
	}
116
}
0 117

  
org.gvsig.raster.reproject/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.reproject.algorithm/src/main/java/org/gvsig/raster/reproject/algorithm/Reproject.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.reproject.algorithm;
23

  
24
import java.awt.geom.Point2D;
25
import java.io.File;
26

  
27
import org.cresques.cts.ICoordTrans;
28
import org.cresques.cts.IProjection;
29
import org.gvsig.fmap.dal.coverage.RasterLocator;
30
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
31
import org.gvsig.fmap.dal.coverage.dataset.BufferParam;
32
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
33
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
34
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
35
import org.gvsig.fmap.dal.coverage.exception.QueryException;
36
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
37
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
38
import org.gvsig.raster.algorithm.process.DataProcess;
39
import org.gvsig.raster.algorithm.util.Interpolation;
40

  
41

  
42
/**
43
 * Reprojects a RasterDataStore. 
44
 *
45
 * @version 30/04/2008
46
 * @author Nacho Brodin nachobrodin@gmail.com
47
 */
48
public class Reproject {
49
	private RasterDataStore   store                 = null;
50
	private String            pathDest              = null;
51
	private int               interpolationMethod   = 0;
52
	private Interpolation     interpolation         = null; 
53
	private DataProcess     process               = null;
54

  
55
	/**
56
	 * Constructor de la clase.
57
	 * @param lyr
58
	 * @param pathDest Ruta de destino
59
	 */
60
	public Reproject(RasterDataStore store, String pathDest, int inter, DataProcess process) {
61
		this.store = store;
62
		this.pathDest = pathDest;
63
		this.interpolationMethod = inter;
64
		this.process = process;
65
	}
66

  
67
	/**
68
	 * M?todo para la transformaci?n del raster.
69
	 * @param destinationSrs Proyecci?n destino
70
	 */
71
	public int warp(IProjection destinationSrs, IProjection sourceSrs, int w, int h, double cellSize) throws ReprojectException {
72
		if (store == null)
73
			throw new ReprojectException("Capa no valida.");
74
		if (!store.isReproyectable())
75
			throw new ReprojectException("Esta capa no se puede reproyectar.");
76
		if (destinationSrs == null || destinationSrs.getAbrev() == null)
77
			throw new ReprojectException("Proyecci?n de destino no valida.");
78

  
79

  
80
		File file = new File(pathDest);
81
		if (!file.getParentFile().canWrite())
82
			throw new ReprojectException("Ruta de destino no valida.");
83

  
84
		ICoordTrans transf = sourceSrs.getCT(destinationSrs);
85
		Extent bbox = store.getExtent();
86
		Point2D ul = new Point2D.Double(bbox.getULX(), bbox.getULY());
87
		Point2D lr = new Point2D.Double(bbox.getLRX(), bbox.getLRY());
88
		//Point2D p = new Point2D.Double(lyr.getFullRasterExtent().getULX(), lyr.getFullRasterExtent().getULY());
89
		ul = transf.convert(ul, ul);
90
		lr = transf.convert(lr, lr);
91
		Extent newBbox = RasterLocator.getManager().getDataStructFactory().createExtent(ul, lr);
92
		
93
		if(w <= 0 || h <= 0 ) {
94
			double[] size = getSize(bbox, newBbox);
95
			w = (int)size[0];
96
			h = (int)size[1];
97
			cellSize = size[2];
98
		}
99
		int dataType = store.getDataType()[0];
100
		BufferParam params = RasterLocator.getManager().getBufferFactory().createBufferParams(
101
				w, h, store.getBandCount(), store.getDataType()[0], true);
102
		Buffer buf = null;
103
		try {
104
			buf = RasterLocator.getManager().getBufferFactory().createBuffer(params);
105
		} catch (Exception e1) {
106
			throw new ReprojectException("Error creating the output buffer", e1);
107
		} 
108
		
109
		NoData nd = RasterLocator.getManager().getDataStructFactory().createDefaultNoData(
110
				store.getBandCount(), dataType);
111
		
112
		RasterQuery query = RasterLocator.getManager().createQuery();
113
		query.setAllDrawableBands();
114
		query.setAreaOfInterest();
115
		query.setReadOnly(true);
116
		try {
117
			ICoordTrans t = destinationSrs.getCT(sourceSrs);
118
			Buffer sourceBuffer = store.query(query);
119
			if(interpolationMethod < 0) {
120
				for (int row = 0; row < buf.getHeight(); row++) {
121
					for (int col = 0; col < buf.getWidth(); col++) {
122
						Point2D p = transformPoint(newBbox, col, row, cellSize, t);
123
						writePixel(dataType, sourceBuffer, buf, p, col, row, nd);
124
					}
125
					process.updatePercent(row, buf.getHeight());
126
				}
127
			} else {
128
				interpolation = new Interpolation(sourceBuffer);
129
				for (int row = 0; row < buf.getHeight(); row++) {
130
					for (int col = 0; col < buf.getWidth(); col++) {
131
						Point2D p = transformPoint(newBbox, col, row, cellSize, t);
132
						writePixelInterpolated(dataType, sourceBuffer, buf, p, col, row, nd, interpolationMethod);
133
					}
134
					process.updatePercent(row, buf.getHeight());
135
				}
136
			}
137
			
138
			process.exportRaster(pathDest, buf, cellSize, newBbox.getULX(), newBbox.getULY());
139
		} catch (ProcessInterruptedException e) {
140
		} catch (QueryException e) {
141
			new ReprojectException("", e);
142
		}
143
		
144
		return 0;
145
	}
146
	
147
	/**
148
	 * Writes one pixel in the destination buffer
149
	 * @param type
150
	 * @param sourceBuffer
151
	 * @param buf
152
	 * @param p
153
	 * @param col
154
	 * @param row
155
	 */
156
	private void writePixel(int type, Buffer sourceBuffer, Buffer buf, Point2D p, int col, int row, NoData nd) {
157
		if(type == Buffer.TYPE_BYTE) {
158
			if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight())
159
				for (int iBand = 0; iBand < store.getBandCount(); iBand++) {
160
					//if(iBand == 0)
161
						//System.out.println("Row:" + row + " Col:" + col + "  Y:" + (int)p.getY() + " X:" + (int)p.getX());
162
					buf.setElem(row, col, iBand, sourceBuffer.getElemByte((int)p.getY(), (int)p.getX(), iBand));
163
				}
164
			else
165
				for (int iBand = 0; iBand < store.getBandCount(); iBand++)
166
					buf.setElem(row, col, iBand, nd.getValue().byteValue());
167
		} else if(type == Buffer.TYPE_DOUBLE) {
168
			if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight())
169
				for (int iBand = 0; iBand < store.getBandCount(); iBand++)
170
					buf.setElem(row, col, iBand, sourceBuffer.getElemDouble((int)p.getY(), (int)p.getX(), iBand));
171
			else
172
				for (int iBand = 0; iBand < store.getBandCount(); iBand++)
173
					buf.setElem(row, col, iBand, nd.getValue().doubleValue());
174
		} else if(type == Buffer.TYPE_FLOAT) {
175
			if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight())
176
				for (int iBand = 0; iBand < store.getBandCount(); iBand++)
177
					buf.setElem(row, col, iBand, sourceBuffer.getElemFloat((int)p.getY(), (int)p.getX(), iBand));
178
			else
179
				for (int iBand = 0; iBand < store.getBandCount(); iBand++)
180
					buf.setElem(row, col, iBand, nd.getValue().floatValue());
181
		} else if(type == Buffer.TYPE_SHORT) {
182
			if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight())
183
				for (int iBand = 0; iBand < store.getBandCount(); iBand++)
184
					buf.setElem(row, col, iBand, sourceBuffer.getElemShort((int)p.getY(), (int)p.getX(), iBand));
185
			else
186
				for (int iBand = 0; iBand < store.getBandCount(); iBand++)
187
					buf.setElem(row, col, iBand, nd.getValue().shortValue());
188
		} else if(type == Buffer.TYPE_INT) {
189
			if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight())
190
				for (int iBand = 0; iBand < store.getBandCount(); iBand++)
191
					buf.setElem(row, col, iBand, sourceBuffer.getElemInt((int)p.getY(), (int)p.getX(), iBand));
192
			else
193
				for (int iBand = 0; iBand < store.getBandCount(); iBand++)
194
					buf.setElem(row, col, iBand, nd.getValue().intValue());
195
		} 
196
	}
197
	
198
	/**
199
	 * Writes one pixel in the destination buffer
200
	 * @param type
201
	 * @param sourceBuffer
202
	 * @param buf
203
	 * @param p
204
	 * @param col
205
	 * @param row
206
	 */
207
	private void writePixelInterpolated(int type, Buffer sourceBuffer, Buffer buf, Point2D p, int col, int row, NoData nd, int interpMethod) {
208
		double value = 0;
209
		if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight())
210
			for (int iBand = 0; iBand < store.getBandCount(); iBand++) {
211
				if(interpMethod == 0) //Nearest neighbor
212
					value = interpolation.getNearestNeighbour(p.getX(), p.getY(), iBand);
213
				if(interpMethod == 1) //Bilinear
214
					value = interpolation.getBilinearValue(p.getX(), p.getY(), iBand);
215
				if(interpMethod == 2) //Inverse distance
216
					value = interpolation.getInverseDistance(p.getX(), p.getY(), iBand);
217
				if(type == Buffer.TYPE_BYTE)
218
					buf.setElem(row, col, iBand, (byte)value);
219
				else if(type == Buffer.TYPE_DOUBLE)
220
					buf.setElem(row, col, iBand, (double)value);
221
				else if(type == Buffer.TYPE_FLOAT)
222
					buf.setElem(row, col, iBand, (float)value);
223
				else if(type == Buffer.TYPE_SHORT)
224
					buf.setElem(row, col, iBand, (short)value);
225
				else if(type == Buffer.TYPE_INT)
226
					buf.setElem(row, col, iBand, (int)value);
227
			}
228
		else
229
			for (int iBand = 0; iBand < store.getBandCount(); iBand++) {
230
				if(type == Buffer.TYPE_BYTE)
231
					buf.setElem(row, col, iBand, nd.getValue().byteValue());
232
				else if(type == Buffer.TYPE_DOUBLE)
233
					buf.setElem(row, col, iBand, nd.getValue().doubleValue());
234
				else if(type == Buffer.TYPE_FLOAT)
235
					buf.setElem(row, col, iBand, nd.getValue().floatValue());
236
				else if(type == Buffer.TYPE_SHORT)
237
					buf.setElem(row, col, iBand, nd.getValue().shortValue());
238
				else if(type == Buffer.TYPE_INT)
239
					buf.setElem(row, col, iBand, nd.getValue().intValue());
240
			}
241
	}
242
	
243
	/**
244
	 * Transforms the upper left coordinate of a pixel using the transformation 
245
	 * which is passed by parameter
246
	 * @param p
247
	 * @param newBbox
248
	 * @param col
249
	 * @param row
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff