Revision 726

View differences:

org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.app/org.gvsig.topology.app.mainplugin/src/main/java/org/gvsig/topology/app/mainplugin/AppTopologyServices.java
155 155
    }
156 156

  
157 157
    @Override
158
    public void refreshView() {
159
        try {
160
            ApplicationManager application = ApplicationLocator.getManager();
161
            ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
162
            if( viewdoc == null ) {
163
                return;
164
            }
165
            viewdoc.getMapContext().invalidate();
166
        } catch (Exception ex) {
167
            LOGGER.warn("Cant refresh view", ex);
168
        }
169
    }
170
    
171
    @Override
158 172
    public void centerTo(Point point) {
159 173
        try {
160 174
            ApplicationManager application = ApplicationLocator.getManager();
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/TopologyImplLibrary.java
35 35
import org.gvsig.topology.rule.ContainsPointRuleFactory;
36 36
import org.gvsig.topology.rule.MustBeLargerThanToleranceLineRuleFactory;
37 37
import org.gvsig.topology.rule.MustNotOverlapPolygonRuleFactory;
38
import org.gvsig.topology.rule.PointMustBeProperlyInsidePolygonRuleFactory;
38 39

  
39 40
/**
40 41
 *
......
63 64
        manager.addRuleFactories(new ContainsPointRuleFactory());
64 65
        manager.addRuleFactories(new MustBeLargerThanToleranceLineRuleFactory());
65 66
        manager.addRuleFactories(new MustNotOverlapPolygonRuleFactory());
67
        manager.addRuleFactories(new PointMustBeProperlyInsidePolygonRuleFactory());
66 68
    }
67 69

  
68 70
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/DefaultTopologyDataSet.java
95 95
        }
96 96
    }
97 97

  
98
    public void restart() {
99
        this.store  = null;
100
        this.spatialIndex = null;
101
    }
102
    
98 103
    @Override
99 104
    public boolean equals(Object obj) {
100 105
        if( !(obj instanceof DefaultTopologyDataSet) ) {
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/DefaultTopologyPlan.java
132 132
            theTaskStatus.message("Preparing the execution of the plan");
133 133
            theTaskStatus.setAutoremove(true);
134 134
            theTaskStatus.setIndeterminate();
135
            for (TopologyDataSet dataSet : this.dataSets.values()) {
136
                dataSet.restart();
137
            }
135 138
            this.getReport().removeAllLines();
136 139
            long steps = 0;
137 140
            for (TopologyRule rule : this.rules) {
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
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
        }
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/PointMustBeProperlyInsidePolygonRule.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.topology.rule;
25

  
26
import org.gvsig.expressionevaluator.Expression;
27
import org.gvsig.expressionevaluator.ExpressionBuilder;
28
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
29
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
30
import org.gvsig.fmap.dal.feature.Feature;
31
import org.gvsig.fmap.dal.feature.FeatureReference;
32
import org.gvsig.fmap.dal.feature.FeatureSet;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.fmap.geom.Geometry;
35
import org.gvsig.tools.dynobject.DynObject;
36
import org.gvsig.tools.task.SimpleTaskStatus;
37
import org.gvsig.topology.lib.spi.AbstractTopologyRule;
38
import org.gvsig.topology.lib.spi.AbstractTopologyRuleAction;
39
import org.gvsig.topology.lib.api.ExecuteTopologyRuleActionException;
40
import org.gvsig.topology.lib.api.TopologyDataSet;
41
import org.gvsig.topology.lib.api.TopologyPlan;
42
import org.gvsig.topology.lib.api.TopologyReport;
43
import org.gvsig.topology.lib.api.TopologyReportLine;
44
import org.gvsig.topology.lib.api.TopologyRule;
45
import org.gvsig.topology.lib.api.TopologyRuleFactory;
46

  
47
/**
48
 *
49
 * @author jjdelcerro
50
 */
51
@SuppressWarnings("UseSpecificCatch")
52
public class PointMustBeProperlyInsidePolygonRule extends AbstractTopologyRule {
53

  
54
    private class DeleteAction extends AbstractTopologyRuleAction {
55

  
56
        public DeleteAction() {
57
            super(
58
                    PointMustBeProperlyInsidePolygonRuleFactory.NAME,
59
                    "Delete",
60
                    "Delete",
61
                    " The Delete fix removes point features that are not properly within polygon features. Note that you can use the Edit tool and move the point inside the polygon feature if you do not want to delete it. This fix can be applied to one or more Must Be Properly Inside errors."
62
            );
63
        }
64

  
65
        @Override
66
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) {
67
            try {
68
                TopologyDataSet dataSet = rule.getDataSet1();
69

  
70
                dataSet.delete(line.getFeature1());
71

  
72
            } catch (Exception ex) {
73
                throw new ExecuteTopologyRuleActionException(ex);
74
            }
75
        }
76

  
77
    }
78

  
79
    private String geomName;
80
    private Expression expression = null;
81
    private ExpressionBuilder expressionBuilder = null;
82

  
83
    public PointMustBeProperlyInsidePolygonRule(
84
            TopologyPlan plan,
85
            TopologyRuleFactory factory
86
    ) {
87
        super(plan, factory);
88
        this.actions.add(new DeleteAction());
89
    }
90

  
91
    public PointMustBeProperlyInsidePolygonRule(
92
            TopologyPlan plan,
93
            TopologyRuleFactory factory,
94
            double tolerance,
95
            String dataSet1,
96
            String dataSet2
97
    ) {
98
        super(plan, factory, tolerance, dataSet1, dataSet2);
99

  
100
        this.addAction(new DeleteAction());
101
    }
102

  
103
    @Override
104
    protected void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature1) throws Exception {
105
        FeatureSet set = null;
106
        try {
107
            FeatureStore store2 = this.getDataSet2().getStore();
108
            if (this.expression == null) {
109
                ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
110
                this.expression = manager.createExpression();
111
                this.expressionBuilder = manager.createExpressionBuilder();
112
                this.geomName = store2.getDefaultFeatureType().getDefaultGeometryAttributeName();
113
            }
114
            Geometry point = feature1.getDefaultGeometry();
115
            TopologyDataSet theDataSet = this.getDataSet2();
116
//            if (theDataSet.getSpatialIndex() != null) {
117
//                boolean ok = false;
118
//                for (FeatureReference featureReference : theDataSet.query(point)) {
119
//                    Feature feature2 = featureReference.getFeature();
120
//                    if( feature2.getDefaultGeometry().overlaps(point) ) {
121
//                        ok = true;
122
//                        break;
123
//                    }
124
//                }
125
//                if( !ok ) {
126
//                    report.addLine(this,
127
//                            this.getDataSet1(),
128
//                            this.getDataSet2(),
129
//                            point,
130
//                            feature1.getReference(),
131
//                            null,
132
//                            false,
133
//                            "The point are error where are not inside a polygon."
134
//                    );
135
//                }
136
//            } else {
137
                this.expression.setPhrase(
138
                        this.expressionBuilder.ifnull(
139
                                this.expressionBuilder.column(this.geomName),
140
                                this.expressionBuilder.constant(false),
141
                                this.expressionBuilder.ST_Overlaps(
142
                                        this.expressionBuilder.column(this.geomName),
143
                                        this.expressionBuilder.geometry(point)
144
                                )
145
                        ).toString()
146
                );
147
                if (theDataSet.findFirst(this.expression) == null) {
148
                    report.addLine(this,
149
                            this.getDataSet1(),
150
                            this.getDataSet2(),
151
                            point,
152
                            feature1.getReference(),
153
                            null,
154
                            false,
155
                            "The point are error where are not inside a polygon."
156
                    );
157
                }
158
//            }
159
        } catch (Exception ex) {
160
            LOGGER.warn("Can't check feature.", ex);
161
        } finally {
162
            if (set != null) {
163
                set.dispose();
164
            }
165
        }
166
    }
167

  
168
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/PointMustBeProperlyInsidePolygonRuleFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.topology.rule;
25

  
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.tools.util.ListBuilder;
28
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory;
29
import org.gvsig.topology.lib.api.TopologyPlan;
30
import org.gvsig.topology.lib.api.TopologyRule;
31

  
32
/**
33
 *
34
 * @author jjdelcerro
35
 */
36
public class PointMustBeProperlyInsidePolygonRuleFactory extends AbstractTopologyRuleFactory {
37
    
38
    public static final String NAME = "PointMustBeProperlyInsidePolygon";
39
    
40
    public PointMustBeProperlyInsidePolygonRuleFactory() {
41
        super(
42
                NAME, 
43
                "Must Be Properly Inside", 
44
                "Requires that points fall within area features. This is useful when the point features are related to polygons, such as wells and well pads or address points and parcels.", 
45
                new ListBuilder<Integer>()
46
                        .add(Geometry.TYPES.POINT)
47
                        .asList(),
48
                new ListBuilder<Integer>()
49
                        .add(Geometry.TYPES.SURFACE)
50
                        .add(Geometry.TYPES.MULTISURFACE)
51
                        .asList()
52
        );
53
    }
54
    
55
    @Override
56
    public TopologyRule createRule(TopologyPlan plan, String dataSet1, String dataSet2, double tolerance) {
57
        TopologyRule rule = new PointMustBeProperlyInsidePolygonRule(plan, this, tolerance, dataSet1, dataSet2);
58
        return rule;
59
    }    
60

  
61
    @Override
62
    public TopologyRule createRule(TopologyPlan plan) {
63
        TopologyRule rule = new PointMustBeProperlyInsidePolygonRule(plan, this);
64
        return rule;
65
    }
66
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyDataSet.java
79 79

  
80 80
    public Feature findFirst(Expression expression);
81 81

  
82
    public void restart();
82 83
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.swing/org.gvsig.topology.swing.impl/src/main/java/org/gvsig/topology/swing/impl/DefaultJTopologyPlanProperties.java
227 227
        if( lstRules.isSelectionEmpty() ) {
228 228
            return;
229 229
        }
230
        int index = lstRules.getSelectedIndex();
230 231
        TopologyRule rule = (TopologyRule) ListElement.getSelected(lstRules);
231 232
        this.plan.removeRule(rule);
232
        lstRules.remove(lstRules.getSelectedIndex());
233
        lstRules.remove(index);
233 234
    }
234 235

  
235 236
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.swing/org.gvsig.topology.swing.impl/src/main/java/org/gvsig/topology/swing/impl/DefaultJTopologyReport.java
417 417
            }
