Revision 726 org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/ContainsPointRule.java
ContainsPointRule.java | ||
---|---|---|
29 | 29 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
30 | 30 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
31 | 31 |
import org.gvsig.fmap.dal.feature.Feature; |
32 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
32 | 33 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
33 | 34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
34 | 35 |
import org.gvsig.fmap.geom.Geometry; |
35 | 36 |
import org.gvsig.fmap.geom.primitive.Point; |
37 |
import org.gvsig.fmap.geom.primitive.Polygon; |
|
36 | 38 |
import org.gvsig.tools.dynobject.DynObject; |
37 | 39 |
import org.gvsig.tools.task.SimpleTaskStatus; |
38 | 40 |
import org.gvsig.topology.lib.spi.AbstractTopologyRule; |
... | ... | |
64 | 66 |
} |
65 | 67 |
|
66 | 68 |
@Override |
67 |
public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) {
|
|
69 |
public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) { |
|
68 | 70 |
try { |
69 |
Point point = line.getGeometry().centroid(); |
|
71 |
Geometry polygon = line.getGeometry(); |
|
72 |
Point point = polygon.centroid(); |
|
73 |
if( !polygon.contains(point) ) { |
|
74 |
point = polygon.getInteriorPoint(); |
|
75 |
} |
|
70 | 76 |
TopologyDataSet dataSet = rule.getDataSet2(); |
71 | 77 |
|
72 | 78 |
EditableFeature feature = dataSet.createNewFeature(); |
73 | 79 |
feature.setDefaultGeometry(point); |
74 | 80 |
dataSet.insert(feature); |
75 |
|
|
81 |
|
|
76 | 82 |
} catch (Exception ex) { |
77 | 83 |
throw new ExecuteTopologyRuleActionException(ex); |
78 | 84 |
} |
... | ... | |
83 | 89 |
private String geomName; |
84 | 90 |
private Expression expression = null; |
85 | 91 |
private ExpressionBuilder expressionBuilder = null; |
86 |
|
|
92 |
|
|
87 | 93 |
public ContainsPointRule( |
88 | 94 |
TopologyPlan plan, |
89 | 95 |
TopologyRuleFactory factory |
... | ... | |
91 | 97 |
super(plan, factory); |
92 | 98 |
this.actions.add(new CreateFetureAction()); |
93 | 99 |
} |
94 |
|
|
100 |
|
|
95 | 101 |
public ContainsPointRule( |
96 | 102 |
TopologyPlan plan, |
97 | 103 |
TopologyRuleFactory factory, |
... | ... | |
100 | 106 |
String dataSet2 |
101 | 107 |
) { |
102 | 108 |
super(plan, factory, tolerance, dataSet1, dataSet2); |
103 |
|
|
109 |
|
|
104 | 110 |
this.addAction(new CreateFetureAction()); |
105 | 111 |
} |
106 | 112 |
|
... | ... | |
109 | 115 |
FeatureSet set = null; |
110 | 116 |
try { |
111 | 117 |
FeatureStore store2 = this.getDataSet2().getStore(); |
112 |
if( this.expression == null ) {
|
|
118 |
if (this.expression == null) {
|
|
113 | 119 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
114 | 120 |
this.expression = manager.createExpression(); |
115 | 121 |
this.expressionBuilder = manager.createExpressionBuilder(); |
116 | 122 |
this.geomName = store2.getDefaultFeatureType().getDefaultGeometryAttributeName(); |
117 |
}
|
|
123 |
} |
|
118 | 124 |
Geometry polygon = feature1.getDefaultGeometry(); |
119 |
this.expression.setPhrase( |
|
120 |
this.expressionBuilder.ifnull( |
|
121 |
this.expressionBuilder.column(this.geomName), |
|
122 |
this.expressionBuilder.constant(false), |
|
123 |
this.expressionBuilder.ST_Intersects( |
|
124 |
this.expressionBuilder.column(this.geomName), |
|
125 |
this.expressionBuilder.geometry(polygon) |
|
126 |
) |
|
127 |
).toString() |
|
128 |
); |
|
129 |
Feature f = store2.findFirst(this.expression); |
|
130 |
if ( f==null ) { |
|
131 |
report.addLine(this, |
|
132 |
this.getDataSet1(), |
|
133 |
this.getDataSet2(), |
|
134 |
polygon, |
|
135 |
feature1.getReference(), |
|
136 |
null, |
|
137 |
false, |
|
138 |
"The polygon is an error because it does not contain a point." |
|
125 |
TopologyDataSet theDataSet = this.getDataSet2(); |
|
126 |
if (theDataSet.getSpatialIndex() != null) { |
|
127 |
boolean ok = false; |
|
128 |
for (FeatureReference featureReference : theDataSet.query(polygon)) { |
|
129 |
Feature feature2 = featureReference.getFeature(); |
|
130 |
if( polygon.contains(feature2.getDefaultGeometry()) ) { |
|
131 |
ok = true; |
|
132 |
break; |
|
133 |
} |
|
134 |
} |
|
135 |
if( !ok ) { |
|
136 |
report.addLine(this, |
|
137 |
this.getDataSet1(), |
|
138 |
this.getDataSet2(), |
|
139 |
polygon, |
|
140 |
feature1.getReference(), |
|
141 |
null, |
|
142 |
false, |
|
143 |
"The polygon is an error because it does not contain a point." |
|
144 |
); |
|
145 |
} |
|
146 |
} else { |
|
147 |
this.expression.setPhrase( |
|
148 |
this.expressionBuilder.ifnull( |
|
149 |
this.expressionBuilder.column(this.geomName), |
|
150 |
this.expressionBuilder.constant(false), |
|
151 |
this.expressionBuilder.ST_Contains( |
|
152 |
this.expressionBuilder.geometry(polygon), |
|
153 |
this.expressionBuilder.column(this.geomName) |
|
154 |
) |
|
155 |
).toString() |
|
139 | 156 |
); |
157 |
if (theDataSet.findFirst(this.expression) == null) { |
|
158 |
report.addLine(this, |
|
159 |
this.getDataSet1(), |
|
160 |
this.getDataSet2(), |
|
161 |
polygon, |
|
162 |
feature1.getReference(), |
|
163 |
null, |
|
164 |
false, |
|
165 |
"The polygon is an error because it does not contain a point." |
|
166 |
); |
|
167 |
} |
|
140 | 168 |
} |
141 |
} catch(Exception ex) { |
|
169 |
} catch (Exception ex) {
|
|
142 | 170 |
LOGGER.warn("Can't check feature.", ex); |
143 | 171 |
} finally { |
144 |
if( set!=null ) {
|
|
172 |
if (set != null) {
|
|
145 | 173 |
set.dispose(); |
146 | 174 |
} |
147 | 175 |
} |
Also available in: Unified diff