Revision 437

View differences:

org.gvsig.lrs/tags/org.gvsig.lrs-1.0.73/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.lrs.lib.impl.DefaultLrsAlgorithmsLibrary
0 2

  
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.73/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/java/org/gvsig/lrs/lib/impl/DefaultLrsAlgorithmsLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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 2
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

  
25
package org.gvsig.lrs.lib.impl;
26

  
27
import org.gvsig.lrs.lib.api.LrsAlgorithmsLibrary;
28
import org.gvsig.lrs.lib.api.LrsAlgorithmsLocator;
29
import org.gvsig.tools.library.AbstractLibrary;
30
import org.gvsig.tools.library.LibraryException;
31

  
32
/**
33
 * @author fdiaz</a>
34
 *
35
 */
36
public class DefaultLrsAlgorithmsLibrary extends AbstractLibrary {
37

  
38
    @Override
39
    public void doRegistration() {
40
        registerAsImplementationOf(LrsAlgorithmsLibrary.class);
41
    }
42

  
43
    @Override
44
    protected void doInitialize() throws LibraryException {
45
        LrsAlgorithmsLocator.registerLrsAlgorithmsManager(DefaultLrsAlgorithmsManager.class);
46
    }
47

  
48
    @Override
49
    protected void doPostInitialize() throws LibraryException {
50
    }
51

  
52
}
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.73/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/java/org/gvsig/lrs/lib/impl/LrsGenerateDynamicSegmentationAlgorithm.java
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.Iterator;
27
import java.util.List;
28

  
29
import org.apache.commons.lang3.StringUtils;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

  
33
import org.gvsig.fmap.dal.DALLocator;
34
import org.gvsig.fmap.dal.DataManager;
35
import org.gvsig.fmap.dal.DataServerExplorer;
36
import org.gvsig.fmap.dal.DataServerExplorerParameters;
37
import org.gvsig.fmap.dal.DataStore;
38
import org.gvsig.fmap.dal.DataTypes;
39
import org.gvsig.fmap.dal.feature.EditableFeature;
40
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
41
import org.gvsig.fmap.dal.feature.EditableFeatureType;
42
import org.gvsig.fmap.dal.feature.Feature;
43
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
44
import org.gvsig.fmap.dal.feature.FeatureQuery;
45
import org.gvsig.fmap.dal.feature.FeatureSet;
46
import org.gvsig.fmap.dal.feature.FeatureStore;
47
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
48
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters;
49
import org.gvsig.fmap.dal.store.shp.SHPStoreProvider;
50
import org.gvsig.fmap.geom.Geometry;
51
import org.gvsig.fmap.geom.GeometryLocator;
52
import org.gvsig.fmap.geom.aggregate.MultiLine;
53
import org.gvsig.fmap.geom.primitive.Point;
54
import org.gvsig.fmap.geom.type.GeometryType;
55
import org.gvsig.lrs.lib.api.LrsAlgorithm;
56
import org.gvsig.lrs.lib.api.LrsAlgorithmParams;
57
import org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams;
58
import org.gvsig.lrs.lib.api.LrsGenerateDynamicSegmentationAlgorithmParams;
59
import org.gvsig.lrs.lib.api.exceptions.LrsCreateRouteException;
60
import org.gvsig.lrs.lib.api.exceptions.LrsException;
61
import org.gvsig.tools.ToolsLocator;
62
import org.gvsig.tools.dataTypes.DataType;
63
import org.gvsig.tools.exception.BaseException;
64
import org.gvsig.tools.i18n.I18nManager;
65
import org.gvsig.tools.locator.LocatorException;
66
import org.gvsig.tools.service.Manager;
67
import org.gvsig.tools.task.SimpleTaskStatus;
68
import org.gvsig.tools.visitor.VisitCanceledException;
69
import org.gvsig.tools.visitor.Visitor;
70

  
71
/**
72
 * @author fdiaz
73
 *
74
 */
