gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.xyshift / src / main / java / org / gvsig / geoprocess / algorithm / xyshift / XYShiftAlgorithm.java @ 175
History | View | Annotate | Download (4.15 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.geoprocess.algorithm.xyshift; |
22 |
|
23 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
24 |
import es.unex.sextante.core.Sextante; |
25 |
import es.unex.sextante.dataObjects.IVectorLayer; |
26 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
27 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
28 |
import es.unex.sextante.outputs.OutputVectorLayer; |
29 |
|
30 |
import org.gvsig.fmap.dal.exception.DataException; |
31 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
32 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
33 |
import org.gvsig.fmap.dal.feature.FeatureType; |
34 |
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation; |
35 |
import org.gvsig.geoprocess.core.gvGeoAlgorithm; |
36 |
import org.gvsig.geoprocess.core.gvVectorLayer; |
37 |
|
38 |
/**
|
39 |
* XYShift algorithm
|
40 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
41 |
*/
|
42 |
public class XYShiftAlgorithm extends gvGeoAlgorithm { |
43 |
public static final String RESULT = "RESULT"; |
44 |
public static final String LAYER = "LAYER"; |
45 |
public static final String CHECK = "CHECK"; |
46 |
public static final String X = "X"; |
47 |
public static final String Y = "Y"; |
48 |
|
49 |
/*
|
50 |
* (non-Javadoc)
|
51 |
* @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
|
52 |
*/
|
53 |
public void defineCharacteristics(){ |
54 |
setName(Sextante.getText("XYShift"));
|
55 |
setGroup(Sextante.getText("gvSIG_Algorithms"));
|
56 |
// setGeneratesUserDefinedRasterOutput(false);
|
57 |
|
58 |
try {
|
59 |
m_Parameters.addInputVectorLayer(LAYER, |
60 |
Sextante.getText("Input_layer"),
|
61 |
IVectorLayer.SHAPE_TYPE_WRONG, |
62 |
true);
|
63 |
m_Parameters.addBoolean(CHECK, Sextante.getText("Selected_geometries"), false); |
64 |
m_Parameters.addNumericalValue(X, Sextante.getText("X_traslation"), 0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE); |
65 |
m_Parameters.addNumericalValue(Y, Sextante.getText("Y_traslation"), 0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE); |
66 |
} catch (RepeatedParameterNameException e) {
|
67 |
Sextante.addErrorToLog(e); |
68 |
} |
69 |
addOutputVectorLayer(RESULT, |
70 |
Sextante.getText("XY-Shift"),
|
71 |
OutputVectorLayer.SHAPE_TYPE_UNDEFINED); |
72 |
} |
73 |
|
74 |
/*
|
75 |
* (non-Javadoc)
|
76 |
* @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
|
77 |
*/
|
78 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
79 |
IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
80 |
boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
|
81 |
double x = m_Parameters.getParameterValueAsDouble(X);
|
82 |
double y = m_Parameters.getParameterValueAsDouble(Y);
|
83 |
|
84 |
FeatureStore storeLayer = null;
|
85 |
if(layer instanceof gvVectorLayer) |
86 |
storeLayer = ((gvVectorLayer)layer).getFeatureStore(); |
87 |
else
|
88 |
return false; |
89 |
|
90 |
try {
|
91 |
FeatureSet features = null;
|
92 |
features = storeLayer.getFeatureSet(); |
93 |
FeatureType featureType = features.getDefaultFeatureType(); |
94 |
FeatureStore outFeatStore = buildOutPutStore(featureType, layer.getShapeType(), Sextante.getText("XYShift"), RESULT);
|
95 |
|
96 |
GeometryOperation operation = new XYShiftOperation(x, y);
|
97 |
operation.setProgressModel(this);
|
98 |
operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
|
99 |
} catch (DataException e) {
|
100 |
Sextante.addErrorToLog(e); |
101 |
return false; |
102 |
} |
103 |
|
104 |
return true; |
105 |
} |
106 |
|
107 |
} |