Revision 554

View differences:

org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.reproject/src/main/java/org/gvsig/geoprocess/algorithm/reproject/ReprojectParametersPanel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.geoprocess.algorithm.reproject;
25

  
26
import java.awt.Dimension;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.awt.Insets;
30
import java.awt.event.ActionEvent;
31
import java.awt.event.ActionListener;
32

  
33
import javax.swing.ComboBoxModel;
34
import javax.swing.DefaultComboBoxModel;
35
import javax.swing.JCheckBox;
36
import javax.swing.JComboBox;
37
import javax.swing.JLabel;
38
import javax.swing.JPanel;
39

  
40
import org.cresques.cts.IProjection;
41
import org.gvsig.app.gui.panels.CRSSelectPanel;
42
import org.gvsig.fmap.crs.CRSFactory;
43
import org.gvsig.geoprocess.lib.api.GeoProcessLocator;
44
import org.gvsig.geoprocess.sextante.gui.algorithm.AlgorithmOutputPanel;
45

  
46
import es.unex.sextante.core.GeoAlgorithm;
47
import es.unex.sextante.core.ObjectAndDescription;
48
import es.unex.sextante.core.OutputObjectsSet;
49
import es.unex.sextante.core.ParametersSet;
50
import es.unex.sextante.core.Sextante;
51
import es.unex.sextante.dataObjects.IVectorLayer;
52
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
53
import es.unex.sextante.gui.algorithm.OutputChannelSelectionPanel;
54
import es.unex.sextante.gui.core.SextanteGUI;
55
import es.unex.sextante.outputs.Output;
56

  
57
/**
58
 * Panel for reproject algorithm
59
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
60
 */
61
public class ReprojectParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener {
62
	private static final long                serialVersionUID       = 1L;
63
	private GeoAlgorithm                     m_Algorithm            = null;
64
	private JComboBox                        layersCombo            = null;
65
	private JCheckBox                        selectionOnly          = null;
66
	//private AlgorithmOutputPanel             output                 = null;
67
	private JLabel                           projLabel              = null;
68
	private CRSSelectPanel                   projectionSrcSelector  = null;
69
	private IProjection                      targetLayerProjection  = null;
70
	private AlgorithmOutputPanel             algorithmOutputPanel   = null;
71
	private OutputChannelSelectionPanel      outputChannelSelectionPanelPol;
72
	private OutputChannelSelectionPanel      outputChannelSelectionPanelLine;
73
	private OutputChannelSelectionPanel      outputChannelSelectionPanelPoint;
74
	private JPanel                           outputPanel;
75
	
76
	public ReprojectParametersPanel() {
77
		super();
78
	}
79

  
80
    public void init(GeoAlgorithm algorithm) {
81
    	m_Algorithm = algorithm;
82
    	initGUI();
83
    	init();
84
    }
85

  
86
	private void initGUI() {
87
		GridBagLayout gbl = new GridBagLayout();
88
		this.setLayout(gbl);
89
		
90
		GridBagConstraints gbc = new GridBagConstraints();
91
		gbc.fill = GridBagConstraints.HORIZONTAL;
92
		gbc.weightx = 1.0;
93
		gbc.gridx = 0;
94
		gbc.gridy = 0;
95
		gbc.insets = new Insets(15, 5, 15, 0);
96
		this.add(getComboPanel(GeoProcessLocator.getGeoProcessManager().getTranslation("Input_layer"), getLayersCombo()), gbc);
97
		
98
		gbc.gridy = 1;
99
		gbc.insets = new Insets(0, 5, 15, 0);
100
		this.add(getSelectionCheck(), gbc);
101
		
102
		gbc.gridy = 2;
103
		this.add(getCurrentProjLabel(), gbc);
104
		
105
		gbc.gridy = 3;
106
		this.add(getProjectionSelector(), gbc);
107
		
108
		gbc.gridy = 4;
109
		gbc.fill = GridBagConstraints.BOTH;
110
		gbc.weighty = 1.0;
111
		gbc.weightx = 1.0;
112
		this.add(new JPanel(), gbc);
113
		
114
		gbc.gridy = 5;
115
		gbc.fill = GridBagConstraints.HORIZONTAL;
116
		gbc.weighty = 0.0;
117
		this.add(getOutputChannelSelectionPanel(), gbc);
118
	}
119
	
120
	/**
121
	 * Gets the output panel (SEXTANTE)
122
	 * @return
123
	 */
124
	private JPanel getOutputChannelSelectionPanel() {
125
		if(outputPanel == null) {
126
			try {
127
				outputPanel = new JPanel();
128
				outputPanel.setLayout(new GridBagLayout());
129
				
130
				final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
131
				final Output out_pol = ooSet.getOutput(ReprojectAlgorithm.RESULT_POL);
132
				final Output out_line = ooSet.getOutput(ReprojectAlgorithm.RESULT_LINE);
133
				final Output out_point = ooSet.getOutput(ReprojectAlgorithm.RESULT_POINT);
134
				
135
				outputChannelSelectionPanelPol = new OutputChannelSelectionPanel(out_pol, m_Algorithm.getParameters());
136
				outputChannelSelectionPanelLine = new OutputChannelSelectionPanel(out_line, m_Algorithm.getParameters());
137
				outputChannelSelectionPanelPoint = new OutputChannelSelectionPanel(out_point, m_Algorithm.getParameters());
138
				
139
				String label = GeoProcessLocator.getGeoProcessManager().getTranslation("Reproject");
140
				
141
				GridBagConstraints gbc = new GridBagConstraints();
142
				gbc.fill = GridBagConstraints.HORIZONTAL;
143
				gbc.insets = new Insets(0, 0, 4, 0);
144
				gbc.weightx = 1;
145
				gbc.gridx = 0;
146
				gbc.gridy = 0;
147
				outputPanel.add(new JLabel(" " + label + " [Polygon]               "), gbc);
148
				
149
				gbc.gridx = 0;
150
				gbc.gridy = 1;
151
				outputPanel.add(new JLabel(" " + label + " [Line]               "), gbc);
152
				
153
				gbc.gridx = 0;
154
				gbc.gridy = 2;
155
				outputPanel.add(new JLabel(" " + label + " [Point]               "), gbc);
156
				
157
				gbc.fill = GridBagConstraints.HORIZONTAL;
158
				gbc.weightx = 1;
159
				gbc.gridx = 1;
160
				gbc.gridy = 0;
161
				outputPanel.add(outputChannelSelectionPanelPol, gbc);
162
				
163
				gbc.gridx = 1;
164
				gbc.gridy = 1;
165
				outputPanel.add(outputChannelSelectionPanelLine, gbc);
166
				
167
				gbc.gridx = 1;
168
				gbc.gridy = 2;
169
				outputPanel.add(outputChannelSelectionPanelPoint, gbc);
170
			} catch (final Exception e) {
171
				Sextante.addErrorToLog(e);
172
			}
173
		}
174
		return outputPanel;
175
	}
176
	
177
	/**
178
	 * Gets the output panel (DAL)
179
	 * @return
180
	 */
181
	@SuppressWarnings("unused")
182
	private AlgorithmOutputPanel getAlgorithmOutputPanel() {
183
		if(algorithmOutputPanel == null)
184
		    algorithmOutputPanel = new AlgorithmOutputPanel();
185
		return algorithmOutputPanel;
186
	}
187
	
188
	/**
189
	 * Gets a new JPanel with the text and JComboBox 
190
	 * @param text
191
	 * @param combo
192
	 * @return
193
	 */
194
	public JPanel getComboPanel(String text, JComboBox combo) {
195
		JPanel panel = new JPanel();
196
		GridBagLayout gbl = new GridBagLayout();
197
		panel.setLayout(gbl);
198

  
199
		GridBagConstraints gbc = new GridBagConstraints();
200
		gbc.fill = GridBagConstraints.NONE;
201
		gbc.weightx = 0;
202
		gbc.gridx = 0;
203
		gbc.insets = new Insets(0, 2, 0, 50);
204
		JLabel label = new JLabel(text);
205
		label.setPreferredSize(new Dimension(180, 18));
206
		panel.add(label, gbc);
207

  
208
		gbc.fill = GridBagConstraints.HORIZONTAL;
209
		gbc.weightx = 1.0;
210
		gbc.gridx = 1;
211
		gbc.anchor = GridBagConstraints.EAST;
212
		gbc.insets = new Insets(0, 2, 0, 0);
213
		panel.add(combo, gbc);
214
		return panel;
215
	}
216
	
217
	/**
218
	 * Gets a ComboBox
219
	 * @return
220
	 */
221
	public JComboBox getLayersCombo() {
222
		if(layersCombo == null) {
223
			layersCombo = new JComboBox();
224
			layersCombo.setPreferredSize(new Dimension(0, 18));
225
			ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList());
226
			layersCombo.setModel(comboModel);
227
			layersCombo.addActionListener(this);
228
		}
229
		return layersCombo;
230
	}