75
public class LrsGenerateDynamicSegmentationAlgorithm implements LrsAlgorithm {
76

  
77
    private static final Logger logger = LoggerFactory.getLogger(LrsGenerateDynamicSegmentationAlgorithm.class);
78

  
79
    private LrsGenerateDynamicSegmentationAlgorithmParams parameters;
80

  
81

  
82
    /**
83
     *
84
     */
85
    public LrsGenerateDynamicSegmentationAlgorithm(LrsGenerateDynamicSegmentationAlgorithmParams parameters) {
86
        this.parameters = parameters;
87

  
88
    }
89

  
90
    /*
91
     * (non-Javadoc)
92
     *
93
     * @see org.gvsig.tools.service.Service#getManager()
94
     */
95
    public Manager getManager() {
96
        return null;
97
    }
98

  
99
    /*
100
     * (non-Javadoc)
101
     *
102
     * @see org.gvsig.lrs.lib.api.LrsAlgorithm#getParams()
103
     */
104
    public  LrsAlgorithmParams getParams() {
105
        return this.parameters;
106
    }
107

  
108
    /*
109
     * (non-Javadoc)
110
     * @see org.gvsig.lrs.lib.api.LrsAlgorithm#execute(org.gvsig.tools.task.SimpleTaskStatus)
111
     */
112
    public void execute(final SimpleTaskStatus taskStatus) throws LrsException {
113
        NewFeatureStoreParameters newFeatureStoreParameters = parameters.getNewFeatureStoreParameters();
114
        final FeatureStore sourceFeatureStore = parameters.getSourceFeatureStore();
115
        final FeatureAttributeDescriptor idRouteField = parameters.getIdRouteField();
116
        final FeatureAttributeDescriptor idTableRouteField = parameters.getValueTableIdRouteField();
117
        FeatureStore tableFeatureStore = parameters.getValueTableFeatureStore();
118
        final FeatureAttributeDescriptor landmarkField = parameters.getLandmarkField();
119
        final FeatureAttributeDescriptor finalLandmarkField = parameters.getFinalLandmarkField();
120
        final FeatureAttributeDescriptor valueField = parameters.getValueField();
121

  
122
        logger.info(parameters.toString());
123

  
124
        taskStatus.setTitle(parameters.getName());
125
        I18nManager i18nManager = ToolsLocator.getI18nManager();
126
        taskStatus.message(i18nManager.getTranslation("processing"));
127

  
128
        try {
129
            final String tableRouteFieldName=idTableRouteField.getName();
130
            final String fromFieldName;
131
            final DataType fromDataType;
132
            final String toFieldName;
133
            final DataType toDataType;
134
            final int geomType;
135
            if (landmarkField!=null){
136
                fromDataType=landmarkField.getDataType();
137
                if (finalLandmarkField!=null){
138
                    fromFieldName="PK INICIAL";
139
                    toFieldName="PK FINAL";
140
                    toDataType=finalLandmarkField.getDataType();
141
                    geomType = Geometry.TYPES.MULTILINE;
142
                }else{
143
                    fromFieldName="PK";
144
                    toFieldName=null;
145
                    toDataType=null;
146
                    geomType = Geometry.TYPES.POINT;
147
                }
148
            }else{
149
                //TODO: Si no hay fromFieldName ?salir por patas?
150
                fromFieldName=null;
151
                fromDataType=null;
152
                toFieldName=null;
153
                toDataType=null;
154
                geomType = Geometry.TYPES.POINT;
155
            }
156

  
157
            final FeatureStore newFeatureStore = createNewDataStore(
158
                newFeatureStoreParameters,
159
                idRouteField,
160
                fromFieldName,
161
                toFieldName,
162
                valueField,
163
                geomType
164
             );
165

  
166
            FeatureSet tableFeatures;
167
            tableFeatures=tableFeatureStore.getFeatureSet();
168
            taskStatus.setRangeOfValues(0, tableFeatures.getSize()-1);
169
            newFeatureStore.edit(FeatureStore.MODE_FULLEDIT);
170

  
171
            tableFeatures.accept(new Visitor() {
172

  
173
                int taskCount=0;
174
                public void visit(Object obj) throws VisitCanceledException, BaseException {
175
                    Feature feature = (Feature) obj;
176
                    String routeName = (String) feature.get(tableRouteFieldName);
177
                    Object objFrom = null;
178
                    Object objTo = null;
179
                    if (fromFieldName != null) {
180
                        objFrom = feature.get(landmarkField.getName());
181
                        double fromValue = LrsAlgorithmUtils.getAsDouble(objFrom, fromDataType);
182
                        Object value = feature.get(valueField.getName());
183
                        if (toFieldName == null || toFieldName.isEmpty()) {
184
                            addSegmentatePointsFeatures(newFeatureStore, sourceFeatureStore, idRouteField, routeName, fromFieldName, fromValue, valueField, value);
185
                        } else {
186
                            objTo = feature.get(finalLandmarkField.getName());
187
                            double toValue = LrsAlgorithmUtils.getAsDouble(objTo, toDataType);
188
                            addSegmentateLinesFeatures(newFeatureStore, sourceFeatureStore, idRouteField, routeName,
189
                                fromFieldName, fromValue, toFieldName, toValue, valueField, value);
190
                        }
191

  
192
                    } else {
193
                        //TODO: ?Exception?
194
                    }
195
                    taskStatus.setCurValue(taskCount++);
196
                }
197

  
198
                private void addSegmentatePointsFeatures(final FeatureStore featureStore,
199
                    FeatureStore sourceFeatureStore, final FeatureAttributeDescriptor idRouteField,
200
                    final String routeName, final String fromFieldName, final double fromValue, final FeatureAttributeDescriptor valueField, final Object value)
201
                    throws LocatorException, BaseException {
202

  
203
                    DataManager dataManager = DALLocator.getDataManager();
204
                    FeatureQuery query = sourceFeatureStore.createFeatureQuery();
205
                    String expression = StringUtils.replace(StringUtils.replace("NOMBRE = 'a%'", "NOMBRE", idRouteField.getName()), "a%", routeName);
206
                    query.setFilter( dataManager.createExpresion(expression) );
207

  
208
                    FeatureSet features = sourceFeatureStore.getFeatureSet(query);
209
                    features.accept(new Visitor() {
210

  
211
                        public void visit(Object obj) throws VisitCanceledException, BaseException {
212
                            Feature feature = (Feature)obj;
213
                            Geometry geom = feature.getDefaultGeometry();
214
                            List<Point>points = LrsAlgorithmUtils.getPointsWithM(geom, fromValue);
215
                            for (Iterator<Point> iterator = points.iterator(); iterator.hasNext();) {
216
                                Point point = (Point) iterator.next();
217
                                EditableFeature newFeature = featureStore.createNewFeature(true);
218
                                newFeature.set(idRouteField.getName(), routeName);
219
                                newFeature.set(fromFieldName, fromValue);
220
                                newFeature.set(valueField.getName(), value);
221
                                newFeature.setDefaultGeometry(point);
222
                                featureStore.insert(newFeature);
223
                            }
224
                        }
225
                    });
226
                }
227

  
228
                private void addSegmentateLinesFeatures(final FeatureStore featureStore,
229
                    FeatureStore sourceFeatureStore, final FeatureAttributeDescriptor idRouteField,
230
                    final String routeName, final String fromFieldName, final double fromValue,
231
                    final String toFieldName, final double toValue, final FeatureAttributeDescriptor valueField, final Object value) throws LocatorException, BaseException {
232

  
233
                    DataManager dataManager = DALLocator.getDataManager();
234
                    FeatureQuery query = sourceFeatureStore.createFeatureQuery();
235
                    String expression = StringUtils.replace(StringUtils.replace("NOMBRE = 'a%'", "NOMBRE", idRouteField.getName()), "a%", routeName);
236
                    query.setFilter( dataManager.createExpresion(expression) );
237

  
238
                    FeatureSet features = sourceFeatureStore.getFeatureSet(query);
239
                    features.accept(new Visitor() {
240

  
241
                        public void visit(Object obj) throws VisitCanceledException, BaseException {
242
                            Feature feature = (Feature) obj;
243
                            Geometry geom = feature.getDefaultGeometry();
244
                            MultiLine lines = LrsAlgorithmUtils.getLinesBetweenTwoM(geom, fromValue, toValue);
245
                            if (lines != null && lines.getPrimitivesNumber()>0) {
246
                                EditableFeature newFeature = featureStore.createNewFeature(true);
247
                                newFeature.set(idRouteField.getName(), routeName);
248
                                newFeature.set(fromFieldName, fromValue);
249
                                newFeature.set(toFieldName, toValue);
250
                                newFeature.set(valueField.getName(), value);
251
                                newFeature.setDefaultGeometry(lines);
252
                                featureStore.insert(newFeature);
253
                            }
254
                        }
255
                    });
256
                }
257
            });
258

  
259
            newFeatureStore.finishEditing();
260

  
261
        } catch (Exception e1) {
262
            taskStatus.abort();
263
            throw new LrsCreateRouteException("Error creating routes", e1);
264
        }
265

  
266

  
267
        taskStatus.terminate();
268

  
269
    }
270

  
271

  
272
    /* (non-Javadoc)
273
     * @see org.gvsig.lrs.lib.api.LrsAlgorithm#setParams(org.gvsig.lrs.lib.api.LrsAlgorithmParams)
274
     */
275
    public void setParams(LrsAlgorithmParams params) throws IllegalArgumentException {
276
        if(!(params instanceof LrsCreateRouteAlgorithmParams)){
277
            throw new IllegalArgumentException("params should be LrsCreateRouteAlgorithmParams type.");
278
        }
279
        this.parameters = (LrsGenerateDynamicSegmentationAlgorithmParams) params;
280

  
281
    }
282

  
283
    private FeatureStore createNewDataStore(
284
        NewFeatureStoreParameters newFeatureStoreParameters,
285
        FeatureAttributeDescriptor idRouteField,
286
        String fromFieldName,
287
        String toFieldName,
288
        FeatureAttributeDescriptor valueField,
289
        int type) throws Exception{
290
        try {
291
            SHPNewStoreParameters shapeStoreParams = (SHPNewStoreParameters)newFeatureStoreParameters;
292
            File file=shapeStoreParams.getFile();
293
            String filePath=file.getPath().substring(0, file.getPath().lastIndexOf(File.separator));
294

  
295
            DataManager dataManager = DALLocator.getDataManager();
296
            DataServerExplorerParameters serverParams =
297
                dataManager.createServerExplorerParameters("FilesystemExplorer");
298
            serverParams.setDynValue("initialpath", filePath);
299
            DataServerExplorer serverExplorer =
300
                dataManager.openServerExplorer(serverParams.getExplorerName(), serverParams);
301

  
302
            EditableFeatureType featureType = (EditableFeatureType)shapeStoreParams.getDefaultFeatureType();
303
            featureType.add(idRouteField.getName(), idRouteField.getType(), idRouteField.getSize());
304
            featureType.add(fromFieldName, DataTypes.DOUBLE);
305
            if(toFieldName!=null){
306
                featureType.add(toFieldName, DataTypes.DOUBLE);
307
            }
308
            featureType.add(valueField.getName(), valueField.getType(), valueField.getSize());
309
            EditableFeatureAttributeDescriptor geometryField = featureType.add("Geometry", DataTypes.GEOMETRY);
310
            GeometryType geometryType = GeometryLocator.getGeometryManager().getGeometryType(type, Geometry.SUBTYPES.GEOM2DM);
311
            geometryField.setGeometryType(geometryType);
312

  
313
            featureType.setDefaultGeometryAttributeName("Geometry");
314

  
315
            shapeStoreParams.setDefaultFeatureType(featureType);
316
            serverExplorer.add("Shape", shapeStoreParams, true);
317

  
318
            DataStore store = dataManager.openStore(SHPStoreProvider.NAME, shapeStoreParams);
319

  
320
            return (FeatureStore)store;
321

  
322
        } catch (Exception e) {
323
            throw new LrsCreateRouteException("Error creating new dataStore", e);
324
        }
325
    }
326

  
327

  
328
}
329

  
330

  
331

  
332

  
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.73/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/java/org/gvsig/lrs/lib/impl/DefaultLrsCalibrateRouteAlgorithmParams.java
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 org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
26
import org.gvsig.fmap.dal.feature.FeatureStore;
27
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
28
import org.gvsig.lrs.lib.api.DistanceUnits;
29
import org.gvsig.lrs.lib.api.LrsCalibrateRouteAlgorithmParams;
30
import org.gvsig.lrs.lib.api.LrsMeasureCalculationMethods;
31

  
32

  
33
/**
34
 * @author dmartinez
35
 *
36
 */
