Revision 25785 branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/impl/MyTransform.java
MyTransform.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.feature.impl; |
2 | 2 |
|
3 |
import java.util.Arrays; |
|
4 |
|
|
3 | 5 |
import org.gvsig.fmap.dal.DataTypes; |
4 | 6 |
import org.gvsig.fmap.dal.exception.DataException; |
5 | 7 |
import org.gvsig.fmap.dal.feature.AbstractFeatureStoreTransform; |
... | ... | |
7 | 9 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
8 | 10 |
import org.gvsig.fmap.dal.feature.Feature; |
9 | 11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
12 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
10 | 13 |
import org.gvsig.fmap.geom.Geometry; |
11 | 14 |
import org.gvsig.fmap.geom.GeometryFactory; |
12 | 15 |
import org.gvsig.fmap.geom.GeometryManager; |
... | ... | |
15 | 18 |
|
16 | 19 |
/** |
17 | 20 |
* |
18 |
* This transform adds a new attribute of type Geometry to the |
|
19 |
* original store's default FeatureType. When applying the transform |
|
20 |
* to a single feature this new attribute is assigned the value of a |
|
21 |
* point whose coordinates proceed from two numeric attributes from the |
|
22 |
* store, called xname, yname. |
|
23 |
* |
|
21 |
* This transform adds a new attribute of type Geometry to the original store's |
|
22 |
* default FeatureType. When applying the transform to a single feature this new |
|
23 |
* attribute is assigned the value of a point whose coordinates proceed from two |
|
24 |
* numeric attributes from the store, called xname, yname. |
|
25 |
* |
|
24 | 26 |
*/ |
25 | 27 |
class MyTransform extends AbstractFeatureStoreTransform { |
26 | 28 |
|
27 | 29 |
private String geomName; |
28 |
private String xname;
|
|
30 |
private String xname; |
|
29 | 31 |
private String yname; |
30 |
|
|
32 |
|
|
31 | 33 |
/** |
32 | 34 |
* Empty default constructor |
33 | 35 |
*/ |
34 | 36 |
public MyTransform() { |
35 | 37 |
} |
36 |
|
|
38 |
|
|
37 | 39 |
/** |
38 |
* Initializes the transform by assigning the source store and the names of the necessary attributes. |
|
39 |
* |
|
40 |
* Initializes the transform by assigning the source store and the names of |
|
41 |
* the necessary attributes. |
|
42 |
* |
|
40 | 43 |
* @param store |
41 |
* source store.
|
|
44 |
* source store.
|
|
42 | 45 |
* |
43 | 46 |
* @param geomName |
44 |
* name of the geometry attribute in the default feature type from the source store. |
|
47 |
* name of the geometry attribute in the default feature type |
|
48 |
* from the source store. |
|
45 | 49 |
* |
46 | 50 |
* @param xname |
47 |
* name of the attribute containing the X coordinates
|
|
51 |
* name of the attribute containing the X coordinates
|
|
48 | 52 |
* |
49 | 53 |
* @param yname |
50 |
* name of the attribute containing the Y coordinates
|
|
54 |
* name of the attribute containing the Y coordinates
|
|
51 | 55 |
* |
52 | 56 |
* @throws DataException |
53 | 57 |
*/ |
54 | 58 |
public void initialize(FeatureStore store, String geomName, String xname, String yname) throws DataException { |
55 |
|
|
59 |
|
|
56 | 60 |
// Initialize some data |
57 | 61 |
this.setFeatureStore(store); |
58 | 62 |
this.geomName = geomName; |
59 | 63 |
this.xname = xname; |
60 | 64 |
this.yname = yname; |
61 |
|
|
65 |
|
|
62 | 66 |
// obtain the feature type, add the new attribute and keep a reference to the resulting feature type |
63 | 67 |
EditableFeatureType type = store.getDefaultFeatureType().getEditable(); |
64 | 68 |
type.add(geomName, DataTypes.GEOMETRY); |
65 |
setDefaultFeatureType(type.getNotEditableCopy()); |
|
69 |
FeatureType[] types = new FeatureType[] { type.getNotEditableCopy() }; |
|
70 |
setFeatureTypes(Arrays.asList(types), types[0]); |
|
66 | 71 |
} |
67 |
|
|
72 |
|
|
68 | 73 |
/** |
69 |
* Applies this transform to a target editable feature, using data from the
|
|
74 |
* Applies this transform to a target editable feature, using data from the |
|
70 | 75 |
* source feature. |
71 | 76 |
*/ |
72 | 77 |
public void applyTransform(Feature source, EditableFeature target) |
73 | 78 |
throws DataException { |
74 |
|
|
79 |
|
|
75 | 80 |
// copy source feature data over target feature |
76 | 81 |
target.copyFrom(source); |
77 |
|
|
82 |
|
|
78 | 83 |
// calculate and assign new attribute's value |
79 | 84 |
GeometryFactory geomFactory = GeometryManager.getInstance().getGeometryFactory(); |
80 | 85 |
Geometry geom = geomFactory.createPoint2D( |
81 |
source.getDouble(xname),
|
|
86 |
source.getDouble(xname), |
|
82 | 87 |
source.getDouble(yname) |
83 | 88 |
); |
84 | 89 |
target.setGeometry(this.geomName, geom); |
... | ... | |
92 | 97 |
|
93 | 98 |
public void setState(PersistentState state) throws PersistenceException { |
94 | 99 |
} |
95 |
|
|
100 |
|
|
96 | 101 |
} |
Also available in: Unified diff