231
	
232
	
233
	/**
234
	 * Gets a CheckBox
235
	 * @return
236
	 */
237
	public JCheckBox getSelectionCheck() {
238
		if(selectionOnly == null) {
239
			selectionOnly = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Selected_geometries"));
240
		}
241
		return selectionOnly;
242
	}
243
	
244
	/**
245
	 * Panel with the projection selector
246
	 * @return
247
	 */
248
	private CRSSelectPanel getProjectionSelector() {
249
		if (projectionSrcSelector == null) {
250
			targetLayerProjection = CRSFactory.getCRS("EPSG:23030");
251
			projectionSrcSelector = CRSSelectPanel.getPanel(targetLayerProjection);
252
			projectionSrcSelector.getJLabel().setText(GeoProcessLocator.getGeoProcessManager().getTranslation("Proyeccion_Destino"));
253
			projectionSrcSelector.setPreferredSize(new java.awt.Dimension(330,35));
254
			projectionSrcSelector.addActionListener(new java.awt.event.ActionListener() {
255
				public void actionPerformed(java.awt.event.ActionEvent e) {
256
					if (projectionSrcSelector.isOkPressed()) {
257
						targetLayerProjection = projectionSrcSelector.getCurProj();
258
					}
259
				}
260
			});
261
		}
262
		projectionSrcSelector.setTransPanelActive(true);
263
		return projectionSrcSelector;
264
	}
265
	
266
	/**
267
	 * Gets the label with the current projection
268
	 * @return
269
	 */
270
	public JLabel getCurrentProjLabel() {
271
		if(projLabel == null)
272
			projLabel = new JLabel();
273
		return projLabel;
274
	}
275
	
276
	//------------------------------------------------------------
277
	
278
	/**
279
	 * Initialize actions
280
	 */
281
	private void init() {
282
		IVectorLayer layer = getSelectedVectorLayer();
283
		IProjection currentProj = (IProjection)layer.getCRS();
284
		getCurrentProjLabel().setText("Proj: " + currentProj.getAbrev());
285
	}
286
	
287
	/*
288
	 * (non-Javadoc)
289
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
290
	 */
291
	public void actionPerformed(ActionEvent e) {
292
		if(e.getSource() ==  getLayersCombo()) {
293
			init();
294
		}
295
	}
296
	
297
	@Override
