Revision 1260 org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.base/src/main/java/org/gvsig/geoprocess/algorithm/base/core/DALFeaturePersister.java
DALFeaturePersister.java | ||
---|---|---|
58 | 58 |
|
59 | 59 |
import es.unex.sextante.core.Sextante; |
60 | 60 |
import org.gvsig.fmap.dal.DataTypes; |
61 |
import org.gvsig.tools.namestranslator.NamesTranslator; |
|
61 | 62 |
|
62 | 63 |
/** |
63 | 64 |
* Writes features in a FeatureStore |
... | ... | |
67 | 68 |
private FeatureStore store = null; |
68 | 69 |
private String[] fieldNames = null; |
69 | 70 |
private GeometryManager geometryManager = null; |
71 |
private NamesTranslator namesTranslator = null; |
|
70 | 72 |
|
71 | 73 |
/** |
72 | 74 |
* Sets the output FeatureType |
73 | 75 |
* @param out |
74 | 76 |
* @throws DataException |
75 | 77 |
*/ |
78 |
public DALFeaturePersister(FeatureStore out, String[] fieldNames, NamesTranslator namesTranslator) { |
|
79 |
this(out, fieldNames); |
|
80 |
this.namesTranslator = namesTranslator; |
|
81 |
} |
|
82 |
|
|
76 | 83 |
public DALFeaturePersister(FeatureStore out, String[] fieldNames) { |
77 | 84 |
this.store = out; |
78 | 85 |
this.fieldNames = fieldNames; |
86 |
this.namesTranslator = null; |
|
79 | 87 |
try { |
80 | 88 |
if(!store.isEditing()) |
81 | 89 |
store.edit(); |
... | ... | |
176 | 184 |
|
177 | 185 |
EditableFeature feat = store.createNewFeature(); |
178 | 186 |
|
179 |
int globalIndex = 0; |
|
180 |
int localIndex = 0; |
|
181 |
Object value = feature1.get(localIndex); |
|
182 |
while(value != null && !(value instanceof org.gvsig.fmap.geom.Geometry)) { |
|
183 |
feat.set(globalIndex, value); |
|
184 |
value = feature1.get(++localIndex); |
|
185 |
globalIndex ++; |
|
186 |
} |
|
187 | 187 |
|
188 |
localIndex = 0; |
|
189 |
value = feature2.get(localIndex); |
|
190 |
while(value != null && !(value instanceof org.gvsig.fmap.geom.Geometry)) { |
|
191 |
feat.set(globalIndex, value); |
|
192 |
value = feature2.get(++localIndex); |
|
193 |
globalIndex ++; |
|
194 |
} |
|
188 |
if (namesTranslator != null) { |
|
189 |
for (FeatureAttributeDescriptor attr1 : feature1.getType().getAttributeDescriptors()) { |
|
190 |
String attrName = attr1.getName(); |
|
191 |
String translation = namesTranslator.getTranslation(attrName); |
|
192 |
Object fValue = feature1.get(attrName); |
|
193 |
if (translation != null && !translation.isEmpty()) { |
|
194 |
feat.set(translation, fValue); |
|
195 |
} |
|
196 |
} |
|
197 |
for (FeatureAttributeDescriptor attr2 : feature2.getType().getAttributeDescriptors()) { |
|
198 |
String attrName = attr2.getName(); |
|
199 |
List<String> translation = namesTranslator.getAllTranslations(attrName); |
|
200 |
Object fValue = feature2.get(attrName); |
|
201 |
if (translation != null && !translation.isEmpty()) { |
|
202 |
feat.set(translation.get(translation.size() - 1), fValue); |
|
203 |
} |
|
204 |
} |
|
205 |
} else { |
|
206 |
feat.copyFrom(feature1); |
|
207 |
feat.copyFrom(feature2); |
|
208 |
} |
|
195 | 209 |
|
196 | 210 |
if(newDalGeom != null && acceptType(store, newDalGeom)) { |
197 | 211 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
... | ... | |
223 | 237 |
throws CreateGeometryException, DataException { |
224 | 238 |
EditableFeature feat = store.createNewFeature(); |
225 | 239 |
|
226 |
int globalIndex = 0; |
|
227 |
int localIndex = 0; |
|
228 |
Object value = feature1.get(localIndex); |
|
229 |
while(value != null && !(value instanceof org.gvsig.fmap.geom.Geometry)) { |
|
230 |
feat.set(globalIndex, value); |
|
231 |
value = feature1.get(++localIndex); |
|
232 |
globalIndex ++; |
|
233 |
} |
|
240 |
if (namesTranslator != null) { |
|
241 |
for (FeatureAttributeDescriptor attr1 : feature1.getType().getAttributeDescriptors()) { |
|
242 |
String attrName = attr1.getName(); |
|
243 |
String translation = namesTranslator.getTranslation(attrName); |
|
244 |
Object fValue = feature1.get(attrName); |
|
245 |
if (translation != null && !translation.isEmpty()) { |
|
246 |
feat.set(translation, fValue); |
|
247 |
} |
|
248 |
} |
|
249 |
for (FeatureAttributeDescriptor attr2 : feature2.getType().getAttributeDescriptors()) { |
|
250 |
String attrName = attr2.getName(); |
|
251 |
List<String> translation = namesTranslator.getAllTranslations(attrName); |
|
252 |
Object fValue = feature2.get(attrName); |
|
253 |
if (translation != null && !translation.isEmpty()) { |
|
254 |
feat.set(translation.get(translation.size() - 1), fValue); |
|
255 |
} |
|
256 |
} |
|
257 |
} else { |
|
258 |
feat.copyFrom(feature1); |
|
259 |
feat.copyFrom(feature2); |
|
260 |
} |
|
234 | 261 |
|
235 |
localIndex = 0; |
|
236 |
value = feature2.get(localIndex); |
|
237 |
while(value != null && !(value instanceof org.gvsig.fmap.geom.Geometry)) { |
|
238 |
feat.set(globalIndex, value); |
|
239 |
value = feature2.get(++localIndex); |
|
240 |
globalIndex ++; |
|
241 |
} |
|
242 |
|
|
243 | 262 |
if(newDalGeom != null && acceptType(store, newDalGeom)) { |
244 | 263 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
245 | 264 |
if(multiGeometry!=null && acceptType(store, multiGeometry)){ |
246 |
feat.setGeometry("GEOMETRY", multiGeometry);
|
|
265 |
feat.setDefaultGeometry(multiGeometry);
|
|
247 | 266 |
} else { |
248 |
feat.setGeometry("GEOMETRY", newDalGeom);
|
|
267 |
feat.setDefaultGeometry(newDalGeom);
|
|
249 | 268 |
} |
250 | 269 |
store.insert(feat); |
251 | 270 |
return feat; |
... | ... | |
254 | 273 |
} |
255 | 274 |
|
256 | 275 |
/** |
257 |
* Converts a geometry collection from JTS to a list of geometries of the selected type. |
|
258 |
* The GeometryCollection is converted only when it is a heterogeneous collection of geometries |
|
259 |
* @param col |
|
276 |
* Converts a geometry collection from JTS to a list of geometries of the selected type.The GeometryCollection is converted only when it is a heterogeneous collection of geometries |
|
260 | 277 |
* @param type |
261 | 278 |
* @return |
262 |
* @throws CreateGeometryException |
|
263 | 279 |
* @throws GeometryOperationException |
264 | 280 |
* @throws GeometryOperationNotSupportedException |
265 | 281 |
*/ |
... | ... | |
723 | 739 |
*/ |
724 | 740 |
public EditableFeature addGeometryToExistingFeature(EditableFeature feature, org.gvsig.fmap.geom.Geometry newGeom) throws CreateGeometryException, DataException { |
725 | 741 |
//Y esto para que c... sirve? |
726 |
for (int i = 0; i < fieldNames.length; i++)
|
|
727 |
feature.set(fieldNames[i], feature.get(i));
|
|
728 |
|
|
742 |
for (String fieldName : fieldNames) {
|
|
743 |
feature.set(fieldName, feature.get(fieldName));
|
|
744 |
} |
|
729 | 745 |
if(acceptType(store, newGeom)) { |
730 | 746 |
feature.setGeometry(fieldNames.length, newGeom); |
731 | 747 |
store.update(feature); |
Also available in: Unified diff