Revision 286
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.fusespatially/src/main/java/org/gvsig/geoprocess/algorithm/fusespatially/FuseSpatiallyOperation.java | ||
---|---|---|
45 | 45 |
package org.gvsig.geoprocess.algorithm.fusespatially; |
46 | 46 |
|
47 | 47 |
import java.util.ArrayList; |
48 |
import java.util.List; |
|
48 | 49 |
import java.util.Stack; |
49 | 50 |
|
50 | 51 |
import org.gvsig.fmap.dal.exception.DataException; |
... | ... | |
67 | 68 |
public class FuseSpatiallyOperation extends GeometryOperation { |
68 | 69 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
69 | 70 |
private int id = 0; |
70 |
private Stack<Feature> featList = null;
|
|
71 |
private List<Feature> featList = null;
|
|
71 | 72 |
private FeatureStore outFeatureStoreTable = null; |
72 | 73 |
private String idField = "FID"; |
73 | 74 |
|
74 |
public FuseSpatiallyOperation(Stack<Feature> f, FeatureStore outFeatStoreTable, String[] fieldNames, String idField) throws DataException {
|
|
75 |
public FuseSpatiallyOperation(List<Feature> f, FeatureStore outFeatStoreTable, String[] fieldNames, String idField) throws DataException {
|
|
75 | 76 |
this.featList = f; |
76 | 77 |
this.outFeatureStoreTable = outFeatStoreTable; |
77 | 78 |
this.idField = idField; |
... | ... | |
88 | 89 |
*/ |
89 | 90 |
public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature feature) { |
90 | 91 |
try { |
91 |
org.gvsig.fmap.geom.Geometry geom = feature.getDefaultGeometry(); |
|
92 |
Geometry jtsInputGeom = GeometryUtil.geomToJTS(geom); |
|
92 |
Geometry jtsInputGeom = GeometryUtil.geomToJTS(g); |
|
93 | 93 |
insertInTable(feature); |
94 | 94 |
|
95 |
int i = featList.size() - 1; |
|
95 |
for (int i = featList.size() - 1; i >= 0; i--) { |
|
96 |
Feature f = featList.get(i); |
|
97 |
g = f.getDefaultGeometry(); |
|
98 |
Geometry jtsGeom = GeometryUtil.geomToJTS(g); //Multigeometry support |
|
99 |
if(jtsGeom.intersects(jtsInputGeom)) { |
|
100 |
jtsInputGeom = jtsInputGeom.union(jtsGeom); |
|
101 |
featList.remove(i); |
|
102 |
insertInTable(f); |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
/*int i = featList.size() - 1; |
|
96 | 107 |
while(i >= 0) { |
97 | 108 |
Feature f = featList.get(i); |
98 | 109 |
geom = f.getDefaultGeometry(); |
... | ... | |
104 | 115 |
i = featList.size(); |
105 | 116 |
} |
106 | 117 |
i --; |
107 |
} |
|
118 |
}*/
|
|
108 | 119 |
|
109 | 120 |
//Cuando no genera dos capas mete los campos de la feature de entrada en la de salida perdiendose el resto |
110 | 121 |
if(outFeatureStoreTable == null) { |
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.fusespatially/src/main/java/org/gvsig/geoprocess/algorithm/fusespatially/FuseSpatiallyAlgorithm.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.geoprocess.algorithm.fusespatially; |
25 | 25 |
|
26 |
import java.util.ArrayList; |
|
26 | 27 |
import java.util.EmptyStackException; |
27 | 28 |
import java.util.List; |
28 | 29 |
import java.util.Stack; |
... | ... | |
175 | 176 |
status.setRangeOfValues(0, numberOfFeatures); |
176 | 177 |
} |
177 | 178 |
|
178 |
Stack<Feature> featList = new Stack<Feature>(); |
|
179 |
//Stack<Feature> featList = new Stack<Feature>(); |
|
180 |
List<Feature> featList = new ArrayList<Feature>(); |
|
179 | 181 |
while( it.hasNext() ) { |
180 | 182 |
Feature feature = (Feature)it.next(); |
181 |
featList.push(feature);
|
|
183 |
featList.add(feature);
|
|
182 | 184 |
} |
183 | 185 |
|
184 | 186 |
|
... | ... | |
186 | 188 |
operation.setFeatureStore(outFeatStore, attrNames); |
187 | 189 |
|
188 | 190 |
try { |
189 |
while (true) {
|
|
190 |
Feature f = featList.pop();
|
|
191 |
operation.invoke(null, f);
|
|
191 |
while (featList.size() > 0) {
|
|
192 |
Feature f = featList.remove(featList.size() - 1);
|
|
193 |
operation.invoke(f.getDefaultGeometry(), f);
|
|
192 | 194 |
} |
193 | 195 |
}catch(EmptyStackException e) { |
194 | 196 |
} |
Also available in: Unified diff