298
    public void assignParameters() {
299
		try {
300
			ParametersSet params = m_Algorithm.getParameters();
301
			params.getParameter(ReprojectAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer());
302
			params.getParameter(ReprojectAlgorithm.SELECTED_GEOM).setParameterValue(getSelectionCheck().isSelected());
303
			String proj = getProjectionSelector().getCurProj().getFullCode();
304
			params.getParameter(ReprojectAlgorithm.DST_PROJECTION).setParameterValue(proj);
305
			
306
			OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
307
			Output outPol = ooSet.getOutput(ReprojectAlgorithm.RESULT_POL);
308
			Output outLine = ooSet.getOutput(ReprojectAlgorithm.RESULT_LINE);
309
			Output outPoint = ooSet.getOutput(ReprojectAlgorithm.RESULT_POINT);
310
			
311
			//Reponer estas l?neas para cambiar el panel de salida y comentar la siguiente
312
			//out.setOutputChannel(new CompositeSourceOutputChannel(getAlgorithmOutputPanel().getOutputParameters()));
313
			outPol.setOutputChannel(outputChannelSelectionPanelPol.getOutputChannel());
314
			outLine.setOutputChannel(outputChannelSelectionPanelLine.getOutputChannel());
315
			outPoint.setOutputChannel(outputChannelSelectionPanelPoint.getOutputChannel());
316
		} catch (Exception e) {
317
			Sextante.addErrorToLog(e);
318
		}
319
	}
320

  
321
	@Override
322
	public void setOutputValue(String arg0, String arg1) {
323
		
324
	}
325

  
326
	@Override
327
	public void setParameterValue(String arg0, String arg1) {
328
		
329
	}
330
	
331
	/**
332
	 * Gets the input layer list
333
	 * @return
334
	 */
335
	private ObjectAndDescription[] getLayerList() {
336
		IVectorLayer[] layers = SextanteGUI.getInputFactory()
337
					.getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG);
338
		ObjectAndDescription[] oad = new ObjectAndDescription[layers.length];
339
		for (int i = 0; i < layers.length; i++)
340
			oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
341
		return oad;
342
	}
343
	
344
	/**
345
	 * Gets the selected vector layer in the JComboBox
346
	 * @return
347
	 */
348
	private IVectorLayer getSelectedVectorLayer() {
349
		if(layersCombo.getSelectedItem() != null)
350
			return (IVectorLayer)((ObjectAndDescription)layersCombo.getSelectedItem()).getObject();
351
		return null;
352
	}
353
	
354
	/**
355
	 * Gets the field list of the selected layer
356
	 * @return
357
	 */
358
	public String[] getFieldList() {
359
		IVectorLayer layer = getSelectedVectorLayer();
360
		String[] data = new String[layer.getFieldCount()];
361
		for (int i = 0; i < layer.getFieldCount(); i++) 
362
			data[i] = layer.getFieldName(i);
363
		return data;
364
	}
365
}
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.reproject/src/main/java/org/gvsig/geoprocess/algorithm/reproject/ReprojectLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.geoprocess.algorithm.reproject;
25

  
26
import org.gvsig.geoprocess.algorithm.base.core.AlgorithmAbstractLibrary;
27
import org.gvsig.i18n.Messages;
28
import org.gvsig.tools.library.LibraryException;
29

  
30
/**
31
 * Initialization of ReprojectLibrary library.
32
 * 
33
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
34
 */
35
public class ReprojectLibrary extends AlgorithmAbstractLibrary {
36

  
37
    @Override
38
    protected void doInitialize() throws LibraryException {
39

  
40
    }
41

  
42
    @Override
43
    protected void doPostInitialize() throws LibraryException {
44
        Messages.addResourceFamily(
45
            "org.gvsig.geoprocess.algorithm.reproject.reproject",
46
            ReprojectLibrary.class.getClassLoader(), ReprojectLibrary.class
47
                .getClass().getName());
48
        registerGeoProcess(new ReprojectAlgorithm());
49
    }
50

  
51
}
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.reproject/src/main/java/org/gvsig/geoprocess/algorithm/reproject/ReprojectAlgorithm.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.geoprocess.algorithm.reproject;
25

  
26
import org.cresques.cts.IProjection;
27
import org.gvsig.fmap.crs.CRSFactory;
28
import org.gvsig.fmap.dal.exception.DataException;
29
import org.gvsig.fmap.dal.feature.FeatureSet;
30
import org.gvsig.fmap.dal.feature.FeatureStore;
31
import org.gvsig.fmap.dal.feature.FeatureType;
32
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
33
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
34

  
35
import es.unex.sextante.core.Sextante;
36
import es.unex.sextante.dataObjects.IVectorLayer;
37
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
38
import es.unex.sextante.exceptions.RepeatedParameterNameException;
39
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
40
import es.unex.sextante.outputs.OutputVectorLayer;
41

  
42
/**
43
 * Reproject algorithm
44
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
45
 */
