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 / DefaultLrsAlgorithmsManager.java @ 26
History | View | Annotate | Download (9.61 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 org.apache.commons.lang3.StringUtils; |
26 |
import org.cresques.cts.IProjection; |
27 |
|
28 |
import org.gvsig.fmap.dal.DALLocator; |
29 |
import org.gvsig.fmap.dal.DataManager; |
30 |
import org.gvsig.fmap.dal.DataServerExplorer; |
31 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
32 |
import org.gvsig.fmap.dal.DataStoreParameters; |
33 |
import org.gvsig.fmap.dal.exception.DataException; |
34 |
import org.gvsig.fmap.dal.exception.InitializeException; |
35 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
36 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
37 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
38 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
39 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
40 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
41 |
import org.gvsig.fmap.dal.feature.FeatureType; |
42 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
43 |
import org.gvsig.fmap.geom.DataTypes; |
44 |
import org.gvsig.fmap.geom.GeometryLocator; |
45 |
import org.gvsig.fmap.geom.GeometryManager; |
46 |
import org.gvsig.fmap.geom.type.GeometryType; |
47 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
48 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
49 |
import org.gvsig.lrs.lib.api.LrsAlgorithm; |
50 |
import org.gvsig.lrs.lib.api.LrsAlgorithmParams; |
51 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsManager; |
52 |
import org.gvsig.lrs.lib.api.LrsCalibrateRouteAlgorithmParams; |
53 |
import org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams; |
54 |
import org.gvsig.lrs.lib.api.LrsEditRouteCalibrationAlgorithmParams; |
55 |
import org.gvsig.lrs.lib.api.LrsEditRouteCalibrationSelectIdRouteAlgorithmParams; |
56 |
import org.gvsig.lrs.lib.api.LrsGenerateDynamicSegmentationAlgorithmParams; |
57 |
import org.gvsig.lrs.lib.api.LrsShowMeasuresAlgorithmParams; |
58 |
import org.gvsig.tools.dynobject.DynObject; |
59 |
import org.gvsig.tools.service.Service; |
60 |
import org.gvsig.tools.service.ServiceException; |
61 |
|
62 |
|
63 |
/**
|
64 |
* @author fdiaz
|
65 |
*
|
66 |
*/
|
67 |
public class DefaultLrsAlgorithmsManager implements LrsAlgorithmsManager { |
68 |
|
69 |
/* (non-Javadoc)
|
70 |
* @see org.gvsig.tools.service.Manager#createServiceParameters(java.lang.String)
|
71 |
*/
|
72 |
public DynObject createServiceParameters(String serviceName) throws ServiceException { |
73 |
// TODO Auto-generated method stub
|
74 |
return null; |
75 |
} |
76 |
|
77 |
/* (non-Javadoc)
|
78 |
* @see org.gvsig.tools.service.Manager#getService(org.gvsig.tools.dynobject.DynObject)
|
79 |
*/
|
80 |
public Service getService(DynObject parameters) throws ServiceException { |
81 |
// TODO Auto-generated method stub
|
82 |
return null; |
83 |
} |
84 |
|
85 |
/* (non-Javadoc)
|
86 |
* @see org.gvsig.lrs.lib.api.LrsAlgorithmsManager#createLrsAlgorithm(org.gvsig.lrs.lib.api.LrsAlgorithmParams)
|
87 |
*/
|
88 |
public LrsAlgorithm createLrsAlgorithm(LrsAlgorithmParams params) {
|
89 |
if(params instanceof LrsCreateRouteAlgorithmParams){ |
90 |
return new LrsCreateRouteAlgorithm((LrsCreateRouteAlgorithmParams)params); |
91 |
} |
92 |
if(params instanceof LrsCalibrateRouteAlgorithmParams){ |
93 |
return new LrsCalibrateRouteAlgorithm((LrsCalibrateRouteAlgorithmParams)params); |
94 |
} |
95 |
if(params instanceof LrsGenerateDynamicSegmentationAlgorithmParams){ |
96 |
return new LrsGenerateDynamicSegmentationAlgorithm((LrsGenerateDynamicSegmentationAlgorithmParams)params); |
97 |
} |
98 |
return null; |
99 |
} |
100 |
|
101 |
/* (non-Javadoc)
|
102 |
* @see org.gvsig.lrs.lib.api.LrsAlgorithmsManager#createLrsCreateRouteAlgorithmParams()
|
103 |
*/
|
104 |
public LrsCreateRouteAlgorithmParams createLrsCreateRouteAlgorithmParams() {
|
105 |
return new DefaultLrsCreateRouteAlgorithmParams(); |
106 |
} |
107 |
|
108 |
/* (non-Javadoc)
|
109 |
* @see org.gvsig.lrs.lib.api.LrsAlgorithmsManager#createLrsCalibrateRouteAlgorithmParams()
|
110 |
*/
|
111 |
public LrsCalibrateRouteAlgorithmParams createLrsCalibrateRouteAlgorithmParams() {
|
112 |
return new DefaultLrsCalibrateRouteAlgorithmParams(); |
113 |
} |
114 |
|
115 |
/* (non-Javadoc)
|
116 |
* @see org.gvsig.lrs.lib.api.LrsAlgorithmsManager#createLrsEditRouteCalibrationAlgorithmParams()
|
117 |
*/
|
118 |
public LrsEditRouteCalibrationAlgorithmParams createLrsEditRouteCalibrationAlgorithmParams() {
|
119 |
return new DefaultLrsEditRouteCalibrationAlgorithmParams(); |
120 |
} |
121 |
|
122 |
/* (non-Javadoc)
|
123 |
* @see org.gvsig.lrs.lib.api.LrsAlgorithmsManager#createLrsEditRouteCalibrationSelectIdRouteAlgorithmParams()
|
124 |
*/
|
125 |
public LrsEditRouteCalibrationSelectIdRouteAlgorithmParams createLrsEditRouteCalibrationSelectIdRouteAlgorithmParams() {
|
126 |
return new DefaultLrsEditRouteCalibrationSelectIdRouteAlgorithmParams(); |
127 |
} |
128 |
|
129 |
/* (non-Javadoc)
|
130 |
* @see org.gvsig.lrs.lib.api.LrsAlgorithmsManager#createLrsShowMeasuresAlgorithmParams()
|
131 |
*/
|
132 |
public LrsShowMeasuresAlgorithmParams createLrsShowMeasuresAlgorithmParams() {
|
133 |
return new DefaultLrsShowMeasuresAlgorithmParams(); |
134 |
} |
135 |
|
136 |
|
137 |
/* (non-Javadoc)
|
138 |
* @see org.gvsig.lrs.lib.api.LrsAlgorithmsManager#createLrsGenerateDynamicSegmentationAlgorithmParams()
|
139 |
*/
|
140 |
public LrsGenerateDynamicSegmentationAlgorithmParams createLrsGenerateDynamicSegmentationAlgorithmParams() {
|
141 |
return new DefaultLrsGenerateDynamicSegmentationAlgorithmParams(); |
142 |
} |
143 |
|
144 |
|
145 |
public void createNewShape(FeatureType sourceFeatureType, |
146 |
int outputLayerType, String outputLayerPath, IProjection projection) throws ValidateDataParametersException, DataException, GeometryTypeNotSupportedException, GeometryTypeNotValidException { |
147 |
|
148 |
DataManager dataManager = DALLocator.getDataManager(); |
149 |
DataServerExplorerParameters eparams = |
150 |
dataManager.createServerExplorerParameters("FilesystemExplorer");
|
151 |
eparams.setDynValue("initialpath", "/data"); |
152 |
DataServerExplorer serverExplorer = |
153 |
dataManager.openServerExplorer(eparams.getExplorerName(), eparams); |
154 |
|
155 |
NewFeatureStoreParameters sparams = |
156 |
(NewFeatureStoreParameters) serverExplorer |
157 |
.getAddParameters("Shape");
|
158 |
|
159 |
EditableFeatureType newEditableFeatureType = |
160 |
(EditableFeatureType) sparams.getDefaultFeatureType(); |
161 |
|
162 |
// Iterate over feature type. Don't add geometry fields.
|
163 |
for (int i = 0; i < sourceFeatureType.size(); i++) { |
164 |
String fieldName =
|
165 |
sourceFeatureType.getAttributeDescriptor(i).getName(); |
166 |
int fieldType =
|
167 |
sourceFeatureType.getAttributeDescriptor(i).getType(); |
168 |
if (fieldType != DataTypes.GEOMETRY) {
|
169 |
newEditableFeatureType.add(fieldName, fieldType); |
170 |
} |
171 |
} |
172 |
|
173 |
// Add new geometry field with new geometry type
|
174 |
FeatureAttributeDescriptor geometryAttribute = |
175 |
(FeatureAttributeDescriptor) sourceFeatureType |
176 |
.get(sourceFeatureType.getDefaultGeometryAttributeName()); |
177 |
EditableFeatureAttributeDescriptor newGeometryAttribute = |
178 |
newEditableFeatureType.add(geometryAttribute.getName(), |
179 |
geometryAttribute.getType(), geometryAttribute.getSize()); |
180 |
|
181 |
GeometryManager geoManager = GeometryLocator.getGeometryManager(); |
182 |
GeometryType sourceLayerGeomType = |
183 |
sourceFeatureType.getDefaultGeometryAttribute().getGeomType(); |
184 |
GeometryType outputLayerGeomType = |
185 |
geoManager.getGeometryType(outputLayerType, |
186 |
sourceLayerGeomType.getSubType()); |
187 |
|
188 |
newGeometryAttribute.setGeometryType(outputLayerGeomType); |
189 |
newGeometryAttribute.setPrecision(geometryAttribute.getPrecision()); |
190 |
newGeometryAttribute.setDefaultValue(geometryAttribute |
191 |
.getDefaultValue()); |
192 |
|
193 |
newEditableFeatureType |
194 |
.setDefaultGeometryAttributeName(geometryAttribute.getName()); |
195 |
|
196 |
if(!StringUtils.endsWithIgnoreCase(outputLayerPath, ".shp")){ |
197 |
outputLayerPath = new StringBuilder().append(outputLayerPath).append(".shp").toString(); |
198 |
} |
199 |
|
200 |
sparams.setDynValue("geometryType", null); |
201 |
sparams.setDynValue("shpfile", outputLayerPath);
|
202 |
sparams.setDynValue("CRS", projection);
|
203 |
sparams.setDynValue("useNullGeometry", false); |
204 |
sparams.setDefaultFeatureType(newEditableFeatureType); |
205 |
sparams.validate(); |
206 |
|
207 |
serverExplorer.add("Shape", sparams, true); |
208 |
} |
209 |
|
210 |
public FeatureStore getFeatureStore(String outputLayerPath, |
211 |
IProjection projection) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException{
|
212 |
|
213 |
DataManager dataManager = DALLocator.getDataManager(); |
214 |
DataStoreParameters dataStoreParams = |
215 |
dataManager.createStoreParameters("Shape");
|
216 |
dataStoreParams.setDynValue("shpfile", outputLayerPath);
|
217 |
dataStoreParams.setDynValue("CRS", projection);
|
218 |
dataStoreParams.setDynValue("useNullGeometry", false); |
219 |
dataStoreParams.validate(); |
220 |
|
221 |
return (FeatureStore) dataManager.openStore("Shape", dataStoreParams); |
222 |
} |
223 |
|
224 |
} |