37
public class DefaultLrsCalibrateRouteAlgorithmParams implements LrsCalibrateRouteAlgorithmParams {
38

  
39
    private FeatureStore sourceFeatureStore;
40
    private FeatureAttributeDescriptor idRouteField;
41
    private NewFeatureStoreParameters newFeatureStoreParameters;
42
    private FeatureStore calibratePointFeatureStore;
43
    private FeatureAttributeDescriptor calibratePointIdRouteField;
44
    private FeatureAttributeDescriptor fromMeasureField;
45
    private LrsMeasureCalculationMethods measureCalculationMethods;
46
    private DistanceUnits measureUnits;
47
    private double searchRadius = 0.0;
48
    private boolean interpolateBetweenCalibrationPoints=false;
49
    private boolean extrapolateBeforeCalibrationPoints=false;
50
    private boolean extrapolateAfterCalibrationPoints=false;
51
    private boolean ignoreSpatialGaps=false;
52
    private boolean includeAll=false;
53
    private final String NAME = "LrsCalibrateRouteAlgorithm";
54
    private final String DESCRIPTION = "Algorithm to calibrate routes with linear reference system.";
55

  
56

  
57

  
58
    /**
59
     *
60
     */
61
    public DefaultLrsCalibrateRouteAlgorithmParams() {
62
        searchRadius = 0.0;
63
    }
64

  
65
    /* (non-Javadoc)
66
     * @see org.gvsig.lrs.lib.api.LrsAlgorithmParams#getName()
67
     */
68
    public String getName() {
69
        return NAME;
70
    }
71

  
72
    /* (non-Javadoc)
73
     * @see org.gvsig.lrs.lib.api.LrsAlgorithmParams#getDescription()
74
     */
75
    public String getDescription() {
76
        return DESCRIPTION;
77
    }
78

  
79
    /*
80
     * (non-Javadoc)
81
     * @see org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams#getSourceFeatureStore()
82
     */
83
    public FeatureStore getSourceFeatureStore() {
84
        return sourceFeatureStore;
85
    }
86

  
87

  
88
    /*
89
     * (non-Javadoc)
90
     * @see org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams#setSourceFeatureStore(org.gvsig.fmap.dal.feature.FeatureStore)
91
     */
92
    public void setSourceFeatureStore(FeatureStore sourceFeatureStore) {
93
        this.sourceFeatureStore = sourceFeatureStore;
94
    }
95

  
96
    /*
97
     * (non-Javadoc)
98
     * @see org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams#getIdRouteField()
99
     */
100
    public FeatureAttributeDescriptor getIdRouteField() {
101
        return idRouteField;
102
    }
103

  
104

  
105
    /*
106
     * (non-Javadoc)
107
     * @see org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams#setIdRouteField(org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor)
108
     */
109
    public void setIdRouteField(FeatureAttributeDescriptor idRouteField) {
110
        this.idRouteField = idRouteField;
111
    }
112

  
113
    /*
114
     * (non-Javadoc)
115
     * @see org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams#getFromMeasureField()
116
     */
117
    public FeatureAttributeDescriptor getFromMeasureField() {
118
        return fromMeasureField;
119
    }
120

  
121
    /*
122
     * (non-Javadoc)
123
     * @see org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams#setFromMeasureField(org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor)
124
     */
125
    public void setFromMeasureField(FeatureAttributeDescriptor fromMeasureField) {
126
        this.fromMeasureField = fromMeasureField;
127
    }
128

  
129
    /*
130
     * (non-Javadoc)
131
     * @see org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams#isIgnoreSpatialGaps()
132
     */
133
    public boolean ignoreSpatialGaps() {
134
        return ignoreSpatialGaps;
135
    }
136

  
137
    /*
138
     * (non-Javadoc)
139
     * @see org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams#setIgnoreSpatialGaps(boolean)
140
     */
141
    public void setIgnoreSpatialGaps(boolean ignoreSpatialGaps) {
142
        this.ignoreSpatialGaps = ignoreSpatialGaps;
143
    }
144

  
145
    public NewFeatureStoreParameters getNewFeatureStoreParameters() {
146
        return this.newFeatureStoreParameters;
147
    }
148

  
149
    public void setNewFeatureStoreParameters(
150
        NewFeatureStoreParameters newFeatureStoreParameters) {
151
        this.newFeatureStoreParameters = newFeatureStoreParameters;
152
    }
153

  
154

  
155
    public FeatureStore getCalibratePointFeatureStore() {
156
        return calibratePointFeatureStore;
157
    }
158

  
159

  
160
    public void setCalibratePointFeatureStore(
161
        FeatureStore calibratePointFeatureStore) {
162
        this.calibratePointFeatureStore = calibratePointFeatureStore;
163
    }
164

  
165

  
166
    public FeatureAttributeDescriptor getCalibratePointIdRouteField() {
167
        return calibratePointIdRouteField;
168
    }
169

  
170

  
171
    public void setCalibratePointIdRouteField(
172
        FeatureAttributeDescriptor calibratePointIdRouteField) {
173
        this.calibratePointIdRouteField = calibratePointIdRouteField;
174
    }
175

  
176

  
177
    public LrsMeasureCalculationMethods getMeasureCalculationMethods() {
178
        return measureCalculationMethods;
179
    }
180

  
181

  
182
    public void setMeasureCalculationMethods(
183
        LrsMeasureCalculationMethods measureCalculationMethods) {
184
        this.measureCalculationMethods = measureCalculationMethods;
185
    }
186

  
187

  
188
    public DistanceUnits getMeasureUnits() {
189
        return measureUnits;
190
    }
191

  
192

  
193
    public void setMeasureUnits(DistanceUnits measureUnits) {
194
        this.measureUnits = measureUnits;
195
    }
196

  
197

  
198
    public double getSearchRadius() {
199
        return searchRadius;
200
    }
201

  
202

  
203
    public void setSearchRadius(double searchRadius) {
204
        this.searchRadius = searchRadius;
205
    }
206

  
207

  
208
    public boolean interpolateBetweenCalibrationPoints() {
209
        return interpolateBetweenCalibrationPoints;
210
    }
211

  
212

  
213
    public void setInterpolateBetweenCalibrationPoints(
214
        boolean interpolateBetweenCalibrationPoints) {
215
        this.interpolateBetweenCalibrationPoints =
216
            interpolateBetweenCalibrationPoints;
217
    }
218

  
219

  
220
    public boolean extrapolateBeforeCalibrationPoints() {
221
        return extrapolateBeforeCalibrationPoints;
222
    }
223

  
224

  
225
    public void setExtrapolateBeforeCalibrationPoints(
226
        boolean extrapolateBeforeCalibrationPoints) {
227
        this.extrapolateBeforeCalibrationPoints =
228
            extrapolateBeforeCalibrationPoints;
229
    }
230

  
231

  
232
    public boolean extrapolateAfterCalibrationPoints() {
233
        return extrapolateAfterCalibrationPoints;
234
    }
235

  
236

  
237
    public void setExtrapolateAfterCalibrationPoints(
238
        boolean extrapolateAfterCalibrationPoints) {
239
        this.extrapolateAfterCalibrationPoints = extrapolateAfterCalibrationPoints;
240
    }
241

  
242

  
243
    public boolean includeAll() {
244
        return includeAll;
245
    }
246

  
247

  
248
    public void setIncludeAll(boolean includeAll) {
249
        this.includeAll = includeAll;
250
    }
251

  
252

  
253
}
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.73/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/java/org/gvsig/lrs/lib/impl/DefaultLrsShowMeasuresAlgorithmParams.java
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 org.gvsig.lrs.lib.api.LrsShowMeasuresAlgorithmParams;
26

  
27

  
28

  
29
/**
30
 * @author dmartinez
31
 *
32
 */