418 418
        }
419 419
        action.execute(rule, line, parameters);
420
        tabData.setEnabledAt(0, true);
421
        tabData.setEnabledAt(1, false);
422
        tabData.setSelectedIndex(0);
423
        pnlParameters.removeAll();
420
        this.tabData.setEnabledAt(0, true);
421
        this.tabData.setEnabledAt(1, false);
422
        this.tabData.setSelectedIndex(0);
423
        this.pnlParameters.removeAll();
424
        this.services.refreshView();
424 425
    }
425 426

  
426 427
    private void doShowActionParametersPanel(
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.swing/org.gvsig.topology.swing.api/src/main/java/org/gvsig/topology/swing/api/TopologySwingServices.java
33 33
 * @author jjdelcerro
34 34
 */
35 35
public interface TopologySwingServices extends TopologyServices {
36
    
36

  
37 37
    public interface WorkingAreaChangedListener {
38
     
38

  
39 39
        public void workingAreaChanged(Envelope workingArea);
40 40
    }
41
    
41

  
42 42
    public TreeModel getDataSetTreeModel();
43
    
43

  
44 44
    public void zoomTo(Envelope envelope);
45
    
45

  
46 46
    public void centerTo(Point point);
47
    
47

  
48 48
    public Envelope getWorkingArea();
49
    
49

  
50 50
    public void addWorkingAreaChangedListener(WorkingAreaChangedListener listener);
51 51

  
52 52
    public void removeWorkingAreaChangedListener(WorkingAreaChangedListener listener);
53 53

  
54
    public void refreshView();
54 55
}
55 56

  

Also available in: Unified diff