Revision 651

View differences:

org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/pom.xml
40 40

  
41 41
	<dependencyManagement>
42 42
		<dependencies>
43
                        <dependency>
44
		                <groupId>org.gvsig</groupId>
43
			<dependency>
44
				<groupId>org.gvsig</groupId>
45 45
		                <artifactId>org.gvsig.raster</artifactId>
46 46
		                <version>2.2.10</version>
47 47
		                <type>pom</type>
......
50 50
			<dependency>
51 51
				<groupId>org.gvsig</groupId>
52 52
				<artifactId>org.gvsig.toolbox</artifactId>
53
				<version>1.0.15</version>
53
				<version>1.0.16</version>
54 54
				<type>pom</type>
55 55
				<scope>import</scope>
56 56
				<optional>true</optional>
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/java/org/gvsig/geoprocess/algorithm/intersection/IntersectionAlgorithm.java
58 58
	public static final String  INTER                 = "INTER";
59 59
	public static final String  SELECTGEOM_INPUT      = "SELECTGEOM_INPUT";
60 60
	public static final String  SELECTGEOM_OVERLAY    = "SELECTGEOM_OVERLAY";
61
	
61

  
62 62
	/*
63 63
	 * (non-Javadoc)
64 64
	 * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
......
67 67
        setName(getTranslation("Intersection"));
68 68
        setGroup(getTranslation("basic_vect_algorithms"));
69 69
        // setGeneratesUserDefinedRasterOutput(false);
70
		
70

  
71 71
		try {
72
			m_Parameters.addInputVectorLayer(LAYER, 
72
			m_Parameters.addInputVectorLayer(LAYER,
73 73
                getTranslation("Input_layer"),
74
												IVectorLayer.SHAPE_TYPE_WRONG, 
74
												IVectorLayer.SHAPE_TYPE_WRONG,
75 75
												true);
76
			m_Parameters.addInputVectorLayer(INTER, 
76
			m_Parameters.addInputVectorLayer(INTER,
77 77
                getTranslation("Overlays_layer"),
78
												IVectorLayer.SHAPE_TYPE_WRONG, 
78
												IVectorLayer.SHAPE_TYPE_WRONG,
79 79
												true);
80
            m_Parameters.addBoolean(SELECTGEOM_INPUT, 
80
            m_Parameters.addBoolean(SELECTGEOM_INPUT,
81 81
            		getTranslation("Selected_geometries_input_layer_inters"), false);
82
            m_Parameters.addBoolean(SELECTGEOM_OVERLAY, 
82
            m_Parameters.addBoolean(SELECTGEOM_OVERLAY,
83 83
            		getTranslation("Selected_geometries_overlay_layer_inters"), false);
84 84
		} catch (RepeatedParameterNameException e) {
85 85
			Sextante.addErrorToLog(e);
......
91 91
		addOutputVectorLayer(RESULT_POINT, getTranslation("Intersection_point"),
92 92
								OutputVectorLayer.SHAPE_TYPE_POINT);
93 93
	}
94
	
94

  
95 95
	/*
96 96
	 * (non-Javadoc)
97 97
	 * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
......
111 111
		boolean selectedGeomInput = m_Parameters.getParameter(SELECTGEOM_INPUT).getParameterValueAsBoolean();
112 112
		boolean selectedGeomOverlay = m_Parameters.getParameter(SELECTGEOM_OVERLAY).getParameterValueAsBoolean();
113 113
		boolean error = false;
114
		
114

  
115 115
		try {
116 116
			error = computesIntersection(layer, inter, layer.getShapeType(), selectedGeomInput, selectedGeomOverlay);
117 117
		} catch (DataException e) {
118 118
			Sextante.addErrorToLog(e);
119 119
			return false;
120 120
		}
121
		
121

  
122 122
		if(getTaskMonitor().isCanceled())
123 123
			return false;
124 124
		if(error)
......
127 127
	                JOptionPane.WARNING_MESSAGE);
128 128
		return true;
129 129
	}
130
	
130

  
131 131
	/**
132 132
	 * Builds a layer with the intersection between the input layer and the templateGeometry
133 133
	 * @param layer
......
137 137
	 *        Output shape type
138 138
	 * @param selectedGeom
139 139
	 *        If it's true only selected geometries will be computed
140
	 * @throws GeoAlgorithmExecutionException 
140
	 * @throws GeoAlgorithmExecutionException
141 141
	 */
