Revision 12556
branches/v10/extensions/extGeoProcessing/src/com/iver/cit/gvsig/geoprocess/impl/dissolve/fmap/AdjacencyDissolveVisitor.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.2 2006-07-21 11:06:06 azabala |
|
48 |
* Revision 1.2.2.1 2007-07-12 09:28:45 azabala |
|
49 |
* optimizations in dissolution of buffered features (we dont use strategies to avoid reading of geometries already processed) |
|
50 |
* |
|
51 |
* Revision 1.2 2006/07/21 11:06:06 azabala |
|
49 | 52 |
* fixed bug 604: empty dist field in buffered dissolved features |
50 | 53 |
* |
51 | 54 |
* Revision 1.1 2006/06/20 18:20:45 azabala |
... | ... | |
59 | 62 |
package com.iver.cit.gvsig.geoprocess.impl.dissolve.fmap; |
60 | 63 |
|
61 | 64 |
import java.awt.geom.Rectangle2D; |
62 |
import java.util.ArrayList; |
|
63 | 65 |
import java.util.List; |
64 | 66 |
import java.util.Stack; |
65 | 67 |
|
68 |
import org.cresques.cts.ICoordTrans; |
|
69 |
|
|
66 | 70 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
67 | 71 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
68 | 72 |
import com.hardcode.gdbms.engine.values.Value; |
69 | 73 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
70 | 74 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
75 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
|
76 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
77 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
|
71 | 78 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
72 | 79 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeatureProcessor; |
73 | 80 |
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes; |
81 |
import com.iver.utiles.swing.threads.CancellableMonitorable; |
|
74 | 82 |
import com.vividsolutions.jts.geom.Geometry; |
83 |
import com.vividsolutions.jts.geom.GeometryCollection; |
|
84 |
import com.vividsolutions.jts.geom.GeometryFactory; |
|
85 |
import com.vividsolutions.jts.precision.EnhancedPrecisionOp; |
|
75 | 86 |
|
76 | 87 |
/** |
77 | 88 |
* <p> |
... | ... | |
91 | 102 |
*/ |
92 | 103 |
private DoubleValue currentBufferDistance = null; |
93 | 104 |
|
105 |
/** |
|
106 |
* FIXME REFACTOR THIS!!!! |
|
107 |
* This is a workaround to avoid the use of strategies |
|
108 |
* and allow the cancelation |
|
109 |
* |
|
110 |
* To optimize disolution of buffers, we need to avoid the reading |
|
111 |
* of geometries that also has been processed. Strategies cant do this |
|
112 |
* |
|
113 |
*/ |
|
114 |
CancellableMonitorable cancelMonitor = null; |
|
115 |
|
|
116 |
// FIXME Probe to optimize the union of the features |
|
117 |
//(buffer + dissolve when applies to almost all features of the layer |
|
118 |
//is very inefficient |
|
119 |
private Geometry geometry; |
|
120 |
|
|
121 |
|
|
94 | 122 |
public AdjacencyDissolveVisitor(String dissolveField, |
95 | 123 |
FeatureProcessor processor) { |
96 | 124 |
super(dissolveField, processor); |
97 | 125 |
} |
98 | 126 |
|
127 |
//FIXME REFACTOR THIS!!! |
|
128 |
public void setCancelMonitor(CancellableMonitorable cancelMonitor){ |
|
129 |
this.cancelMonitor = cancelMonitor; |
|
130 |
} |
|
131 |
|
|
99 | 132 |
protected boolean verifyIfDissolve(DissolvedFeature f1, DissolvedFeature f2) { |
100 | 133 |
Geometry geo1 = f1.getJtsGeometry(); |
101 | 134 |
Geometry geo2 = f2.getJtsGeometry(); |
... | ... | |
136 | 169 |
Stack toDissol = new Stack();// stack for adjacent features |
137 | 170 |
DissolvedFeature feature = createFeature(g, index); |
138 | 171 |
toDissol.push(feature); |
139 |
ArrayList geometries = new ArrayList(); |
|
140 |
Value[] values = dissolveGeometries(toDissol, geometries); |
|
141 |
Geometry geometry = union(geometries); |
|
172 |
|
|
173 |
// ArrayList geometries = new ArrayList(); |
|
174 |
|
|
175 |
Value[] values = dissolveGeometries(toDissol/*, geometries*/); |
|
176 |
|
|
177 |
// Geometry geometry = union(geometries); |
|
178 |
|
|
142 | 179 |
Value[] valuesWithFID = new Value[values.length + 1]; |
143 | 180 |
System.arraycopy(values, 0, valuesWithFID, 1, values.length); |
144 | 181 |
valuesWithFID[0] = ValueFactory.createValue(fid); |
... | ... | |
161 | 198 |
* We overwrite this method to ignore sumarization values and to |
162 | 199 |
* add buffer distance to the attributes of the result features. |
163 | 200 |
*/ |
164 |
protected Value[] dissolveGeometries(Stack toDissol, |
|
165 |
List geometries) throws com.iver.cit.gvsig.fmap.DriverException, |
|
201 |
protected Value[] dissolveGeometries(Stack toDissol/*,
|
|
202 |
List geometries*/) throws com.iver.cit.gvsig.fmap.DriverException,
|
|
166 | 203 |
VisitException { |
167 | 204 |
|
168 | 205 |
IndividualGeometryDissolveVisitor visitor = null; |
169 | 206 |
DissolvedFeature feature = null; |
170 | 207 |
while (toDissol.size() != 0) { |
171 | 208 |
feature = (DissolvedFeature) toDissol.pop(); |
209 |
|
|
210 |
|
|
172 | 211 |
// flags this idx (to not to process in future) |
173 | 212 |
dissolvedGeometries.set(feature.getIndex()); |
213 |
|
|
174 | 214 |
if (visitor == null) { |
175 | 215 |
visitor = new IndividualGeometryDissolveVisitor(feature, |
176 | 216 |
dissolvedGeometries, toDissol, |
... | ... | |
179 | 219 |
} else { |
180 | 220 |
visitor.setProcessedFeature(feature); |
181 | 221 |
} |
222 |
|
|
182 | 223 |
Rectangle2D bounds = feature.getGeometry().getBounds2D(); |
183 | 224 |
double xmin = bounds.getMinX(); |
184 | 225 |
double ymin = bounds.getMinY(); |
... | ... | |
187 | 228 |
double magnify = 15d; |
188 | 229 |
Rectangle2D query = new Rectangle2D.Double(xmin - magnify, ymin |
189 | 230 |
- magnify, (xmax - xmin) + magnify, (ymax - ymin) + magnify); |
190 |
|
|
191 |
strategy.process(visitor, query); |
|
231 |
|
|
232 |
if (dissolvedLayer.getISpatialIndex() == null) { |
|
233 |
strategy.process(visitor, query); |
|
234 |
}else{ |
|
235 |
process(visitor, query); |
|
236 |
} |
|
237 |
|
|
192 | 238 |
//al final de toda la pila de llamadas recursivas, |
193 | 239 |
//geometries tendr? todas las geometrias que debemos dissolver |
194 |
geometries.add(feature.getJtsGeometry()); |
|
240 |
// geometries.add(feature.getJtsGeometry()); |
|
241 |
|
|
242 |
if(geometry == null){ |
|
243 |
geometry = feature.getJtsGeometry(); |
|
244 |
}else{ |
|
245 |
GeometryFactory factory = geometry.getFactory(); |
|
246 |
Geometry[] geoms = new Geometry[]{geometry, feature.getJtsGeometry()}; |
|
247 |
GeometryCollection collection = factory.createGeometryCollection(geoms); |
|
248 |
geometry = EnhancedPrecisionOp.buffer(collection, 0d); |
|
249 |
} |
|
250 |
|
|
251 |
|
|
252 |
|
|
195 | 253 |
}// while |
196 | 254 |
Value[] values = new Value[1]; |
197 | 255 |
values[0] = currentBufferDistance; |
198 | 256 |
return values; |
199 | 257 |
} |
200 | 258 |
|
259 |
void process(IndividualGeometryDissolveVisitor visitor, Rectangle2D query){ |
|
260 |
if (visitor.start(dissolvedLayer)) { |
|
261 |
ReadableVectorial va = dissolvedLayer.getSource(); |
|
262 |
ICoordTrans ct = dissolvedLayer.getCoordTrans(); |
|
263 |
List lstRecs = dissolvedLayer.getISpatialIndex().query(query); |
|
264 |
Integer idRec; |
|
265 |
int index; |
|
266 |
try { |
|
267 |
va.start(); |
|
268 |
DriverAttributes attr = va.getDriverAttributes(); |
|
269 |
boolean bMustClone = false; |
|
270 |
if (attr != null) { |
|
271 |
if (attr.isLoadedInMemory()) { |
|
272 |
bMustClone = attr.isLoadedInMemory(); |
|
273 |
} |
|
274 |
} |
|
275 |
|
|
276 |
for (int i = 0; i < lstRecs.size(); i++) { |
|
277 |
if(cancelMonitor != null){ |
|
278 |
if(cancelMonitor.isCanceled()) |
|
279 |
return; |
|
280 |
} |
|
281 |
idRec = (Integer) lstRecs.get(i); |
|
282 |
index = idRec.intValue(); |
|
283 |
if(getDissolvedGeometries().get(index)) |
|
284 |
continue; |
|
285 |
|
|
286 |
IGeometry geom = va.getShape(index); |
|
287 |
if (geom == null)// azabala |
|
288 |
continue; |
|
289 |
if (ct != null) { |
|
290 |
if (bMustClone) |
|
291 |
geom = geom.cloneGeometry(); |
|
292 |
geom.reProject(ct); |
|
293 |
} |
|
294 |
if (geom.intersects(query)) |
|
295 |
visitor.visit(geom, index); |
|
296 |
}// for |
|
297 |
va.stop(); |
|
298 |
} catch (DriverIOException e) { |
|
299 |
// TODO Auto-generated catch block |
|
300 |
e.printStackTrace(); |
|
301 |
} catch (VisitException e) { |
|
302 |
// TODO Auto-generated catch block |
|
303 |
e.printStackTrace(); |
|
304 |
} |
|
305 |
}// if visitor.start |
|
306 |
|
|
307 |
visitor.stop(dissolvedLayer); |
|
308 |
} |
|
201 | 309 |
|
202 | 310 |
|
203 | 311 |
|
312 |
|
|
204 | 313 |
|
205 | 314 |
} |
branches/v10/extensions/extGeoProcessing/src/com/iver/cit/gvsig/geoprocess/impl/dissolve/fmap/DissolveVisitor.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.2 2006-07-27 17:21:06 azabala |
|
48 |
* Revision 1.2.2.1 2007-07-12 09:28:45 azabala |
|
49 |
* optimizations in dissolution of buffered features (we dont use strategies to avoid reading of geometries already processed) |
|
50 |
* |
|
51 |
* Revision 1.2 2006/07/27 17:21:06 azabala |
|
49 | 52 |
* *** empty log message *** |
50 | 53 |
* |
51 | 54 |
* Revision 1.1 2006/06/20 18:20:45 azabala |
... | ... | |
185 | 188 |
public int getNumProcessedGeometries() { |
186 | 189 |
return dissolvedGeometries.cardinality(); |
187 | 190 |
} |
191 |
|
|
192 |
public FBitSet getDissolvedGeometries(){ |
|
193 |
return dissolvedGeometries; |
|
194 |
} |
|
188 | 195 |
|
189 | 196 |
public void setDissolvedAttributesInfo(Map numericField_sumFunction) { |
190 | 197 |
this.numericField_sumarizeFunction = numericField_sumFunction; |
... | ... | |
245 | 252 |
Geometry[] geom = new Geometry[geometries.size()]; |
246 | 253 |
geometries.toArray(geom); |
247 | 254 |
GeometryFactory fact = geom[0].getFactory(); |
248 |
Geometry geomColl = fact.createGeometryCollection(geom); |
|
249 |
System.out.println(geomColl.toText()); |
|
250 |
union = geomColl.buffer(0); |
|
251 |
System.out.println(union.toText()); |
|
255 |
Geometry geomColl = fact.createGeometryCollection(geom); |
|
256 |
union = geomColl.buffer(0); |
|
252 | 257 |
return union; |
253 | 258 |
} |
259 |
|
|
254 | 260 |
|
255 | 261 |
/** |
256 | 262 |
* FIXME Redise?ar esto, pues el codigo es similar al de Spatial Join |
branches/v10/extensions/extGeoProcessing/src/com/iver/cit/gvsig/geoprocess/impl/buffer/fmap/BufferGeoprocess.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.3 2006-07-21 11:04:50 azabala |
|
48 |
* Revision 1.3.2.1 2007-07-12 09:27:16 azabala |
|
49 |
* optimizations in dissolution of buffered features (we dont use strategies to avoid reading of geometries already processed) |
|
50 |
* |
|
51 |
* Revision 1.3 2006/07/21 11:04:50 azabala |
|
49 | 52 |
* Unified createTask and process() methods |
50 | 53 |
* |
51 | 54 |
* Revision 1.2 2006/06/29 07:33:57 fjp |
... | ... | |
113 | 116 |
import java.io.IOException; |
114 | 117 |
import java.util.Map; |
115 | 118 |
|
119 |
import org.cresques.cts.ICoordTrans; |
|
116 | 120 |
import org.cresques.cts.IProjection; |
117 | 121 |
|
118 | 122 |
import com.iver.andami.PluginServices; |
119 | 123 |
import com.iver.cit.gvsig.fmap.DriverException; |
124 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
120 | 125 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
121 | 126 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
122 | 127 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
... | ... | |
128 | 133 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
129 | 134 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
130 | 135 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
136 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
|
131 | 137 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
132 | 138 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
133 | 139 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
... | ... | |
511 | 517 |
final String of = PluginServices.getText(this, "De"); |
512 | 518 |
|
513 | 519 |
return new IMonitorableTask() { |
520 |
DissolveVisitor dissolveVisitor; |
|
521 |
|
|
514 | 522 |
private boolean finished = false; |
515 | 523 |
String currentNote = note; |
516 | 524 |
|
... | ... | |
523 | 531 |
} |
524 | 532 |
|
525 | 533 |
public int getCurrentStep() { |
526 |
return cancelMonitor.getCurrentStep(); |
|
534 |
if(currentNote == note2) |
|
535 |
return dissolveVisitor.getDissolvedGeometries().cardinality(); |
|
536 |
else |
|
537 |
return cancelMonitor.getCurrentStep(); |
|
527 | 538 |
} |
528 | 539 |
|
529 | 540 |
public String getStatusMessage() { |
... | ... | |
563 | 574 |
bufferVisitor.setBufferProcessor(new GeometryPersisterProcessor( |
564 | 575 |
resultLayerDefinition, schemaManager, writer)); |
565 | 576 |
computeOnlyBuffers(strategy, cancelMonitor); |
577 |
|
|
566 | 578 |
//dissolving buffers |
567 |
currentNote = note2; |
|
568 | 579 |
cancelMonitor.setCurrentStep(0); |
569 | 580 |
FLyrVect tempLayer = createTempLayer(); |
570 | 581 |
tempLayer.createSpatialIndex(); |
... | ... | |
574 | 585 |
writer); |
575 | 586 |
// AdjacencyDissolveVisitor dissolveVisitor = |
576 | 587 |
// new AdjacencyDissolveVisitor(null, processor); |
577 |
DissolveVisitor dissolveVisitor =
|
|
588 |
dissolveVisitor = |
|
578 | 589 |
createDissolveVisitor(processor); |
590 |
currentNote = note2; |
|
591 |
|
|
592 |
|
|
579 | 593 |
Strategy secondPassStrategy = StrategyManager.getStrategy(tempLayer); |
580 | 594 |
dissolveVisitor.setStrategy(secondPassStrategy); |
581 |
long t0 = System.currentTimeMillis(); |
|
582 |
secondPassStrategy.process(dissolveVisitor, cancelMonitor); |
|
583 |
long t1 = System.currentTimeMillis(); |
|
584 |
System.out.println((t1-t0)+" en dissolver los buffers"); |
|
595 |
if(dissolveVisitor instanceof AdjacencyDissolveVisitor){ |
|
596 |
((AdjacencyDissolveVisitor)dissolveVisitor).setCancelMonitor(cancelMonitor); |
|
597 |
} |
|
598 |
// secondPassStrategy.process(dissolveVisitor, cancelMonitor); |
|
599 |
|
|
600 |
|
|
601 |
ReadableVectorial source = tempLayer.getSource(); |
|
602 |
ICoordTrans ct = tempLayer.getCoordTrans(); |
|
603 |
|
|
604 |
if(dissolveVisitor.start(tempLayer)){ |
|
605 |
source.start(); |
|
606 |
for (int i = 0; i < source.getShapeCount(); i++) { |
|
607 |
if(cancelMonitor.isCanceled()){ |
|
608 |
source.stop(); |
|
609 |
return; |
|
610 |
} |
|
611 |
if(dissolveVisitor.getDissolvedGeometries().get(i)) |
|
612 |
continue; |
|
613 |
IGeometry geom = source.getShape(i); |
|
614 |
if (ct != null) { |
|
615 |
geom.reProject(ct); |
|
616 |
} |
|
617 |
dissolveVisitor.visit(geom, i); |
|
618 |
}//for |
|
619 |
source.stop(); |
|
620 |
} |
|
621 |
dissolveVisitor.stop(tempLayer); |
|
622 |
|
|
585 | 623 |
} else { |
586 | 624 |
computeOnlyBuffers(strategy, cancelMonitor); |
587 | 625 |
} |
Also available in: Unified diff