Revision 10626 trunk/extensions/extGeoprocessingExtensions/src/com/iver/cit/gvsig/geoprocess/impl/topology/lineclean/fmap/LineCleanGeoprocess.java
LineCleanGeoprocess.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.1 2006-12-21 17:23:27 azabala |
|
48 |
* Revision 1.2 2007-03-06 16:48:14 caballero |
|
49 |
* Exceptions |
|
50 |
* |
|
51 |
* Revision 1.1 2006/12/21 17:23:27 azabala |
|
49 | 52 |
* *** empty log message *** |
50 | 53 |
* |
51 | 54 |
* Revision 1.1 2006/12/04 19:42:23 azabala |
... | ... | |
80 | 83 |
package com.iver.cit.gvsig.geoprocess.impl.topology.lineclean.fmap; |
81 | 84 |
|
82 | 85 |
import java.io.File; |
83 |
import java.io.IOException; |
|
84 | 86 |
import java.util.Map; |
85 | 87 |
|
88 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
86 | 89 |
import com.iver.andami.PluginServices; |
87 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
88 | 90 |
import com.iver.cit.gvsig.fmap.MapContext; |
89 | 91 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
90 | 92 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
91 | 93 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
92 | 94 |
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
93 | 95 |
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
94 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
95 | 96 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
96 | 97 |
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager; |
97 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.MultiShpWriter; |
|
98 | 98 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
99 | 99 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
100 | 100 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
101 | 101 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
102 | 102 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
103 | 103 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
104 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
|
105 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
|
106 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
|
107 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
|
108 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
|
109 | 104 |
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocess; |
110 | 105 |
import com.iver.cit.gvsig.geoprocess.core.fmap.DefinitionUtils; |
111 | 106 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2; |
... | ... | |
114 | 109 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
115 | 110 |
import com.iver.cit.gvsig.util.SnappingCoordinateMap; |
116 | 111 |
import com.iver.utiles.swing.threads.AbstractMonitorableTask; |
117 |
import com.iver.utiles.swing.threads.Cancellable; |
|
118 | 112 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
119 | 113 |
import com.iver.utiles.swing.threads.IPipedTask; |
120 | 114 |
|
... | ... | |
125 | 119 |
*/ |
126 | 120 |
private ILayerDefinition resultLayerDefinition; |
127 | 121 |
|
128 |
|
|
122 |
|
|
129 | 123 |
/** |
130 | 124 |
* flag to only clip selection of input layer |
131 | 125 |
*/ |
132 | 126 |
private boolean onlyFirstLayerSelection = false; |
133 |
|
|
127 |
|
|
134 | 128 |
/** |
135 | 129 |
* Processes features (writing them) |
136 | 130 |
*/ |
... | ... | |
141 | 135 |
*/ |
142 | 136 |
private IWriter intersectionsWriter; |
143 | 137 |
FeaturePersisterProcessor2 intersectsProcessor; |
144 |
|
|
145 |
|
|
138 |
|
|
139 |
|
|
146 | 140 |
public LineCleanGeoprocess(FLyrVect inputLayer){ |
147 | 141 |
this.firstLayer = inputLayer; |
148 | 142 |
} |
149 |
|
|
150 |
|
|
143 |
|
|
144 |
|
|
151 | 145 |
public void setParameters(Map params) throws GeoprocessException { |
152 | 146 |
Boolean firstLayerSelection = (Boolean) params.get("firstlayerselection"); |
153 | 147 |
if (firstLayerSelection != null) |
154 |
this.onlyFirstLayerSelection =
|
|
148 |
this.onlyFirstLayerSelection = |
|
155 | 149 |
firstLayerSelection.booleanValue(); |
156 | 150 |
|
157 | 151 |
} |
... | ... | |
168 | 162 |
throw new GeoprocessException( |
169 | 163 |
"Capa de entrada vacia"); |
170 | 164 |
} |
171 |
} catch (DriverIOException e) {
|
|
165 |
} catch (ReadDriverException e) {
|
|
172 | 166 |
throw new GeoprocessException( |
173 | 167 |
"Error al verificar si la capa est? vac?a"); |
174 |
}
|
|
168 |
} |
|
175 | 169 |
} |
176 | 170 |
|
177 | 171 |
public void process() throws GeoprocessException { |
... | ... | |
193 | 187 |
} |
194 | 188 |
return resultLayerDefinition; |
195 | 189 |
} |
196 |
|
|
197 |
|
|
190 |
|
|
191 |
|
|
198 | 192 |
class LineCleanTask extends AbstractMonitorableTask implements IPipedTask{ |
199 | 193 |
|
200 | 194 |
private LineCleanTask() { |
... | ... | |
208 | 202 |
int numShapes = firstLayer.getSource().getShapeCount(); |
209 | 203 |
setFinalStep(numShapes); |
210 | 204 |
}// else |
211 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) {
|
|
205 |
} catch (ReadDriverException e) {
|
|
212 | 206 |
// TODO Auto-generated catch block |
213 | 207 |
e.printStackTrace(); |
214 |
} catch (DriverIOException e) { |
|
215 |
// TODO Auto-generated catch block |
|
216 |
e.printStackTrace(); |
|
217 | 208 |
} |
218 | 209 |
setDeterminatedProcess(true); |
219 | 210 |
setStatusMessage(PluginServices.getText(this, |
220 | 211 |
"LineClean._Progress_Message")); |
221 | 212 |
|
222 | 213 |
} |
223 |
|
|
214 |
|
|
224 | 215 |
/** |
225 | 216 |
* Verifies cancelation events, and return a boolean flag if processes must |
226 | 217 |
* be stopped for this cancelations events. |
227 |
*
|
|
218 |
* |
|
228 | 219 |
* @param cancel |
229 | 220 |
* @param va |
230 | 221 |
* @param visitor |
... | ... | |
241 | 232 |
} |
242 | 233 |
return false; |
243 | 234 |
} |
244 |
|
|
245 |
|
|
235 |
|
|
236 |
|
|
246 | 237 |
public void run() throws Exception { |
247 | 238 |
processor = |
248 | 239 |
new FeaturePersisterProcessor2(writer); |
249 |
|
|
240 |
|
|
250 | 241 |
intersectionsWriter = new ShpWriter(); |
251 |
String temp = System.getProperty("java.io.tmpdir") +
|
|
252 |
"/intersections_" +
|
|
242 |
String temp = System.getProperty("java.io.tmpdir") + |
|
243 |
"/intersections_" + |
|
253 | 244 |
System.currentTimeMillis() + |
254 | 245 |
".shp"; |
255 | 246 |
File newFile = new File(temp); |
256 | 247 |
((ShpWriter) intersectionsWriter).setFile(newFile); |
257 |
|
|
248 |
|
|
258 | 249 |
ILayerDefinition intersectDefinition = new SHPLayerDefinition(); |
259 | 250 |
intersectDefinition.setShapeType(XTypes.POINT); |
260 | 251 |
FieldDescription[] intersectFields = new FieldDescription[2]; |
... | ... | |
269 | 260 |
intersectFields[1].setFieldName("FID2"); |
270 | 261 |
intersectFields[1].setFieldType(XTypes.INTEGER); |
271 | 262 |
intersectDefinition.setFieldsDesc(intersectFields); |
272 |
|
|
263 |
|
|
273 | 264 |
((ShpWriter) intersectionsWriter).initialize( |
274 | 265 |
(LayerDefinition) intersectDefinition); |
275 | 266 |
((SHPLayerDefinition) intersectDefinition).setFile(newFile); |
276 |
|
|
277 |
ShpSchemaManager interSchMg =
|
|
267 |
|
|
268 |
ShpSchemaManager interSchMg = |
|
278 | 269 |
new ShpSchemaManager(newFile.getAbsolutePath()); |
279 | 270 |
interSchMg.createSchema(intersectDefinition); |
280 |
|
|
281 |
intersectsProcessor = new
|
|
271 |
|
|
272 |
intersectsProcessor = new |
|
282 | 273 |
FeaturePersisterProcessor2(intersectionsWriter); |
283 |
|
|
274 |
|
|
284 | 275 |
FBitSet selection = null; |
285 |
SnappingCoordinateMap coordMap =
|
|
276 |
SnappingCoordinateMap coordMap = |
|
286 | 277 |
new SnappingCoordinateMap(LineCleanVisitor.DEFAULT_SNAP); |
287 |
LineCleanVisitor visitor =
|
|
278 |
LineCleanVisitor visitor = |
|
288 | 279 |
new LineCleanVisitor(processor, |
289 | 280 |
intersectsProcessor, |
290 |
onlyFirstLayerSelection,
|
|
281 |
onlyFirstLayerSelection, |
|
291 | 282 |
resultLayerDefinition, |
292 | 283 |
intersectDefinition, |
293 | 284 |
firstLayer, |
294 | 285 |
firstLayer.getRecordset(), coordMap); |
295 |
|
|
286 |
|
|
296 | 287 |
try { |
297 | 288 |
processor.start(); |
298 | 289 |
intersectsProcessor.start(); |
299 |
|
|
290 |
|
|
300 | 291 |
ReadableVectorial va = firstLayer.getSource(); |
301 | 292 |
va.start(); |
302 | 293 |
for (int i = 0; i < va.getShapeCount(); i++) {// for each geometry |
... | ... | |
309 | 300 |
reportStep(); |
310 | 301 |
visitor.visit(va.getShape(i), i); |
311 | 302 |
} |
312 |
|
|
303 |
|
|
313 | 304 |
}else{ |
314 | 305 |
reportStep(); |
315 | 306 |
visitor.visit(va.getShape(i), i); |
... | ... | |
318 | 309 |
va.stop(); |
319 | 310 |
processor.finish(); |
320 | 311 |
intersectsProcessor.finish(); |
321 |
|
|
322 |
|
|
323 |
} catch (DriverIOException e) {
|
|
312 |
|
|
313 |
|
|
314 |
} catch (ReadDriverException e) {
|
|
324 | 315 |
e.printStackTrace(); |
325 | 316 |
} |
326 | 317 |
} |
... | ... | |
354 | 345 |
*/ |
355 | 346 |
public void setEntry(Object object) { |
356 | 347 |
// TODO Auto-generated method stub |
357 |
|
|
348 |
|
|
358 | 349 |
} |
359 | 350 |
} |
360 | 351 |
|
361 |
|
|
352 |
|
|
362 | 353 |
public IMonitorableTask createTask() { |
363 | 354 |
return new LineCleanTask(); |
364 | 355 |
} |
365 |
|
|
366 |
|
|
356 |
|
|
357 |
|
|
367 | 358 |
public FLayer getResult() throws GeoprocessException { |
368 |
|
|
359 |
|
|
369 | 360 |
FLyrVect cleanedLayer = (FLyrVect) createLayerFrom(this.writer); |
370 | 361 |
FLyrVect pseudoNodes = (FLyrVect) createLayerFrom(this.intersectionsWriter); |
371 | 362 |
try { |
... | ... | |
383 | 374 |
solution.addLayer(pseudoNodes); |
384 | 375 |
return solution; |
385 | 376 |
} |
386 |
} catch (DriverIOException e) {
|
|
377 |
} catch (ReadDriverException e) {
|
|
387 | 378 |
throw new GeoprocessException("Error de lectura de datos"); |
388 | 379 |
} |
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
|
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
|
393 | 384 |
} |
394 | 385 |
|
395 | 386 |
} |
Also available in: Unified diff