svn-gvsig-desktop / 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 @ 47359
History | View | Annotate | Download (2.69 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.fmap.dal.swing.impl.searchPostProcess.distinctOn; |
7 |
|
8 |
// public static void selfRegister(){
|
9 |
|
10 |
import java.util.List; |
11 |
import org.gvsig.fmap.dal.DataTypes; |
12 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
13 |
import org.gvsig.fmap.geom.Geometry; |
14 |
import org.gvsig.fmap.geom.GeometryUtils; |
15 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
16 |
import org.gvsig.fmap.geom.primitive.Primitive; |
17 |
import static org.gvsig.tools.dynobject.DynField.RELATION_TYPE_NONE; |
18 |
|
19 |
|
20 |
public class STConvexHullAggregateOperation extends AbstractAggregateOperation { |
21 |
|
22 |
public static class SumAggregateOperationFactory implements AggregateOperationFactory{ |
23 |
|
24 |
public static final String NAME = "ST_ConvexHull"; |
25 |
|
26 |
@Override
|
27 |
public String getName() { |
28 |
return NAME;
|
29 |
} |
30 |
|
31 |
@Override
|
32 |
public AggregateOperation create(Object... os) { |
33 |
return new STConvexHullAggregateOperation(); |
34 |
} |
35 |
|
36 |
@Override
|
37 |
public boolean isApplicable(Object... value) { |
38 |
return Geometry.class.isAssignableFrom((Class<?>) value[0]); |
39 |
} |
40 |
|
41 |
} |
42 |
|
43 |
Geometry geom; |
44 |
|
45 |
public STConvexHullAggregateOperation() {
|
46 |
this.geom = null; |
47 |
} |
48 |
|
49 |
@Override
|
50 |
public boolean isApplicable(Object... value) { |
51 |
return value[0] instanceof Geometry; |
52 |
} |
53 |
|
54 |
@Override
|
55 |
public void reset() { |
56 |
this.geom = null; |
57 |
} |
58 |
|
59 |
@Override
|
60 |
public void perform(Object value) { |
61 |
try {
|
62 |
if (value == null) { |
63 |
return;
|
64 |
} |
65 |
if( geom == null ) { |
66 |
geom = ((Geometry)value).convexHull(); |
67 |
return;
|
68 |
} |
69 |
MultiPolygon mp = GeometryUtils.createMultiPolygon(geom.getGeometryType().getSubType()); |
70 |
mp.addPrimitive((Primitive) geom); |
71 |
mp.addPrimitive((Primitive) value); |
72 |
geom = mp.convexHull(); |
73 |
} catch (Exception ex) { |
74 |
throw new RuntimeException("",ex); |
75 |
} |
76 |
} |
77 |
|
78 |
@Override
|
79 |
public Object getValue() { |
80 |
return this.geom; |
81 |
} |
82 |
|
83 |
@Override
|
84 |
public void fixAttributeDescriptor(EditableFeatureAttributeDescriptor descriptor) { |
85 |
super.fixAttributeDescriptor(descriptor);
|
86 |
|
87 |
descriptor.setDataType(DataTypes.GEOMETRY); |
88 |
descriptor.setGeometryType(Geometry.TYPES.POLYGON, Geometry.SUBTYPES.GEOM2D); |
89 |
|
90 |
descriptor.setRelationType(RELATION_TYPE_NONE); |
91 |
descriptor.getForeingKey().clean(); |
92 |
descriptor.setAvailableValues((List)null); |
93 |
|
94 |
} |
95 |
|
96 |
|
97 |
} |