Revision 47362

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/searchPostProcess/distinctOn/DistinctOn.java
184 184
					status.cancel();
185 185
					return null;
186 186
				}
187
				if (aggregateFeature != null) {
188
					if (Objects.equals(feature.get(uniqueFieldName), aggregateFeature.get(uniqueFieldName))) {
189
						for (Map.Entry<String, AggregateOperation> entry : aggregates.entrySet()) {
190
							String name = entry.getKey();
191
							AggregateOperation operation = entry.getValue();
192
							Object value = feature.get(name);
193
							if (operation.isApplicable(value)) {
194
								operation.perform(value);
195
							}
196
							aggregateFeature.set(name, operation.getValue());
197
						}
198
					} else {
199
                                            aggregateFeature.set(DISTINCT_ON_PRIMARY_KEY, counter++);
200
                                            storeResults.insert(aggregateFeature);
201
                                            aggregateFeature = null;
202
					}
203
				}
204

  
205 187
				if (aggregateFeature == null) {
206
					aggregateFeature = storeResults.createNewFeature(feature);
207
					for (Map.Entry<String, AggregateOperation> entry : aggregates.entrySet()) {
208
						String name = entry.getKey();
209
						AggregateOperation operation = entry.getValue();
210
						operation.reset();
211
						Object value = feature.get(name);
212
						if (operation.isApplicable(value)) {
213
							operation.perform(value);
214
						}
215
						aggregateFeature.set(name, operation.getValue());
216
					}
217
				}
188
                                    
189
                                    aggregateFeature = storeResults.createNewFeature(feature);
190
                                }
191
                                
192
                                if (!Objects.equals(feature.get(uniqueFieldName), aggregateFeature.get(uniqueFieldName))) {
193
                                    //Recoge lo agregado y lo inserta
194
                                    for (Map.Entry<String, AggregateOperation> entry : aggregates.entrySet()) {
195
                                        String name = entry.getKey();
196
                                        AggregateOperation operation = entry.getValue();
197
                                        aggregateFeature.set(name, operation.getValue());
198
                                    }
199
                                    aggregateFeature.set(DISTINCT_ON_PRIMARY_KEY, counter++);
200
                                    storeResults.insert(aggregateFeature);
201
                                    //Resetear las operaciones de agregado y la feature agregada
202
                                    for (Map.Entry<String, AggregateOperation> entry : aggregates.entrySet()) {
203
                                        AggregateOperation operation = entry.getValue();
204
                                        operation.reset();
205
                                    }
206
                                    aggregateFeature = storeResults.createNewFeature(feature);
207
                                }
208
                                //Evalua las funciones de agregado de la feature corriente
209
                                for (Map.Entry<String, AggregateOperation> entry : aggregates.entrySet()) {
210
                                        String name = entry.getKey();
211
                                        AggregateOperation operation = entry.getValue();
212
                                        Object value = feature.get(name);
213
                                        if (operation.isApplicable(value)) {
214
                                                operation.perform(value);
215
                                        }
216
                                }
217
                                
218
//                                
219
//                                
220
//                                
221
////				if (aggregateFeature != null) {
222
//					if (Objects.equals(feature.get(uniqueFieldName), aggregateFeature.get(uniqueFieldName))) {
223
//						for (Map.Entry<String, AggregateOperation> entry : aggregates.entrySet()) {
224
//							String name = entry.getKey();
225
//							AggregateOperation operation = entry.getValue();
226
//							Object value = feature.get(name);
227
//							if (operation.isApplicable(value)) {
228
//								operation.perform(value);
229
//							}
230
//						}
231
//					} else {
232
//                                            for (Map.Entry<String, AggregateOperation> entry : aggregates.entrySet()) {
233
//                                                    String name = entry.getKey();
234
//                                                    AggregateOperation operation = entry.getValue();
235
//                                                    aggregateFeature.set(name, operation.getValue());
236
//                                            }
237
//                                            aggregateFeature.set(DISTINCT_ON_PRIMARY_KEY, counter++);
238
//                                            storeResults.insert(aggregateFeature);
239
//                                            aggregateFeature = null;
240
//					}
241
////				}
242
//
243
////				if (aggregateFeature == null) {
244
////					aggregateFeature = storeResults.createNewFeature(feature);
245
////					for (Map.Entry<String, AggregateOperation> entry : aggregates.entrySet()) {
246
////						String name = entry.getKey();
247
////						AggregateOperation operation = entry.getValue();
248
////						operation.reset();
249
////						Object value = feature.get(name);
250
////						if (operation.isApplicable(value)) {
251
////							operation.perform(value);
252
////						}
253
////						aggregateFeature.set(name, operation.getValue());
254
////					}
255
////				}
218 256
				status.incrementCurrentValue();