33
public class DefaultLrsShowMeasuresAlgorithmParams implements LrsShowMeasuresAlgorithmParams {
34

  
35

  
36
    private double distance = 0.0;
37
    private final String NAME = "LrsShowMeasuresAlgorithm";
38
    private final String DESCRIPTION = "Algorithm to show measures with linear reference system.";
39

  
40

  
41
    /**
42
     *
43
     */
44
    public DefaultLrsShowMeasuresAlgorithmParams() {
45
        distance = 0.0;
46
    }
47

  
48
    /* (non-Javadoc)
49
     * @see org.gvsig.lrs.lib.api.LrsAlgorithmParams#getName()
50
     */
51
    public String getName() {
52
        return NAME;
53
    }
54

  
55
    /* (non-Javadoc)
56
     * @see org.gvsig.lrs.lib.api.LrsAlgorithmParams#getDescription()
57
     */
58
    public String getDescription() {
59
        return DESCRIPTION;
60
    }
61

  
62
    public double getDistance() {
63
        return distance;
64
    }
65

  
66
    public void setDistance(double distance) {
67
        this.distance = distance;
68
    }
69

  
70
}
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.73/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/java/org/gvsig/lrs/lib/impl/LrsAlgorithmUtils.java
1
/*
2
 * Copyright 2015 DiSiD Technologies S.L.L. All rights reserved.
3
 *
4
 * Project  : DiSiD org.gvsig.lrs.lib.impl
5
 * SVN Id   : $Id$
6
 */
7
package org.gvsig.lrs.lib.impl;
8

  
9
import java.io.File;
10
import java.util.ArrayList;
11
import java.util.List;
12

  
13
import org.gvsig.fmap.dal.DALLocator;
14
import org.gvsig.fmap.dal.DataManager;
15
import org.gvsig.fmap.dal.DataServerExplorer;
16
import org.gvsig.fmap.dal.DataServerExplorerParameters;
17
import org.gvsig.fmap.dal.DataStore;
18
import org.gvsig.fmap.dal.DataTypes;
19
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
20
import org.gvsig.fmap.dal.feature.EditableFeatureType;
21
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
22
import org.gvsig.fmap.dal.feature.FeatureStore;
23
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
24
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.fmap.geom.GeometryLocator;
27
import org.gvsig.fmap.geom.GeometryManager;
28
import org.gvsig.fmap.geom.aggregate.MultiLine;
29
import org.gvsig.fmap.geom.exception.CreateGeometryException;
30
import org.gvsig.fmap.geom.operation.GeometryOperationException;
31
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
32
import org.gvsig.fmap.geom.primitive.Line;
33
import org.gvsig.fmap.geom.primitive.Point;
34
import org.gvsig.fmap.geom.type.GeometryType;
35
import org.gvsig.lrs.lib.api.exceptions.LrsCreateRouteException;
36
import org.gvsig.tools.dataTypes.DataType;
37
import org.gvsig.tools.locator.LocatorException;
38

  
39
/**
40
 * @author fdiaz
41
 *
42
 */
