Revision 287

View differences:

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
59 59
import org.gvsig.geoprocess.algorithm.base.core.DALFeaturePersister;
60 60
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation;
61 61
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil;
62
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
62 63

  
63 64
import com.vividsolutions.jts.geom.Geometry;
64 65
/**
......
71 72
	private List<Feature>                    featList              = null;
72 73
	private FeatureStore                     outFeatureStoreTable  = null;
73 74
	private String                           idField               = "FID";
75
	private AbstractSextanteGeoProcess       geoprocess            = null;
76
	private int                              procesSize           = 0;
74 77
	
75 78
	public FuseSpatiallyOperation(List<Feature> f, FeatureStore outFeatStoreTable, String[] fieldNames, String idField) throws DataException {
76 79
		this.featList = f;
......
82 85
		this.featList = f;
83 86
		this.outFeatureStoreTable = outFeatStoreTable;
84 87
	}
88
	
89
	public void setGeoProcess(AbstractSextanteGeoProcess geoprocess, int size) {
90
		this.geoprocess = geoprocess;
91
		this.procesSize = size;
92
	}
85 93

  
86 94
	/*
87 95
	 * (non-Javadoc)
......
92 100
			Geometry jtsInputGeom = GeometryUtil.geomToJTS(g);
93 101
			insertInTable(feature);
94 102
			
95
			for (int i = featList.size() - 1; i >= 0; i--) {
96
				Feature f = featList.get(i);
103
			int cont = featList.size() - 1;
104
			while(cont >= 0 && !geoprocess.getTaskMonitor().isCanceled()) {
105
				Feature f = featList.get(cont);
97 106
				g = f.getDefaultGeometry();
98 107
				Geometry jtsGeom = GeometryUtil.geomToJTS(g); //Multigeometry support
99 108
				if(jtsGeom.intersects(jtsInputGeom)) {
100 109
					jtsInputGeom = jtsInputGeom.union(jtsGeom);
101
					featList.remove(i);
110
					featList.remove(cont);
111
					geoprocess.setProgress(procesSize - featList.size(), procesSize);
112
					cont = featList.size();
102 113
					insertInTable(f);
103 114
				}
115
				cont --;
104 116
			}
105
			
106
			/*int i = featList.size() - 1;
107
			while(i >= 0) {
108
				Feature f = featList.get(i);
109
				geom = f.getDefaultGeometry();
110
				Geometry jtsGeom = GeometryUtil.geomToJTS(geom); //Multigeometry support
111
				if(jtsInputGeom.intersects(jtsGeom)) {
112
					jtsInputGeom = jtsInputGeom.union(jtsGeom);
113
					featList.remove(i);
114
					insertInTable(f);
115
					i = featList.size();
116
				}
117
				i --;
118
			}*/
119 117

  
120 118
			//Cuando no genera dos capas mete los campos de la feature de entrada en la de salida perdiendose el resto
121 119
			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
24 24
package org.gvsig.geoprocess.algorithm.fusespatially;
25 25

  
26 26
import java.util.ArrayList;
27
import java.util.EmptyStackException;
28 27
import java.util.List;
29
import java.util.Stack;
30 28

  
31 29
import org.gvsig.fmap.dal.exception.DataException;
32 30
import org.gvsig.fmap.dal.feature.Feature;
33 31
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
34 32
import org.gvsig.fmap.dal.feature.FeatureSet;
35 33
import org.gvsig.fmap.dal.feature.FeatureStore;
36
import org.gvsig.fmap.dal.feature.FeatureType;
37
import org.gvsig.geoprocess.algorithm.base.core.DALFeaturePersister;
38 34
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
39 35
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
40 36
import org.gvsig.tools.dispose.DisposableIterator;
......
50 46

  
51 47
/**
52 48
 * Fuse spatially algorithm
49
 * Optimizaci?n:
50
 * 1- Recorrer todas las features y 
51
 * 		crear un hash con la lista de solapes para cada elemento
52
 * 		crear lista REV en la que cada elemento apunta a una feature y tiene un booleano que dices si ese elemento ha sido procesado
53
 * 2- Recorrer REV
54
 *      Obtener la lista de solapes del hash para el primer elemento sin marcar de REV
55
 *      Marcar REV de ese elemento
56
 *      Union de elementos que solapan en esa entrada del hash
57
 *      Para cada elemento que solapa:
58
 *          Obtener la lista de solapes del hash 
59
 *          Marcar REV de ese elemento
60
 *          Union de elementos que solapan en esa entrada del hash
61
 * 
53 62
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
54 63
 */