46
public class ReprojectAlgorithm extends AbstractSextanteGeoProcess {
47
	public static final String        RESULT_POL        = "RESULT_POL";
48
	public static final String        RESULT_POINT      = "RESULT_POINT";
49
	public static final String        RESULT_LINE       = "RESULT_LINE";
50
	public static final String        LAYER             = "LAYER";
51
	public static final String        SELECTED_GEOM     = "SELECTED_GEOM";
52
	public static final String        DST_PROJECTION    = "DST_PROJECTION";
53
	
54
	/*
55
	 * (non-Javadoc)
56
	 * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
57
	 */
58
	public void defineCharacteristics() {
59
        setName(getTranslation("Reproject"));
60
        setGroup(getTranslation("basic_vect_algorithms"));
61
        // setGeneratesUserDefinedRasterOutput(false);
62
		
63
		try {
64
			m_Parameters.addInputVectorLayer(LAYER, 
65
                getTranslation("Input_layer"),
66
												IVectorLayer.SHAPE_TYPE_WRONG, 
67
												true);
68
			m_Parameters.addBoolean(SELECTED_GEOM, 
69
                getTranslation("Selected_geometries"),
70
									false);
71
            m_Parameters
72
                .addString(DST_PROJECTION, getTranslation("Projection"));
73
            
74
            addOutputVectorLayer(RESULT_POL, getTranslation("Reproject_polygon"),
75
					OutputVectorLayer.SHAPE_TYPE_POLYGON);
76
			addOutputVectorLayer(RESULT_LINE, getTranslation("Reproject_line"),
77
					OutputVectorLayer.SHAPE_TYPE_LINE);
78
			addOutputVectorLayer(RESULT_POINT, getTranslation("Reproject_point"),
79
					OutputVectorLayer.SHAPE_TYPE_POINT);
80
			
81
		} catch (RepeatedParameterNameException e) {
82
			Sextante.addErrorToLog(e);
83
		}
84
	}
85
	
86
	/*
87
	 * (non-Javadoc)
88
	 * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
89
	 */
90
	public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
91
		if(existsOutPutFile(RESULT_POL, 0) || 
92
			existsOutPutFile(RESULT_LINE, 0) ||
93
			existsOutPutFile(RESULT_POINT, 0)) {
94
    		throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
95
    	}
96
		IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
97
		boolean selectedGeom = m_Parameters.getParameterValueAsBoolean(SELECTED_GEOM);
98
		String dstProj = m_Parameters.getParameterValueAsString(DST_PROJECTION);
99
		
100
		FeatureStore storeLayer = null;
101
		if(layer instanceof FlyrVectIVectorLayer)
102
			storeLayer = ((FlyrVectIVectorLayer)layer).getFeatureStore();
103
		else
104
			return false;
105
		
106
		try {
107
			FeatureSet features = null;
108
			features = storeLayer.getFeatureSet();
109
			FeatureType featureType = features.getDefaultFeatureType();
110
            /*FeatureStore outFeatStore =
111
                buildOutPutStore(featureType, layer.getShapeType(),
112
                    getTranslation("Reproject"), RESULT);
113
			IProjection projOutput = CRSFactory.getCRS(dstProj);
114
			ReprojectOperation operation = new ReprojectOperation(((IProjection)layer.getCRS()), projOutput, this);
115
            operation.setTaskStatus(getStatus());
116
			operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);*/
117
			
118
			IProjection projOutput = CRSFactory.getCRS(dstProj);
119
			ReprojectOperation operation = new ReprojectOperation(((IProjection)layer.getCRS()), projOutput, this);
120
            operation.setTaskStatus(getStatus());
121
            
122
            if (isPolygon(storeLayer) || isUndefined(storeLayer)) {
123
				FeatureStore outFeatStore =
124
					buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON,
125
							getTranslation("Reproject_polygon"), RESULT_POL);
126
				operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, 
127
						selectedGeom, false, true);
128
			} else {
129
				buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON,
130
						getTranslation("Null_polygon"), RESULT_POL);
131
			}
132
			
133
			if (isLine(storeLayer) || isUndefined(storeLayer)) {
134
				FeatureStore outFeatStore =
135
					buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_LINE,
136
							getTranslation("Reproject_line"), RESULT_LINE);
137
				operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, 
138
						selectedGeom, false, true);
139
			} else {
140
				buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_LINE,
141
						getTranslation("Null_line"), RESULT_LINE);
142
			}
143
			
144
			if (isPoint(storeLayer) || isUndefined(storeLayer)) {
145
				FeatureStore outFeatStore =
146
					buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT,
147
							getTranslation("Reproject_point"), RESULT_POINT);
148
				operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, 
149
						selectedGeom, false, true);
150
			} else {
151
				buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT,
152
						getTranslation("Null_point"), RESULT_POINT);
153
			}
154
		} catch (DataException e) {
155
			Sextante.addErrorToLog(e);
156
			return false;
157
		}
158
		
159
		if(getTaskMonitor().isCanceled())
160
			return false;
161
		
162
		return true;
163
	}
164

  
165
    @Override
166
    public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() {
167
        return ReprojectParametersPanel.class;
168
    }
169
}
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.reproject/src/main/java/org/gvsig/geoprocess/algorithm/reproject/ReprojectOperation.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.geoprocess.algorithm.reproject;
25

  
26
import java.util.Iterator;
27
import java.util.List;
28

  
29
import es.unex.sextante.core.Sextante;
30

  
31
import org.cresques.cts.ICoordTrans;
32
import org.cresques.cts.IProjection;
33

  
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.feature.EditableFeature;
36
import org.gvsig.fmap.dal.feature.Feature;
37
import org.gvsig.fmap.geom.exception.CreateGeometryException;
38
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation;
39
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
40

  
41
/**
42
 * Operation to reproject a Feature
43
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
44
 */
