Revision 1259

View differences:

org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.base/src/main/java/org/gvsig/geoprocess/algorithm/base/core/DALFeaturePersister.java
617 617
			}
618 618
	           org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom);
619 619
               if(multiGeometry!=null && acceptType(store, multiGeometry)){
620
                   feat.setGeometry("GEOMETRY", multiGeometry);
620
                   feat.setDefaultGeometry(multiGeometry);
621 621
               } else {
622
                   feat.setGeometry("GEOMETRY", newDalGeom);
622
                   feat.setDefaultGeometry(newDalGeom);
623 623
               }
624 624
			store.insert(feat);
625 625
			return feat;
......
644 644
			feat.set(2, value2);
645 645
	           org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom);
646 646
               if(multiGeometry!=null && acceptType(store, multiGeometry)){
647
                   feat.setGeometry("GEOMETRY", multiGeometry);
647
                   feat.setDefaultGeometry(multiGeometry);
648 648
               } else {
649
                   feat.setGeometry("GEOMETRY", newDalGeom);
649
                   feat.setDefaultGeometry(newDalGeom);
650 650
               }
651 651
			store.insert(feat);
652 652
			return feat;
......
682 682
			//Sets the geometry
683 683
			org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom);
684 684
			if(multiGeometry!=null && acceptType(store, multiGeometry)){
685
			    feat.setGeometry("GEOMETRY", multiGeometry);
685
			    feat.setDefaultGeometry(multiGeometry);
686 686
			} else {
687
			    feat.setGeometry("GEOMETRY", newGeom);
687
			    feat.setDefaultGeometry(newGeom);
688 688
			}
689 689
			store.insert(feat);
690 690
			return feat;
......
704 704
			EditableFeature feat = store.createNewFeature(store.getDefaultFeatureType(), feature);
705 705
			org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom);
706 706
			if (multiGeometry!=null && acceptType(store, multiGeometry)){
707
				feat.setGeometry(fieldNames.length, multiGeometry);
707
				feat.setDefaultGeometry(multiGeometry);
708 708
			} else {
709
				feat.setGeometry(fieldNames.length, newGeom);
709
				feat.setDefaultGeometry(newGeom);
710 710
			}
711 711
			store.insert(feat);
712 712
			return feat;
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.spatialjoin/src/main/java/org/gvsig/geoprocess/algorithm/spatialjoin/SpatiallyIndexedSpatialJoinOperation.java
29 29
import org.apache.commons.lang3.mutable.MutableObject;
30 30

  
31 31
import es.unex.sextante.core.Sextante;
32
import java.util.List;
32 33

  
33 34
import org.gvsig.fmap.dal.exception.DataException;
34 35
import org.gvsig.fmap.dal.feature.EditableFeature;
35 36
import org.gvsig.fmap.dal.feature.Feature;
37
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
36 38
import org.gvsig.fmap.dal.feature.FeatureIndex;
37 39
import org.gvsig.fmap.dal.feature.FeatureIndexes;
38 40
import org.gvsig.fmap.dal.feature.FeatureReference;
......
49 51
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
50 52
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
51 53
import org.gvsig.tools.exception.BaseException;
54
import org.gvsig.tools.namestranslator.NamesTranslator;
52 55
import org.gvsig.tools.visitor.VisitCanceledException;
53 56
import org.gvsig.tools.visitor.Visitor;
54 57

  
......
57 60
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
58 61
 */
59 62
public class SpatiallyIndexedSpatialJoinOperation extends GeometryOperation {
60
	private FeatureStore               storeOverlay        = null;
61
	private FeatureSelection           featureSelection    = null;
62 63

  
63
	/**
64
	 * Geometry.distance() is a costly operation. Thats the reason for we are
65
	 * only using a nearest neighbor. TODO SpatialIndex works with Rectangle2D,
66
	 * and this may be a simplification that drives to errors. Make additional
67
	 * probes to use a number of default neighbors
68
	 */
69
	static final int                  DEFAULT_NUM_NEIGBOURS = 1;
64
    private FeatureStore storeOverlay = null;
65
    private FeatureSelection featureSelection = null;
70 66

  
71
	/**
72
	 * Number of neighbors that nearestFinder must found.
73
	 */
74
	int                               numOfNeighbours       = DEFAULT_NUM_NEIGBOURS;
67
    /**
68
     * Geometry.distance() is a costly operation. Thats the reason for we are
69
     * only using a nearest neighbor. TODO SpatialIndex works with Rectangle2D,
70
     * and this may be a simplification that drives to errors. Make additional
71
     * probes to use a number of default neighbors
72
     */
73
    static final int DEFAULT_NUM_NEIGBOURS = 1;
75 74

  
76
	/**
77
	 * Specialized instance in nearest neighbor search.
78
	 */
79
	private SpatialIndex              index                 = null;
75
    /**
76
     * Number of neighbors that nearestFinder must found.
77
     */
78
    int numOfNeighbours = DEFAULT_NUM_NEIGBOURS;
80 79

  
81
	public SpatiallyIndexedSpatialJoinOperation(FlyrVectIVectorLayer targetLayer, SpatialIndex index, AbstractSextanteGeoProcess p) {
82
		super(p);
83
		this.index = index;
84
		storeOverlay = targetLayer.getFeatureStore();
85
	}
80
    /**
81
     * Specialized instance in nearest neighbor search.
82
     */
83
    private SpatialIndex index = null;
86 84

  
87
	/*
85
    public SpatiallyIndexedSpatialJoinOperation(FlyrVectIVectorLayer targetLayer, SpatialIndex index, AbstractSextanteGeoProcess p) {
86
        super(p);
87
        this.index = index;
88
        storeOverlay = targetLayer.getFeatureStore();
89
    }
90

  
91
    /*
88 92
	 * (non-Javadoc)
89 93
	 * @see org.gvsig.geoprocess.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.Feature)
90
	 */
91
	@SuppressWarnings({ "unchecked", "deprecation" })
94
     */
95
    @SuppressWarnings({"unchecked", "deprecation"})
92 96
    public EditableFeature invoke(final org.gvsig.fmap.geom.Geometry g, Feature featureInput) {
93
	    final MutableObject<Feature> foundFeature = new MutableObject<Feature>(null);
97
        final MutableObject<Feature> foundFeature = new MutableObject<Feature>(null);
94 98
        boolean addedFeature = false;
95
        if (g == null)
99
        if (g == null) {
96 100
            return lastEditFeature;
101
        }
97 102

  
98 103
        try {
99 104
            final MutableDouble nearestDistance = new MutableDouble(Double.POSITIVE_INFINITY);
......
125 130
                }
126 131
            }
127 132

  
128
            if(foundFeature!=null){
133
            if (foundFeature != null) {
129 134
                buildFeature(featureInput, foundFeature.getValue(), new Double(nearestDistance.getValue()), g);
130 135
                addedFeature = true;
131 136
            }
......
137 142
        return lastEditFeature;
138 143
    }
139 144

  
140
	/**
141
	 * Builds a feature and adds it to the output file
142
	 * @param feat1
143
	 * @param feat2
144
	 * @param value
145
	 * @param g
146
	 * @throws DataException
147
	 */
148
	private void buildFeature(Feature feat1, Feature feat2, Object value, org.gvsig.fmap.geom.Geometry g) throws DataException {
149
		EditableFeature outFeat = persister.getOutputFeatureStore().createNewFeature();
150
		int sizeFeat1 = feat1.getType().size() - 1;
145
    /**
146
     * Builds a feature and adds it to the output file
147
     *
148
     * @param feat1
149
     * @param feat2
150
     * @param value
151
     * @param g
152
     * @throws DataException
153
     */
154
    private void buildFeature(Feature feat1, Feature feat2, Object value, org.gvsig.fmap.geom.Geometry g) throws DataException {
155
        EditableFeature outFeat = persister.getOutputFeatureStore().createNewFeature();
156
        NamesTranslator nameTranslator;
157
        try {
158
            nameTranslator = ((SpatialJoinAlgorithm) this.process).namesTranslator;
159
        } catch (Exception ex) {
160
            nameTranslator = null;
161
        }
162
        if (nameTranslator != null) {
163
            for (FeatureAttributeDescriptor attr1 : feat1.getType().getAttributeDescriptors()) {
164
                String attrName = attr1.getName();
165
                String translation = nameTranslator.getTranslation(attrName);
166
                Object fValue = feat1.get(attrName);
167
                if (translation!=null && !translation.isEmpty()) {
168
                    outFeat.set(translation, fValue);
169
                }
170
            }
171
            for (FeatureAttributeDescriptor attr2 : feat2.getType().getAttributeDescriptors()) {
172
                String attrName = attr2.getName();
173
                List<String> translation = nameTranslator.getAllTranslations(attrName);
174
                Object fValue = feat2.get(attrName);
175
                if (translation!=null && !translation.isEmpty()) {
176
                    outFeat.set(translation.get(translation.size() - 1), fValue);
177
                }
178
            }
179
            outFeat.set(nameTranslator.getTranslation("DIST"), (Object) value);
180
        } else {
181
            outFeat.copyFrom(feat2);
182
            outFeat.copyFrom(feat1);
183
            outFeat.set("DIST", (Object) value);
184
        }
151 185

  
152
		for (int i = 0; i < sizeFeat1; i++)
153
			outFeat.set(i, feat1.get(i));
186
        try {
187
            persister.addFeature(outFeat, g);
188
        } catch (CreateGeometryException e) {
189
            Sextante.addErrorToLog(e);
190
        }
191
    }
154 192

  
155
		for (int i = sizeFeat1; i < sizeFeat1 + feat2.getType().size() - 1; i++)
156
			outFeat.set(i, feat2.get(i - sizeFeat1));
157

  
158
		outFeat.set(outFeat.getType().size() - 2, value);
159
		try {
160
			persister.addFeature(outFeat, g);
161
		} catch (CreateGeometryException e) {
162
			Sextante.addErrorToLog(e);
163
		}
164
	}
165

  
166
	/*
193
    /*
167 194
	 * (non-Javadoc)
168 195
	 * @see org.gvsig.geoprocess.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.EditableFeature)
169
	 */
170
	public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput) {
196
     */
197
    public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput) {
171 198

  
172
	}
