root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vectorTools / transform / TransformAlgorithm.java @ 59
History | View | Annotate | Download (5.53 KB)
1 |
|
---|---|
2 |
|
3 |
package es.unex.sextante.vectorTools.transform; |
4 |
|
5 |
import com.vividsolutions.jts.geom.Geometry; |
6 |
import com.vividsolutions.jts.geom.util.AffineTransformation; |
7 |
|
8 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
9 |
import es.unex.sextante.additionalInfo.AdditionalInfoVectorLayer; |
10 |
import es.unex.sextante.core.GeoAlgorithm; |
11 |
import es.unex.sextante.core.Sextante; |
12 |
import es.unex.sextante.dataObjects.IFeature; |
13 |
import es.unex.sextante.dataObjects.IFeatureIterator; |
14 |
import es.unex.sextante.dataObjects.IVectorLayer; |
15 |
import es.unex.sextante.dataObjects.vectorFilters.BoundingBoxFilter; |
16 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
17 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
18 |
import es.unex.sextante.outputs.OutputVectorLayer; |
19 |
|
20 |
|
21 |
public class TransformAlgorithm |
22 |
extends
|
23 |
GeoAlgorithm { |
24 |
|
25 |
public static final String DISTANCEX = "DISTANCEX"; |
26 |
public static final String DISTANCEY = "DISTANCEY"; |
27 |
public static final String ANCHORX = "ANCHORX"; |
28 |
public static final String ANCHORY = "ANCHORY"; |
29 |
public static final String ANGLE = "ANGLE"; |
30 |
public static final String SCALEX = "SCALEX"; |
31 |
public static final String LAYER = "LAYER"; |
32 |
public static final String SCALEY = "SCALEY"; |
33 |
public static final String RESULT = "RESULT"; |
34 |
|
35 |
private IVectorLayer m_Output;
|
36 |
private double dDistanceX; |
37 |
private double dDistanceY; |
38 |
private double dAnchorX; |
39 |
private double dAnchorY; |
40 |
private double dAngle; |
41 |
private double dScaleX; |
42 |
private double dScaleY; |
43 |
IVectorLayer layerIn; |
44 |
|
45 |
|
46 |
@Override
|
47 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
48 |
|
49 |
int i;
|
50 |
|
51 |
dDistanceX = m_Parameters.getParameterValueAsDouble(DISTANCEX); |
52 |
dDistanceY = m_Parameters.getParameterValueAsDouble(DISTANCEY); |
53 |
dAnchorX = m_Parameters.getParameterValueAsDouble(ANCHORX); |
54 |
dAnchorY = m_Parameters.getParameterValueAsDouble(ANCHORY); |
55 |
dAngle = m_Parameters.getParameterValueAsDouble(ANGLE); |
56 |
dScaleX = m_Parameters.getParameterValueAsDouble(SCALEX); |
57 |
dScaleY = m_Parameters.getParameterValueAsDouble(SCALEY); |
58 |
layerIn = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
59 |
|
60 |
if (!m_bIsAutoExtent) {
|
61 |
layerIn.addFilter(new BoundingBoxFilter(m_AnalysisExtent));
|
62 |
} |
63 |
|
64 |
m_Output = getNewVectorLayer(RESULT, Sextante.getText("Capa_transformada"), layerIn.getShapeType(),
|
65 |
layerIn.getFieldTypes(), layerIn.getFieldNames()); |
66 |
|
67 |
final AffineTransformation at = new AffineTransformation(); |
68 |
at.compose(AffineTransformation.translationInstance(-dAnchorX, -dAnchorY)); |
69 |
at.compose(AffineTransformation.rotationInstance(Math.toRadians(dAngle)));
|
70 |
at.compose(AffineTransformation.translationInstance(dAnchorX, dAnchorY)); |
71 |
at.compose(AffineTransformation.scaleInstance(dScaleX, dScaleY)); |
72 |
at.compose(AffineTransformation.translationInstance(dDistanceX, dDistanceY)); |
73 |
final IFeatureIterator iter = layerIn.iterator();
|
74 |
i = 0;
|
75 |
final int iShapeCount = layerIn.getShapesCount(); |
76 |
while (iter.hasNext() && setProgress(i, iShapeCount)) {
|
77 |
final IFeature feature = iter.next();
|
78 |
final Geometry geom = (Geometry) feature.getGeometry().clone();
|
79 |
geom.apply(at); |
80 |
m_Output.addFeature(geom, feature.getRecord().getValues()); |
81 |
} |
82 |
|
83 |
return !m_Task.isCanceled();
|
84 |
|
85 |
} |
86 |
|
87 |
|
88 |
@Override
|
89 |
public void defineCharacteristics() { |
90 |
|
91 |
setName(Sextante.getText("Transform"));
|
92 |
setGroup(Sextante.getText("Tools_for_vector_layers"));
|
93 |
setUserCanDefineAnalysisExtent(true);
|
94 |
|
95 |
try {
|
96 |
m_Parameters.addInputVectorLayer(LAYER, Sextante.getText("Input_layer"), AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true); |
97 |
m_Parameters.addNumericalValue(DISTANCEX, Sextante.getText("Translation_X"),
|
98 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE, 0, Double.NEGATIVE_INFINITY, Double.MAX_VALUE); |
99 |
m_Parameters.addNumericalValue(DISTANCEY, Sextante.getText("Translation_Y"),
|
100 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE, 0, Double.NEGATIVE_INFINITY, Double.MAX_VALUE); |
101 |
m_Parameters.addNumericalValue(ANGLE, Sextante.getText("Rotation_angle"),
|
102 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE, 0, Double.NEGATIVE_INFINITY, Double.MAX_VALUE); |
103 |
m_Parameters.addNumericalValue(SCALEX, Sextante.getText("Scale_factor__X"),
|
104 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE, 1, Double.NEGATIVE_INFINITY, Double.MAX_VALUE); |
105 |
m_Parameters.addNumericalValue(SCALEY, Sextante.getText("Scale_Factor__Y"),
|
106 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE, 1, Double.NEGATIVE_INFINITY, Double.MAX_VALUE); |
107 |
m_Parameters.addNumericalValue(ANCHORX, Sextante.getText("Anchor_point_X"),
|
108 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE, 0, Double.NEGATIVE_INFINITY, Double.MAX_VALUE); |
109 |
m_Parameters.addNumericalValue(ANCHORY, Sextante.getText("Anchor_point_Y"),
|
110 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE, 0, Double.NEGATIVE_INFINITY, Double.MAX_VALUE); |
111 |
addOutputVectorLayer(RESULT, Sextante.getText("Capa_transformada"), OutputVectorLayer.SHAPE_TYPE_UNDEFINED, LAYER);
|
112 |
} |
113 |
catch (final RepeatedParameterNameException e) { |
114 |
Sextante.addErrorToLog(e); |
115 |
} |
116 |
} |
117 |
|
118 |
} |