45
public class ReprojectOperation extends GeometryOperation {
46
	private ICoordTrans                      transf           = null;
47

  
48
	public ReprojectOperation(IProjection srcProj, IProjection dstProj, AbstractSextanteGeoProcess p) {
49
		super(p);
50
		this.transf = srcProj.getCT(dstProj);
51
	}
52

  
53
	/*
54
	 * (non-Javadoc)
55
	 * @see org.gvsig.geoprocess.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.Feature)
56
	 */
57
	@SuppressWarnings("unchecked")
58
	public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature feature) {
59
		List geomList = feature.getGeometries();
60
		try {
61
			if(geomList == null) {
62
				org.gvsig.fmap.geom.Geometry geom = feature.getDefaultGeometry();
63
				geom.reProject(transf);
64
				EditableFeature editFeat = feature.getEditable();
65
				editFeat.setDefaultGeometry(geom);
66
				persister.addFeature(feature, geom);
67
			} else {
68
				Iterator<org.gvsig.fmap.geom.Geometry> itGeom = geomList.iterator();
69
				EditableFeature editFeat = null;
70
				boolean first = true;
71
				int nGeom = 0;
72
				while(itGeom.hasNext()) {
73
					org.gvsig.fmap.geom.Geometry geom = itGeom.next();
74
					geom.reProject(transf);
75
					editFeat = feature.getEditable();
76
					editFeat.setGeometry(nGeom, geom);
77
					nGeom ++;
78
					if(first) 
79
						persister.addFeature(editFeat, geom);
80
					else 
81
						persister.addGeometryToExistingFeature(editFeat, geom);
82
				}
83
			}
84
		} catch (DataException e) {
85
			Sextante.addErrorToLog(e);
86
		} catch (CreateGeometryException e) {
87
			Sextante.addErrorToLog(e);
88
		}
89
		
90
		return lastEditFeature;
91
	}
92
	
93
	@Override
94
	public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput) {
95
	}
96
}
97

  
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.reproject/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.geoprocess.algorithm.reproject.ReprojectLibrary
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.reproject/src/main/resources/org/gvsig/geoprocess/algorithm/reproject/reproject.properties
1
#
2
# gvSIG. Desktop Geographic Information System.
3
#
4
# Copyright (C) 2007-2012 gvSIG Association.
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
# For any additional information, do not hesitate to contact us
22
# at info AT gvsig.com, or visit our website www.gvsig.com.
23
#
24

  
25
basic_vect_algorithms=Capas vectoriales
26
Reproject=Reproyecci?n
27
Input_layer=Capa de entrada
28
Selected_geometries=Geometrias seleccionadas
29
Projection=Proyecci?n
30
Proyeccion_Destino=Proyecci?n destino
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.reproject/src/main/resources/org/gvsig/geoprocess/algorithm/reproject/reproject_en.properties
1
#
2
# gvSIG. Desktop Geographic Information System.
3
#
4
# Copyright (C) 2007-2012 gvSIG Association.
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
# For any additional information, do not hesitate to contact us
22
# at info AT gvsig.com, or visit our website www.gvsig.com.
23
#
24

  
25
basic_vect_algorithms=Vector layers tools
26
Reproject=Reproject
27
Input_layer=Input cover
28
Selected_geometries=Selected geometries
29
Projection=Projection
30
Proyeccion_Destino=Projection of destination
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.reproject/src/main/resources/help/ReprojectAlgorithm.xml
1
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2012 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
	<help>
28
		<element name="DESCRIPTION" text="Este geoproceso permite cambiar la proyecci&#243;n geod&#233;sica de los elementos vectoriales de la capa de entrada. Para tal f&#237;n, el usuario deber&#225; especificar la nueva proyecci&#243;n a aplicar.&#10;&#10;Este geoproceso puede ser de gran utilidad para hacer concordar cartograf&#237;as en un mismo proyecto cartograf&#237;as que se encuentran en proyecciones distintas." description="Descripci&#243;n" type="0">
29
			<image description="" file="reprojectdesc.png">
30
			</image>
31
		</element>
32
		<element name="ADDITIONAL_INFO" text="" description="Informaci&#243;n adicional" type="0">
33
		</element>
34
		<element name="EXTENSION_AUTHOR" text="Nacho Brodin" description="Algoritmo creado por" type="0">
35
		</element>
36
		<element name="HELP_AUTHOR" text="" description="Ayuda creada por" type="0">
37
		</element>
38
		<element name="USER_NOTES" text="" description="Notas de usuario" type="0">
39
		</element>
40
		<element name="LAYER" text="" description="Capa de entrada" type="3">
41
		</element>
42
		<element name="SELECTED_GEOM" text="" description="Geometrias seleccionadas" type="3">
43
		</element>
44
		<element name="DST_PROJECTION" text="" description="Proyecci&#243;n" type="3">
45
		</element>
46
		<element name="OUTPUT_DESCRIPTION" text="" description="Descripci&#243;n" type="2">
47
		</element>
48
		<element name="RESULT" text="" description="Reproyecci&#243;n" type="2">
49
		</element>
50
	</help>
51
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.reproject/src/main/resources/help/ReprojectAlgorithm_en.xml
1
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2012 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
	<help>
28
		<element name="DESCRIPTION" text="This geoprocess reproject all features of the input layer. To do that, user must specify the new projection for them.&#10;&#10;This is useful to load layers with different projections in a same project." description="Descripci&#243;n" type="0">
29
			<image description="" file="reprojectdesc.png">
30
			</image>
31
		</element>
32
		<element name="ADDITIONAL_INFO" text="" description="Informaci&#243;n adicional" type="0">
33
		</element>
34
		<element name="EXTENSION_AUTHOR" text="Nacho Brodin" description="Algoritmo creado por" type="0">
35
		</element>
36
		<element name="HELP_AUTHOR" text="" description="Ayuda creada por" type="0">
37
		</element>
38
		<element name="USER_NOTES" text="" description="Notas de usuario" type="0">
39
		</element>
40
		<element name="LAYER" text="" description="Capa de entrada" type="3">
41
		</element>
42
		<element name="SELECTED_GEOM" text="" description="Geometrias seleccionadas" type="3">
43
		</element>
44
		<element name="DST_PROJECTION" text="" description="Proyecci&#243;n" type="3">
45
		</element>
46
		<element name="OUTPUT_DESCRIPTION" text="" description="Descripci&#243;n" type="2">
47
		</element>
48
		<element name="RESULT" text="" description="Reproyecci&#243;n" type="2">
49
		</element>
50
	</help>
51
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.reproject/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<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">
3
  <modelVersion>4.0.0</modelVersion>