199
    }
173 200

  
174 201
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.spatialjoin/src/main/java/org/gvsig/geoprocess/algorithm/spatialjoin/SpatialJoinAlgorithm.java
56 56
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
57 57
import org.gvsig.tools.dynobject.DynObject;
58 58
import org.gvsig.tools.exception.BaseException;
59
import org.gvsig.tools.namestranslator.NamesTranslator;
59 60
import org.gvsig.tools.visitor.VisitCanceledException;
60 61
import org.gvsig.tools.visitor.Visitor;
61 62

  
62 63
/**
63 64
 * Spatial join algorithm
65
 *
64 66
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
65 67
 */
66 68
public class SpatialJoinAlgorithm extends AbstractSextanteGeoProcess {
67 69

  
68
	public static final String        NEW_FIELD             = "NUM_RELA";
69
	public static final String        RESULT                = "RESULT";
70
	public static final String        LAYER1                = "LAYER1";
71
	public static final String        LAYER2                = "LAYER2";
72
	public static final String        SELECTGEOM_INPUT      = "SELECTGEOM_INPUT";
73
	public static final String        SELECTGEOM_OVERLAY    = "SELECTGEOM_OVERLAY";
74
	public static final String        NEAREST               = "NEAREST";
75
	public static final String        FUNCTION_LIST         = "FUNCTION_LIST";
76
	public static final String        Summary[]             = {"Min", "Max", "Sum", "Avg"};
77
	private boolean                   funcList[]            = new boolean[Summary.length];
78
	private HashMap<String, String>   funcMap               = new HashMap<String, String>();
70
    public static final String NEW_FIELD = "NUM_RELA";
71
    public static final String RESULT = "RESULT";
72
    public static final String LAYER1 = "LAYER1";
73
    public static final String LAYER2 = "LAYER2";
74
    public static final String SELECTGEOM_INPUT = "SELECTGEOM_INPUT";
75
    public static final String SELECTGEOM_OVERLAY = "SELECTGEOM_OVERLAY";
76
    public static final String NEAREST = "NEAREST";
77
    public static final String FUNCTION_LIST = "FUNCTION_LIST";
78
    public static final String Summary[] = {"Min", "Max", "Sum", "Avg"};
79
    private boolean funcList[] = new boolean[Summary.length];
80
    private HashMap<String, String> funcMap = new HashMap<String, String>();
81
    public NamesTranslator namesTranslator;
79 82

  
80
	public void defineCharacteristics(){
83
    public void defineCharacteristics() {
81 84
        setName(getTranslation("Spatialjoin"));
82 85
        setGroup(getTranslation("basic_vect_algorithms"));
83 86
        // setGeneratesUserDefinedRasterOutput(false);
84 87

  
85
		try {
86
			m_Parameters.addInputVectorLayer(LAYER1,
87
                getTranslation("Input_layer"),
88
												IVectorLayer.SHAPE_TYPE_WRONG,
89
												true);
90
			m_Parameters.addInputVectorLayer(LAYER2,
91
                getTranslation("Input_layer"),
92
												IVectorLayer.SHAPE_TYPE_WRONG,
93
												true);
88
        try {
89
            m_Parameters.addInputVectorLayer(LAYER1,
90
                    getTranslation("Input_layer"),
91
                    IVectorLayer.SHAPE_TYPE_WRONG,
92
                    true);
93
            m_Parameters.addInputVectorLayer(LAYER2,
94
                    getTranslation("Input_layer"),
95
                    IVectorLayer.SHAPE_TYPE_WRONG,
96
                    true);
94 97
            m_Parameters.addBoolean(SELECTGEOM_INPUT,
95
            		getTranslation("Selected_geometries_input_layer"), false);
98
                    getTranslation("Selected_geometries_input_layer"), false);
96 99
            m_Parameters.addBoolean(SELECTGEOM_OVERLAY,
97
            		getTranslation("Selected_geometries_overlay_layer"), false);
100
                    getTranslation("Selected_geometries_overlay_layer"), false);
98 101
            m_Parameters.addBoolean(NEAREST, getTranslation("use_the_nearest"), false);
99 102
            m_Parameters.addString(FUNCTION_LIST,
100
                getTranslation("Function_list"));
101
		} catch (RepeatedParameterNameException e) {
102
			Sextante.addErrorToLog(e);
103
		}
104
		addOutputVectorLayer(RESULT,getTranslation("Spatialjoin"),
105
								OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
106
	}
103
                    getTranslation("Function_list"));
104
        } catch (RepeatedParameterNameException e) {
105
            Sextante.addErrorToLog(e);
106
        }
107
        addOutputVectorLayer(RESULT, getTranslation("Spatialjoin"),
108
                OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
109
    }
107 110

  
108
	public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
109
		if(existsOutPutFile(SpatialJoinAlgorithm.RESULT, 0)) {
110
    		throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
111
    	}
112
		IVectorLayer layer1 = m_Parameters.getParameterValueAsVectorLayer(LAYER1); //Capa de entrada
113
		IVectorLayer layer2 = m_Parameters.getParameterValueAsVectorLayer(LAYER2); //Capa de revestimiento
114
		boolean selectedGeomInput = m_Parameters.getParameter(SELECTGEOM_INPUT).getParameterValueAsBoolean();
