gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.xyshift / src / main / java / org / gvsig / geoprocess / algorithm / xyshift / XYShiftAlgorithm.java @ 335
History | View | Annotate | Download (6.52 KB)
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; |
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.outputs.OutputVectorLayer; |
40 |
|
41 |
/**
|
42 |
* XYShift algorithm
|
43 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
44 |
*/
|
45 |
public class XYShiftAlgorithm extends AbstractSextanteGeoProcess { |
46 |
|
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 CHECK = "CHECK"; |
52 |
public static final String X = "X"; |
53 |
public static final String Y = "Y"; |
54 |
|
55 |
/*
|
56 |
* (non-Javadoc)
|
57 |
* @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
|
58 |
*/
|
59 |
public void defineCharacteristics(){ |
60 |
setName(getTranslation("XYShift"));
|
61 |
setGroup(getTranslation("basic_vect_algorithms"));
|
62 |
// setGeneratesUserDefinedRasterOutput(false);
|
63 |
|
64 |
try {
|
65 |
m_Parameters.addInputVectorLayer(LAYER, |
66 |
getTranslation("Input_layer"),
|
67 |
IVectorLayer.SHAPE_TYPE_WRONG, |
68 |
true);
|
69 |
m_Parameters.addBoolean(CHECK, |
70 |
getTranslation("Selected_geometries"), false); |
71 |
m_Parameters.addNumericalValue(X, getTranslation("X_traslation"),
|
72 |
0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE);
|
73 |
m_Parameters.addNumericalValue(Y, getTranslation("Y_traslation"),
|
74 |
0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE);
|
75 |
} catch (RepeatedParameterNameException e) {
|
76 |
Sextante.addErrorToLog(e); |
77 |
} |
78 |
addOutputVectorLayer(RESULT_POL, getTranslation("XYShift_polygon"),
|
79 |
OutputVectorLayer.SHAPE_TYPE_POLYGON); |
80 |
addOutputVectorLayer(RESULT_LINE, getTranslation("XYShift_line"),
|
81 |
OutputVectorLayer.SHAPE_TYPE_LINE); |
82 |
addOutputVectorLayer(RESULT_POINT, getTranslation("XYShift_point"),
|
83 |
OutputVectorLayer.SHAPE_TYPE_POINT); |
84 |
} |
85 |
|
86 |
/*
|
87 |
* (non-Javadoc)
|
88 |
* @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
|
89 |
*/
|
90 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
91 |
if(existsOutPutFile(XYShiftAlgorithm.RESULT_POL, 0) || |
92 |
existsOutPutFile(XYShiftAlgorithm.RESULT_LINE, 0) ||
|
93 |
existsOutPutFile(XYShiftAlgorithm.RESULT_POINT, 0)) {
|
94 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
95 |
} |
96 |
IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
97 |
boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
|
98 |
double x = m_Parameters.getParameterValueAsDouble(X);
|
99 |
double y = m_Parameters.getParameterValueAsDouble(Y);
|
100 |
|
101 |
FeatureStore storeLayer = null;
|
102 |
if(layer instanceof FlyrVectIVectorLayer) |
103 |
storeLayer = ((FlyrVectIVectorLayer)layer).getFeatureStore(); |
104 |
else
|
105 |
return false; |
106 |
|
107 |
try {
|
108 |
FeatureSet features = null;
|
109 |
features = storeLayer.getFeatureSet(); |
110 |
FeatureType featureType = features.getDefaultFeatureType(); |
111 |
|
112 |
if (isPolygon(storeLayer) || isUndefined(storeLayer)) {
|
113 |
FeatureStore outFeatStore = |
114 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON, |
115 |
getTranslation("XYShift_polygon"), RESULT_POL);
|
116 |
|
117 |
GeometryOperation operation = new XYShiftOperation(x, y, this); |
118 |
operation.setTaskStatus(getStatus()); |
119 |
operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, |
120 |
selectedGeom, false, true); |
121 |
} else {
|
122 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON, |
123 |
getTranslation("Null_polygon"), RESULT_POL);
|
124 |
} |
125 |
|
126 |
if (isLine(storeLayer) || isUndefined(storeLayer)) {
|
127 |
FeatureStore outFeatStore = |
128 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_LINE, |
129 |
getTranslation("XYShift_line"), RESULT_LINE);
|
130 |
|
131 |
GeometryOperation operation = new XYShiftOperation(x, y, this); |
132 |
operation.setTaskStatus(getStatus()); |
133 |
operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, |
134 |
selectedGeom, false, true); |
135 |
} else {
|
136 |
buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_LINE, |
137 |
getTranslation("Null_line"), RESULT_LINE);
|
138 |
} |
139 |
|
140 |
if (isPoint(storeLayer) || isUndefined(storeLayer)) {
|
141 |
FeatureStore outFeatStore = |
142 |
buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT, |
143 |
getTranslation("XYShift_point"), RESULT_POINT);
|
144 |
|
145 |
GeometryOperation operation = new XYShiftOperation(x, y, this); |
146 |
operation.setTaskStatus(getStatus()); |
147 |
operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, |
148 |
selectedGeom, false, true); |
149 |
} else {
|
150 |
buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT, |
151 |
getTranslation("Null_point"), RESULT_POINT);
|
152 |
} |
153 |
} catch (DataException e) {
|
154 |
Sextante.addErrorToLog(e); |
155 |
return false; |
156 |
} |
157 |
|
158 |
if(getTaskMonitor().isCanceled())
|
159 |
return false; |
160 |
|
161 |
return true; |
162 |
} |
163 |
|
164 |
} |