4
  <artifactId>org.gvsig.geoprocess.algorithm.reproject</artifactId>
5
  <packaging>jar</packaging>
6
  <name>org.gvsig.geoprocess.algorithm.reproject</name>
7
	
8
	<parent>
9
		<groupId>org.gvsig</groupId>
10
		<artifactId>org.gvsig.geoprocess.algorithm</artifactId>
11
		<version>2.2.4</version>
12
	</parent>
13
	
14
	<dependencies>
15
		<dependency>
16
		    <groupId>org.gvsig</groupId>
17
   			<artifactId>org.gvsig.geoprocess.algorithm.base</artifactId>
18
            <scope>compile</scope>
19
   		</dependency>
20
   		<!-- <dependency>
21
			<groupId>org.geotools</groupId>
22
			<artifactId>gt2-main</artifactId>
23
            <scope>compile</scope>
24
		</dependency> -->
25
	</dependencies>
26
	
27
</project>
0 28

  
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.xyshift/src/main/resources/org/gvsig/geoprocess/algorithm/xyshift/xyshift.properties
1
#
2
# gvSIG. Desktop Geographic Information System.
3
#
4
# Copyright (C) 2007-2012 gvSIG Association.
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
# For any additional information, do not hesitate to contact us
22
# at info AT gvsig.com, or visit our website www.gvsig.com.
23
#
24

  
25
basic_vect_algorithms=Capas vectoriales
26
XYShift=Desplazamiento en X e Y
27
Input_layer=Capa de entrada
28
Selected_geometries_xy=Geom. seleccionadas (Capa entrada)
29
X_traslation=Traslaci?n en X
30
Y_traslation=Traslaci?n en Y
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.xyshift/src/main/resources/org/gvsig/geoprocess/algorithm/xyshift/xyshift_en.properties
1
#
2
# gvSIG. Desktop Geographic Information System.
3
#
4
# Copyright (C) 2007-2012 gvSIG Association.
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
# For any additional information, do not hesitate to contact us
22
# at info AT gvsig.com, or visit our website www.gvsig.com.
23
#
24

  
25
basic_vect_algorithms=Vector layers tools
26
XYShift=X and Y shift
27
Input_layer=Input cover
28
Selected_geometries_xy=Selected features (Input cover)
29
X_traslation=X shift
30
Y_traslation=Y shift
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.xyshift/src/main/resources/help/XYShiftAlgorithm.xml
1
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2012 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
	<help>
28
		<element name="DESCRIPTION" text="Este geoproceso permite aplicar una transformaci&#243;n de traslaci&#243;n sobre todos los puntos de las geometr&#237;as de la capa de entrada. Para tal fin, el usuario deber&#225; especificar el desplazamiento en X y en Y a aplicar.&#10;&#10;Este geoproceso puede ser de gran utilidad para hacer concordar cartograf&#237;as procedentes de fuentes distintas, en lo que se viene a denominar por el t&#233;rmino ingl&#233;s conflation." description="Descripci&#243;n" type="0">
29
			<image description="" file="xyshiftdesc.png">
30
			</image>
31
		</element>
32
		<element name="ADDITIONAL_INFO" text="" description="Informaci&#243;n adicional" type="0">
33
		</element>
34
		<element name="EXTENSION_AUTHOR" text="Nacho Brodin" description="Algoritmo creado por" type="0">
35
		</element>
36
		<element name="HELP_AUTHOR" text="" description="Ayuda creada por" type="0">
37
		</element>
38
		<element name="USER_NOTES" text="" description="Notas de usuario" type="0">
39
		</element>
40
		<element name="LAYER" text="" description="Capa de entrada" type="3">
41
		</element>
42
		<element name="CHECK" text="" description="Geometrias seleccionadas" type="3">
43
		</element>
44
		<element name="X" text="" description="Traslaci&#243;n en X" type="3">
45
		</element>
46
		<element name="Y" text="" description="Traslaci&#243;n en Y" type="3">
47
		</element>
48
		<element name="OUTPUT_DESCRIPTION" text="" description="Descripci&#243;n" type="2">
49
		</element>
50
		<element name="RESULT" text="" description="XY-Shift" type="2">
51
		</element>
52
	</help>
53
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.xyshift/src/main/resources/help/XYShiftAlgorithm_en.xml
1
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2012 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
	<help>
28
		<element name="DESCRIPTION" text="This geoprocess applies a 2D translation transform to all points of the geometry of all the features of the input layer. To do that, user must enter x and y offsets.&#10;&#10;This is useful for conflation task, to integrate layers from different sources and cartographic technical specs" description="Descripci&#243;n" type="0">
29
			<image description="" file="xyshiftdesc.png">
30
			</image>
31
		</element>
32
		<element name="ADDITIONAL_INFO" text="" description="Informaci&#243;n adicional" type="0">
33
		</element>
34
		<element name="EXTENSION_AUTHOR" text="Nacho Brodin" description="Algoritmo creado por" type="0">
35
		</element>
36
		<element name="HELP_AUTHOR" text="" description="Ayuda creada por" type="0">
37
		</element>
38
		<element name="USER_NOTES" text="" description="Notas de usuario" type="0">
39
		</element>
40
		<element name="LAYER" text="" description="Capa de entrada" type="3">
41
		</element>
42
		<element name="CHECK" text="" description="Geometrias seleccionadas" type="3">
43
		</element>
44
		<element name="X" text="" description="Traslaci&#243;n en X" type="3">
45
		</element>
46
		<element name="Y" text="" description="Traslaci&#243;n en Y" type="3">
47
		</element>
48
		<element name="OUTPUT_DESCRIPTION" text="" description="Descripci&#243;n" type="2">
49
		</element>
50
		<element name="RESULT" text="" description="XY-Shift" type="2">
51
		</element>
52
	</help>
