svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.lib / org.gvsig.exportto.lib.api / src / main / java / org / gvsig / export / spi / AbstractExportParametersGeometry.java @ 44469
History | View | Annotate | Download (9.89 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.export.spi; |
7 |
|
8 |
import org.cresques.cts.ICoordTrans; |
9 |
import org.cresques.cts.IProjection; |
10 |
import org.gvsig.export.ExportParameters; |
11 |
import org.gvsig.fmap.geom.GeometryLocator; |
12 |
import org.gvsig.fmap.geom.GeometryManager; |
13 |
import org.gvsig.fmap.geom.type.GeometryType; |
14 |
import org.gvsig.export.ExportParametersGeometry; |
15 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
16 |
import org.gvsig.fmap.geom.Geometry; |
17 |
import org.gvsig.tools.ToolsLocator; |
18 |
import org.gvsig.tools.dynobject.DynStruct; |
19 |
import org.gvsig.tools.persistence.PersistenceManager; |
20 |
import org.gvsig.tools.persistence.PersistentState; |
21 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
22 |
|
23 |
/**
|
24 |
*
|
25 |
* @author jjdelcerro
|
26 |
*/
|
27 |
public abstract class AbstractExportParametersGeometry |
28 |
extends AbstractExportParameters
|
29 |
implements ExportParametersGeometry {
|
30 |
|
31 |
private IProjection contextProjection;
|
32 |
private IProjection sourceProjection;
|
33 |
private IProjection targetProjection;
|
34 |
|
35 |
private ICoordTrans sourceTransformation;
|
36 |
private ICoordTrans targetTransformation;
|
37 |
|
38 |
private int geometryChecks; |
39 |
private int geometryChecksAction; |
40 |
private boolean tryToFixGeometry; |
41 |
private String geometryFieldName; |
42 |
private int geometryType; |
43 |
private int geometrySubtype; |
44 |
|
45 |
public AbstractExportParametersGeometry(ExportServiceFactory factory) {
|
46 |
super(factory);
|
47 |
} |
48 |
|
49 |
@Override
|
50 |
public boolean needsSelectTargetProjection() { |
51 |
return true; |
52 |
} |
53 |
|
54 |
@Override
|
55 |
public void setContextProjection(IProjection projection) { |
56 |
this.contextProjection = projection;
|
57 |
} |
58 |
|
59 |
@Override
|
60 |
public IProjection getContextProjection() {
|
61 |
return this.contextProjection; |
62 |
} |
63 |
|
64 |
@Override
|
65 |
public void setSourceProjection(IProjection sourceProjection) { |
66 |
this.sourceProjection = sourceProjection;
|
67 |
} |
68 |
|
69 |
@Override
|
70 |
public IProjection getSourceProjection() {
|
71 |
return sourceProjection;
|
72 |
} |
73 |
|
74 |
@Override
|
75 |
public ICoordTrans getSourceTransformation() {
|
76 |
return sourceTransformation;
|
77 |
} |
78 |
|
79 |
@Override
|
80 |
public void setSourceTransformation(ICoordTrans contextTransformation) { |
81 |
this.sourceTransformation = contextTransformation;
|
82 |
} |
83 |
|
84 |
@Override
|
85 |
public void setTargetProjection(IProjection targetProjection) { |
86 |
this.targetProjection = targetProjection;
|
87 |
} |
88 |
|
89 |
@Override
|
90 |
public IProjection getTargetProjection() {
|
91 |
if (this.targetProjection == null) { |
92 |
return this.sourceProjection; |
93 |
} |
94 |
return this.targetProjection; |
95 |
} |
96 |
|
97 |
@Override
|
98 |
public void setTargetTransformation(ICoordTrans transformation) { |
99 |
this.targetTransformation = transformation;
|
100 |
} |
101 |
|
102 |
@Override
|
103 |
public ICoordTrans getTargetTransformation() {
|
104 |
return targetTransformation;
|
105 |
} |
106 |
|
107 |
@Override
|
108 |
public int getGeometryChecks() { |
109 |
return this.geometryChecks; |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public int getGeometryChecksAction() { |
114 |
return this.geometryChecksAction; |
115 |
} |
116 |
|
117 |
@Override
|
118 |
public boolean getTryToFixGeometry() { |
119 |
return this.tryToFixGeometry; |
120 |
} |
121 |
|
122 |
@Override
|
123 |
public void setGeometryChecks(int geometryChecks) { |
124 |
this.geometryChecks = geometryChecks;
|
125 |
} |
126 |
|
127 |
@Override
|
128 |
public void setGeometryChecksAction(int geometryChecksAction) { |
129 |
this.geometryChecksAction = geometryChecksAction;
|
130 |
} |
131 |
|
132 |
@Override
|
133 |
public void setTryToFixGeometry(boolean tryToFixGeometry) { |
134 |
this.tryToFixGeometry = tryToFixGeometry;
|
135 |
} |
136 |
|
137 |
@Override
|
138 |
public String getSourceGeometryFieldName() { |
139 |
return this.geometryFieldName; |
140 |
} |
141 |
|
142 |
@Override
|
143 |
public void setSourceGeometryFieldName(String geometryFieldName) { |
144 |
this.geometryFieldName = geometryFieldName;
|
145 |
} |
146 |
|
147 |
@Override
|
148 |
public int getTargetGeometryTypeAsInt() { |
149 |
return geometryType;
|
150 |
} |
151 |
|
152 |
@Override
|
153 |
public int getTargetGeometrySubtype() { |
154 |
return geometrySubtype;
|
155 |
} |
156 |
|
157 |
@Override
|
158 |
public void setTargetGeometryType(int geometryType) { |
159 |
this.geometryType = geometryType;
|
160 |
} |
161 |
|
162 |
@Override
|
163 |
public void setTargetGeometrySubtype(int subtype) { |
164 |
this.geometrySubtype = subtype;
|
165 |
} |
166 |
|
167 |
@Override
|
168 |
public void setTargetGeometryType(GeometryType type) { |
169 |
this.geometryType = type.getType();
|
170 |
this.geometrySubtype = type.getSubType();
|
171 |
} |
172 |
|
173 |
@Override
|
174 |
public GeometryType getTargetGeometryType() {
|
175 |
try {
|
176 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
177 |
GeometryType type = geomManager.getGeometryType( |
178 |
geometryType, |
179 |
geometryType |
180 |
); |
181 |
return type;
|
182 |
} catch (Exception ex) { |
183 |
throw new RuntimeException("Can't create geoemtry type from type " + geometryType + ", subtype " + geometrySubtype + ".", ex); |
184 |
} |
185 |
} |
186 |
|
187 |
@Override
|
188 |
public ExportParameters clone() throws CloneNotSupportedException { |
189 |
AbstractExportParametersGeometry clone = (AbstractExportParametersGeometry) super.clone();
|
190 |
clone.setContextProjection(this.contextProjection);
|
191 |
clone.setSourceProjection(this.sourceProjection);
|
192 |
clone.setTargetProjection(this.targetProjection);
|
193 |
clone.setSourceTransformation(this.sourceTransformation);
|
194 |
clone.setTargetTransformation(this.targetTransformation);
|
195 |
clone.setSourceGeometryFieldName(this.geometryFieldName);
|
196 |
clone.setGeometryChecks(this.geometryChecks);
|
197 |
clone.setGeometryChecksAction(this.geometryChecksAction);
|
198 |
clone.setTryToFixGeometry(this.tryToFixGeometry);
|
199 |
clone.setTargetGeometryType(this.geometryType);
|
200 |
clone.setTargetGeometrySubtype(this.geometrySubtype);
|
201 |
return clone;
|
202 |
} |
203 |
|
204 |
public static void registerPersistence() { |
205 |
|
206 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
207 |
if (manager.getDefinition("AbstractExportParametersGeometry") == null) { |
208 |
DynStruct definition = manager.addDefinition(AbstractExportParametersGeometry.class, |
209 |
"AbstractExportParametersGeometry", "AbstractExportParametersGeometry persistence definition", null, null); |
210 |
definition.addDynFieldObject("contextProjection").setClassOfValue(IProjection.class);
|
211 |
definition.addDynFieldObject("sourceProjection").setClassOfValue(IProjection.class);
|
212 |
definition.addDynFieldObject("targetProjection").setClassOfValue(IProjection.class);
|
213 |
definition.addDynFieldObject("sourceTransformation").setClassOfValue(ICoordTrans.class);
|
214 |
definition.addDynFieldObject("targetTransformation").setClassOfValue(ICoordTrans.class);
|
215 |
definition.addDynFieldInt("geometryChecks");
|
216 |
definition.addDynFieldInt("geometryChecksAction");
|
217 |
definition.addDynFieldBoolean("tryToFixGeometry");
|
218 |
definition.addDynFieldString("geometryFieldName");
|
219 |
definition.addDynFieldInt("geometryType");
|
220 |
definition.addDynFieldInt("geometrySubtype");
|
221 |
definition.extend(manager.getDefinition("AbstractExportParameters"));
|
222 |
} |
223 |
} |
224 |
|
225 |
public void saveToState(PersistentState state) throws PersistenceException { |
226 |
super.saveToState(state);
|
227 |
state.set("contextProjection", this.contextProjection); |
228 |
state.set("sourceProjection", this.sourceProjection); |
229 |
state.set("targetProjection", this.targetProjection); |
230 |
state.set("sourceTransformation", this.sourceTransformation); |
231 |
state.set("targetTransformation", this.targetTransformation); |
232 |
state.set("geometryChecks", this.geometryChecks); |
233 |
state.set("geometryChecksAction", this.geometryChecksAction); |
234 |
state.set("tryToFixGeometry", this.tryToFixGeometry); |
235 |
state.set("geometryFieldName", this.geometryFieldName); |
236 |
state.set("geometryType", this.geometryType); |
237 |
state.set("geometrySubtype", this.geometrySubtype); |
238 |
} |
239 |
|
240 |
public void loadFromState(PersistentState state) throws PersistenceException { |
241 |
super.loadFromState(state);
|
242 |
this.contextProjection = (IProjection) state.get("contextProjection"); |
243 |
this.sourceProjection = (IProjection) state.get("sourceProjection"); |
244 |
this.targetProjection = (IProjection) state.get("targetProjection"); |
245 |
this.sourceTransformation = (ICoordTrans) state.get("sourceTransformation"); |
246 |
this.targetTransformation = (ICoordTrans) state.get("targetTransformation"); |
247 |
this.geometryChecks = state.getInt("geometryChecks"); |
248 |
this.geometryChecksAction = state.getInt("geometryChecksAction"); |
249 |
this.tryToFixGeometry = state.getBoolean("tryToFixGeometry"); |
250 |
this.geometryFieldName = state.getString("geometryFieldName"); |
251 |
this.geometryType = state.getInt("geometryType"); |
252 |
this.geometrySubtype = state.getInt("geometrySubtype"); |
253 |
} |
254 |
|
255 |
@Override
|
256 |
public ICoordTrans getTransformationToUse() {
|
257 |
FeatureAttributeDescriptor geo_att = this.getSourceFeatureType().getDefaultGeometryAttribute();
|
258 |
|
259 |
IProjection sourceProjection; |
260 |
ICoordTrans coord_trans = null;
|
261 |
Geometry reproj_geom; |
262 |
IProjection targetProjection = this.getTargetProjection();
|
263 |
if (geo_att != null) { |
264 |
sourceProjection = geo_att.getSRS(); |
265 |
// this comparison is perhaps too preventive
|
266 |
// we could have two instances of same projection
|
267 |
// so we would do more computations than needed
|
268 |
if (sourceProjection != null && targetProjection != null && sourceProjection != targetProjection) { |
269 |
if (this.getTargetTransformation() != null) { |
270 |
coord_trans = this.getTargetTransformation();
|
271 |
} else {
|
272 |
coord_trans = sourceProjection.getCT(targetProjection); |
273 |
} |
274 |
} |
275 |
|
276 |
} |
277 |
return coord_trans;
|
278 |
} |
279 |
} |