root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / rule / FeatureRulePolygon.java @ 24496
History | View | Annotate | Download (1.88 KB)
1 |
package org.gvsig.fmap.dal.feature.rule; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.dal.exceptions.DataException; |
4 |
import org.gvsig.fmap.dal.feature.AbstractFeatureRule; |
5 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
6 |
import org.gvsig.fmap.dal.feature.Feature; |
7 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
8 |
import org.gvsig.fmap.geom.Geometry; |
9 |
import org.gvsig.fmap.geom.GeometryFactory; |
10 |
import org.gvsig.fmap.geom.GeometryManager; |
11 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
12 |
import org.gvsig.fmap.geom.util.Converter; |
13 |
|
14 |
public class FeatureRulePolygon extends AbstractFeatureRule { |
15 |
|
16 |
public FeatureRulePolygon() {
|
17 |
super("RulePolygon", "Ensure orientation of geometry"); |
18 |
} |
19 |
|
20 |
public void validate(Feature feature, FeatureStore store) |
21 |
throws DataException {
|
22 |
|
23 |
try {
|
24 |
Geometry geom = feature.getDefaultGeometry(); |
25 |
GeneralPathX gp = new GeneralPathX();
|
26 |
gp.append(geom.getPathIterator(null, Converter.FLATNESS), true); |
27 |
|
28 |
if (gp.isClosed()) {
|
29 |
if (gp.isCCW()) {
|
30 |
gp.flip(); |
31 |
GeometryFactory geomFactory = GeometryManager.getInstance() |
32 |
.getGeometryFactory(); |
33 |
geom = geomFactory.createPolygon2D(gp); |
34 |
EditableFeature editable = feature.getEditable(); |
35 |
editable.setDefaultGeometry(geom); |
36 |
store.update(editable); |
37 |
} |
38 |
} |
39 |
} catch (Exception e) { |
40 |
throw new FeatureRulePolygonException(e, store.getName()); |
41 |
} |
42 |
} |
43 |
|
44 |
public class FeatureRulePolygonException extends DataException { |
45 |
|
46 |
/**
|
47 |
*
|
48 |
*/
|
49 |
private static final long serialVersionUID = -3014970171661713021L; |
50 |
private final static String MESSAGE_FORMAT = "Can't apply rule in store %(store)s."; |
51 |
private final static String MESSAGE_KEY = "_FeatureRulePolygonException"; |
52 |
|
53 |
public FeatureRulePolygonException(Throwable cause, String store) { |
54 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
|
55 |
this.setValue("store", store); |
56 |
} |
57 |
} |
58 |
|
59 |
} |