53
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.xyshift/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.geoprocess.algorithm.xyshift.XYShiftLibrary
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.xyshift/src/main/java/org/gvsig/geoprocess/algorithm/xyshift/XYShiftOperation.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25

  
26
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
27
 *
28
 * Copyright (C) 2010 Generalitat Valenciana.
29
 *
30
 * This program is free software; you can redistribute it and/or
31
 * modify it under the terms of the GNU General Public License
32
 * as published by the Free Software Foundation; either version 2
33
 * of the License, or (at your option) any later version.
34
 *
35
 * This program is distributed in the hope that it will be useful,
36
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38
 * GNU General Public License for more details.
39
 *
40
 * You should have received a copy of the GNU General Public License
41
 * along with this program; if not, write to the Free Software
42
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
43
 */
44

  
45
package org.gvsig.geoprocess.algorithm.xyshift;
46

  
47
import java.util.Iterator;
48
import java.util.List;
49

  
50
import org.gvsig.fmap.dal.exception.DataException;
51
import org.gvsig.fmap.dal.feature.EditableFeature;
52
import org.gvsig.fmap.dal.feature.Feature;
53
import org.gvsig.fmap.geom.Geometry;
54
import org.gvsig.fmap.geom.GeometryLocator;
55
import org.gvsig.fmap.geom.GeometryManager;
56
import org.gvsig.fmap.geom.aggregate.MultiCurve;
57
import org.gvsig.fmap.geom.aggregate.MultiPoint;
58
import org.gvsig.fmap.geom.aggregate.MultiSurface;
59
import org.gvsig.fmap.geom.exception.CreateGeometryException;
60
import org.gvsig.fmap.geom.primitive.Curve;
61
import org.gvsig.fmap.geom.primitive.GeneralPathX;
62
import org.gvsig.fmap.geom.primitive.OrientablePrimitive;
63
import org.gvsig.fmap.geom.primitive.Point;
64
import org.gvsig.fmap.geom.primitive.Surface;
65
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation;
66
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
67

  
68
import es.unex.sextante.core.Sextante;
69
/**
70
 * Translates all geometries
71
 * @author Nacho Brodin (nachobrodin@gmail.com)
72
 */
73
@SuppressWarnings("deprecation")
74
public class XYShiftOperation extends GeometryOperation {
75
	private double                           x                = 0D;
76
	private double                           y                = 0D;
77
	private GeometryManager                  geometryManager  = null;
78

  
79
	public XYShiftOperation(double x, double y, AbstractSextanteGeoProcess p) {
80
		super(p);
81
		this.x = x;
82
		this.y = y;
83
		this.geometryManager = GeometryLocator.getGeometryManager();
84
	}
85
	/*
86
	 * (non-Javadoc)
87
	 * @see org.gvsig.geoprocess.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.Feature)
88
	 */
89
	@SuppressWarnings("unchecked")
90
	public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature feature) {
91
		List geomList = feature.getGeometries();
92
		try {
93
			if(!persister.isCompatibleType(feature.getDefaultGeometry()))
94
				return lastEditFeature;
95
			
96
			if(geomList == null) {
97
				org.gvsig.fmap.geom.Geometry oldGeom = feature.getDefaultGeometry();
98
				Geometry newGeom = shiftGeometry(oldGeom);
99
				lastEditFeature = persister.addFeature(feature, newGeom);
100
			} else {
101
				Iterator<org.gvsig.fmap.geom.Geometry> itGeom = geomList.iterator();
102
				EditableFeature editFeat = null;
103
				int nGeom = 0;
104
				while(itGeom.hasNext()) {
105
					org.gvsig.fmap.geom.Geometry oldGeom = itGeom.next();
106
					Geometry newGeom = shiftGeometry(oldGeom);
107
					nGeom ++;
108
					if(editFeat == null) 
109
						editFeat = persister.addFeature(feature, newGeom);
110
					else 
111
						persister.addGeometryToExistingFeature(editFeat, newGeom);
112
					lastEditFeature = editFeat;
113
				}
114
			}
115
		} catch (DataException e) {
116
			Sextante.addErrorToLog(e);
117
		} catch (CreateGeometryException e1) {
118
			Sextante.addErrorToLog(e1);
119
		}
120
		
121
		return lastEditFeature;
122
	}
123
	
124
	/**
125
	 * Shifts all coordinates in a geometry
126
	 * @param oldGeom
127
	 * @return
128
	 * @throws CreateGeometryException
129
	 */
130
	private Geometry shiftGeometry(Geometry oldGeom) throws CreateGeometryException {
131
		if(oldGeom.getType() == Geometry.TYPES.SURFACE)
132
			return shiftSurface((Surface)oldGeom);
133
		else if(oldGeom.getType() == Geometry.TYPES.MULTISURFACE)
134
			return shiftMultiSurface((MultiSurface)oldGeom);
135
		else if(oldGeom.getType() == Geometry.TYPES.CURVE) 
136
			return shiftCurve((Curve)oldGeom);
137
		else if(oldGeom.getType() == Geometry.TYPES.MULTICURVE)
138
			return shiftMultiCurve((MultiCurve)oldGeom);
139
		else if(oldGeom.getType() == Geometry.TYPES.POINT) 
140
			return shiftPoint((Point)oldGeom);
141
		else if(oldGeom.getType() == Geometry.TYPES.MULTIPOINT)
142
			return shiftMultiPoint((MultiPoint)oldGeom);
143
		return oldGeom;
144
	}
145
	
146
	/**
147
	 * Shifts all coordinates in a surface
148
	 * @param geom
149
	 * @return
150
	 * @throws CreateGeometryException
151
	 */
