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 | 237 | cordinyana | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 175 | cordinyana | *
|
4 | 245 | cordinyana | * Copyright (C) 2007-2012 gvSIG Association.
|
5 | 175 | cordinyana | *
|
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 | 237 | cordinyana | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 245 | cordinyana | *
|
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 | 175 | cordinyana | */
|
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 | 218 | cordinyana | import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
32 | 225 | cordinyana | import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer; |
33 | 175 | cordinyana | |
34 | 271 | nbrodin | 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 | 175 | cordinyana | /**
|
42 | * XYShift algorithm
|
||
43 | * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
||
44 | */
|
||
45 | 191 | cordinyana | public class XYShiftAlgorithm extends AbstractSextanteGeoProcess { |
46 | |||
47 | 329 | nbrodin | 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 | 175 | cordinyana | |
55 | /*
|
||
56 | * (non-Javadoc)
|
||
57 | * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
|
||
58 | */
|
||
59 | public void defineCharacteristics(){ |
||
60 | 244 | cordinyana | setName(getTranslation("XYShift"));
|
61 | setGroup(getTranslation("basic_vect_algorithms"));
|
||
62 | 175 | cordinyana | // setGeneratesUserDefinedRasterOutput(false);
|
63 | |||
64 | try {
|
||
65 | m_Parameters.addInputVectorLayer(LAYER, |
||
66 | 244 | cordinyana | getTranslation("Input_layer"),
|
67 | 175 | cordinyana | IVectorLayer.SHAPE_TYPE_WRONG, |
68 | true);
|
||
69 | 244 | cordinyana | 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 | 175 | cordinyana | } catch (RepeatedParameterNameException e) {
|
76 | Sextante.addErrorToLog(e); |
||
77 | } |
||
78 | 329 | nbrodin | 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 | 175 | cordinyana | } |
85 | 329 | nbrodin | |
86 | 175 | cordinyana | /*
|
87 | * (non-Javadoc)
|
||
88 | * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
|
||
89 | */
|
||
90 | public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
||
91 | 329 | nbrodin | if(existsOutPutFile(XYShiftAlgorithm.RESULT_POL, 0) || |
92 | existsOutPutFile(XYShiftAlgorithm.RESULT_LINE, 0) ||
|
||
93 | existsOutPutFile(XYShiftAlgorithm.RESULT_POINT, 0)) {
|
||
94 | 271 | nbrodin | throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
95 | } |
||
96 | 175 | cordinyana | 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 | 225 | cordinyana | if(layer instanceof FlyrVectIVectorLayer) |
103 | storeLayer = ((FlyrVectIVectorLayer)layer).getFeatureStore(); |
||
104 | 175 | cordinyana | else
|
105 | return false; |
||
106 | |||
107 | try {
|
||
108 | FeatureSet features = null;
|
||
109 | features = storeLayer.getFeatureSet(); |
||
110 | FeatureType featureType = features.getDefaultFeatureType(); |
||
111 | |||
112 | 329 | nbrodin | 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 | 335 | nbrodin | operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, |
120 | selectedGeom, false, true); |
||
121 | 329 | nbrodin | } 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 | 335 | nbrodin | operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, |
134 | selectedGeom, false, true); |
||
135 | 329 | nbrodin | } else {
|
136 | 330 | nbrodin | buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_LINE, |
137 | 329 | nbrodin | getTranslation("Null_line"), RESULT_LINE);
|
138 | } |
||
139 | |||
140 | if (isPoint(storeLayer) || isUndefined(storeLayer)) {
|
||
141 | FeatureStore outFeatStore = |
||
142 | 330 | nbrodin | buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT, |
143 | 329 | nbrodin | getTranslation("XYShift_point"), RESULT_POINT);
|
144 | |||
145 | GeometryOperation operation = new XYShiftOperation(x, y, this); |
||
146 | operation.setTaskStatus(getStatus()); |
||
147 | 335 | nbrodin | operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, |
148 | selectedGeom, false, true); |
||
149 | 329 | nbrodin | } else {
|
150 | 330 | nbrodin | buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT, |
151 | 329 | nbrodin | getTranslation("Null_point"), RESULT_POINT);
|
152 | } |
||
153 | 175 | cordinyana | } catch (DataException e) {
|
154 | Sextante.addErrorToLog(e); |
||
155 | return false; |
||
156 | } |
||
157 | |||
158 | 327 | nbrodin | if(getTaskMonitor().isCanceled())
|
159 | return false; |
||
160 | |||
161 | 175 | cordinyana | return true; |
162 | } |
||
163 | |||
164 | } |