219 257
			}
220 258
			if (aggregateFeature != null) {
221
                                aggregateFeature.set(DISTINCT_ON_PRIMARY_KEY, counter++);
222
				storeResults.insert(aggregateFeature);
259
                            //Recoge lo agregado y lo inserta
260
                            for (Map.Entry<String, AggregateOperation> entry : aggregates.entrySet()) {
261
                                String name = entry.getKey();
262
                                AggregateOperation operation = entry.getValue();
263
                                aggregateFeature.set(name, operation.getValue());
264
                            }
265
                            aggregateFeature.set(DISTINCT_ON_PRIMARY_KEY, counter++);
266
                            storeResults.insert(aggregateFeature);
223 267
			}
224 268

  
225 269
			storeResults.finishEditing();
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/searchPostProcess/distinctOn/STIntersectionAggregateOperation.java
16 16

  
17 17
 public class STIntersectionAggregateOperation extends AbstractAggregateOperation {
18 18
    
19
    public static class SumAggregateOperationFactory implements AggregateOperationFactory{
19
    public static class STIntersectionAggregateOperationFactory implements AggregateOperationFactory{
20 20

  
21
        public static final String NAME = "ST_Intersection";
21
        public static final String NAME = "Intersection";
22 22

  
23 23
        @Override
24 24
        public String getName() {
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/searchPostProcess/distinctOn/STConvexHullAggregateOperation.java
12 12
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
13 13
import org.gvsig.fmap.geom.Geometry;
14 14
import org.gvsig.fmap.geom.GeometryUtils;
15
import org.gvsig.fmap.geom.aggregate.Aggregate;
15 16
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
16 17
import org.gvsig.fmap.geom.primitive.Primitive;
17 18
import static org.gvsig.tools.dynobject.DynField.RELATION_TYPE_NONE;
......
19 20

  
20 21
 public class STConvexHullAggregateOperation extends AbstractAggregateOperation {
21 22
    
22
    public static class SumAggregateOperationFactory implements AggregateOperationFactory{
23
    public static class STConvexHullAggregateOperationFactory implements AggregateOperationFactory{
23 24

  
24
        public static final String NAME = "ST_ConvexHull";
25
        public static final String NAME = "ConvexHull";
25 26

  
26 27
        @Override
27 28
        public String getName() {
......
67 68
                return;
68 69
            }
69 70
            MultiPolygon mp = GeometryUtils.createMultiPolygon(geom.getGeometryType().getSubType());
70
            mp.addPrimitive((Primitive) geom);
71
            mp.addPrimitive((Primitive) value);
71
            mp.addPrimitives(geom);
72
            mp.addPrimitives((Geometry)value);
72 73
            geom = mp.convexHull();
73 74
        } catch (Exception ex) {
74 75
            throw new RuntimeException("",ex);
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/searchPostProcess/distinctOn/STExtentAggregateOperation.java
18 18

  
19 19
 public class STExtentAggregateOperation extends AbstractAggregateOperation {
20 20
    
21
    public static class SumAggregateOperationFactory implements AggregateOperationFactory{
21
    public static class STExtentAggregateOperationFactory implements AggregateOperationFactory{
22 22

  
23
        public static final String NAME = "ST_Extent";
23
        public static final String NAME = "Extent";
24 24

  
25 25
        @Override
26 26
        public String getName() {
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/searchPostProcess/distinctOn/STUnionAggregateOperation.java
6 6
package org.gvsig.fmap.dal.swing.impl.searchPostProcess.distinctOn;
7 7

  
8 8
//    public static void selfRegister(){
9

  
9
import java.util.Iterator;
10 10
import java.util.List;
11
import org.gvsig.fmap.dal.DataTypes;
12 11
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
13 12
import org.gvsig.fmap.geom.Geometry;
13
import static org.gvsig.fmap.geom.Geometry.TYPES.COMPLEX;
14
import static org.gvsig.fmap.geom.Geometry.TYPES.CURVE;
15
import static org.gvsig.fmap.geom.Geometry.TYPES.GEOMETRY;
16
import static org.gvsig.fmap.geom.Geometry.TYPES.MULTICURVE;
17
import static org.gvsig.fmap.geom.Geometry.TYPES.MULTIPOINT;
18
import static org.gvsig.fmap.geom.Geometry.TYPES.MULTISURFACE;
19
import static org.gvsig.fmap.geom.Geometry.TYPES.POINT;
20
import static org.gvsig.fmap.geom.Geometry.TYPES.SURFACE;
21
import org.gvsig.fmap.geom.GeometryLocator;
22
import org.gvsig.fmap.geom.GeometryManager;
23
import org.gvsig.fmap.geom.aggregate.MultiCurve;
24
import org.gvsig.fmap.geom.aggregate.MultiPoint;
25
import org.gvsig.fmap.geom.aggregate.MultiSurface;
26
import org.gvsig.fmap.geom.complex.Complex;
27
import org.gvsig.fmap.geom.type.GeometryType;
14 28
import static org.gvsig.tools.dynobject.DynField.RELATION_TYPE_NONE;
15 29

  
30
public class STUnionAggregateOperation extends AbstractAggregateOperation {
16 31

  
17
 public class STUnionAggregateOperation extends AbstractAggregateOperation {
18
    
19
    public static class SumAggregateOperationFactory implements AggregateOperationFactory{
32
    public static class STUnionAggregateOperationFactory implements AggregateOperationFactory {
20 33

  
21
        public static final String NAME = "ST_Union";
34
        public static final String NAME = "Combine";
22 35

  
23 36
        @Override
24 37
        public String getName() {
......
34 47
        public boolean isApplicable(Object... value) {
35 48
            return Geometry.class.isAssignableFrom((Class<?>) value[0]);
36 49
        }
37
        
50

  
38 51
    }
39
    
40
    Geometry geom;
41 52

  
53
    private static final int HAS_POINT = 1;
54
    private static final int HAS_CURVE = 2;
55
    private static final int HAS_SURFACE = 4;
56

  
57
    MultiPoint multiPoint;
58
    MultiCurve multiCurve;
59
    MultiSurface multiSurface;
60
    int resultType;
61
    int resultSubType;
62
    GeometryManager geometryManager;
63

  
42 64
    public STUnionAggregateOperation() {
43
        this.geom = null;
65
        this.multiPoint = null;
66
        this.multiCurve = null;
67
        this.multiSurface = null;
68
        this.resultType = 0;
69
        this.resultSubType = Geometry.SUBTYPES.UNKNOWN;
70
        geometryManager = GeometryLocator.getGeometryManager();
44 71
    }
45 72

  
46 73
    @Override
......
50 77

  
51 78
    @Override
52 79
    public void reset() {
53
        this.geom = null;
80
        this.multiPoint = null;
81
        this.multiCurve = null;
82
        this.multiSurface = null;
83
        this.resultType = 0;
84
        this.resultSubType = Geometry.SUBTYPES.UNKNOWN;
54 85
    }
55 86

  
56 87
    @Override
......
59 90
            if (value == null) {
60 91
                return;
61 92
            }
62
            if( geom == null ) {
63
                geom = (Geometry)value;
64
                return;
93

  
94
            Geometry geom = (Geometry) value;
95
            GeometryType type = geom.getGeometryType();
96

  
97
            if (multiPoint == null) {
98
                this.resultSubType = type.getSubType();
99
                multiPoint = geometryManager.createMultiPoint(resultSubType);
100
                multiCurve = geometryManager.createMultiCurve(resultSubType);
101
                multiSurface = geometryManager.createMultiSurface(resultSubType);
65 102
            }
66
            geom = geom.union((Geometry) value);
103

  
104
            if (type.isTypeOf(POINT)
105
                    || type.isTypeOf(MULTIPOINT)) {
106
                multiPoint.addPrimitives(geom);
107
                resultType |= HAS_POINT;
108
            } else if (type.isTypeOf(CURVE)
109
                    || type.isTypeOf(MULTICURVE)) {
110
                multiCurve.addPrimitives(geom);
111
                resultType |= HAS_CURVE;
112
            } else if (type.isTypeOf(SURFACE)
113
                    || type.isTypeOf(MULTISURFACE)) {
114
                multiSurface.addPrimitives(geom);
115
                resultType |= HAS_SURFACE;
116
            } else if (type.isTypeOf(COMPLEX)) {
117
                Complex complex = (Complex) value;
118
                Iterator<Geometry> complexIt = complex.iterator();
119
                while (complexIt.hasNext()) {
120
                    Geometry geom1 = complexIt.next();
121
                    if (geom1.getGeometryType().isTypeOf(POINT)
122
                            || geom1.getGeometryType().isTypeOf(MULTIPOINT)) {
123
                        multiPoint.addPrimitives(geom1);
124
                        resultType |= HAS_POINT;
125
                    } else if (geom1.getGeometryType().isTypeOf(CURVE)
126
                            || geom1.getGeometryType().isTypeOf(MULTICURVE)) {
127
                        multiCurve.addPrimitives(geom1);
128
                        resultType |= HAS_CURVE;
129

  
130
                    } else if (geom1.getGeometryType().isTypeOf(SURFACE)
131
                            || geom1.getGeometryType().isTypeOf(MULTISURFACE)) {
132
                        multiSurface.addPrimitives(geom1);
133
                        resultType |= HAS_SURFACE;
134
                    }
135
                }
136
            }
137

  
67 138
        } catch (Exception ex) {
68
            throw new RuntimeException("",ex);
139
            throw new RuntimeException("", ex);
69 140
        }
70 141
    }
71 142

  
72 143
    @Override
73 144
    public Object getValue() {
74
        return this.geom;
145
        try {
146

  
147
            if (resultType == HAS_POINT) {
148
                return multiPoint.union();
149
            }
150
            if (resultType == HAS_CURVE) {
151
                return multiCurve.dissolve();
152
            }
153
            if (resultType == HAS_SURFACE) {
154
                return multiSurface.union();
155
            }
156
            Geometry combinedGeometry = geometryManager.create(COMPLEX, this.resultSubType);
157
            Complex complex = (Complex) combinedGeometry;
158
            if ((resultType & HAS_POINT) == HAS_POINT) {
159
                complex.addPrimitives(multiPoint.union());
160
            }
161
            if ((resultType & HAS_CURVE) == HAS_CURVE) {
162
                complex.addPrimitives(multiCurve.dissolve());
163
            }
164
            if ((resultType & HAS_SURFACE) == HAS_SURFACE) {
165
                complex.addPrimitives(multiSurface.union());
166
            }
167
            return complex;
168
        } catch (Exception ex) {
169
            throw new RuntimeException("", ex);
170
        }
171

  
75 172
    }
76 173

  
77 174
    @Override
78 175
    public void fixAttributeDescriptor(EditableFeatureAttributeDescriptor descriptor) {
79 176
        super.fixAttributeDescriptor(descriptor);
80
        
177

  
81 178
//        descriptor.setDataType(DataTypes.GEOMETRY);
82 179
//        descriptor.setGeometryType(Geometry.TYPES.POLYGON, Geometry.SUBTYPES.GEOM2D);
83

  
84 180
        descriptor.setRelationType(RELATION_TYPE_NONE);
85 181
        descriptor.getForeingKey().clean();
86
        descriptor.setAvailableValues((List)null);
182
        descriptor.setAvailableValues((List) null);
87 183
    }
88
    
89
    
184

  
90 185
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/DefaultDALSwingLibrary.java
66 66
import org.gvsig.fmap.dal.swing.impl.searchPostProcess.distinctOn.MaxAggregateOperation.MaxAggregateOperationFactory;
67 67
import org.gvsig.fmap.dal.swing.impl.searchPostProcess.distinctOn.MinAggregateOperation.MinAggregateOperationFactory;
68 68
import org.gvsig.fmap.dal.swing.impl.searchPostProcess.distinctOn.NullAggregateOperation.NullAggregateOperationFactory;
69
import org.gvsig.fmap.dal.swing.impl.searchPostProcess.distinctOn.STConvexHullAggregateOperation;
70
import org.gvsig.fmap.dal.swing.impl.searchPostProcess.distinctOn.STConvexHullAggregateOperation.STConvexHullAggregateOperationFactory;
71
import org.gvsig.fmap.dal.swing.impl.searchPostProcess.distinctOn.STExtentAggregateOperation.STExtentAggregateOperationFactory;
72
import org.gvsig.fmap.dal.swing.impl.searchPostProcess.distinctOn.STIntersectionAggregateOperation.STIntersectionAggregateOperationFactory;
73
import org.gvsig.fmap.dal.swing.impl.searchPostProcess.distinctOn.STUnionAggregateOperation.STUnionAggregateOperationFactory;
69 74
import org.gvsig.fmap.dal.swing.impl.searchPostProcess.distinctOn.SumAggregateOperation.SumAggregateOperationFactory;
70 75
import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel;
71 76
import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchParameters;
......
159 164
            DistinctOn.registerAggregateOperation(new LastAggregateOperationFactory());
160 165
            DistinctOn.registerAggregateOperation(new NullAggregateOperationFactory());
161 166
            
167
            DistinctOn.registerAggregateOperation(new STConvexHullAggregateOperationFactory());
168
            DistinctOn.registerAggregateOperation(new STExtentAggregateOperationFactory());
169
//            DistinctOn.registerAggregateOperation(new STIntersectionAggregateOperationFactory());
170
            DistinctOn.registerAggregateOperation(new STUnionAggregateOperationFactory());
171
            
162 172
            ShowFormForOpenStoreParametersAction.selfRegister();
163 173
            
164 174
            SelectionAddActionFactory.selfRegister();

Also available in: Unified diff