152
	private Surface shiftSurface(Surface geom) throws CreateGeometryException {
153
		Surface surface = (Surface)geometryManager.create(Geometry.TYPES.SURFACE, Geometry.SUBTYPES.GEOM2D);
154
		return (Surface)shiftGeom(geom, surface);
155
	}
156
	
157
	/**
158
	 * Shifts all coordinates in a multisurface
159
	 * @param geom
160
	 * @return
161
	 * @throws CreateGeometryException
162
	 */
163
	private MultiSurface shiftMultiSurface(MultiSurface geom) throws CreateGeometryException {
164
		MultiSurface surface = (MultiSurface)geometryManager.create(Geometry.TYPES.MULTISURFACE, geom.getGeometryType().getSubType());
165
		for (int i = 0; i < geom.getPrimitivesNumber(); i++) {
166
			Surface s = geom.getSurfaceAt(i);
167
			Surface newSurface = shiftSurface(s);
168
			surface.addSurface(newSurface);
169
		}
170
		return surface;
171
	}
172
	
173
	/**
174
	 * Shifts all coordinates in a curve
175
	 * @param geom
176
	 * @return
177
	 * @throws CreateGeometryException
178
	 */
179
	private Curve shiftCurve(Curve geom) throws CreateGeometryException {
180
		Curve curve = (Curve)geometryManager.create(Geometry.TYPES.CURVE, Geometry.SUBTYPES.GEOM2D);
181
		return (Curve)shiftGeom(geom, curve);
182
	}
183
	
184
	private OrientablePrimitive shiftGeom(OrientablePrimitive src, OrientablePrimitive dst) throws CreateGeometryException {
185
		GeneralPathX gp = (GeneralPathX)src.getGeneralPath().clone();
186
		double[] pcoords = gp.getPointCoords();
187
		
188
		for (int i = 0; i < pcoords.length; i++) {
189
			if((i % 2) == 0)
190
				pcoords[i] = pcoords[i] + x;
191
			else 
192
				pcoords[i] = pcoords[i] + y;
193
		}
194
		gp.setPointCoords(pcoords);
195
		dst.setGeneralPath(gp);
196
		return dst;
197
	}
198
	
199
	/**
200
	 * Shifts all coordinates in a multicurve
201
	 * @param geom
202
	 * @return
203
	 * @throws CreateGeometryException
204
	 */
205
	private MultiCurve shiftMultiCurve(MultiCurve geom) throws CreateGeometryException {
206
		MultiCurve curve = (MultiCurve)geometryManager.create(Geometry.TYPES.MULTICURVE, geom.getGeometryType().getSubType());
207
		for (int i = 0; i < geom.getPrimitivesNumber(); i++) {
208
			Curve c = geom.getCurveAt(i);
209
			Curve newCurve = shiftCurve(c);
210
			curve.addCurve(newCurve);
211
		}
212
		return curve;
213
	}
214
	
215
	/**
216
	 * Shifts a point
217
	 * @param geom
218
	 * @return
219
	 * @throws CreateGeometryException
220
	 */
221
	private Point shiftPoint(Point geom) throws CreateGeometryException {
222
		Point point = (Point)geometryManager.create(Geometry.TYPES.POINT, geom.getGeometryType().getSubType());
223
		point.setX(geom.getX() + x);
224
		point.setY(geom.getY() + y);
225
		return point;
226
	}
227
	
228
	/**
229
	 * Shifts all coordinates in a multisurface
230
	 * @param geom
231
	 * @return
232
	 * @throws CreateGeometryException
233
	 */
234
	private MultiPoint shiftMultiPoint(MultiPoint geom) throws CreateGeometryException {
235
		MultiPoint point = (MultiPoint)geometryManager.create(Geometry.TYPES.MULTIPOINT, geom.getGeometryType().getSubType());
236
		for (int i = 0; i < geom.getPrimitivesNumber(); i++) {
237
			Point p = geom.getPointAt(i);
238
			Point newPoint = shiftPoint(p);
239
			point.addPoint(newPoint);
240
		}
241
		return point;
242
	}
243
	
244
	/*
245
	 * (non-Javadoc)
246
	 * @see org.gvsig.geoprocess.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.EditableFeature)
247
	 */
248
	public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature feature) {
249
	}
250
}
251

  
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.xyshift/src/main/java/org/gvsig/geoprocess/algorithm/xyshift/XYShiftLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.geoprocess.algorithm.xyshift;
25

  
26
import org.gvsig.geoprocess.algorithm.base.core.AlgorithmAbstractLibrary;
27
import org.gvsig.i18n.Messages;
28
import org.gvsig.tools.library.LibraryException;
29

  
30
/**
31
 * Initialization of XYShiftLibrary library.
32
 * 
33
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
34
 */
35
public class XYShiftLibrary extends AlgorithmAbstractLibrary {
36

  
37
    @Override
38
    protected void doInitialize() throws LibraryException {
39
        // Nothing to do
40
    }
41

  
42
    @Override
43
    protected void doPostInitialize() throws LibraryException {
44
        Messages.addResourceFamily(
45
            "org.gvsig.geoprocess.algorithm.xyshift.xyshift",
46
            XYShiftLibrary.class.getClassLoader(), XYShiftLibrary.class
47
                .getClass().getName());
48
        registerGeoProcess(new XYShiftAlgorithm());
49
    }
50

  
51
}
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.4/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.xyshift/src/main/java/org/gvsig/geoprocess/algorithm/xyshift/XYShiftAlgorithm.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.geoprocess.algorithm.xyshift;
25

  
26
import org.gvsig.fmap.dal.exception.DataException;
27
import org.gvsig.fmap.dal.feature.FeatureSet;
28
import org.gvsig.fmap.dal.feature.FeatureStore;
29
import org.gvsig.fmap.dal.feature.FeatureType;
30
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation;
31
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
32
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
33

  
34
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff