Revision 6497
trunk/extensions/extGeoProcessing/src/com/iver/cit/gvsig/geoprocess/impl/dissolve/fmap/AdjacencyDissolveVisitor.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.1 2006-06-20 18:20:45 azabala |
|
48 |
* Revision 1.2 2006-07-21 11:06:06 azabala |
|
49 |
* fixed bug 604: empty dist field in buffered dissolved features |
|
50 |
* |
|
51 |
* Revision 1.1 2006/06/20 18:20:45 azabala |
|
49 | 52 |
* first version in cvs |
50 | 53 |
* |
51 | 54 |
* Revision 1.1 2006/05/24 21:11:14 azabala |
... | ... | |
55 | 58 |
*/ |
56 | 59 |
package com.iver.cit.gvsig.geoprocess.impl.dissolve.fmap; |
57 | 60 |
|
61 |
import java.awt.geom.Rectangle2D; |
|
62 |
import java.util.ArrayList; |
|
63 |
import java.util.List; |
|
64 |
import java.util.Stack; |
|
65 |
|
|
58 | 66 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
67 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
|
68 |
import com.hardcode.gdbms.engine.values.Value; |
|
69 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
59 | 70 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
71 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
|
60 | 72 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeatureProcessor; |
73 |
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes; |
|
61 | 74 |
import com.vividsolutions.jts.geom.Geometry; |
62 | 75 |
|
63 | 76 |
/** |
... | ... | |
72 | 85 |
* |
73 | 86 |
*/ |
74 | 87 |
public class AdjacencyDissolveVisitor extends DissolveVisitor { |
75 |
|
|
88 |
|
|
89 |
/** |
|
90 |
* Reference to the buffer distance of the visited buffered feature. |
|
91 |
*/ |
|
92 |
private DoubleValue currentBufferDistance = null; |
|
93 |
|
|
76 | 94 |
public AdjacencyDissolveVisitor(String dissolveField, |
77 | 95 |
FeatureProcessor processor) { |
78 | 96 |
super(dissolveField, processor); |
79 | 97 |
} |
80 |
|
|
98 |
|
|
81 | 99 |
protected boolean verifyIfDissolve(DissolvedFeature f1, DissolvedFeature f2) { |
82 | 100 |
Geometry geo1 = f1.getJtsGeometry(); |
83 | 101 |
Geometry geo2 = f2.getJtsGeometry(); |
... | ... | |
95 | 113 |
*/ |
96 | 114 |
protected DissolvedFeature createFeature(IGeometry g, int index) |
97 | 115 |
throws DriverException { |
98 |
DissolvedFeature solution |
|
99 |
= new DissolvedFeature(g, null, index); |
|
116 |
DissolvedFeature solution = new DissolvedFeature(g, null, index); |
|
100 | 117 |
return solution; |
101 | 118 |
} |
119 |
|
|
120 |
/** |
|
121 |
* We overwrite this method because we are not interested in save sumarization |
|
122 |
* function values with dissolved features. |
|
123 |
* Instead, we want to add buffer distance like an attribute of them. |
|
124 |
*/ |
|
125 |
public void visit(IGeometry g, int index) throws VisitException { |
|
126 |
if(g == null) |
|
127 |
return; |
|
128 |
if(g.getGeometryType() != XTypes.POLYGON && |
|
129 |
g.getGeometryType() != XTypes.MULTI) |
|
130 |
return; |
|
131 |
if (!dissolvedGeometries.get(index)) { |
|
132 |
try { |
|
133 |
int fieldIndex = recordset.getFieldIndexByName("DIST"); |
|
134 |
currentBufferDistance = (DoubleValue) recordset.getFieldValue(index, fieldIndex); |
|
135 |
// if we havent dissolved this feature |
|
136 |
Stack toDissol = new Stack();// stack for adjacent features |
|
137 |
DissolvedFeature feature = createFeature(g, index); |
|
138 |
toDissol.push(feature); |
|
139 |
ArrayList geometries = new ArrayList(); |
|
140 |
Value[] values = dissolveGeometries(toDissol, geometries); |
|
141 |
Geometry geometry = union(geometries); |
|
142 |
Value[] valuesWithFID = new Value[values.length + 1]; |
|
143 |
System.arraycopy(values, 0, valuesWithFID, 1, values.length); |
|
144 |
valuesWithFID[0] = ValueFactory.createValue(fid); |
|
145 |
DissolvedFeature dissolved = new DissolvedFeature(null,valuesWithFID, fid/*index*/); |
|
146 |
dissolved.setJtsGeometry(geometry); |
|
147 |
this.featureProcessor.processFeature(dissolved); |
|
148 |
fid++; |
|
149 |
resetFunctions(); |
|
150 |
} catch (DriverException e) { |
|
151 |
throw new VisitException( |
|
152 |
"Error al procesar las geometrias a fusionar durante dissolve"); |
|
153 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) { |
|
154 |
throw new VisitException( |
|
155 |
"Error al procesar las geometrias a fusionar durante dissolve"); |
|
156 |
} |
|
157 |
}// if |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* We overwrite this method to ignore sumarization values and to |
|
162 |
* add buffer distance to the attributes of the result features. |
|
163 |
*/ |
|
164 |
protected Value[] dissolveGeometries(Stack toDissol, |
|
165 |
List geometries) throws com.iver.cit.gvsig.fmap.DriverException, |
|
166 |
VisitException { |
|
102 | 167 |
|
168 |
IndividualGeometryDissolveVisitor visitor = null; |
|
169 |
DissolvedFeature feature = null; |
|
170 |
while (toDissol.size() != 0) { |
|
171 |
feature = (DissolvedFeature) toDissol.pop(); |
|
172 |
// flags this idx (to not to process in future) |
|
173 |
dissolvedGeometries.set(feature.getIndex()); |
|
174 |
if (visitor == null) { |
|
175 |
visitor = new IndividualGeometryDissolveVisitor(feature, |
|
176 |
dissolvedGeometries, toDissol, |
|
177 |
numericField_sumarizeFunction); |
|
178 |
visitor.setDissolveField(this.dissolveField); |
|
179 |
} else { |
|
180 |
visitor.setProcessedFeature(feature); |
|
181 |
} |
|
182 |
Rectangle2D bounds = feature.getGeometry().getBounds2D(); |
|
183 |
double xmin = bounds.getMinX(); |
|
184 |
double ymin = bounds.getMinY(); |
|
185 |
double xmax = bounds.getMaxX(); |
|
186 |
double ymax = bounds.getMaxY(); |
|
187 |
double magnify = 15d; |
|
188 |
Rectangle2D query = new Rectangle2D.Double(xmin - magnify, ymin |
|
189 |
- magnify, (xmax - xmin) + magnify, (ymax - ymin) + magnify); |
|
190 |
|
|
191 |
strategy.process(visitor, query); |
|
192 |
//al final de toda la pila de llamadas recursivas, |
|
193 |
//geometries tendr? todas las geometrias que debemos dissolver |
|
194 |
geometries.add(feature.getJtsGeometry()); |
|
195 |
}// while |
|
196 |
Value[] values = new Value[1]; |
|
197 |
values[0] = currentBufferDistance; |
|
198 |
return values; |
|
199 |
} |
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
103 | 205 |
} |
Also available in: Unified diff