Revision 307

View differences:

org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/java/org/gvsig/geoprocess/algorithm/intersection/IntersectionOperation.java
47 47
import org.gvsig.tools.dispose.DisposableIterator;
48 48

  
49 49
import com.vividsolutions.jts.geom.Geometry;
50
import com.vividsolutions.jts.geom.GeometryCollection;
51
import com.vividsolutions.jts.geom.LineString;
52
import com.vividsolutions.jts.geom.MultiLineString;
53
import com.vividsolutions.jts.geom.MultiPoint;
54
import com.vividsolutions.jts.geom.MultiPolygon;
55
import com.vividsolutions.jts.geom.Point;
56
import com.vividsolutions.jts.geom.Polygon;
50 57
import com.vividsolutions.jts.precision.EnhancedPrecisionOp;
51 58

  
52 59
import es.unex.sextante.core.Sextante;
......
146 153
			if(jtsGeom.intersects(overlaysGeom)) {
147 154
				Geometry newGeom = EnhancedPrecisionOp.intersection(jtsGeom, overlaysGeom);
148 155
				if(!newGeom.isEmpty()) {
149
					
150
					//Para intersecciones entre pol?gonos cuando la salida es de tipo l?nea 
151
					//la generamos a partir del pol?gono resultante de la intersecci?n
152
					if( g1 instanceof Surface && 
153
						g2 instanceof Surface &&
154
						(outPutType == TYPES.MULTICURVE)) {
155
						GeometryOperationContext ctx = new GeometryOperationContext();
156
						ctx.setAttribute(FromJTS.PARAM, newGeom);
157
						org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry)geomManager.invokeOperation(FromJTS.NAME, ctx);
158
						newGeom = (Geometry)newDalGeom.invokeOperation("toJTSLineString", null);
159
					} 
160
					
161
					lastEditFeature = persister.addFeature(featureInput, featureOverlay, newGeom);
156
					if(typesMatch(outPutType, newGeom) || newGeom instanceof GeometryCollection) {
157
						lastEditFeature = persister.addFeature(featureInput, featureOverlay, newGeom);
158
					} else {
159
						//Para intersecciones entre pol?gonos cuando la salida es de tipo l?nea 
160
						//la generamos a partir del pol?gono resultante de la intersecci?n
161
						if( g1 instanceof Surface && 
162
								g2 instanceof Surface &&
163
								outPutType == TYPES.MULTICURVE &&
164
								(newGeom instanceof Polygon || newGeom instanceof MultiPolygon)) {
165
							GeometryOperationContext ctx = new GeometryOperationContext();
166
							ctx.setAttribute(FromJTS.PARAM, newGeom);
167
							org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry)geomManager.invokeOperation(FromJTS.NAME, ctx);
168
							newGeom = (Geometry)newDalGeom.invokeOperation("toJTSLineString", null);
169
						} 
170

  
171
						lastEditFeature = persister.addFeature(featureInput, featureOverlay, newGeom);
172
					}
162 173
				}
163 174
			}
164 175
		} catch (CreateGeometryException e) {
......
173 184
		return lastEditFeature;
174 185
	}
175 186
	
187
	private boolean typesMatch(int dalType, Geometry newGeom) {
188
		return 
189
		   ((dalType == TYPES.MULTICURVE && 
190
		   (newGeom instanceof MultiLineString || newGeom instanceof LineString)) ||
191
		   (dalType == TYPES.MULTIPOINT && 
192
		   (newGeom instanceof MultiPoint || newGeom instanceof Point)) ||
193
		   (dalType == TYPES.MULTISURFACE && 
194
	       (newGeom instanceof Polygon || newGeom instanceof MultiPolygon)) ||
195
	       (dalType == TYPES.CURVE && newGeom instanceof LineString) ||
196
	       (dalType == TYPES.SURFACE && newGeom instanceof Polygon) ||
197
	       (dalType == TYPES.POINT && newGeom instanceof Point));
198
		   
199
	}
200
	
176 201
//	private MultiCurve convertPolygonJTS2LineJTS(Polygon p) {
177 202
//		
178 203
//	}
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
152 152
		FeatureStore outFeatStorePoint = null;
153 153
		
154 154
		IntersectionOperation operation = new IntersectionOperation(storeOverlay, this);
155
		
155
		operation.setTaskStatus(getStatus());
156
		 
156 157
		//La de puntos se genera siempre
157 158
		outFeatStorePoint =
158 159
			buildOutPutStoreFromUnion(featureType1, featureType2,
159 160
					IVectorLayer.SHAPE_TYPE_POINT,
160 161
					getTranslation("Intersection_point"), RESULT_POINT);
161 162
		
163
		getStatus().setTitle("Point");
162 164
		operation.computesGeometryOperation(storeLayer, outFeatStorePoint, attrNames, selectedGeom, true);
163 165

  
164 166
		//La de pol?gonos solo si es intersecci?n entre pol?gonos
......
166 168
			outFeatStorePol =
167 169
              buildOutPutStoreFromUnion(featureType1, featureType2,
168 170
            		  IVectorLayer.SHAPE_TYPE_POLYGON, getTranslation("Intersection_polygon"), RESULT_POL);
171
			getStatus().setTitle("Polygon");
169 172
			operation.computesGeometryOperation(storeLayer, outFeatStorePol, attrNames, selectedGeom, true);
170 173
		}
171 174
		
......
174 177
			outFeatStoreLine =
175 178
              buildOutPutStoreFromUnion(featureType1, featureType2,
176 179
            		  IVectorLayer.SHAPE_TYPE_LINE, getTranslation("Intersection_line"), RESULT_LINE);
180
			getStatus().setTitle("Line");
177 181
			operation.computesGeometryOperation(storeLayer, outFeatStoreLine, attrNames, selectedGeom, true);
178 182
		}
179 183

  

Also available in: Unified diff