55 64
public class FuseSpatiallyAlgorithm extends AbstractSextanteGeoProcess {
......
58 67
	public static final String        RESULT_TABLE      = "RESULT_TABLE";
59 68
	public static final String        LAYER             = "LAYER";
60 69
	public static final String        SELECTED_GEOM     = "SELECTED_GEOM";
61
	private SimpleTaskStatus          status            = null;
62 70

  
63 71
	/*
64 72
	 * (non-Javadoc)
......
82 90
	 * (non-Javadoc)
83 91
	 * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
84 92
	 */
93
	@SuppressWarnings("unchecked")
85 94
	public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
86 95
		if(existsOutPutFile(DissolveAlgorithm.RESULT, 0)) {
87 96
    		throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
......
109 118
		}
110 119
	}
111 120
	
121
	@SuppressWarnings("unchecked")
112 122
	public boolean execute(FeatureStore inputStoreLayer, 
113 123
			FeatureStore outFeatStore,
114 124
			int shapeType, 
......
153 163
	 *        If it is true only the selected geometries will be processed
154 164
	 * @throws DataException
155 165
	 */
166
	@SuppressWarnings("deprecation")
156 167
	public void computesGeometryOperation(FeatureStore inFeatStore,
157 168
									FeatureStore outFeatStore,
158 169
									FeatureStore outFeatStoreTable,
......
186 197
		
187 198
		FuseSpatiallyOperation operation = new FuseSpatiallyOperation(featList, outFeatStoreTable, attrNamesTable, idField);
188 199
		operation.setFeatureStore(outFeatStore, attrNames);
200
		int size = featList.size();
201
		operation.setGeoProcess(this, size);
189 202
		
190
		try {
191
			while (featList.size() > 0) {
192
				Feature f = featList.remove(featList.size() - 1);	
193
				operation.invoke(f.getDefaultGeometry(), f);
194
			}
195
		}catch(EmptyStackException e) {
203
		while (featList.size() > 0 && !m_Task.isCanceled()) {
204
			Feature f = featList.remove(featList.size() - 1);	
205
			operation.invoke(f.getDefaultGeometry(), f);
206
			setProgress(size - featList.size(), size);
196 207
		}
197
		
208

  
198 209
		if(operation.getWriter() != null)
199 210
			operation.getWriter().end();
200 211
	}
201 212
	
213
	public boolean setProgress(int step, int size) {
214
		return super.setProgress(step, size);
215
	}
216
	
202 217
	/**
203 218
	 * Builds the output FeatureStore 
204 219
	 * @param featureType
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.dissolve/src/main/java/org/gvsig/geoprocess/algorithm/dissolve/AtomicDissolveOperation.java
48 48
import java.util.Iterator;
49 49
import java.util.List;
50 50

  
51
import com.vividsolutions.jts.geom.Geometry;
52

  
53
import es.unex.sextante.core.Sextante;
54

  
55 51
import org.gvsig.fmap.dal.exception.DataException;
56 52
import org.gvsig.fmap.dal.feature.EditableFeature;
57 53
import org.gvsig.fmap.dal.feature.Feature;
......
61 57
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation;
62 58
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil;
63 59
import org.gvsig.tools.dispose.DisposableIterator;
60

  
61
import com.vividsolutions.jts.geom.Geometry;
62

  
63
import es.unex.sextante.core.Sextante;
64 64
/**
65 65
 * Atomic dissolve operation
66 66
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
......
126 126
	public void setFeatureStore(FeatureStore in) {
127 127
		this.inFeatureStore = in;
128 128
	}
129

  
129
	
130 130
	/*
131 131
	 * (non-Javadoc)
132 132
	 * @see org.gvsig.geoprocess.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.Feature)
......
141 141
		//Si son iguales las geometrias no se opera
142 142
		if(g1.compareTo(g2) == 0)
143 143
			return null;
144
		/*boolean verify =  false;
145
		for (int i = 0; i < geometryList.size(); i++) {
146
			if(rule.verifyIfDissolve(geometryList.get(i), g2, this.feature, feature)) {
147
				verify = true;
148
				break;
149
			}
150
		}*/
151
		if(geometryList.size() > 1)
152
			System.out.println();
144 153
		
145 154
		if(rule.verifyIfDissolve(g1, g2, this.feature, feature)) {
146 155
			geometryList.add(g2);
......
162 171
		}
163 172
		return result;
164 173
	}
174

  
175
	/*
176
	 * (non-Javadoc)
177
	 * @see org.gvsig.geoprocess.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.Feature)
178
	 */
179
	/*public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature feature) {
180
		com.vividsolutions.jts.geom.Geometry g2 = GeometryUtil.geomToJTS(g);
181
		List<Geometry> geomToJoin = new ArrayList<Geometry>();
182
		Geometry newGeom = null;
183
		
184
		for (int i = 0; i < geometryList.size(); i++) {
185
			Geometry g1 = geometryList.get(i);
186
			if(g1 == null)
187
				return null;
188
			
189
			//Si son iguales las geometrias no se opera
190
			if(g1.compareTo(g2) == 0)
191
				return null;
192
			
193
			geomToJoin.clear();
194
			geomToJoin.add(g1);
195
			
196
			if(rule.verifyIfDissolve(g1, g2, this.feature, feature)) {
197
				geomToJoin.add(g2);
198
				newGeom = GeometryUtil.geometryUnion(geomToJoin, g.getGeometryType().getType());
199
				g2 = newGeom;
200
			}
201
		}
202
		
203
		if(newGeom != null) {
204
			try {
205
				result = outFeatureStore.createNewFeature();
206
				result.setDouble(0, newFeatID);
207
				result.set(1, feature.get(rule.getIndexField()));
208
				summary.updateValues(feature);
209
				summary.loadEditableFeature(result);
210

  
211
				result.setGeometry("GEOMETRY", GeometryUtil.jtsToGeom(newGeom));
212
				analizedFeats[featAnalized] = true;
213
			} catch (DataException e) {
214
				Sextante.addErrorToLog(e);
215
			}
216
		}
217
		return result;
218
	}*/
165 219
	
166 220
	/*
167 221
	 * (non-Javadoc)
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.buffer/src/main/java/org/gvsig/geoprocess/algorithm/buffer/OutBufferOperation.java
67 67
        double bufferDistance =
68 68
            distance.getBufferDistance(userDistance, projection,
69 69
                getDistanceUnits(), getMapUnits());
70

  
70
        
71
        if(originalGeometry == null)
72
        	return null;
73
        
71 74
        if (originalGeometry.getDimension() != 0)
72 75
            inputParam =
73 76
                TopologyPreservingSimplifier.simplify(originalGeometry,
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
288 288

  
289 289
    @Override
290 290
    protected void setProgressText(String sText) {
291
    	super.setProgressText(sText);
291 292
        getStatus().message(sText);
292 293
    }
293 294

  
294 295
    @Override
295
    protected boolean setProgress(int iStep, int iTotalNumberOfSteps) {
296
    public boolean setProgress(int iStep, int iTotalNumberOfSteps) {
297
    	super.setProgress(iStep, iTotalNumberOfSteps);
296 298
        SimpleTaskStatusDelegated status = getStatus();
297 299
        status.setRangeOfValues(0, iTotalNumberOfSteps);
298 300
        status.setCurValue(iStep);
......
379 381
    		return (new File(s + ".tif").exists());
380 382
    	return false;
381 383
    }
384
    
385
    public ITaskMonitor getTaskMonitor() {
386
    	return m_Task;
387
    }
382 388
}

Also available in: Unified diff