142 142
	private boolean computesIntersection(IVectorLayer layer,
143 143
								IVectorLayer overlay,
144
								int shapeType, 
144
								int shapeType,
145 145
								boolean selectedGeomInput,
146 146
								boolean selectedGeomOverlay) throws DataException, GeoAlgorithmExecutionException {
147 147
		FeatureStore storeLayer = null;
148 148
		FeatureStore storeOverlay = null;
149
		if(layer instanceof FlyrVectIVectorLayer && 
149
		if(layer instanceof FlyrVectIVectorLayer &&
150 150
			overlay instanceof FlyrVectIVectorLayer) {
151 151
			storeLayer = ((FlyrVectIVectorLayer)layer).getFeatureStore();
152 152
			storeOverlay = ((FlyrVectIVectorLayer)overlay).getFeatureStore();
......
159 159
		FeatureStore outFeatStorePol = null;
160 160
		FeatureStore outFeatStoreLine = null;
161 161
		FeatureStore outFeatStorePoint = null;
162
		
162

  
163 163
		IntersectionOperation operation = new IntersectionOperation(storeOverlay, this);
164 164
		operation.setTaskStatus(getStatus());
165
		 
165

  
166 166
		//La de puntos se genera siempre
167 167
		outFeatStorePoint =
168 168
			buildOutPutStoreFromUnion(featureType1, featureType2,
169 169
					IVectorLayer.SHAPE_TYPE_POINT,
170 170
					getTranslation("Intersection_point"), RESULT_POINT);
171
		
172
		getStatus().setTitle("Point");
173
		operation.computesGeometryOperation(storeLayer, outFeatStorePoint, attrNames, 
174
				selectedGeomInput, selectedGeomOverlay, true);
175 171

  
172
        if (outFeatStorePoint != null) {
173
            getStatus().setTitle("Point");
174
            operation.computesGeometryOperation(storeLayer, outFeatStorePoint,
175
                attrNames, selectedGeomInput, selectedGeomOverlay, true);
176
        }
176 177
		//La de pol?gonos solo si es intersecci?n entre pol?gonos
177 178
		if (isPolygon(storeLayer) && isPolygon(storeOverlay)) {
178 179
			outFeatStorePol =
179 180
              buildOutPutStoreFromUnion(featureType1, featureType2,
180 181
            		  IVectorLayer.SHAPE_TYPE_POLYGON, getTranslation("Intersection_polygon"), RESULT_POL);
181
			getStatus().setTitle("Polygon");
182
			operation.computesGeometryOperation(storeLayer, outFeatStorePol, attrNames, 
183
					selectedGeomInput, selectedGeomOverlay, true);
182
            if (outFeatStorePol != null) {
183
                getStatus().setTitle("Polygon");
184
                operation.computesGeometryOperation(storeLayer,
185
                    outFeatStorePol, attrNames, selectedGeomInput,
186
                    selectedGeomOverlay, true);
187
            }
184 188
		}
185
		
189

  
186 190
		//La capa de l?neas se genera cuando ning?na de las dos es de puntos
187 191
		if (!isPoint(storeLayer) && !isPoint(storeOverlay)) {
188 192
			outFeatStoreLine =
189 193
              buildOutPutStoreFromUnion(featureType1, featureType2,
190 194
            		  IVectorLayer.SHAPE_TYPE_LINE, getTranslation("Intersection_line"), RESULT_LINE);
191
			getStatus().setTitle("Line");
192
			operation.computesGeometryOperation(storeLayer, outFeatStoreLine, attrNames, 
193
					selectedGeomInput, selectedGeomOverlay, true);
195
            if (outFeatStoreLine != null) {
196
                getStatus().setTitle("Line");
197
                operation.computesGeometryOperation(storeLayer,
198
                    outFeatStoreLine, attrNames, selectedGeomInput,
199
                    selectedGeomOverlay, true);
200
            }
194 201
		}
195 202

  
196 203
		if(outFeatStorePol == null) {
197 204
			getNewVectorLayer(RESULT_POL, getTranslation("Null_polygon"),
198 205
                    OutputVectorLayer.SHAPE_TYPE_POLYGON, new Class[]{Integer.class}, new String[]{""});
199 206
		}
200
		
207

  
201 208
		if(outFeatStoreLine == null) {
202 209
			getNewVectorLayer(RESULT_LINE, getTranslation("Null_line"),
203 210
                    OutputVectorLayer.SHAPE_TYPE_LINE, new Class[]{Integer.class}, new String[]{""});
204 211
		}
205
		
212

  
206 213
		if(outFeatStorePoint == null) {
207 214
			getNewVectorLayer(RESULT_POINT, getTranslation("Null_point"),
208 215
                    OutputVectorLayer.SHAPE_TYPE_POINT, new Class[]{Integer.class}, new String[]{""});
209 216
		}
210
		
217

  
211 218
		return operation.getErrorInfo();
212 219
	}
213
	
220

  
214 221
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.lib/org.gvsig.geoprocess.lib.sextante/src/main/java/org/gvsig/geoprocess/lib/sextante/core/DefaultOutputFactory.java
51 51
import es.unex.sextante.gui.core.DefaultTaskMonitor;
52 52
import es.unex.sextante.outputs.FileOutputChannel;
53 53
import es.unex.sextante.outputs.IOutputChannel;
54
import es.unex.sextante.outputs.NullOutputChannel;
54 55

  
55 56
/**
56 57
 * An OutputFactory based on the gvSIG data model. Supports only file-based
57 58
 * outputs.
58
 * 
59
 *
59 60
 * @author volaya
60
 * 
61
 *
61 62
 */
62 63
public class DefaultOutputFactory extends OutputFactory {
63 64

  
......
72 73
            sizes);
73 74

  
74 75
    }
75
    
76

  
76 77
    private int[] getSizesFromTypeClass(final Class[] types) {
77 78
        final int[] sizes = new int[types.length];
78 79
        for (int i = 0; i < sizes.length; i++) {
......
99 100
                    crs, fieldSize);
100 101
                return layer;
101 102

  
102
            } else
103
                if (channel instanceof FileOutputChannel) {
104
                    FlyrVectIVectorLayer layer = new FlyrVectIVectorLayer();
105
                    String fileName =
106
                        ((FileOutputChannel) channel).getFilename();
107
                    layer.create(sName, fileName, iShapeType, types, sFields,
108
                        crs, fieldSize);
109
                    return layer;
110
                }
103
            } else if (channel instanceof FileOutputChannel) {
104
                FlyrVectIVectorLayer layer = new FlyrVectIVectorLayer();
105
                String fileName = ((FileOutputChannel) channel).getFilename();
106
                layer.create(sName, fileName, iShapeType, types, sFields, crs,
107
                    fieldSize);
108
                return layer;
109
            } else if (channel instanceof NullOutputChannel) {
110
                return null;
111
            }
