gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.algorithm / org.gvsig.sextante.app.algorithm.xyshift / src / main / java / org / gvsig / sextante / app / algorithm / xyshift / XYShiftAlgorithm.java @ 46
History | View | Annotate | Download (4.71 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2010 Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
*/
|
21 |
package org.gvsig.sextante.app.algorithm.xyshift; |
22 |
|
23 |
import org.gvsig.fmap.dal.exception.DataException; |
24 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
25 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
26 |
import org.gvsig.fmap.dal.feature.FeatureType; |
27 |
import org.gvsig.sextante.app.algorithm.base.core.GeometryOperation; |
28 |
import org.gvsig.sextante.app.algorithm.base.core.IProgressModel; |
29 |
import org.gvsig.sextante.app.extension.core.gvGeoAlgorithm; |
30 |
import org.gvsig.sextante.app.extension.core.gvVectorLayer; |
31 |
|
32 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
33 |
import es.unex.sextante.core.Sextante; |
34 |
import es.unex.sextante.dataObjects.IVectorLayer; |
35 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
36 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
37 |
import es.unex.sextante.outputs.OutputVectorLayer; |
38 |
|
39 |
/**
|
40 |
* XYShift algorithm
|
41 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
42 |
*/
|
43 |
public class XYShiftAlgorithm extends gvGeoAlgorithm implements IProgressModel { |
44 |
public static final String RESULT = "RESULT"; |
45 |
public static final String LAYER = "LAYER"; |
46 |
public static final String CHECK = "CHECK"; |
47 |
public static final String X = "X"; |
48 |
public static final String Y = "Y"; |
49 |
private int nSteps = 0; |
50 |
|
51 |
/*
|
52 |
* (non-Javadoc)
|
53 |
* @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
|
54 |
*/
|
55 |
public void defineCharacteristics(){ |
56 |
setName(Sextante.getText("XYShift"));
|
57 |
setGroup(Sextante.getText("gvSIG_Algorithms"));
|
58 |
setGeneratesUserDefinedRasterOutput(false);
|
59 |
|
60 |
try {
|
61 |
m_Parameters.addInputVectorLayer(LAYER, |
62 |
Sextante.getText("Input_layer"),
|
63 |
IVectorLayer.SHAPE_TYPE_WRONG, |
64 |
true);
|
65 |
m_Parameters.addBoolean(CHECK, Sextante.getText("Selected_geometries"), false); |
66 |
m_Parameters.addNumericalValue(X, Sextante.getText("X_traslation"), 0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE); |
67 |
m_Parameters.addNumericalValue(Y, Sextante.getText("Y_traslation"), 0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE); |
68 |
} catch (RepeatedParameterNameException e) {
|
69 |
Sextante.addErrorToLog(e); |
70 |
} |
71 |
addOutputVectorLayer(RESULT, |
72 |
Sextante.getText("Difference"),
|
73 |
OutputVectorLayer.SHAPE_TYPE_UNDEFINED); |
74 |
} |
75 |
|
76 |
/*
|
77 |
* (non-Javadoc)
|
78 |
* @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
|
79 |
*/
|
80 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
81 |
IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
82 |
boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
|
83 |
double x = m_Parameters.getParameterValueAsDouble(X);
|
84 |
double y = m_Parameters.getParameterValueAsDouble(Y);
|
85 |
|
86 |
FeatureStore storeLayer = null;
|
87 |
if(layer instanceof gvVectorLayer) |
88 |
storeLayer = ((gvVectorLayer)layer).getFeatureStore(); |
89 |
else
|
90 |
return false; |
91 |
|
92 |
try {
|
93 |
FeatureSet features = null;
|
94 |
features = storeLayer.getFeatureSet(); |
95 |
FeatureType featureType = features.getDefaultFeatureType(); |
96 |
FeatureStore outFeatStore = buildOutPutStore(featureType, layer.getShapeType(), Sextante.getText("XYShift"), RESULT);
|
97 |
|
98 |
GeometryOperation operation = new XYShiftOperation(x, y);
|
99 |
operation.setProgressModel(this);
|
100 |
operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
|
101 |
} catch (DataException e) {
|
102 |
Sextante.addErrorToLog(e); |
103 |
return false; |
104 |
} |
105 |
|
106 |
return true; |
107 |
} |
108 |
|
109 |
/*
|
110 |
* (non-Javadoc)
|
111 |
* @see org.gvsig.sextante.app.algorithm.base.core.IProgressAdapter#setProgress(int)
|
112 |
*/
|
113 |
public void setProgress(int iStep) { |
114 |
super.setProgress(iStep, nSteps);
|
115 |
} |
116 |
|
117 |
/*
|
118 |
* (non-Javadoc)
|
119 |
* @see org.gvsig.sextante.app.algorithm.base.core.IProgressAdapter#setTotalNumberOfSteps(int)
|
120 |
*/
|
121 |
public void setTotalNumberOfSteps(int nSteps) { |
122 |
this.nSteps = nSteps;
|
123 |
} |
124 |
|
125 |
} |