gvsig-lrs / org.gvsig.lrs / trunk / org.gvsig.lrs / org.gvsig.lrs.lib / org.gvsig.lrs.lib.impl / src / main / java / org / gvsig / lrs / lib / impl / LrsCalibrateRouteAlgorithm.java @ 16
History | View | Annotate | Download (8.11 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2015 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.lrs.lib.impl; |
24 |
|
25 |
import java.io.File; |
26 |
import java.util.ArrayList; |
27 |
import java.util.HashMap; |
28 |
import java.util.Iterator; |
29 |
import java.util.List; |
30 |
import java.util.Map; |
31 |
import java.util.Map.Entry; |
32 |
|
33 |
import org.apache.commons.lang3.mutable.Mutable; |
34 |
import org.apache.commons.lang3.mutable.MutableInt; |
35 |
import org.gvsig.fmap.dal.DALLocator; |
36 |
import org.gvsig.fmap.dal.DataManager; |
37 |
import org.gvsig.fmap.dal.DataServerExplorer; |
38 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
39 |
import org.gvsig.fmap.dal.DataStore; |
40 |
import org.gvsig.fmap.dal.DataStoreParameters; |
41 |
import org.gvsig.fmap.dal.DataTypes; |
42 |
import org.gvsig.fmap.dal.exception.DataException; |
43 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
44 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
45 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
46 |
import org.gvsig.fmap.dal.feature.Feature; |
47 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
48 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
49 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
50 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
51 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
52 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
53 |
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters; |
54 |
import org.gvsig.fmap.geom.Geometry; |
55 |
import org.gvsig.fmap.geom.GeometryLocator; |
56 |
import org.gvsig.fmap.geom.GeometryManager; |
57 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
58 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
59 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
60 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
61 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
62 |
import org.gvsig.fmap.geom.primitive.Envelope; |
63 |
import org.gvsig.fmap.geom.primitive.Line; |
64 |
import org.gvsig.fmap.geom.primitive.Point; |
65 |
import org.gvsig.fmap.geom.type.GeometryType; |
66 |
import org.gvsig.lrs.lib.api.DistanceUnits; |
67 |
import org.gvsig.lrs.lib.api.LrsAlgorithm; |
68 |
import org.gvsig.lrs.lib.api.LrsAlgorithmParams; |
69 |
import org.gvsig.lrs.lib.api.LrsCalibrateRouteAlgorithmParams; |
70 |
import org.gvsig.lrs.lib.api.LrsCoordinatesPriority; |
71 |
import org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams; |
72 |
import org.gvsig.lrs.lib.api.LrsMeasureCalculationMethods; |
73 |
import org.gvsig.lrs.lib.api.LrsSourceOfMeasures; |
74 |
import org.gvsig.lrs.lib.api.exceptions.LrsCreateRouteException; |
75 |
import org.gvsig.lrs.lib.api.exceptions.LrsException; |
76 |
import org.gvsig.tools.ToolsLocator; |
77 |
import org.gvsig.tools.dataTypes.DataType; |
78 |
import org.gvsig.tools.exception.BaseException; |
79 |
import org.gvsig.tools.i18n.I18nManager; |
80 |
import org.gvsig.tools.service.Manager; |
81 |
import org.gvsig.tools.task.SimpleTaskStatus; |
82 |
import org.gvsig.tools.visitor.VisitCanceledException; |
83 |
import org.gvsig.tools.visitor.Visitor; |
84 |
import org.slf4j.Logger; |
85 |
import org.slf4j.LoggerFactory; |
86 |
|
87 |
/**
|
88 |
* @author dmartinez
|
89 |
*
|
90 |
*/
|
91 |
public class LrsCalibrateRouteAlgorithm implements LrsAlgorithm { |
92 |
|
93 |
private static final Logger logger = LoggerFactory.getLogger(LrsCalibrateRouteAlgorithm.class); |
94 |
|
95 |
private LrsCalibrateRouteAlgorithmParams parameters;
|
96 |
|
97 |
/**
|
98 |
*
|
99 |
*/
|
100 |
public LrsCalibrateRouteAlgorithm(LrsCalibrateRouteAlgorithmParams parameters) {
|
101 |
this.parameters = parameters;
|
102 |
|
103 |
} |
104 |
|
105 |
/*
|
106 |
* (non-Javadoc)
|
107 |
*
|
108 |
* @see org.gvsig.tools.service.Service#getManager()
|
109 |
*/
|
110 |
public Manager getManager() {
|
111 |
return null; |
112 |
} |
113 |
|
114 |
/*
|
115 |
* (non-Javadoc)
|
116 |
*
|
117 |
* @see org.gvsig.lrs.lib.api.LrsAlgorithm#getParams()
|
118 |
*/
|
119 |
public LrsAlgorithmParams getParams() {
|
120 |
return this.parameters; |
121 |
} |
122 |
|
123 |
/* (non-Javadoc)
|
124 |
* @see org.gvsig.lrs.lib.api.LrsAlgorithm#setParams(org.gvsig.lrs.lib.api.LrsAlgorithmParams)
|
125 |
*/
|
126 |
public void setParams(LrsAlgorithmParams params) throws IllegalArgumentException { |
127 |
if(!(params instanceof LrsCreateRouteAlgorithmParams)){ |
128 |
throw new IllegalArgumentException("params should be LrsCalibrateRouteAlgorithmParams type."); |
129 |
} |
130 |
// TODO Auto-generated method stub
|
131 |
} |
132 |
|
133 |
/*
|
134 |
* (non-Javadoc)
|
135 |
* @see org.gvsig.lrs.lib.api.LrsAlgorithm#execute(org.gvsig.tools.task.SimpleTaskStatus)
|
136 |
*/
|
137 |
public void execute(final SimpleTaskStatus taskStatus) throws LrsException { |
138 |
NewFeatureStoreParameters newFeatureStoreParameters = parameters.getNewFeatureStoreParameters(); |
139 |
|
140 |
FeatureStore sourceFeatureStore = parameters.getSourceFeatureStore(); |
141 |
FeatureAttributeDescriptor idRouteField = parameters.getIdRouteField(); |
142 |
|
143 |
logger.info(parameters.toString()); |
144 |
|
145 |
taskStatus.setTitle(parameters.getName()); |
146 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
147 |
taskStatus.message(i18nManager.getTranslation("calibrating_features"));
|
148 |
|
149 |
try {
|
150 |
final FeatureStore newFeatureStore=LrsAlgorithmUtils.createNewDataStore(newFeatureStoreParameters,idRouteField);
|
151 |
newFeatureStore.edit(FeatureStore.MODE_FULLEDIT); |
152 |
|
153 |
FeatureSet sourceFeatures; |
154 |
if (sourceFeatureStore.getFeatureSelection().getSize()>0){ |
155 |
sourceFeatures=sourceFeatureStore.getFeatureSelection(); |
156 |
}else{
|
157 |
sourceFeatures=sourceFeatureStore.getFeatureSet(); |
158 |
} |
159 |
|
160 |
taskStatus.setRangeOfValues(0, sourceFeatures.getSize()-1); |
161 |
final MutableInt taskCount=new MutableInt(); |
162 |
taskCount.setValue(0);
|
163 |
|
164 |
sourceFeatures.accept(new Visitor() {
|
165 |
|
166 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
167 |
Feature feature=(Feature)obj; |
168 |
|
169 |
EditableFeature calibratedFeature=calibrateRoute(feature); |
170 |
|
171 |
newFeatureStore.update(calibratedFeature); |
172 |
|
173 |
taskStatus.setCurValue(taskCount.getValue()); |
174 |
taskCount.increment(); |
175 |
} |
176 |
}); |
177 |
newFeatureStore.finishEditing(); |
178 |
|
179 |
|
180 |
} catch (Exception e1) { |
181 |
taskStatus.abort(); |
182 |
throw new LrsCreateRouteException("Error calibrating routes", e1); |
183 |
} |
184 |
|
185 |
taskStatus.terminate(); |
186 |
taskStatus.terminate(); |
187 |
} |
188 |
|
189 |
private EditableFeature calibrateRoute(Feature feature) {
|
190 |
FeatureStore calibratePointFeatureStore= parameters.getCalibratePointFeatureStore(); |
191 |
FeatureAttributeDescriptor idRouteCalibratePointField =parameters.getCalibratePointIdRouteField(); |
192 |
FeatureAttributeDescriptor fromMeasureField = parameters.getFromMeasureField(); |
193 |
|
194 |
LrsMeasureCalculationMethods calculationMethod= parameters.getMeasureCalculationMethods(); |
195 |
Double searchRadius=parameters.getSearchRadius();
|
196 |
DistanceUnits measureUnits = parameters.getMeasureUnits(); |
197 |
boolean interpolateBetweenCalibrationPoints=parameters.interpolateBetweenCalibrationPoints();
|
198 |
boolean extrapolateBeforeCalibrationPoints=parameters.extrapolateBeforeCalibrationPoints();
|
199 |
boolean extrapolateAfterCalibrationPoints=parameters.extrapolateAfterCalibrationPoints();
|
200 |
boolean ignoreSpatialGaps = parameters.ignoreSpatialGaps();
|
201 |
boolean includeAll=parameters.includeAll();
|
202 |
|
203 |
// TODO Must calculate the calibrated Feature
|
204 |
|
205 |
return null; |
206 |
} |
207 |
|
208 |
|
209 |
class MStructure{ |
210 |
Geometry geometry; |
211 |
Double fromField;
|
212 |
Double toField;
|
213 |
} |
214 |
|
215 |
} |
216 |
|
217 |
|
218 |
|
219 |
|