115
		boolean selectedGeomOverlay = m_Parameters.getParameter(SELECTGEOM_OVERLAY).getParameterValueAsBoolean();
116
		boolean nearest = m_Parameters.getParameterValueAsBoolean(NEAREST);
117
		String functionList = m_Parameters.getParameterValueAsString(FUNCTION_LIST);
118
		loadSummary(functionList);
111
    public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
112
        if (existsOutPutFile(SpatialJoinAlgorithm.RESULT, 0)) {
113
            throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
114
        }
115
        IVectorLayer layer1 = m_Parameters.getParameterValueAsVectorLayer(LAYER1); //Capa de entrada
116
        IVectorLayer layer2 = m_Parameters.getParameterValueAsVectorLayer(LAYER2); //Capa de revestimiento
117
        boolean selectedGeomInput = m_Parameters.getParameter(SELECTGEOM_INPUT).getParameterValueAsBoolean();
118
        boolean selectedGeomOverlay = m_Parameters.getParameter(SELECTGEOM_OVERLAY).getParameterValueAsBoolean();
119
        boolean nearest = m_Parameters.getParameterValueAsBoolean(NEAREST);
120
        String functionList = m_Parameters.getParameterValueAsString(FUNCTION_LIST);
121
        loadSummary(functionList);
119 122

  
120
		FlyrVectIVectorLayer inputLayer = null;
121
		FlyrVectIVectorLayer overlayLayer = null;
123
        FlyrVectIVectorLayer inputLayer = null;
124
        FlyrVectIVectorLayer overlayLayer = null;
122 125
		if(layer2 instanceof FlyrVectIVectorLayer && layer1 instanceof FlyrVectIVectorLayer) {
123 126
			overlayLayer = ((FlyrVectIVectorLayer)layer2); //Capa de revestimiento
124 127
			inputLayer = ((FlyrVectIVectorLayer)layer1); //Capa de entrada
125 128
		} else
126
			return false;
129
            return false;
127 130

  
128
		DataManager dataManager = DALLocator.getDataManager();
131
        DataManager dataManager = DALLocator.getDataManager();
129 132

  
130
		//Builds the output and computes the operation
131
		try {
132
			FeatureType featureTypeInputLayer = inputLayer.getFeatureStore().getDefaultFeatureType(); //Capa de entrada
133
			FeatureType featureTypeOverlayLayer = overlayLayer.getFeatureStore().getDefaultFeatureType(); //Capa de revestimiento
133
        //Builds the output and computes the operation
134
        try {
135
            FeatureType featureTypeInputLayer = inputLayer.getFeatureStore().getDefaultFeatureType(); //Capa de entrada
136
            FeatureType featureTypeOverlayLayer = overlayLayer.getFeatureStore().getDefaultFeatureType(); //Capa de revestimiento
134 137

  
135
			GeometryOperation operation = null;
136
			FeatureStore outFeatStore = null;
138
            GeometryOperation operation = null;
139
            FeatureStore outFeatStore = null;
140
            this.namesTranslator = NamesTranslator.createTrimTranslator(10);
137 141

  
138 142
            if (nearest) {
139 143
                outFeatStore =
140 144
                    buildOutPutStoreFromUnion(featureTypeInputLayer, featureTypeOverlayLayer,
141
                        inputLayer.getShapeType(), getTranslation("SpatialJoin"),
142
                        RESULT, "DIST", Double.class);
145
                                inputLayer.getShapeType(), getTranslation("SpatialJoin"),
146
                                RESULT, "DIST", Double.class, namesTranslator);
143 147

  
144 148
                operation =
145 149
                    new SpatiallyIndexedSpatialJoinOperation(overlayLayer, createIndex(overlayLayer.getFeatureStore(), selectedGeomOverlay), this);
146 150
            } else {
147 151
                outFeatStore =
148 152
                    buildSpatialJoinOutPutStore(featureTypeInputLayer,
149
                        inputLayer.getShapeType(), getTranslation("SpatialJoin"),
150
                        RESULT);
151
                IDissolveRule rule = new DissolveRule(0, funcMap);
152
                Summary summary =
153
                    new Summary(rule, outFeatStore.getDefaultFeatureType());
154
                operation =
155
                    new IntersectsSpatialJoinOperation(overlayLayer,
156
                        createIndex(overlayLayer.getFeatureStore(), selectedGeomOverlay), summary, this);
153
                                inputLayer.getShapeType(), getTranslation("SpatialJoin"),
154
                                RESULT);
155
                IDissolveRule rule = new DissolveRule(featureTypeInputLayer.getAttributeName(0), funcMap);
156
                
157
                Summary summary
158
                        = new Summary(rule, outFeatStore.getDefaultFeatureType());
159
                operation
160
                        = new IntersectsSpatialJoinOperation(overlayLayer,
161
                                createIndex(overlayLayer.getFeatureStore(), selectedGeomOverlay), summary, this);
157 162
            }
158 163

  
159 164
            operation.setTaskStatus(getStatus());
160
			operation.computesGeometryOperation(inputLayer.getFeatureStore(),
161
					outFeatStore,
162
					attrNames,
163
					selectedGeomInput,
164
					selectedGeomOverlay,
165
					true);
166
		} catch (Exception e) {
167
			Sextante.addErrorToLog(e);
165
            operation.computesGeometryOperation(inputLayer.getFeatureStore(),
166
                    outFeatStore,
167
                    attrNames,
168
                    selectedGeomInput,
169
                    selectedGeomOverlay,
170
                    true);
171
        } catch (Exception e) {
172
            Sextante.addErrorToLog(e);
168 173
        }
169 174

  
170
		return true;
171
	}
175
        return true;
176
    }