111 112
        }
112 113

  
113
        
114 114
        throw new UnsupportedOutputChannelException();
115 115
    }
116 116

  
......
131 131
        }
132 132

  
133 133
    }
134
    
134

  
135 135
    public IRasterLayer getNewEmptyRORasterLayer(final String sName,
136 136
            final int iDataType, final AnalysisExtent extent, final int iBands,
137 137
            final IOutputChannel channel, final Object crs)
......
211 211
    public Object getDefaultCRS() {
212 212
    	//Uses the active view
213 213
    	IWindow window = PluginServices.getMDIManager().getActiveWindow();
214
    	
214

  
215 215
    	//If there is not active view then it looks for a view
216 216
    	if(window == null || !(window instanceof AbstractViewPanel)) {
217 217
    		IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
......
222 222
				}
223 223
			}
224 224
    	}
225
    	
225

  
226 226
    	if(window != null && window instanceof AbstractViewPanel) {
227 227
    		return ((AbstractViewPanel)window).getMapControl().getProjection();
228 228
    	} else {
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.lib/org.gvsig.geoprocess.lib.sextante/src/main/java/org/gvsig/geoprocess/lib/sextante/AbstractSextanteGeoProcess.java
162 162
            IVectorLayer output =
163 163
                getNewVectorLayer(sextanteLayerLabel, sextanteLayerName,
164 164
                    shapeType, types, attrNames);
165
            return ((FlyrVectIVectorLayer) output).getFeatureStore();
165
            if (output != null) {
166
                return ((FlyrVectIVectorLayer) output).getFeatureStore();
167
            }
166 168
        } catch (UnsupportedOutputChannelException e) {
167 169
            Sextante.addErrorToLog(e);
168 170
        } catch (GeoAlgorithmExecutionException e) {
......
248 250
            IVectorLayer output =
249 251
                getNewVectorLayer(sextanteLayerLabel, sextanteLayerName,
250 252
                    shapeType, types, attrNames);
251
            return ((FlyrVectIVectorLayer) output).getFeatureStore();
253
            if (output != null) {
254
                return ((FlyrVectIVectorLayer) output).getFeatureStore();
255
            }
252 256
        } catch (UnsupportedOutputChannelException e) {
253 257
            Sextante.addErrorToLog(e);
254 258
        } catch (GeoAlgorithmExecutionException e) {

Also available in: Unified diff