Revision 1106 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

View differences:

AbstractSextanteGeoProcess.java
61 61
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
62 62
import es.unex.sextante.outputs.IOutputChannel;
63 63
import es.unex.sextante.outputs.Output;
64
import java.util.ArrayList;
65
import java.util.List;
66
import org.gvsig.fmap.dal.feature.EditableFeatureType;
64 67

  
65 68
/**
66 69
 * Base implementation for Sextante based {@link GeoProcess} objects.
......
132 135
    protected FeatureStore buildOutPutStore(FeatureType featureType,
133 136
        int shapeType, String sextanteLayerName, String sextanteLayerLabel) {
134 137

  
135
        Class<?>[] types = null;
136
        if (featureType.getDefaultGeometryAttribute() != null) {
137
            // Tiene campo GEOMETRY.
138
            // Hay que quitarlo
139
            attrNames = new String[featureType.size() - 1];
140
            types = new Class[featureType.size() - 1];
141
        } else {
142
            attrNames = new String[featureType.size()];
143
            types = new Class[featureType.size()];
144
        }
138
//        Class<?>[] types = null;
139
//        if (featureType.getDefaultGeometryAttribute() != null) {
140
//            // Tiene campo GEOMETRY.
141
//            // Hay que quitarlo
142
//            attrNames = new String[featureType.size() - 1];
143
//            types = new Class[featureType.size() - 1];
144
//        } else {
145
//            attrNames = new String[featureType.size()];
146
//            types = new Class[featureType.size()];
147
//        }
148
        List<Class> types = new ArrayList();
149
        List<String> theAttrNames = new ArrayList();
145 150

  
146
        int i = 0;
151
        List<FeatureAttributeDescriptor> emulateds = new ArrayList();
147 152
        @SuppressWarnings("unchecked")
148 153
        Iterator<FeatureAttributeDescriptor> it = featureType.iterator();
149 154
        while (it.hasNext()) {
150 155
            FeatureAttributeDescriptor attribute = it.next();
151
            String attrName = attribute.getName();
152
            if(attribute.getDataType().getType() != DataTypes.GEOMETRY) {
153
            	if(i < attrNames.length) {
154
            		attrNames[i] = attrName;
155
            		types[i] = attribute.getObjectClass();
156
            	}
157
                i++;
156
            if(attribute.isComputed()){
157
                emulateds.add(attribute);
158
            } else {
159
                String attrName = attribute.getName();
160
                if(attribute.getDataType().getType() != DataTypes.GEOMETRY) {
161
                    theAttrNames.add(attrName);
162
                    types.add(attribute.getObjectClass());
163
                }
158 164
            }
159 165
        }
160 166

  
161 167
        try {
162
            IVectorLayer output =
163
                getNewVectorLayer(sextanteLayerLabel, sextanteLayerName,
164
                    shapeType, types, attrNames);
168
            FlyrVectIVectorLayer output
169
                    = (FlyrVectIVectorLayer) getNewVectorLayer(
170
                            sextanteLayerLabel, 
171
                            sextanteLayerName,
172
                            shapeType, 
173
                            types.toArray(new Class[types.size()]), 
174
                            theAttrNames.toArray(new String[theAttrNames.size()])
175
                    );
165 176
            if (output != null) {
166
                return ((FlyrVectIVectorLayer) output).getFeatureStore();
177
                FeatureStore store = output.getFeatureStore();
178
                if (!emulateds.isEmpty()) {
179
                    try {
180
                        boolean needStartEditingMode = !(store.isEditing() || store.isAppending());
181
                        if (needStartEditingMode) {
182
                            store.edit();
183
                        }
184
                        EditableFeatureType ft = store.getDefaultFeatureType().getEditable();
185

  
186
                        for (FeatureAttributeDescriptor emulated : emulateds) {
187
                            theAttrNames.add(emulated.getName());
188
                            ft.add(emulated.getName(), emulated.getType(), emulated.getFeatureAttributeEmulator());
189
                        }
190
                        store.update(ft);
191
                        if (needStartEditingMode) {
192
                            store.finishEditing();
193
                        }
194
                        
195
                    } catch (Exception e) {
196
                        Sextante.addErrorToLog(e);
197
                    }
198
                }
199
                this.attrNames = theAttrNames.toArray(new String[theAttrNames.size()]);
200
                return output.getFeatureStore();
167 201
            }
168 202
        } catch (UnsupportedOutputChannelException e) {
169 203
            Sextante.addErrorToLog(e);

Also available in: Unified diff