svn-gvsig-desktop / trunk / extensions / extGeoprocessingExtensions / src / com / iver / cit / gvsig / geoprocess / impl / xyshift / fmap / XYShiftGeoprocess.java @ 10626
History | View | Annotate | Download (7.06 KB)
1 |
/*
|
---|---|
2 |
* Created on 27-jun-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: XYShiftGeoprocess.java 10626 2007-03-06 16:55:54Z caballero $
|
47 |
* $Log$
|
48 |
* Revision 1.3 2007-03-06 16:48:14 caballero
|
49 |
* Exceptions
|
50 |
*
|
51 |
* Revision 1.2 2006/06/29 17:58:31 azabala
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
* Revision 1.1 2006/06/28 18:17:21 azabala
|
55 |
* first version in cvs
|
56 |
*
|
57 |
*
|
58 |
*/
|
59 |
package com.iver.cit.gvsig.geoprocess.impl.xyshift.fmap; |
60 |
|
61 |
import java.util.Map; |
62 |
|
63 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
64 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
65 |
import com.iver.andami.PluginServices; |
66 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
67 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
68 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
69 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
70 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
71 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
72 |
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocess; |
73 |
import com.iver.cit.gvsig.geoprocess.core.fmap.DefinitionUtils; |
74 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2; |
75 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
76 |
import com.iver.cit.gvsig.geoprocess.core.util.UnitUtils; |
77 |
import com.iver.utiles.swing.threads.AbstractMonitorableTask; |
78 |
import com.iver.utiles.swing.threads.DefaultCancellableMonitorable; |
79 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
80 |
/**
|
81 |
* This geoprocess apply an offset in x and y directions producing
|
82 |
* a new FLyrVect whose coordinates has been shifted.
|
83 |
* @author azabala
|
84 |
*
|
85 |
*/
|
86 |
public class XYShiftGeoprocess extends AbstractGeoprocess { |
87 |
|
88 |
/**
|
89 |
* Schema of the result layer
|
90 |
*/
|
91 |
|
92 |
private ILayerDefinition resultLayerDefinition;
|
93 |
|
94 |
/**
|
95 |
* flag to only clip selection of input layer
|
96 |
*/
|
97 |
private boolean onlyInputLayerSelection = false; |
98 |
|
99 |
/**
|
100 |
* feature visitor to apply an xy shift
|
101 |
*/
|
102 |
private XYShifterFeatureVisitor visitor;
|
103 |
|
104 |
/**
|
105 |
* Processes shifted features (writing them)
|
106 |
*/
|
107 |
FeaturePersisterProcessor2 processor; |
108 |
|
109 |
/**
|
110 |
* x offset
|
111 |
*/
|
112 |
private double offsetX; |
113 |
/**
|
114 |
* y offset
|
115 |
*/
|
116 |
private double offsetY; |
117 |
|
118 |
|
119 |
public XYShiftGeoprocess(FLyrVect inputLayer){
|
120 |
setFirstOperand(inputLayer); |
121 |
} |
122 |
|
123 |
|
124 |
public void setParameters(Map params) throws GeoprocessException { |
125 |
Boolean firstLayerSelection = (Boolean) |
126 |
params.get("firstlayerselection");
|
127 |
if (firstLayerSelection != null) |
128 |
this.onlyInputLayerSelection =
|
129 |
firstLayerSelection.booleanValue(); |
130 |
Double xShift = (Double) |
131 |
params.get("xshift");
|
132 |
if(xShift != null) |
133 |
this.offsetX = UnitUtils.
|
134 |
getInInternalUnits(xShift.doubleValue()); |
135 |
Double yShift = (Double) |
136 |
params.get("yshift");
|
137 |
if(yShift != null) |
138 |
this.offsetY = UnitUtils.
|
139 |
getInInternalUnits(yShift.doubleValue()); |
140 |
} |
141 |
|
142 |
public void checkPreconditions() throws GeoprocessException { |
143 |
//TODO llevar a un metodo verifyWriter de AbstractGeoprocess
|
144 |
if (this.writer == null || this.schemaManager == null) { |
145 |
throw new GeoprocessException( |
146 |
"Operacion de xyshift sin especificar capa de resultados");
|
147 |
} |
148 |
if(offsetX == 0 && offsetY == 0) |
149 |
throw new GeoprocessException("Geoproceso XYShift inicializado con un offset de 0,0"); |
150 |
|
151 |
} |
152 |
|
153 |
public void process() throws GeoprocessException { |
154 |
try {
|
155 |
new XYShiftTask().run();
|
156 |
} catch (Exception e) { |
157 |
throw new GeoprocessException("Error al ejecutar el geoproceso XYShift", e); |
158 |
} |
159 |
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* ITask (cancelable and progres-monitorable task) which makes all
|
164 |
* xyshift computations
|
165 |
* @author azabala
|
166 |
*
|
167 |
*/
|
168 |
class XYShiftTask extends AbstractMonitorableTask{ |
169 |
|
170 |
private XYShiftTask(){
|
171 |
setInitialStep(0);
|
172 |
try {
|
173 |
if(onlyInputLayerSelection){
|
174 |
int numSelected = firstLayer.
|
175 |
getRecordset(). |
176 |
getSelection(). |
177 |
cardinality(); |
178 |
setFinalStep(numSelected); |
179 |
}else{
|
180 |
int numShapes = firstLayer.getSource().getShapeCount();
|
181 |
setFinalStep(numShapes); |
182 |
}//else
|
183 |
} catch (ReadDriverException e) {
|
184 |
// TODO Auto-generated catch block
|
185 |
e.printStackTrace(); |
186 |
} |
187 |
setDeterminatedProcess(true);
|
188 |
setStatusMessage(PluginServices.getText(this, "XYShift._Progress_Message")); |
189 |
|
190 |
} |
191 |
|
192 |
public void run() throws Exception { |
193 |
processor = |
194 |
new FeaturePersisterProcessor2(writer);
|
195 |
visitor = new XYShifterFeatureVisitor(processor,
|
196 |
createLayerDefinition(), offsetX, offsetY ); |
197 |
if(onlyInputLayerSelection)
|
198 |
visitor.setSelection(firstLayer.getRecordset().getSelection()); |
199 |
Strategy strategy = StrategyManager.getStrategy(firstLayer); |
200 |
try {
|
201 |
//AbstractMonitorableTask is a cancel monitor too
|
202 |
strategy.process(visitor, this);
|
203 |
} catch (Exception e) { |
204 |
e.printStackTrace(); |
205 |
} |
206 |
} |
207 |
|
208 |
//TODO INTERNACIONALIZAR LOS MENSAJES
|
209 |
public String getNote() { |
210 |
return "Desplazando features..." + |
211 |
" " +
|
212 |
getCurrentStep()+ |
213 |
" "+
|
214 |
"de"+
|
215 |
" "+
|
216 |
getFinishStep(); |
217 |
} |
218 |
|
219 |
public void cancel() { |
220 |
setCanceled(true);
|
221 |
XYShiftGeoprocess.this.cancel(); |
222 |
} |
223 |
} |
224 |
|
225 |
|
226 |
public IMonitorableTask createTask() {
|
227 |
return new XYShiftTask(); |
228 |
} |
229 |
|
230 |
public void setFirstOperand(FLyrVect firstLayer) { |
231 |
super.firstLayer = firstLayer;
|
232 |
} |
233 |
|
234 |
|
235 |
public ILayerDefinition createLayerDefinition() {
|
236 |
if(resultLayerDefinition == null){ |
237 |
try {
|
238 |
resultLayerDefinition = DefinitionUtils. |
239 |
createLayerDefinition(super.firstLayer);
|
240 |
} catch (ReadDriverException e) {
|
241 |
// TODO Auto-generated catch block
|
242 |
e.printStackTrace(); |
243 |
} |
244 |
} |
245 |
return resultLayerDefinition;
|
246 |
} |
247 |
|
248 |
private DefaultCancellableMonitorable createCancelMonitor() {
|
249 |
DefaultCancellableMonitorable monitor = new DefaultCancellableMonitorable();
|
250 |
monitor.setInitialStep(0);
|
251 |
monitor.setDeterminatedProcess(true);
|
252 |
int numSteps = 0; |
253 |
try {
|
254 |
if (onlyInputLayerSelection){
|
255 |
FBitSet selection = firstLayer.getRecordset().getSelection(); |
256 |
numSteps = selection.cardinality(); |
257 |
}else{
|
258 |
numSteps = firstLayer.getSource().getShapeCount(); |
259 |
} |
260 |
monitor.setFinalStep(numSteps); |
261 |
} catch (ReadDriverException e) {
|
262 |
// TODO Auto-generated catch block
|
263 |
e.printStackTrace(); |
264 |
} |
265 |
return monitor;
|
266 |
} |
267 |
|
268 |
|
269 |
} |
270 |
|