43
public class LrsAlgorithmUtils {
44

  
45
    static protected FeatureStore createNewDataStore(NewFeatureStoreParameters newFeatureStoreParameters,
46
        FeatureAttributeDescriptor idRouteField) throws Exception {
47
        return createNewDataStore(newFeatureStoreParameters, idRouteField, Geometry.TYPES.MULTILINE);
48
    }
49

  
50
    static protected FeatureStore createNewDataStore(NewFeatureStoreParameters newFeatureStoreParameters,
51
        FeatureAttributeDescriptor idRouteField, int type) throws Exception {
52
        try {
53
            SHPNewStoreParameters shapeStoreParams = (SHPNewStoreParameters) newFeatureStoreParameters;
54
            File file = shapeStoreParams.getFile();
55
            String filePath = file.getPath().substring(0, file.getPath().lastIndexOf(File.separator));
56

  
57
            DataManager dataManager = DALLocator.getDataManager();
58
            DataServerExplorerParameters serverParams =
59
                dataManager.createServerExplorerParameters("FilesystemExplorer");
60
            serverParams.setDynValue("initialpath", filePath);
61
            DataServerExplorer serverExplorer =
62
                dataManager.openServerExplorer(serverParams.getExplorerName(), serverParams);
63

  
64
            EditableFeatureType featureType = (EditableFeatureType) shapeStoreParams.getDefaultFeatureType();
65
            featureType.add(idRouteField.getName(), idRouteField.getType(), idRouteField.getSize());
66
            EditableFeatureAttributeDescriptor geometryField = featureType.add("Geometry", DataTypes.GEOMETRY);
67
            GeometryType geometryType =
68
                GeometryLocator.getGeometryManager().getGeometryType(type, Geometry.SUBTYPES.GEOM2DM);
69
            geometryField.setGeometryType(geometryType);
70

  
71
            featureType.setDefaultGeometryAttributeName("Geometry");
72

  
73
            shapeStoreParams.setDefaultFeatureType(featureType);
74
            serverExplorer.add("Shape", shapeStoreParams, true);
75

  
76
            DataStore store = dataManager.createStore(shapeStoreParams);
77

  
78
            return (FeatureStore) store;
79

  
80
        } catch (Exception e) {
81
            throw new LrsCreateRouteException("Error creating new dataStore", e);
82
        }
83
    }
84

  
85
    static protected Double getAsDouble(Object obj, DataType dataType) {
86
        if (obj == null || dataType == null) {
87
            return null;
88
        }
89
        Double result = Double.NaN;
90
        if (dataType.equals(DataTypes.DOUBLE)) {
91
            result = (Double) obj;
92
        } else if (dataType.isNumeric()) {
93
            result = Double.valueOf(String.valueOf(obj));
94
        }
95
        return result;
96
    }
97

  
98
    static List<Point> getPointsWithM(Geometry geom, double m) throws CreateGeometryException, LocatorException {
99

  
100
        List<Point> points = new ArrayList<Point>();
101

  
102
        if (geom instanceof Line) {
103
            Line line = (Line) geom;
104
            for (int i = 0; i < line.getNumVertices() - 1; i++) {
105
                Point currentVertex = line.getVertex(i);
106
                Point nextVertex = line.getVertex(i + 1);
107
                Point point = getPointWithMBetweenTwoMPoints(m, currentVertex, nextVertex);
108
                if (point != null && !points.contains(point)) {
109
                    points.add(point);
110
                }
111
            }
112
        } else if (geom instanceof MultiLine) {
113
            MultiLine multiLine = (MultiLine) geom;
114
            for (int p = 0; p < multiLine.getPrimitivesNumber(); p++) {
115
                Line line = (Line) multiLine.getPrimitiveAt(p);
116
                for (int i = 0; i < line.getNumVertices() - 1; i++) {
117
                    Point point = getPointWithMBetweenTwoMPoints(m, line.getVertex(i), line.getVertex(i + 1));
118
                    if (point != null && !points.contains(point)) {
119
                        points.add(point);
120
                    }
121
                }
122
            }
123
        }
124
        return points;
125
    }
126

  
127
    private static boolean isInRange(double v, double r1, double r2) {
128
        if (r1 < r2) {
129
            return v >= r1 && v <= r2;
130
        } else if (r1 > r2) {
131
            return v >= r2 && v <= r1;
132
        } else {
133
            return v == r1;
134
        }
135
    }
136

  
137
    static MultiLine getLinesBetweenTwoM(Geometry geom, double m1, double m2) throws CreateGeometryException,
138
        LocatorException {
139
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
140

  
141
        MultiLine lines = null;
142
        if (geom instanceof Line) {
143
            lines = getLinesBetweenTwoM((Line) geom, m1, m2);
144
        } else if (geom instanceof MultiLine) {
145
            lines = (MultiLine) geomManager.create(Geometry.TYPES.MULTILINE, geom.getGeometryType().getSubType());
146
            MultiLine multiLine = (MultiLine) geom;
147
            for (int i = 0; i < multiLine.getPrimitivesNumber(); i++) {
148
                MultiLine auxMultiLine = getLinesBetweenTwoM(multiLine.getPrimitiveAt(i), m1, m2);
149
                for (int j = 0; j < auxMultiLine.getPrimitivesNumber(); j++) {
150
                    lines.addPrimitive(auxMultiLine.getPrimitiveAt(j));
151
                }
152
            }
153
        }
154
        return lines;
155
    }
156

  
157
    static private MultiLine getLinesBetweenTwoM(Line line, double m1, double m2) throws CreateGeometryException {
158
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
159
        MultiLine lines = (MultiLine) geomManager.create(Geometry.TYPES.MULTILINE, line.getGeometryType().getSubType());
160
        Line auxLine = (Line) geomManager.create(Geometry.TYPES.LINE, line.getGeometryType().getSubType());
161

  
162
        boolean inSegment = false;
163
        if (line.getNumVertices() > 0) {
164
            int ivertex = 0;
165
            Point previousVertex = null;
166
            while (ivertex < line.getNumVertices()) {
167
                if (!inSegment) { // NO ESTAMOS EN UN SEGMENTO VALIDO
168
                    Point vertex = line.getVertex(ivertex);
169
                    double m = vertex.getCoordinateAt(vertex.getDimension() - 1);
170
                    if (isInRange(m, m1, m2)) {
171
                        // Si la m del vertice actual entra en el rango:
172
                        if (previousVertex == null) {
173
                            // Si no hay previousVertex, este debe ser el primer
174
                            // vertice, entonces
175
                            // - a?adimos el v?rtice a la linea
176
                            // - marcamos que estamos en un segmento valido
177
                            // - nos guardamos el vertice como previousVertex
178
                            // - aumentamos el indice para coger el siguiente
179
                            // v?rtice en la pr?xima iteraci?n
180
                            auxLine.addVertex(vertex);
181
                            previousVertex = vertex;
182
                            inSegment = true;
183
                            ivertex++;
184
                        } else {
185
                            // - Calculamos qu? punto habr?a iniciado el
186
                            // segmento v?lido
187
                            double previousM = previousVertex.getCoordinateAt(previousVertex.getDimension() - 1);
188
                            // FIXME: Esta comprobaci?n se podr?a quitar
189
                            if (isInRange(m1, previousM, m) || isInRange(m2, previousM, m)) {
190
                                Point point = getPointWithMBetweenTwoMPoints(m1, previousVertex, vertex);
191
                                if (point == null) {
192
                                    point = getPointWithMBetweenTwoMPoints(m2, previousVertex, vertex);
193
                                }
194
                                if (point != null) {
195
                                    // - A?adimos el punto a la linea auxiliar
196
                                    // - Marcamos que estamos en un segmento v?lido
197
                                    // - nos guardamos el punto como previousVertex
198
                                    // - y NO aumentamos el indice
199
                                    auxLine.addVertex(point);
200
                                    inSegment = true;
201
                                    previousVertex = point;
202
                                } else {
203
                                    // Nunca deber?a pasar por aqu?
204
                                }
205
                            }
206
                        }
207
                    } else {
208
                        // Cabe la posibilidad de que entre un vertice y otro se
209
                        // entre y se salga del rango
210
                        if (previousVertex != null) {
211
                            double previousM = previousVertex.getCoordinateAt(previousVertex.getDimension() - 1);
212
                            if (isInRange(m1, previousM, m) && isInRange(m2, previousM, m)) {
213
                                Point point1 = getPointWithMBetweenTwoMPoints(m1, previousVertex, vertex);
214
                                Point point2 = getPointWithMBetweenTwoMPoints(m2, previousVertex, vertex);
215
                                auxLine.addVertex(point1);
216
                                auxLine.addVertex(point2);
217
                                lines.addPrimitive(auxLine);
218
                            }
219
                        }
220

  
221
                        // Si la m del v?rtice actual no entra en el rango:
222
                        // - nos guardamos el vertice como previousVertex
223
                        // - aumentamos el indice para coger el siguiente
224
                        // v?rtice en la pr?xima iteraci?n
225
                        previousVertex = vertex;
226
                        ivertex++;
227
                    }
228
                } else { // ESTAMOS EN UN SEGMENTO VALIDO
229
                    Point vertex = line.getVertex(ivertex);
230
                    double m = vertex.getCoordinateAt(previousVertex.getDimension() - 1);
231
                    if (isInRange(m, m1, m2)) {
232
                        // Si la m del vertice actual entra en el rango:
233
                        // - a?adimos el v?rtice a la linea
234
                        // - aumentamos el indice para coger el siguiente
235
                        // v?rtice en la pr?xima iteraci?n
236
                        auxLine.addVertex(vertex);
237
                        previousVertex = vertex;
238
                        ivertex++;
239
                    } else {
240
                        // Si la m del v?rtice actual no entra en el rango:
241
                        // - Calculamos el punto que habr?a finalizado el
242
                        // segmento v?lido entre el vertice anterior y el actual
243
                        Point point = getPointWithMBetweenTwoMPoints(m1, previousVertex, vertex);
244
                        if (point == null) {
245
                            point = getPointWithMBetweenTwoMPoints(m2, previousVertex, vertex);
246
                        }
247
                        if (point != null) {
248
                            // - A?adimos el punto a la linea auxiliar
249
                            // - a?adimos la linea y creamos una nueva
250
                            // - Marcamos que NO estamos en un segmento v?lido
251
                            // - nos guardamos el punto como previousVertex
252
                            // - y NO aumentamos el indice
253
                            auxLine.addVertex(point);
254
                            lines.addPrimitive(auxLine);
255
                            auxLine =
256
                                (Line) geomManager.create(Geometry.TYPES.LINE, line.getGeometryType().getSubType());
257
                            inSegment = false;
258
                            previousVertex = point;
259
                        } else {
260
                            // Nunca deber?a pasar por aqu?
261
                        }
262
                    }
263
                }
264
            }
265
        }
266
        if (inSegment && auxLine.getNumVertices() > 0) {
267
            lines.addPrimitive(auxLine);
268
        }
269
        return lines;
270
    }
271

  
272
    /*
273
     *
274
     */
275
    private static Point getPointWithMBetweenTwoMPoints(double m, Point p1, Point p2) throws CreateGeometryException,
276
        LocatorException {
277
        double x;
278
        double y;
279
        double m1 = p1.getCoordinateAt(p1.getDimension() - 1);
280
        double m2 = p2.getCoordinateAt(p2.getDimension() - 1);
281

  
282
        if (m1 <= m2) {
283
            if (m < m1 || m > m2) {
284
                return null;
285
            }
286
        } else {
287
            if (m < m2 || m > m1) {
288
                return null;
289
            }
290
        }
291

  
292
        double x1 = p1.getX();
293
        double x2 = p2.getX();
294
        double y1 = p1.getY();
295
        double y2 = p2.getY();
296
        if (x1 == x2) {
297
            x = x1;
298
        } else {
299
            x = ((x2 - x1) * (m - m1) / (m2 - m1)) + x1;
300
        }
301
        if (y1 == y2) {
302
            y = y1;
303
        } else {
304
            y = ((y2 - y1) * (m - m1) / (m2 - m1)) + y1;
305
        }
306

  
307
        Point point = (Point) GeometryLocator.getGeometryManager().create(p1.getGeometryType());
308
        point.setX(x);
309
        point.setY(y);
310
        point.setCoordinateAt(point.getDimension() - 1, m);
311
        return point;
312
    }
313

  
314

  
315

  
316
    /**
317
     * Returns geometry length without gaps
318
     * @param geometry
319
     * @return
320
     * @throws GeometryOperationNotSupportedException
321
     * @throws GeometryOperationException
322
     */
323
    static protected Double getGeometryLength(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException{
324
        return getGeometryLength(geometry, true);
325
    }
326

  
327
    /**
328
     * Returns geometry length without gaps with the option to not ignore spatial gaps.
329
     * @param geometry
330
     * @param ignoreSpatialGaps
331
     * @return
332
     * @throws GeometryOperationNotSupportedException
333
     * @throws GeometryOperationException
334
     */
335
    static protected Double getGeometryLength(Geometry geometry,
336
        boolean ignoreSpatialGaps)
337
            throws GeometryOperationNotSupportedException,
338
            GeometryOperationException {
339
        if (geometry instanceof Line) {
340
            Line line = (Line) geometry;
341
            return getLineLength(line);
342
        }
343
        if (geometry instanceof MultiLine) {
344
            MultiLine multiLine = (MultiLine) geometry;
345
            return getMultiLineLength(multiLine, ignoreSpatialGaps);
346
        }
347
        return Double.NaN;
348
    }
349

  
350
    /**
351
     * @param line
352
     * @return lenght
353
     * @throws GeometryOperationException
354
     * @throws GeometryOperationNotSupportedException
355
     */
356
    static protected double getLineLength(Line line)
357
        throws GeometryOperationNotSupportedException,
358
        GeometryOperationException {
359
        double lenght = 0;
360
        Point previousVertex = null;
361
        for (int i = 0; i < line.getNumVertices(); i++) {
362
            Point vertex = line.getVertex(i);
363
            if (previousVertex != null) {
364
                lenght += previousVertex.distance(vertex);
365
            }
366
            previousVertex = vertex;
367
        }
368
        return lenght;
369
    }
370

  
371
    /**
372
     * @param multiLine
373
     * @return lenght
374
     * @throws GeometryOperationException
375
     * @throws GeometryOperationNotSupportedException
376
     */
377
    static protected double getMultiLineLength(MultiLine multiLine,
378
        boolean ignoreSpatialGaps)
379
            throws GeometryOperationNotSupportedException,
380
            GeometryOperationException {
381
        double length = 0;
382
        Point previousVertex = null;
383
        for (int j = 0; j < multiLine.getPrimitivesNumber(); j++) {
384
            Line line = (Line) multiLine.getPrimitiveAt(j);
385
            if (ignoreSpatialGaps) {
386
                previousVertex = null;
387
            }
388
            for (int i = 0; i < line.getNumVertices(); i++) {
389
                Point vertex = line.getVertex(i);
390
                if (previousVertex != null) {
391
                    length += previousVertex.distance(vertex);
392
                }
393
                previousVertex = vertex;
394
            }
395
        }
396
        return length;
397
    }
398

  
399
    /**
400
     * Extracts the lines in a Line or Multiline
401
     * @param geometry
402
     * @return
403
     */
404
    static protected List<Line> extractLines(Geometry geometry){
405
        List<Line> lines=new ArrayList<Line>();
406
        if (geometry instanceof  Line){
407
            lines.add((Line) geometry);
408
        }
409
        if (geometry instanceof MultiLine){
410
            MultiLine multiline=(MultiLine)geometry;
411
            for (int i=0;i<multiline.getPrimitivesNumber();i++){
412
                lines.add((Line) multiline.getPrimitiveAt(i));
413
            }
414
        }
415
        return lines;
416
    }
417

  
418
    static protected List<Point> extractPoints(Geometry geometry){
419
        List<Point> points=new ArrayList<Point>();
420
        List<Line> lines=LrsAlgorithmUtils.extractLines(geometry);
421
        for (Line line: lines){
422
            for (int i=0;i<line.getNumVertices();i++){
423
                points.add(line.getVertex(i));
424
            }
425
        }
426
        return points;
427
    }
428

  
429

  
430
    static protected Point extractFirstPoint(Geometry geometry){
431
        Point firstPoint=null;
432
        List<Line> lines= LrsAlgorithmUtils.extractLines(geometry);
433
        if (lines!=null && !lines.isEmpty()){
434
            firstPoint=lines.get(0).getVertex(0);
435
        }
436
        return firstPoint;
437
    }
438

  
439
    static protected boolean equalPoints(Point point1, Point point2){
440
        if ( point1.getX()==point2.getX() && point1.getY()==point2.getY()){
441
            return true;
442
        }
443
        return false;
444
    }
445

  
446
    static protected Geometry insertVertex(Geometry geometry, Point vertex, int index){
447
        if (geometry instanceof Line){
448
            Line line=(Line)geometry;
449
            line.insertVertex(index, vertex);
450
        }
451
        if (geometry instanceof MultiLine){
452
            List<Line> lines=extractLines(geometry);
453
            for(Line line:lines){
454
                if (index<=line.getNumVertices()){
455
                    line.insertVertex(index, vertex);
456
                    return geometry;
457
                }else{
458
                    index-=line.getNumVertices();
459
                }
460

  
461
            }
462
        }
463
        return geometry;
464
    }
465

  
466
    /**
467
     * Reduced versi?n of straight line through two points equation to calculate M's
468
     *
469
     * @param totalLength
470
     * @param minValue
471
     * @param maxValue
472
     * @param relativeDistance
473
     * @return
474
     */
475
    static protected double calculateM(Double totalLength, Double minValue, Double maxValue, Double relativeDistance) {
476
        return LrsAlgorithmUtils.straightLineThroughTwoPointsEquation(0, totalLength, minValue, maxValue, relativeDistance);
477
    }
478

  
479
    /**
480
     * Straight line through two points equation.
481
     *
482
     * @param x1
483
     * @param x2
484
     * @param y1
485
     * @param y2
486
     * @param x
487
     * @return
488
     */
489
    static protected double straightLineThroughTwoPointsEquation(double x1, double x2, double y1, double y2, double x) {
490
        if (x2 - x1 == 0.0) {
491
            return Double.POSITIVE_INFINITY;
492
        }
493
        return ((y2 - y1) * (x - x1) / (x2 - x1)) + y1;
494
    }
495

  
496
}
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.73/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/java/org/gvsig/lrs/lib/impl/DefaultLrsEditRouteCalibrationSelectIdRouteAlgorithmParams.java
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 org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
26
import org.gvsig.fmap.dal.feature.FeatureStore;
27
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
28
import org.gvsig.lrs.lib.api.DistanceUnits;
29
import org.gvsig.lrs.lib.api.LrsCalibrateRouteAlgorithmParams;
30
import org.gvsig.lrs.lib.api.LrsEditRouteCalibrationSelectIdRouteAlgorithmParams;
31
import org.gvsig.lrs.lib.api.LrsMeasureCalculationMethods;
32

  
33

  
34
/**
35
 * @author dmartinez
36
 *
37
 */
38
public class DefaultLrsEditRouteCalibrationSelectIdRouteAlgorithmParams implements LrsEditRouteCalibrationSelectIdRouteAlgorithmParams {
39

  
40
    private FeatureAttributeDescriptor idRouteField;
41
    private final String NAME = "LrsEditRouteCalibrationSelectIdRouteAlgorithm";
42
    private final String DESCRIPTION = "Algorithm to select id route to edit calibration with linear reference system.";
43

  
44

  
45
    /* (non-Javadoc)
46
     * @see org.gvsig.lrs.lib.api.LrsAlgorithmParams#getName()
47
     */
48
    public String getName() {
49
        return NAME;
50
    }
51

  
52
    /* (non-Javadoc)
53
     * @see org.gvsig.lrs.lib.api.LrsAlgorithmParams#getDescription()
54
     */
55
    public String getDescription() {
56
        return DESCRIPTION;
57
    }
58

  
59
    /*
60
     * (non-Javadoc)
61
     * @see org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams#getIdRouteField()
62
     */
63
    public FeatureAttributeDescriptor getIdRouteField() {
64
        return idRouteField;
65
    }
66

  
67
    /*
68
     * (non-Javadoc)
69
     * @see org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams#setIdRouteField(org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor)
70
     */
71
    public void setIdRouteField(FeatureAttributeDescriptor idRouteField) {
72
        this.idRouteField = idRouteField;
73
    }
74

  
75
}
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.73/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/java/org/gvsig/lrs/lib/impl/DefaultLrsAlgorithmsManager.java
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 org.gvsig.lrs.lib.api.MeasuresCalculator;
26

  
27
import java.util.List;
28

  
29
import org.apache.commons.lang3.StringUtils;
30
import org.cresques.cts.IProjection;
31

  
32
import org.gvsig.fmap.dal.DALLocator;
33
import org.gvsig.fmap.dal.DataManager;
34
import org.gvsig.fmap.dal.DataServerExplorer;
35
import org.gvsig.fmap.dal.DataServerExplorerParameters;
36
import org.gvsig.fmap.dal.DataStoreParameters;
37
import org.gvsig.fmap.dal.exception.DataException;
38
import org.gvsig.fmap.dal.exception.InitializeException;
39
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
40
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
41
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
42
import org.gvsig.fmap.dal.feature.EditableFeatureType;
43
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
44
import org.gvsig.fmap.dal.feature.FeatureStore;
45
import org.gvsig.fmap.dal.feature.FeatureType;
46
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
47
import org.gvsig.fmap.geom.DataTypes;
48
import org.gvsig.fmap.geom.Geometry;
49
import org.gvsig.fmap.geom.GeometryLocator;
50
import org.gvsig.fmap.geom.GeometryManager;
51
import org.gvsig.fmap.geom.exception.CreateGeometryException;
52
import org.gvsig.fmap.geom.operation.GeometryOperationException;
53
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
54
import org.gvsig.fmap.geom.primitive.Line;
55
import org.gvsig.fmap.geom.primitive.Point;
56
import org.gvsig.fmap.geom.type.GeometryType;
57
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
58
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
59
import org.gvsig.lrs.lib.api.LrsAlgorithm;
60
import org.gvsig.lrs.lib.api.LrsAlgorithmParams;
61
import org.gvsig.lrs.lib.api.LrsAlgorithmsManager;
62
import org.gvsig.lrs.lib.api.LrsCalibrateRouteAlgorithmParams;
63
import org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams;
64
import org.gvsig.lrs.lib.api.LrsEditRouteCalibrationAlgorithmParams;
65
import org.gvsig.lrs.lib.api.LrsEditRouteCalibrationSelectIdRouteAlgorithmParams;
66
import org.gvsig.lrs.lib.api.LrsGenerateDynamicSegmentationAlgorithmParams;
67
import org.gvsig.lrs.lib.api.LrsShowMeasuresAlgorithmParams;
68
import org.gvsig.tools.dynobject.DynObject;
69
import org.gvsig.tools.locator.LocatorException;
70
import org.gvsig.tools.service.Service;
71
import org.gvsig.tools.service.ServiceException;
72

  
73

  
74
/**
75
 * @author fdiaz
76
 *
77
 */
78
public class DefaultLrsAlgorithmsManager implements LrsAlgorithmsManager {
79

  
80
    /* (non-Javadoc)
81
     * @see org.gvsig.tools.service.Manager#createServiceParameters(java.lang.String)
82
     */
83
    public DynObject createServiceParameters(String serviceName) throws ServiceException {
84
        // TODO Auto-generated method stub
85
        return null;
86
    }
87

  
88
    /* (non-Javadoc)
89
     * @see org.gvsig.tools.service.Manager#getService(org.gvsig.tools.dynobject.DynObject)
90
     */
91
    public Service getService(DynObject parameters) throws ServiceException {
92
        // TODO Auto-generated method stub
93
        return null;
94
    }
95

  
96
    /* (non-Javadoc)
97
     * @see org.gvsig.lrs.lib.api.LrsAlgorithmsManager#createLrsAlgorithm(org.gvsig.lrs.lib.api.LrsAlgorithmParams)
98
     */
99
    public LrsAlgorithm createLrsAlgorithm(LrsAlgorithmParams params) {
100
        if(params instanceof LrsCreateRouteAlgorithmParams){
101
            return new LrsCreateRouteAlgorithm((LrsCreateRouteAlgorithmParams)params);
102
        }
103
        if(params instanceof LrsCalibrateRouteAlgorithmParams){
104
            return new LrsCalibrateRouteAlgorithm((LrsCalibrateRouteAlgorithmParams)params);
105
        }
106
        if(params instanceof LrsGenerateDynamicSegmentationAlgorithmParams){
107
            return new LrsGenerateDynamicSegmentationAlgorithm((LrsGenerateDynamicSegmentationAlgorithmParams)params);
108
        }
109
        return null;
110
    }
111

  
112
    /* (non-Javadoc)
113
     * @see org.gvsig.lrs.lib.api.LrsAlgorithmsManager#createLrsCreateRouteAlgorithmParams()
114
     */
115
    public LrsCreateRouteAlgorithmParams createLrsCreateRouteAlgorithmParams() {
116
        return new DefaultLrsCreateRouteAlgorithmParams();
117
    }
118

  
119
    /* (non-Javadoc)
120
     * @see org.gvsig.lrs.lib.api.LrsAlgorithmsManager#createLrsCalibrateRouteAlgorithmParams()
121
     */
122
    public LrsCalibrateRouteAlgorithmParams createLrsCalibrateRouteAlgorithmParams() {
123
        return new DefaultLrsCalibrateRouteAlgorithmParams();
124
    }
125

  
126
    /* (non-Javadoc)
127
     * @see org.gvsig.lrs.lib.api.LrsAlgorithmsManager#createLrsEditRouteCalibrationAlgorithmParams()
128
     */
129
    public LrsEditRouteCalibrationAlgorithmParams createLrsEditRouteCalibrationAlgorithmParams() {
130
        return new DefaultLrsEditRouteCalibrationAlgorithmParams();
131
    }
132

  
133
    /* (non-Javadoc)
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff