Revision 335 org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.difference/src/main/java/org/gvsig/geoprocess/algorithm/difference/DifferenceAlgorithm.java

View differences:

DifferenceAlgorithm.java
43 43
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
44 44
 */
45 45
public class DifferenceAlgorithm extends AbstractSextanteGeoProcess {
46
	public static final String  RESULT_POL        = "RESULT_POL";
47
	public static final String  RESULT_POINT      = "RESULT_POINT";
48
	public static final String  RESULT_LINE       = "RESULT_LINE";
49
	public static final String  LAYER             = "LAYER";
50
	public static final String  DIF               = "DIF";
51
	public static final String  CHECK_INPUT       = "CHECK_INPUT";
52
	public static final String  CHECK_OUTPUT      = "CHECK_OUTPUT";
46 53

  
47
	public static final String  RESULT    = "RESULT";
48
	public static final String  LAYER     = "LAYER";
49
	public static final String  DIF       = "DIF";
50
	public static final String  CHECK     = "CHECK";
51

  
52 54
	public void defineCharacteristics(){
53 55
        setName(getTranslation("Difference"));
54 56
        setGroup(getTranslation("basic_vect_algorithms"));
......
61 63
			m_Parameters.addInputVectorLayer(DIF, getTranslation("Overlays_layer"),
62 64
												IVectorLayer.SHAPE_TYPE_WRONG, 
63 65
												true);
64
            m_Parameters.addBoolean(CHECK, 
66
            m_Parameters.addBoolean(CHECK_INPUT, 
65 67
            		getTranslation("Selected_geometries_input_layer"), false);
68
            m_Parameters.addBoolean(CHECK_OUTPUT, 
69
            		getTranslation("Selected_geometries_input_layer"), false);
66 70
		} catch (RepeatedParameterNameException e) {
67 71
			Sextante.addErrorToLog(e);
68 72
		}
69
		addOutputVectorLayer(RESULT, getTranslation("Difference"),
70
								OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
73
		
74
		addOutputVectorLayer(RESULT_POL, getTranslation("Difference_polygon"),
75
				OutputVectorLayer.SHAPE_TYPE_POLYGON);
76
		addOutputVectorLayer(RESULT_LINE, getTranslation("Difference_line"),
77
				OutputVectorLayer.SHAPE_TYPE_LINE);
78
		addOutputVectorLayer(RESULT_POINT, getTranslation("Difference_point"),
79
				OutputVectorLayer.SHAPE_TYPE_POINT);
71 80
	}
72 81
	
73 82
	/*
......
75 84
	 * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
76 85
	 */
77 86
	public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
78
		if(existsOutPutFile(DifferenceAlgorithm.RESULT, 0)) {
87
		if(existsOutPutFile(RESULT_POL, 0) || 
88
			existsOutPutFile(RESULT_LINE, 0) ||
89
			existsOutPutFile(RESULT_POINT, 0)) {
79 90
    		throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
80 91
    	}
81 92
		org.gvsig.fmap.geom.Geometry overlayGeometry = null;
82 93
		IVectorLayer dif = m_Parameters.getParameterValueAsVectorLayer(DIF);
83 94
		IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
84
		boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
95
		boolean selectedGeomInput = m_Parameters.getParameter(CHECK_INPUT).getParameterValueAsBoolean();
96
		boolean selectedGeomOutput = m_Parameters.getParameter(CHECK_OUTPUT).getParameterValueAsBoolean();
85 97
		
86 98
		try {
87
			overlayGeometry = ScalableUnionOperation.joinLayerGeometries(dif);
99
			overlayGeometry = ScalableUnionOperation.joinLayerGeometries(dif, selectedGeomOutput);
88 100
		} catch (Exception e) {
89 101
			Sextante.addErrorToLog(e);
90 102
			return false;
......
100 112
			FeatureSet features = null;
101 113
			features = storeLayer.getFeatureSet();
102 114
			FeatureType featureType = features.getDefaultFeatureType();
103
            FeatureStore outFeatStore =
104
                buildOutPutStore(featureType, layer.getShapeType(),
105
                    getTranslation("Difference"), RESULT);
106

  
115
			
107 116
			GeometryOperation operation = new DifferenceOperation(overlayGeometry, this);
108 117
            operation.setTaskStatus(getStatus());
109
			operation.computesGeometryOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
118
            
119
            if (isPolygon(storeLayer) || isUndefined(storeLayer)) {
120
				FeatureStore outFeatStore =
121
					buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON,
122
							getTranslation("Difference_polygon"), RESULT_POL);
123

  
124
				operation.computesGeometryOperation(storeLayer, outFeatStore, 
125
						attrNames, selectedGeomInput, selectedGeomOutput, true);
126
			} else {
127
				buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON,
128
						getTranslation("Null_polygon"), RESULT_POL);
129
			}
130
            
131
            if (isLine(storeLayer) || isUndefined(storeLayer)) {
132
				FeatureStore outFeatStore =
133
					buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_LINE,
134
							getTranslation("Difference_line"), RESULT_LINE);
135

  
136
				operation.computesGeometryOperation(storeLayer, outFeatStore, 
137
						attrNames, selectedGeomInput, selectedGeomOutput, true);
138
			} else {
139
				buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_LINE,
140
						getTranslation("Null_line"), RESULT_LINE);
141
			}
142
			
143
			if (isPoint(storeLayer) || isUndefined(storeLayer)) {
144
				FeatureStore outFeatStore =
145
					buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT,
146
							getTranslation("Difference_point"), RESULT_POINT);
147

  
148
				operation.computesGeometryOperation(storeLayer, outFeatStore, 
149
						attrNames, selectedGeomInput, selectedGeomOutput, true);
150
			} else {
151
				buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT,
152
						getTranslation("Null_point"), RESULT_POINT);
153
			}
154
            
110 155
		} catch (DataException e) {
111 156
			Sextante.addErrorToLog(e);
112 157
			return false;

Also available in: Unified diff