172 177

  
173
	private SpatialIndex createIndex(FeatureStore store, boolean selectionOnly) throws BaseException{
174
	    GeometryManager geomManager = GeometryLocator.getGeometryManager();
178
    private SpatialIndex createIndex(FeatureStore store, boolean selectionOnly) throws BaseException {
179
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
175 180

  
176
	    SpatialIndexFactory factory = geomManager.getSpatialIndexFactory(geomManager.SPATIALINDEX_DEFAULT_RTREE);
177
	    DynObject parameters = factory.createParameters();
181
        SpatialIndexFactory factory = geomManager.getSpatialIndexFactory(geomManager.SPATIALINDEX_DEFAULT_RTREE);
182
        DynObject parameters = factory.createParameters();
178 183

  
179
	    SpatialIndex index = (SpatialIndex) factory.create(parameters, geomManager);
180
	    final SpatialIndex wrappedIndex = store.wrapSpatialIndex(index);
184
        SpatialIndex index = (SpatialIndex) factory.create(parameters, geomManager);
185
        final SpatialIndex wrappedIndex = store.wrapSpatialIndex(index);
181 186

  
182
	    Visitor visitor = new Visitor() {
187
        Visitor visitor = new Visitor() {
183 188

  
184 189
            @Override
185 190
            public void visit(Object obj) throws VisitCanceledException, BaseException {
186
                Feature f=(Feature) obj;
191
                Feature f = (Feature) obj;
187 192
                Geometry g = f.getDefaultGeometry();
188 193
                FeatureReference ref = f.getReference();
189 194
                wrappedIndex.insert(g, ref);
190 195
            }
191 196
        };
192
        if(selectionOnly){
197
        if (selectionOnly) {
193 198
            store.getFeatureSelection().accept(visitor);
194 199
        } else {
195 200
            store.accept(visitor);
196 201
        }
197 202

  
198
	    return wrappedIndex;
199
	}
203
        return wrappedIndex;
204
    }
200 205

  
201
	/**
202
	 * Checks if the parameter is in Summary list
203
	 * @param it
204
	 * @return the position in the list
205
	 */
206
	private int isInList(String it) {
207
		for (int i = 0; i < Summary.length; i++) {
208
			if(Summary[i].compareTo(it) == 0)
209
				return i;
210
		}
211
		return -1;
212
	}
206
    /**
207
     * Checks if the parameter is in Summary list
208
     *
209
     * @param it
210
     * @return the position in the list
211
     */
212
    private int isInList(String it) {
213
        for (int i = 0; i < Summary.length; i++) {
214
            if (Summary[i].compareTo(it) == 0) {
215
                return i;
216
            }
217
        }
218
        return -1;
219
    }
213 220

  
214
	/**
215
	 * Loads the list of functions to use
216
	 * @param functionList
217
	 */
218
	private void loadSummary(String functionList) {
219
		String[] attrList = functionList.split(";");
220
		for (int i = 0; i < attrList.length; i++) {
221
			String[] func = attrList[i].split(",");
222
			for (int j = 1; j < func.length; j++) {
223
				int pos = isInList(func[j]);
224
				if(pos != -1) {
225
					funcList[pos] = true;
226
					funcMap.put(Summary[pos], func[0]);
227
				}
228
			}
229
		}
230
	}
221
    /**
222
     * Loads the list of functions to use
223
     *
224
     * @param functionList
225
     */
226
    private void loadSummary(String functionList) {
227
        String[] attrList = functionList.split(";");
228
        for (int i = 0; i < attrList.length; i++) {
229
            String[] func = attrList[i].split(",");
230
            for (int j = 1; j < func.length; j++) {
231
                int pos = isInList(func[j]);
232
                if (pos != -1) {
233
                    funcList[pos] = true;
234
                    funcMap.put(Summary[pos], func[0]);
235
                }
236
            }
237
        }
238
    }
231 239

  
232
	/**
233
	 * Builds the output FeatureStore
234
	 * @param featureType
235
	 * @return FeatureStore
236
	 */
237
	protected FeatureStore buildSpatialJoinOutPutStore(FeatureType featureType1,
238
											int shapeType,
239
											String sextanteLayerName,
240
											String sextanteLayerLabel) {
241
		ArrayList<Class> typesList = new ArrayList<Class>();
242
		ArrayList<String> attr = new ArrayList<String>();
240
    /**
241
     * Builds the output FeatureStore
242
     *
243
     * @param featureType
244
     * @return FeatureStore
245
     */
246
    protected FeatureStore buildSpatialJoinOutPutStore(FeatureType featureType1,
247
            int shapeType,
248
            String sextanteLayerName,
249
            String sextanteLayerLabel) {
250
        ArrayList<Class> typesList = new ArrayList<Class>();
251
        ArrayList<String> attr = new ArrayList<String>();
243 252

  
244
		Iterator it = featureType1.iterator();
245
		while( it.hasNext() ) {
246
			FeatureAttributeDescriptor attribute = (FeatureAttributeDescriptor)it.next();
247
			if (attribute.getDataType().getType() != DataTypes.GEOMETRY) {
248
				attr.add(attribute.getName());
249
				typesList.add(attribute.getObjectClass());
250
			}
251
		}
253
        Iterator it = featureType1.iterator();
254
        while (it.hasNext()) {
255
            FeatureAttributeDescriptor attribute = (FeatureAttributeDescriptor) it.next();
256
            if (attribute.getDataType().getType() != DataTypes.GEOMETRY) {
257
                attr.add(attribute.getName());
258
                typesList.add(attribute.getObjectClass());
259
            }
260
        }
252 261

  
253
		for (int i = 0; i < funcList.length; i++) {
254
			if(funcList[i]) {
255
				String fieldName = funcMap.get(Summary[i]);
256
				if(fieldName.length() >= 6)
257
					fieldName = fieldName.substring(0, 7);
258
				attr.add(fieldName + "_" + Summary[i]);
259
				typesList.add(Double.class);
260
			}
261
		}
262
        for (int i = 0; i < funcList.length; i++) {
263
            if (funcList[i]) {
264
                String fieldName = funcMap.get(Summary[i]);
265
                if (fieldName.length() >= 6) {
266
                    fieldName = fieldName.substring(0, 7);
267
                }
268
                attr.add(fieldName + "_" + Summary[i]);
269
                typesList.add(Double.class);
270
            }
271
        }
262 272

  
263
		attr.add(NEW_FIELD);
264
		typesList.add(Integer.class);
273
        attr.add(NEW_FIELD);
274
        typesList.add(Integer.class);
265 275

  
266
		attrNames = new String[attr.size()];
267
		attr.toArray(attrNames);
268
		Class[] types = new Class[typesList.size()];
269
		typesList.toArray(types);
276
        attrNames = new String[attr.size()];
277
        attr.toArray(attrNames);
278
        Class[] types = new Class[typesList.size()];
279
        typesList.toArray(types);
270 280

  
271
		try {
272
			IVectorLayer output = getNewVectorLayer(sextanteLayerLabel,
273
													sextanteLayerName,
274
													shapeType, types, attrNames);
275
			return ((FlyrVectIVectorLayer)output).getFeatureStore();
276
		} catch (UnsupportedOutputChannelException e) {
277
			Sextante.addErrorToLog(e);
281
        try {
282
            IVectorLayer output = getNewVectorLayer(sextanteLayerLabel,
283
                    sextanteLayerName,
284
                    shapeType, types, attrNames);
285
            return ((FlyrVectIVectorLayer) output).getFeatureStore();
286
        } catch (UnsupportedOutputChannelException e) {
287
            Sextante.addErrorToLog(e);
278 288
        } catch (GeoAlgorithmExecutionException e) {
279 289
            Sextante.addErrorToLog(e);
280 290
        }
281
		return null;
282
	}
291
        return null;
292
    }
283 293

  
284 294
    @Override
285 295
    public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() {
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
140 140
			try {
141 141
				result = outFeatureStore.createNewFeature();
142 142
				result.setDouble(0, newFeatID);
143
				result.set(1, feature.get(rule.getIndexField()));
143
				result.set(1, feature.get(rule.getFieldName()));
144 144
				summary.updateValues(feature);
145 145
				summary.loadEditableFeature(result);
146 146

  
......
210 210
				Geometry newGeom = GeometryUtil.geometryUnion(geometryList, feature.getDefaultGeometry().getGeometryType().getType());
211 211
				result = outFeatureStore.createNewFeature();
212 212
				result.setDouble(0, newFeatID);
213
				result.set(1, feature.get(rule.getIndexField()));
213
				result.set(1, feature.get(rule.getFieldName()));
214 214
				summary.updateValues(feature);
215 215
				summary.loadEditableFeature(result);
216 216
				result.setGeometry("GEOMETRY", GeometryUtil.jtsToGeom(newGeom));
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.dissolve/src/main/java/org/gvsig/geoprocess/algorithm/dissolve/DissolveOperationFast.java
351 351
    private void addFeatureToOutput(Geometry newGeom, Feature feat, int newFeatID) throws DataException, CreateGeometryException {
352 352
        EditableFeature result = persister.getOutputFeatureStore().createNewFeature();
353 353
        result.setDouble(0, newFeatID);
354
        result.set(1, feat.get(rule.getIndexField()));
354
        result.set(1, feat.get(rule.getFieldName()));
355 355
        result.setGeometry("GEOMETRY", GeometryUtil.jtsToGeom(newGeom));
356 356
        summary.loadEditableFeature(result);
357 357
        lastEditFeature = persister.addFeature(result, result.getDefaultGeometry());
......
391 391
                elem.insertedToJoin = true;
392 392
            }
393 393
            try {
394
                summary.updateValues(elem.feat);
394 395
                addFeatureToOutput(elem.jtsGeom, elem.feat, iFeat);
395 396
            } catch (CreateGeometryException e) {
396 397
                logger.info("Error a?adiendo geometr?a", e);
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.dissolve/src/main/java/org/gvsig/geoprocess/algorithm/dissolve/IDissolveRule.java
64 64
	 * Gets the index of the field to apply the dissolve rule
65 65
	 * @return
66 66
	 */
67
	public int getIndexField();
67
	public String getFieldName();
68 68
}
69 69

  
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.dissolve/src/main/java/org/gvsig/geoprocess/algorithm/dissolve/DissolveParametersPanel.java
58 58
import es.unex.sextante.gui.algorithm.OutputChannelSelectionPanel;
59 59
import es.unex.sextante.gui.core.SextanteGUI;
60 60
import es.unex.sextante.outputs.Output;
61
import java.util.Arrays;
61 62

  
62 63
/**
63 64
 * Panel for dissolve algorithm
......
385 386
	 */
386 387
	public List<String> getFieldList() {
387 388
		IVectorLayer layer = getSelectedVectorLayer();
388
		String geometryAttrName = "GEOMETRY";
389
		if(layer instanceof FlyrVectIVectorLayer) {
390
			FeatureStore featStore = ((FlyrVectIVectorLayer)layer).getFeatureStore();
391
			try {
392
				geometryAttrName = featStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
393
			} catch (DataException e) {
394
				//Se usa el nombre por defecto
395
			}
396
		}
397
		List<String> data = new ArrayList<String>();
398
		for (int i = 0; i < layer.getFieldCount(); i++) {
399
			if(!layer.getFieldName(i).equals(geometryAttrName))
400
				data.add(layer.getFieldName(i));
401
		}
402
		return data;
389
		return Arrays.asList(layer.getFieldNames());
403 390
	}
404 391
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.dissolve/src/main/java/org/gvsig/geoprocess/algorithm/dissolve/Summary.java
153 153
			FeatureAttributeDescriptor[] desc = featType.getAttributeDescriptors();
154 154
			Object obj = null;
155 155
			String fName = null;
156
			sum = avg = sumAvg = 0;
156
			sum = avg = sumAvg = nfeat = 0;
157 157
			
158 158
			for (int i = 0; i < desc.length; i++) {
159 159
				String fieldName = desc[i].getName();
......
172 172
						min = ((Number)obj).doubleValue();
173 173
					}
174 174
				}
175
				
176
				if(fieldName.endsWith("_Sum")) {
177
					fName = rule.getFieldName("Sum");
178
					if(fName != null) {
179
						obj = feature.get(fName);
180
						sum = ((Number)obj).doubleValue();
181
					}
182
				}
183
				
184
				if(fieldName.endsWith("_Avg")) {
185
					nfeat = 1;
186
					fName = rule.getFieldName("Avg");
187
					if(fName != null) {
188
						obj = feature.get(fName);
189
						sumAvg = ((Number)obj).doubleValue();
190
						avg = sumAvg;
191
					}
192
				}
175
                                
193 176
				fName = null;
194 177
			}
195 178
			
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.dissolve/src/main/java/org/gvsig/geoprocess/algorithm/dissolve/DissolveAlgorithm.java
42 42
import es.unex.sextante.exceptions.UnsupportedOutputChannelException;
43 43
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
44 44
import es.unex.sextante.outputs.OutputVectorLayer;
45
import org.gvsig.fmap.geom.Geometry;
45 46

  
46 47
/**
47 48
 * Dissolve algorithm
......
60 61
	private boolean                   funcList[]        = new boolean[Summary.length];
61 62
	private HashMap<String, String>   funcMap           = new HashMap<String, String>();
62 63

  
63
	/*
64
    /*
64 65
	 * (non-Javadoc)
65 66
	 * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
66
	 */
67
     */
67 68
	public void defineCharacteristics(){
68 69
        setName(getTranslation("Dissolve"));
69 70
        setGroup(getTranslation("basic_vect_algorithms"));
70 71
        // setGeneratesUserDefinedRasterOutput(false);
71
		try {
72
			m_Parameters.addInputVectorLayer(LAYER, getTranslation("Input_layer"), IVectorLayer.SHAPE_TYPE_WRONG, true);
73
			m_Parameters.addBoolean(SELECTED_GEOM, getTranslation("Selected_geometries"), false);
74
			m_Parameters.addBoolean(DISSOLV_ADJ, getTranslation("Selected_geometries"), false);
75
			m_Parameters.addNumericalValue(FIELD, getTranslation("Field"), 0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
72
        try {
73
            m_Parameters.addInputVectorLayer(LAYER, getTranslation("Input_layer"), IVectorLayer.SHAPE_TYPE_WRONG, true);
74
            m_Parameters.addBoolean(SELECTED_GEOM, getTranslation("Selected_geometries"), false);
75
            m_Parameters.addBoolean(DISSOLV_ADJ, getTranslation("Selected_geometries"), false);
76
            m_Parameters.addNumericalValue(FIELD, getTranslation("Field"), 0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
76 77
            m_Parameters.addString(FUNCTION_LIST, getTranslation("Function_list"));
77
			addOutputVectorLayer(RESULT, getTranslation("Dissolve"), OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
78
		} catch (RepeatedParameterNameException e) {
79
			Sextante.addErrorToLog(e);
80
		}
81
		//setExternalParameters(new DissolveParametersPanel());
82
	}
83
	
84
	/*
78
            addOutputVectorLayer(RESULT, getTranslation("Dissolve"), OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
79
        } catch (RepeatedParameterNameException e) {
80
            Sextante.addErrorToLog(e);
81
        }
82
        //setExternalParameters(new DissolveParametersPanel());
83
    }
84

  
85
    /*
85 86
	 * (non-Javadoc)
86 87
	 * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
87
	 */
88
	public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
89
		//long t1 = System.currentTimeMillis();
88
     */
89
    public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
90
        //long t1 = System.currentTimeMillis();
90 91
		if(existsOutPutFile(DissolveAlgorithm.RESULT, 0)) {
91
    		throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
92
    	}
93
		IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
94
		int indexField = m_Parameters.getParameterValueAsInt(FIELD);
95
		boolean selectedGeom = m_Parameters.getParameterValueAsBoolean(SELECTED_GEOM);
96
		boolean dissolvAdj = m_Parameters.getParameterValueAsBoolean(DISSOLV_ADJ);
97
		String functionList = m_Parameters.getParameterValueAsString(FUNCTION_LIST);
98
		loadSummary(functionList);
99
		
100
		FeatureStore storeLayer = null;
92
            throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
93
        }
94
        IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
95
        int indexField = m_Parameters.getParameterValueAsInt(FIELD);
96
        boolean selectedGeom = m_Parameters.getParameterValueAsBoolean(SELECTED_GEOM);
97
        boolean dissolvAdj = m_Parameters.getParameterValueAsBoolean(DISSOLV_ADJ);
98
        String functionList = m_Parameters.getParameterValueAsString(FUNCTION_LIST);
99
        loadSummary(functionList);
100

  
101
        FeatureStore storeLayer = null;
101 102
		if(layer instanceof FlyrVectIVectorLayer)
102 103
			storeLayer = ((FlyrVectIVectorLayer)layer).getFeatureStore();
103 104
		else
104
			return false;
105
		
106
		FeatureSet features = null;
107
		FeatureType featureType = null;
108
		try {
109
			features = storeLayer.getFeatureSet();
110
			featureType = features.getDefaultFeatureType();
111
		} catch (DataException e) {
112
			Sextante.addErrorToLog(e);
113
			return false;
114
		}
115
        FeatureStore outFeatStore =
116
            buildDissolvedOutPutStore(featureType, indexField,
117
                layer.getShapeType(), getTranslation("Dissolve"), RESULT);
118
		IDissolveRule criteria = null;
119
		if(dissolvAdj)
120
			criteria = new AdjacencyDissolveRule(indexField, funcMap);
121
		else
122
			criteria = new DissolveRule(indexField, funcMap);
123
		
124
		try {
125
			DissolveOperationFast operation = new DissolveOperationFast(criteria, this);
105
            return false;
106

  
107
        FeatureSet features = null;
108
        FeatureType featureType = null;
109
        try {
110
            features = storeLayer.getFeatureSet();
111
            featureType = features.getDefaultFeatureType();
112
        } catch (DataException e) {
113
            Sextante.addErrorToLog(e);
114
            return false;
115
        }
116

  
117
        int layerType = layer.getShapeType();
118
        switch (layerType) {
119
            case IVectorLayer.SHAPE_TYPE_POINT:
120
                layerType = IVectorLayer.SHAPE_TYPE_MULTIPOINT;
121
                break;
122
            case IVectorLayer.SHAPE_TYPE_LINE:
123
                layerType = IVectorLayer.SHAPE_TYPE_MULTILINE;
124
                break;
125
            case IVectorLayer.SHAPE_TYPE_POLYGON:
126
                layerType = IVectorLayer.SHAPE_TYPE_MULTIPOLYGON;
127
                break;
128
            default:
129
                break;
130
        }
131
        
132
        FeatureStore outFeatStore = buildDissolvedOutPutStore(featureType, layer.getFieldName(indexField),
133
                        layerType, getTranslation("Dissolve"), RESULT);
134
        IDissolveRule criteria = null;
135
        if (dissolvAdj) {
136
            criteria = new AdjacencyDissolveRule(layer.getFieldName(indexField), funcMap);
137
        } else {
138
            criteria = new DissolveRule(layer.getFieldName(indexField), funcMap);
139
        }
140

  
141
        try {
142
            DissolveOperationFast operation = new DissolveOperationFast(criteria, this);
126 143
            operation.setTaskStatus(getStatus());
127
			operation.computesGeometryOperation(storeLayer, outFeatStore, attrNames, 
128
					selectedGeom, false, true);
129
		} catch (DataException e) {
130
			Sextante.addErrorToLog(e);
131
			return false;
132
		}
133
		//long t2 = System.currentTimeMillis();
134
		//System.out.println(t2 - t1);
144
            operation.computesGeometryOperation(storeLayer, outFeatStore, attrNames,
145
                    selectedGeom, false, true);
146
        } catch (DataException e) {
147
            Sextante.addErrorToLog(e);
148
            return false;
149
        }
150
        //long t2 = System.currentTimeMillis();
151
        //System.out.println(t2 - t1);
135 152
		if(getTaskMonitor().isCanceled())
136
			return false;
137
		return true;
138
	}
139
	
140
	/**
141
	 * Checks if the parameter is in Summary list
142
	 * @param it
143
	 * @return the position in the list
144
	 */
145
	private int isInList(String it) {
146
		for (int i = 0; i < Summary.length; i++) {
153
            return false;
154
        return true;
155
    }
156

  
157
    /**
158
     * Checks if the parameter is in Summary list
159
     * @param it
160
     * @return the position in the list
161
     */
162
    private int isInList(String it) {
163
        for (int i = 0; i < Summary.length; i++) {
147 164
			if(Summary[i].compareTo(it) == 0)
148
				return i;
149
		}
150
		return -1;
151
	}
152
	
153
	/**
154
	 * Loads the list of functions to use
155
	 * @param functionList
156
	 */
157
	private void loadSummary(String functionList) {
158
		String[] attrList = functionList.split(";");
159
		for (int i = 0; i < attrList.length; i++) {
160
			String[] func = attrList[i].split(",");
161
			for (int j = 1; j < func.length; j++) {
162
				int pos = isInList(func[j]);
165
                return i;
166
            }
167
        return -1;
168
    }
169

  
170
    /**
171
     * Loads the list of functions to use
172
     * @param functionList
173
     */
174
    private void loadSummary(String functionList) {
175
        String[] attrList = functionList.split(";");
176
        for (int i = 0; i < attrList.length; i++) {
177
            String[] func = attrList[i].split(",");
178
            for (int j = 1; j < func.length; j++) {
179
                int pos = isInList(func[j]);
163 180
				if(pos != -1) {
164
					funcList[pos] = true;
165
					funcMap.put(Summary[pos], func[0]);
166
				}
167
			}
168
		}
169
	}
170
	
171
	/**
172
	 * Builds the output FeatureStore 
173
	 * @param featureType
174
	 * @return FeatureStore
175
	 */
176
	@SuppressWarnings("unchecked")
177
	protected FeatureStore buildDissolvedOutPutStore(FeatureType featureType1,
178
											int indexField,
179
											int shapeType,
180
											String sextanteLayerName, 
181
											String sextanteLayerLabel) {
182
		ArrayList<Class> typesList = new ArrayList<Class>();
183
		ArrayList<String> attr = new ArrayList<String>();
184
		attr.add("FID");
185
		typesList.add(Integer.class);
186
		FeatureAttributeDescriptor desc = featureType1.getAttributeDescriptor(indexField);
187
		attr.add(desc.getName());
188
		typesList.add(desc.getObjectClass());
181
                    funcList[pos] = true;
182
                    funcMap.put(Summary[pos], func[0]);
183
                }
184
            }
185
        }
186
    }
187

  
188
    /**
189
     * Builds the output FeatureStore
190
     * @param featureType
191
     * @return FeatureStore
192
     */
193
    @SuppressWarnings("unchecked")
194
    protected FeatureStore buildDissolvedOutPutStore(FeatureType featureType1,
195
            String fieldField,
196
            int shapeType,
197
            String sextanteLayerName,
198
            String sextanteLayerLabel) {
199
        ArrayList<Class> typesList = new ArrayList<Class>();
200
        ArrayList<String> attr = new ArrayList<String>();
201
        attr.add("FID");
202
        typesList.add(Integer.class);
203
        FeatureAttributeDescriptor desc = featureType1.getAttributeDescriptor(fieldField);
204
        attr.add(desc.getName());
205
        typesList.add(desc.getObjectClass());
189 206
		for (int i = 0; i < funcList.length; i++) 
190 207
			if(funcList[i]) {
191
				String fieldName = funcMap.get(Summary[i]);
208
                String fieldName = funcMap.get(Summary[i]);
192 209
				if(fieldName.length() >= 6)
193
					fieldName = fieldName.substring(0, 5);
194
				attr.add(fieldName + "_" + Summary[i]);
195
				typesList.add(Double.class);
196
			}
197
		
198
		attrNames = new String[attr.size()];
199
		attr.toArray(attrNames);
200
		Class[] types = new Class[typesList.size()];
201
		typesList.toArray(types);
202
		
203
		try {
204
			IVectorLayer output = getNewVectorLayer(sextanteLayerLabel,
205
													sextanteLayerName,
206
													shapeType, types, attrNames);
210
                    fieldName = fieldName.substring(0, 5);
211
                attr.add(fieldName + "_" + Summary[i]);
212
                typesList.add(Double.class);
213
            }
214

  
215
        attrNames = new String[attr.size()];
216
        attr.toArray(attrNames);
217
        Class[] types = new Class[typesList.size()];
218
        typesList.toArray(types);
219

  
220
        try {
221
            IVectorLayer output = getNewVectorLayer(sextanteLayerLabel,
222
                    sextanteLayerName,
223
                    shapeType, types, attrNames);
207 224
			return ((FlyrVectIVectorLayer)output).getFeatureStore();
208
		} catch (UnsupportedOutputChannelException e) {
209
			Sextante.addErrorToLog(e);
225
        } catch (UnsupportedOutputChannelException e) {
226
            Sextante.addErrorToLog(e);
210 227
        } catch (GeoAlgorithmExecutionException e) {
211 228
            Sextante.addErrorToLog(e);
212 229
        }
213
		return null;
214
	}
230
        return null;
231
    }
215 232

  
216 233
    @Override
217 234
    public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() {
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.dissolve/src/main/java/org/gvsig/geoprocess/algorithm/dissolve/DissolveRule.java
37 37
 * a given (and single) field.
38 38
 */
39 39
public class DissolveRule implements IDissolveRule {
40
	protected int                    indexField           = -1;
40
	protected String                    nameField           = null;
41 41
	private HashMap<String, String>  funcMap              = null;
42 42
	
43
	public DissolveRule(int indexField, HashMap<String, String> funcMap) {
44
		this.indexField = indexField;
43
	public DissolveRule(String nameField, HashMap<String, String> funcMap) {
44
		this.nameField = nameField;
45 45
		this.funcMap = funcMap;
46 46
	}
47 47
	
......
50 50
	 * @see org.gvsig.geoprocess.algorithm.dissolve.IDissolveCriteria#verifyIfDissolve(com.vividsolutions.jts.geom.Geometry, com.vividsolutions.jts.geom.Geometry, org.gvsig.fmap.dal.feature.Feature)
51 51
	 */
52 52
	public boolean verifyIfDissolve(Geometry g1, Geometry g2, Feature f1, Feature f2) {
53
		Object obj1 = f1.get(indexField);
54
		Object obj2 = f2.get(indexField);
53
		Object obj1 = f1.get(nameField);
54
		Object obj2 = f2.get(nameField);
55 55
		return compareTo(obj1, obj2);
56 56
	}
57 57
	
......
115 115
	 * (non-Javadoc)
116 116
	 * @see org.gvsig.geoprocess.algorithm.dissolve.IDissolveCriteria#getIndexField()
117 117
	 */
118
	public int getIndexField() {
119
		return indexField;
118
	public String getFieldName() {
119
		return nameField;
120 120
	}
121 121

  
122 122
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.dissolve/src/main/java/org/gvsig/geoprocess/algorithm/dissolve/AdjacencyDissolveRule.java
35 35
 */
36 36
public class AdjacencyDissolveRule extends DissolveRule {
37 37

  
38
	public AdjacencyDissolveRule(int indexField, HashMap<String, String> funcMap) {
39
		super(indexField, funcMap);
38
	public AdjacencyDissolveRule(String nameField, HashMap<String, String> funcMap) {
39
		super(nameField, funcMap);
40 40
	}
41 41
	
42 42
	/*
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
44 44
import es.unex.sextante.exceptions.WrongParameterIDException;
45 45
import es.unex.sextante.exceptions.WrongParameterTypeException;
46 46
import es.unex.sextante.outputs.OutputVectorLayer;
47
import org.gvsig.tools.namestranslator.NamesTranslator;
47 48

  
48 49
/**
49 50
 * Union algorithm
......
57 58
	public static final String  LAYER2                = "LAYER2";
58 59
	public static final String  SELECTGEOM_INPUT      = "SELECTGEOM_INPUT";
59 60
	public static final String  SELECTGEOM_OVERLAY    = "SELECTGEOM_OVERLAY";
61
    private NamesTranslator nameTranslator;
60 62
	
61 63
	/*
62 64
	 * (non-Javadoc)
......
105 107
		IVectorLayer layer2 = m_Parameters.getParameterValueAsVectorLayer(LAYER2);
106 108
		boolean selectedGeomInput = m_Parameters.getParameter(SELECTGEOM_INPUT).getParameterValueAsBoolean();
107 109
		boolean selectedGeomOverlay = m_Parameters.getParameter(SELECTGEOM_OVERLAY).getParameterValueAsBoolean();
110
                this.nameTranslator = NamesTranslator.createTrimTranslator(10);
108 111
		
109 112
		FeatureStore storeLayer1 = null;
110 113
		FeatureStore storeLayer2 = null;
......
131 134
						featureType2, 
132 135
						layer1.getShapeType(), 
133 136
						getTranslation("Union_polygon"),
134
                        RESULT1);
137
                        RESULT1, nameTranslator);
135 138
				computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay);
136 139
			} else
137 140
			//PTO-PTO
......
140 143
						featureType2, 
141 144
						layer1.getShapeType(), 
142 145
						getTranslation("Union_point"),
143
                        RESULT1);
146
                        RESULT1, nameTranslator);
144 147
				computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay);
145 148
			} else
146 149
			//LIN-LIN	
......
149 152
						featureType2, 
150 153
						IVectorLayer.SHAPE_TYPE_POINT, 
151 154
                        getTranslation("Union_point"), 
152
                        RESULT1);
155
                        RESULT1, nameTranslator);
153 156
				computesIntersection(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay, true);
154 157
				featStoreOut2 = buildOutPutStoreFromUnion(featureType1, 
155 158
						featureType2, 
156 159
						IVectorLayer.SHAPE_TYPE_LINE, 
157 160
                        getTranslation("Union_line"), 
158
                        RESULT2);
161
                        RESULT2, nameTranslator);
159 162
				computesDifference(storeLayer1, storeLayer2, featStoreOut2, selectedGeomInput, selectedGeomOverlay, false);
160 163
				computesDifference(storeLayer2, storeLayer1, featStoreOut2, selectedGeomInput, selectedGeomOverlay, true);
161 164
			} else
......
165 168
				featStoreOut1 = buildOutPutStoreFromUnion(featureType1, 
166 169
						featureType2, 
167 170
						IVectorLayer.SHAPE_TYPE_LINE, 
168
                        getTranslation("Union_line"), RESULT1);
171
                        getTranslation("Union_line"), RESULT1, nameTranslator);
169 172
				computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay);
170 173
				featStoreOut2 = buildOutPutStoreFromUnion(featureType1, 
171 174
						featureType2, 
172 175
						IVectorLayer.SHAPE_TYPE_POLYGON, 
173 176
                        getTranslation("Union_polygon"), 
174
                        RESULT2);
177
                        RESULT2, nameTranslator);
175 178
				computesDifference(storeLayer1, storeLayer2, featStoreOut2, selectedGeomInput, selectedGeomOverlay, false);
176 179
				computesDifference(storeLayer2, storeLayer1, featStoreOut2, selectedGeomInput, selectedGeomOverlay, true);
177 180
			} else
......
179 182
			if( (isPolygon(storeLayer1) && isPoint(storeLayer2)) || 
180 183
				(isPoint(storeLayer1) && isPolygon(storeLayer2))) { 
181 184
				featStoreOut1 = buildOutPutStoreFromUnion(featureType1, featureType2, IVectorLayer.SHAPE_TYPE_POINT, 
182
                        getTranslation("Union_point"), RESULT1);
185
                        getTranslation("Union_point"), RESULT1, nameTranslator);
183 186
				computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay);
184 187
				featStoreOut2 = buildOutPutStoreFromUnion(featureType1, featureType2, IVectorLayer.SHAPE_TYPE_POLYGON, 
185
                        getTranslation("Union_polygon"), RESULT2);
188
                        getTranslation("Union_polygon"), RESULT2, nameTranslator);
186 189
				computesUnion(storeLayer1, storeLayer2, featStoreOut2, selectedGeomInput, selectedGeomOverlay);
187 190
			} else
188 191
			//PTO-LIN
189 192
			if( (isPoint(storeLayer1) && isLine(storeLayer2)) || 
190 193
				(isLine(storeLayer1) && isPoint(storeLayer2))) { 
191 194
				featStoreOut1 = buildOutPutStoreFromUnion(featureType1, featureType2, IVectorLayer.SHAPE_TYPE_POINT, 
192
                        getTranslation("Union_point"), RESULT1);
195
                        getTranslation("Union_point"), RESULT1, nameTranslator);
193 196
				computesUnion(storeLayer1, storeLayer2, featStoreOut1, selectedGeomInput, selectedGeomOverlay);
194 197
				featStoreOut2 = buildOutPutStoreFromUnion(featureType1, featureType2, IVectorLayer.SHAPE_TYPE_LINE, 
195
                        getTranslation("Union_line"), RESULT2);
198
                        getTranslation("Union_line"), RESULT2, nameTranslator);
196 199
				computesUnion(storeLayer1, storeLayer2, featStoreOut2, selectedGeomInput, selectedGeomOverlay);
197 200
			}
198 201
			
199 202
			if(featStoreOut2 == null) {
200 203
				featStoreOut2 = buildOutPutStoreFromUnion(featureType1, featureType2, IVectorLayer.SHAPE_TYPE_WRONG, 
201
                        getTranslation("Null_Layer"), RESULT2);
204
                        getTranslation("Null_Layer"), RESULT2, nameTranslator);
202 205
			}
203 206
			
204 207
		} catch (ReadException e) {
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
36 36
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
37 37
import es.unex.sextante.exceptions.RepeatedParameterNameException;
38 38
import es.unex.sextante.outputs.OutputVectorLayer;
39
import org.gvsig.tools.namestranslator.NamesTranslator;
39 40

  
40 41
/**
41 42
 * Intersection algorithm
......
58 59
	public static final String  INTER                 = "INTER";
59 60
	public static final String  SELECTGEOM_INPUT      = "SELECTGEOM_INPUT";
60 61
	public static final String  SELECTGEOM_OVERLAY    = "SELECTGEOM_OVERLAY";
62
    private NamesTranslator nameTranslator;
61 63

  
62 64
	/*
63 65
	 * (non-Javadoc)
......
162 164

  
163 165
		IntersectionOperation operation = new IntersectionOperation(storeOverlay, this);
164 166
		operation.setTaskStatus(getStatus());
167
                this.nameTranslator = NamesTranslator.createTrimTranslator(10);
165 168

  
166 169
		//La de puntos se genera siempre
167 170
		outFeatStorePoint =
168 171
			buildOutPutStoreFromUnion(featureType1, featureType2,
169 172
					IVectorLayer.SHAPE_TYPE_POINT,
170
					getTranslation("Intersection_point"), RESULT_POINT);
173
					getTranslation("Intersection_point"), RESULT_POINT,nameTranslator);
171 174

  
172 175
        if (outFeatStorePoint != null) {
173 176
            getStatus().setTitle("Point");
......
178 181
		if (isPolygon(storeLayer) && isPolygon(storeOverlay)) {
179 182
			outFeatStorePol =
180 183
              buildOutPutStoreFromUnion(featureType1, featureType2,
181
            		  IVectorLayer.SHAPE_TYPE_POLYGON, getTranslation("Intersection_polygon"), RESULT_POL);
184
            		  IVectorLayer.SHAPE_TYPE_POLYGON, getTranslation("Intersection_polygon"), RESULT_POL, nameTranslator);
182 185
            if (outFeatStorePol != null) {
183 186
                getStatus().setTitle("Polygon");
184 187
                operation.computesGeometryOperation(storeLayer,
......
191 194
		if (!isPoint(storeLayer) && !isPoint(storeOverlay)) {
192 195
			outFeatStoreLine =
193 196
              buildOutPutStoreFromUnion(featureType1, featureType2,
194
            		  IVectorLayer.SHAPE_TYPE_LINE, getTranslation("Intersection_line"), RESULT_LINE);
197
            		  IVectorLayer.SHAPE_TYPE_LINE, getTranslation("Intersection_line"), RESULT_LINE, nameTranslator);
195 198
            if (outFeatStoreLine != null) {
196 199
                getStatus().setTitle("Line");
197 200
                operation.computesGeometryOperation(storeLayer,
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.lib/org.gvsig.geoprocess.lib.sextante/src/main/java/org/gvsig/geoprocess/lib/sextante/dataObjects/FlyrVectIVectorLayer.java
96 96
    private List<String> names = new ArrayList<String>();
97 97
    private List<Class<?>> types = new ArrayList<Class<?>>();
98 98
    private String viewName = null;
99
    private NamesTranslator namesTranslator;
99 100

  
100 101

  
101 102

  
......
219 220
        final EditableFeatureType featureType, final int[] fieldSize, final int subtype) {
220 221
        final int[] iTypes = getTypes(types);
221 222

  
222
        NamesTranslator namesTranslator = NamesTranslator.createTrimTranslator(11);
223
        this.namesTranslator = NamesTranslator.createTrimTranslator(11);
223 224
        namesTranslator.setSourceNames(fields);
224 225
        fields = namesTranslator.getTranslatedNamesAsArray();
225 226
        
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
66 66
import org.gvsig.fmap.dal.feature.EditableFeatureType;
67 67
import org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory;
68 68
import org.gvsig.tools.evaluator.Evaluator;
69
import org.gvsig.tools.namestranslator.NamesTranslator;
69 70

  
70 71
/**
71 72
 * Base implementation for Sextante based {@link GeoProcess} objects.
......
217 218
     */
218 219
    protected FeatureStore buildOutPutStoreFromUnion(FeatureType featureType1,
219 220
        FeatureType featureType2, int shapeType, String sextanteLayerName,
220
        String sextanteLayerLabel) {
221
        String sextanteLayerLabel, NamesTranslator nameTranslator) {
221 222
        return buildOutPutStoreFromUnion(featureType1, featureType2, shapeType,
222
            sextanteLayerName, sextanteLayerLabel, null, null);
223
            sextanteLayerName, sextanteLayerLabel, null, null, nameTranslator);
223 224
    }
224 225

  
225 226
    /**
......
230 231
     */
231 232
    protected FeatureStore buildOutPutStoreFromUnion(FeatureType featureType1,
232 233
        FeatureType featureType2, int shapeType, String sextanteLayerName,
233
        String sextanteLayerLabel, String newField, Class<?> newFieldType) {
234
        String sextanteLayerLabel, String newField, Class<?> newFieldType, NamesTranslator nameTranslator) {
235
        
236
        nameTranslator.clear();
237

  
234 238
        int sizeAux = 0;
235 239
        if (newField != null && newFieldType != null)
236 240
            sizeAux = 1;
......
259 263
                (FeatureAttributeDescriptor) it.next();
260 264
            if(attribute.getDataType().getType() != DataTypes.GEOMETRY) {
261 265
                attrNames[i] = attribute.getName();
266
                nameTranslator.addSource(attribute.getName());
262 267
                types[i] = attribute.getObjectClass();
263 268
                i++;
264 269
            }
......
272 277
                String attrName =
273 278
                    checkAttrName(attribute.getName(), featureType1.size() - 1);
274 279
                attrNames[i] = attrName;
280
                nameTranslator.addSource(attribute.getName());
275 281
                types[i] = attribute.getObjectClass();
276 282
                i++;
277 283
            }
......
279 285

  
280 286
        if (newField != null && newFieldType != null) {
281 287
            attrNames[attrNames.length - 1] = newField;
288
            nameTranslator.addSource(newField);
282 289
            types[types.length - 1] = newFieldType;
283 290
        }
284 291

  
285 292
        try {
286 293
            IVectorLayer output =
287 294
                getNewVectorLayer(sextanteLayerLabel, sextanteLayerName,
288
                    shapeType, types, attrNames);
295
                    shapeType, types, nameTranslator.getTranslatedNamesAsArray());
289 296
            if (output != null) {
290 297
                return ((FlyrVectIVectorLayer) output).getFeatureStore();
291 298
            }

Also available in: Unified diff