Revision 336 org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.union/src/main/java/org/gvsig/geoprocess/algorithm/union/UnionAlgorithm.java
UnionAlgorithm.java | ||
---|---|---|
51 | 51 |
*/ |
52 | 52 |
public class UnionAlgorithm extends AbstractSextanteGeoProcess { |
53 | 53 |
|
54 |
public static final String RESULT1 = "RESULT1"; |
|
55 |
public static final String RESULT2 = "RESULT2"; |
|
56 |
public static final String LAYER1 = "LAYER1"; |
|
57 |
public static final String LAYER2 = "LAYER2"; |
|
58 |
public static final String CHECK = "CHECK"; |
|
54 |
public static final String RESULT1 = "RESULT1"; |
|
55 |
public static final String RESULT2 = "RESULT2"; |
|
56 |
public static final String LAYER1 = "LAYER1"; |
|
57 |
public static final String LAYER2 = "LAYER2"; |
|
58 |
public static final String SELECTGEOM_INPUT = "SELECTGEOM_INPUT"; |
|
59 |
public static final String SELECTGEOM_OVERLAY = "SELECTGEOM_OVERLAY"; |
|
59 | 60 |
|
60 | 61 |
/* |
61 | 62 |
* (non-Javadoc) |
... | ... | |
75 | 76 |
getTranslation("Input_layer") + " 2", |
76 | 77 |
IVectorLayer.SHAPE_TYPE_WRONG, |
77 | 78 |
true); |
78 |
m_Parameters.addBoolean(CHECK, |
|
79 |
getTranslation("Selected_geometries"), false); |
|
79 |
m_Parameters.addBoolean(SELECTGEOM_INPUT, |
|
80 |
getTranslation("Selected_geometries_input_layer"), false); |
|
81 |
m_Parameters.addBoolean(SELECTGEOM_OVERLAY, |
|
82 |
getTranslation("Selected_geometries_overlay_layer"), false); |
|
80 | 83 |
} catch (RepeatedParameterNameException e) { |
81 | 84 |
Sextante.addErrorToLog(e); |
82 | 85 |
} |
... | ... | |
100 | 103 |
|
101 | 104 |
IVectorLayer layer1 = m_Parameters.getParameterValueAsVectorLayer(LAYER1); |
102 | 105 |
IVectorLayer layer2 = m_Parameters.getParameterValueAsVectorLayer(LAYER2); |
103 |
boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean(); |
|
106 |
boolean selectedGeomInput = m_Parameters.getParameter(SELECTGEOM_INPUT).getParameterValueAsBoolean(); |
|
107 |
boolean selectedGeomOverlay = m_Parameters.getParameter(SELECTGEOM_OVERLAY).getParameterValueAsBoolean(); |
|
104 | 108 |
|
105 | 109 |
FeatureStore storeLayer1 = null; |
106 | 110 |
FeatureStore storeLayer2 = null; |
... | ... | |
112 | 116 |
return false; |
113 | 117 |
|
114 | 118 |
try { |
115 |
FeatureSet features1 = null; |
|
116 |
features1 = storeLayer1.getFeatureSet(); |
|
117 |
FeatureType featureType1 = features1.getDefaultFeatureType(); |
|
119 |
FeatureType featureType1 = storeLayer1.getDefaultFeatureType(); |
|
118 | 120 |
|
119 | 121 |
FeatureSet features2 = null; |
120 | 122 |
features2 = storeLayer2.getFeatureSet(); |
... | ... | |
130 | 132 |
layer1.getShapeType(), |
131 | 133 |
getTranslation("Union_polygon"), |
132 | 134 |
RESULT1); |
133 |
computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeom); |
|
135 |
computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay);
|
|
134 | 136 |
} else |
135 | 137 |
//PTO-PTO |
136 | 138 |
if(isPoint(storeLayer1) && isPoint(storeLayer2)) { |
... | ... | |
139 | 141 |
layer1.getShapeType(), |
140 | 142 |
getTranslation("Union_point"), |
141 | 143 |
RESULT1); |
142 |
computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeom); |
|
144 |
computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay);
|
|
143 | 145 |
} else |
144 | 146 |
//LIN-LIN |
145 | 147 |
if(isLine(storeLayer1) && isLine(storeLayer2)) { |
... | ... | |
148 | 150 |
IVectorLayer.SHAPE_TYPE_POINT, |
149 | 151 |
getTranslation("Union_point"), |
150 | 152 |
RESULT1); |
151 |
computesIntersection(storeLayer1, storeLayer2, featStoreOut1, selectedGeom, true); |
|
153 |
computesIntersection(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay, true);
|
|
152 | 154 |
featStoreOut2 = buildOutPutStoreFromUnion(featureType1, |
153 | 155 |
featureType2, |
154 | 156 |
IVectorLayer.SHAPE_TYPE_LINE, |
155 | 157 |
getTranslation("Union_line"), |
156 | 158 |
RESULT2); |
157 |
computesDifference(storeLayer1, storeLayer2, featStoreOut2, selectedGeom, false); |
|
158 |
computesDifference(storeLayer2, storeLayer1, featStoreOut2, selectedGeom, true); |
|
159 |
computesDifference(storeLayer1, storeLayer2, featStoreOut2, selectedGeomInput, selectedGeomOverlay, false);
|
|
160 |
computesDifference(storeLayer2, storeLayer1, featStoreOut2, selectedGeomInput, selectedGeomOverlay, true);
|
|
159 | 161 |
} else |
160 | 162 |
//POL-LIN |
161 | 163 |
if( (isPolygon(storeLayer1) && isLine(storeLayer2)) || |
... | ... | |
164 | 166 |
featureType2, |
165 | 167 |
IVectorLayer.SHAPE_TYPE_LINE, |
166 | 168 |
getTranslation("Union_line"), RESULT1); |
167 |
computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeom); |
|
169 |
computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay);
|
|
168 | 170 |
featStoreOut2 = buildOutPutStoreFromUnion(featureType1, |
169 | 171 |
featureType2, |
170 | 172 |
IVectorLayer.SHAPE_TYPE_POLYGON, |
171 | 173 |
getTranslation("Union_polygon"), |
172 | 174 |
RESULT2); |
173 |
computesDifference(storeLayer1, storeLayer2, featStoreOut2, selectedGeom, false); |
|
174 |
computesDifference(storeLayer2, storeLayer1, featStoreOut2, selectedGeom, true); |
|
175 |
computesDifference(storeLayer1, storeLayer2, featStoreOut2, selectedGeomInput, selectedGeomOverlay, false);
|
|
176 |
computesDifference(storeLayer2, storeLayer1, featStoreOut2, selectedGeomInput, selectedGeomOverlay, true);
|
|
175 | 177 |
} else |
176 | 178 |
//POL-PTO |
177 | 179 |
if( (isPolygon(storeLayer1) && isPoint(storeLayer2)) || |
178 | 180 |
(isPoint(storeLayer1) && isPolygon(storeLayer2))) { |
179 | 181 |
featStoreOut1 = buildOutPutStoreFromUnion(featureType1, featureType2, IVectorLayer.SHAPE_TYPE_POINT, |
180 | 182 |
getTranslation("Union_point"), RESULT1); |
181 |
computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeom); |
|
183 |
computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay);
|
|
182 | 184 |
featStoreOut2 = buildOutPutStoreFromUnion(featureType1, featureType2, IVectorLayer.SHAPE_TYPE_POLYGON, |
183 | 185 |
getTranslation("Union_polygon"), RESULT2); |
184 |
computesUnion(storeLayer1, storeLayer2, featStoreOut2, selectedGeom); |
|
186 |
computesUnion(storeLayer1, storeLayer2, featStoreOut2, selectedGeomInput, selectedGeomOverlay);
|
|
185 | 187 |
} else |
186 | 188 |
//PTO-LIN |
187 | 189 |
if( (isPoint(storeLayer1) && isLine(storeLayer2)) || |
188 | 190 |
(isLine(storeLayer1) && isPoint(storeLayer2))) { |
189 | 191 |
featStoreOut1 = buildOutPutStoreFromUnion(featureType1, featureType2, IVectorLayer.SHAPE_TYPE_POINT, |
190 | 192 |
getTranslation("Union_point"), RESULT1); |
191 |
computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeom); |
|
193 |
computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay);
|
|
192 | 194 |
featStoreOut2 = buildOutPutStoreFromUnion(featureType1, featureType2, IVectorLayer.SHAPE_TYPE_LINE, |
193 | 195 |
getTranslation("Union_line"), RESULT2); |
194 |
computesUnion(storeLayer1, storeLayer2, featStoreOut2, selectedGeom); |
|
196 |
computesUnion(storeLayer1, storeLayer2, featStoreOut2, selectedGeomInput, selectedGeomOverlay);
|
|
195 | 197 |
} |
196 | 198 |
|
197 | 199 |
if(featStoreOut2 == null) { |
... | ... | |
222 | 224 |
* @throws WrongParameterIDException |
223 | 225 |
* @throws NullParameterValueException |
224 | 226 |
*/ |
225 |
private void computesUnion(FeatureStore storeLayer1, FeatureStore storeLayer2, FeatureStore featStoreOut, boolean selectedGeom) throws DataException, WrongParameterTypeException, WrongParameterIDException, NullParameterValueException { |
|
226 |
computesIntersection(storeLayer1, storeLayer2, featStoreOut, selectedGeom, false); |
|
227 |
computesDifference(storeLayer1, storeLayer2, featStoreOut, selectedGeom, false); |
|
228 |
computesDifference(storeLayer2, storeLayer1, featStoreOut, selectedGeom, true); |
|
227 |
private void computesUnion(FeatureStore storeLayer1, FeatureStore storeLayer2, |
|
228 |
FeatureStore featStoreOut, boolean selectedGeomInput, boolean selectGeomOverlay) throws DataException, WrongParameterTypeException, WrongParameterIDException, NullParameterValueException { |
|
229 |
computesIntersection(storeLayer1, storeLayer2, featStoreOut, selectedGeomInput, selectGeomOverlay, false); |
|
230 |
computesDifference(storeLayer1, storeLayer2, featStoreOut, selectedGeomInput, selectGeomOverlay, false); |
|
231 |
computesDifference(storeLayer2, storeLayer1, featStoreOut, selectedGeomInput, selectGeomOverlay, true); |
|
229 | 232 |
} |
230 | 233 |
|
231 | 234 |
/** |
... | ... | |
240 | 243 |
* @throws WrongParameterIDException |
241 | 244 |
* @throws NullParameterValueException |
242 | 245 |
*/ |
243 |
private void computesIntersection(FeatureStore storeLayer1, FeatureStore storeLayer2, FeatureStore featStoreOut, boolean selectedGeom, boolean close) throws DataException, WrongParameterTypeException, WrongParameterIDException, NullParameterValueException { |
|
246 |
private void computesIntersection(FeatureStore storeLayer1, FeatureStore storeLayer2, |
|
247 |
FeatureStore featStoreOut, boolean selectedGeomInput, boolean selectGeomOverlay, boolean close) throws DataException, WrongParameterTypeException, WrongParameterIDException, NullParameterValueException { |
|
244 | 248 |
GeometryOperation intersection = new IntersectionOperation(storeLayer2, this); |
245 | 249 |
intersection.setTaskStatus(getStatus()); |
246 | 250 |
intersection.computesGeometryOperation(storeLayer1, featStoreOut, attrNames, |
247 |
selectedGeom, false, close);
|
|
251 |
selectedGeomInput, selectGeomOverlay, close);
|
|
248 | 252 |
} |
249 | 253 |
|
250 | 254 |
/** |
... | ... | |
259 | 263 |
* @throws WrongParameterIDException |
260 | 264 |
* @throws NullParameterValueException |
261 | 265 |
*/ |
262 |
private void computesDifference(FeatureStore storeLayer1, FeatureStore storeLayer2, FeatureStore featStoreOut, boolean selectedGeom, boolean close) throws DataException, WrongParameterTypeException, WrongParameterIDException, NullParameterValueException { |
|
263 |
Geometry unionGeom1 = ScalableUnionOperation.joinLayerGeometries(storeLayer2, false); |
|
266 |
private void computesDifference(FeatureStore storeLayer1, FeatureStore storeLayer2, |
|
267 |
FeatureStore featStoreOut, boolean selectedGeomInput, boolean selectGeomOverlay, boolean close) throws DataException, WrongParameterTypeException, WrongParameterIDException, NullParameterValueException { |
|
268 |
Geometry unionGeom1 = ScalableUnionOperation.joinLayerGeometries(storeLayer2, selectGeomOverlay); |
|
264 | 269 |
GeometryOperation differenceL1_L2 = new DifferenceOperation(unionGeom1, this); |
265 | 270 |
differenceL1_L2.setTaskStatus(getStatus()); |
266 | 271 |
differenceL1_L2.computesGeometryOperation(storeLayer1, featStoreOut, attrNames, |
267 |
selectedGeom, false, close);
|
|
272 |
selectedGeomInput, selectGeomOverlay, close);
|
|
268 | 273 |
} |
269 | 274 |
|
270 | 275 |
} |
Also available in: Unified diff