Revision 1262
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 | ||
---|---|---|
62 | 62 |
|
63 | 63 |
/** |
64 | 64 |
* Writes features in a FeatureStore |
65 |
* |
|
65 | 66 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
66 | 67 |
*/ |
67 | 68 |
public class DALFeaturePersister { |
68 |
private FeatureStore store = null; |
|
69 |
private String[] fieldNames = null; |
|
70 |
private GeometryManager geometryManager = null; |
|
71 |
private NamesTranslator namesTranslator = null; |
|
72 | 69 |
|
73 |
/** |
|
74 |
* Sets the output FeatureType |
|
75 |
* @param out |
|
76 |
* @throws DataException |
|
77 |
*/ |
|
78 |
public DALFeaturePersister(FeatureStore out, String[] fieldNames, NamesTranslator namesTranslator) { |
|
79 |
this(out, fieldNames); |
|
80 |
this.namesTranslator = namesTranslator; |
|
70 |
private FeatureStore store = null; |
|
71 |
private String[] fieldNames = null; |
|
72 |
private GeometryManager geometryManager = null; |
|
73 |
private NamesTranslator namesTranslator = null; |
|
74 |
|
|
75 |
/** |
|
76 |
* Sets the output FeatureType |
|
77 |
* |
|
78 |
* @param out |
|
79 |
* @throws DataException |
|
80 |
*/ |
|
81 |
public DALFeaturePersister(FeatureStore out, String[] fieldNames, NamesTranslator namesTranslator) { |
|
82 |
this(out, fieldNames); |
|
83 |
this.namesTranslator = namesTranslator; |
|
84 |
} |
|
85 |
|
|
86 |
public DALFeaturePersister(FeatureStore out, String[] fieldNames) { |
|
87 |
this.store = out; |
|
88 |
this.fieldNames = fieldNames; |
|
89 |
this.namesTranslator = null; |
|
90 |
try { |
|
91 |
if (!store.isEditing()) { |
|
92 |
store.edit(); |
|
93 |
} |
|
94 |
} catch (DataException e) { |
|
95 |
} catch (NullPointerException e) { |
|
81 | 96 |
} |
82 |
|
|
83 |
public DALFeaturePersister(FeatureStore out, String[] fieldNames) { |
|
84 |
this.store = out; |
|
85 |
this.fieldNames = fieldNames; |
|
86 |
this.namesTranslator = null; |
|
87 |
try { |
|
88 |
if(!store.isEditing()) |
|
89 |
store.edit(); |
|
90 |
} catch (DataException e) { |
|
91 |
} catch (NullPointerException e) { |
|
92 |
} |
|
93 |
geometryManager = GeometryLocator.getGeometryManager(); |
|
94 |
} |
|
97 |
geometryManager = GeometryLocator.getGeometryManager(); |
|
98 |
} |
|
95 | 99 |
|
96 |
/** |
|
97 |
* Gets the list of field names |
|
98 |
* @return |
|
99 |
*/ |
|
100 |
public String[] getFieldNames() { |
|
101 |
try { |
|
102 |
FeatureAttributeDescriptor[] attrs = store.getDefaultFeatureType().getAttributeDescriptors(); |
|
103 |
String[] fieldNames = new String[attrs.length]; |
|
104 |
for (int i = 0; i < attrs.length; i++) { |
|
105 |
fieldNames[i] = attrs[i].getName(); |
|
106 |
} |
|
107 |
return fieldNames; |
|
108 |
} catch (DataException e) { |
|
109 |
Sextante.addErrorToLog(e); |
|
110 |
} |
|
111 |
return null; |
|
112 |
} |
|
100 |
/** |
|
101 |
* Gets the list of field names |
|
102 |
* |
|
103 |
* @return |
|
104 |
*/ |
|
105 |
public String[] getFieldNames() { |
|
106 |
try { |
|
107 |
FeatureAttributeDescriptor[] attrs = store.getDefaultFeatureType().getAttributeDescriptors(); |
|
108 |
String[] fieldNames = new String[attrs.length]; |
|
109 |
for (int i = 0; i < attrs.length; i++) { |
|
110 |
fieldNames[i] = attrs[i].getName(); |
|
111 |
} |
|
112 |
return fieldNames; |
|
113 |
} catch (DataException e) { |
|
114 |
Sextante.addErrorToLog(e); |
|
115 |
} |
|
116 |
return null; |
|
117 |
} |
|
113 | 118 |
|
114 |
/** |
|
115 |
* Gets the list of field names |
|
116 |
* @return |
|
117 |
*/ |
|
118 |
public String[] getFieldNamesWithoutGeom() { |
|
119 |
try { |
|
120 |
FeatureAttributeDescriptor[] attrs = store.getDefaultFeatureType().getAttributeDescriptors(); |
|
121 |
int nFields = attrs.length; |
|
122 |
for (int j = 0; j < nFields; j++) { |
|
123 |
if(attrs[j].getName().compareTo("GEOMETRY") == 0) { |
|
124 |
nFields --; |
|
125 |
break; |
|
126 |
} |
|
127 |
} |
|
119 |
/** |
|
120 |
* Gets the list of field names |
|
121 |
* |
|
122 |
* @return |
|
123 |
*/ |
|
124 |
public String[] getFieldNamesWithoutGeom() { |
|
125 |
try { |
|
126 |
FeatureAttributeDescriptor[] attrs = store.getDefaultFeatureType().getAttributeDescriptors(); |
|
127 |
int nFields = attrs.length; |
|
128 |
for (int j = 0; j < nFields; j++) { |
|
129 |
if (attrs[j].getName().compareTo("GEOMETRY") == 0) { |
|
130 |
nFields--; |
|
131 |
break; |
|
132 |
} |
|
133 |
} |
|
128 | 134 |
|
129 |
int cont = 0;
|
|
130 |
String[] fieldNames = new String[nFields];
|
|
131 |
for (int i = 0; i < attrs.length; i++) {
|
|
132 |
if(attrs[i].getName().compareTo("GEOMETRY") != 0) {
|
|
133 |
fieldNames[cont] = attrs[i].getName();
|
|
134 |
cont ++;
|
|
135 |
}
|
|
136 |
}
|
|
137 |
return fieldNames;
|
|
138 |
} catch (DataException e) {
|
|
139 |
Sextante.addErrorToLog(e);
|
|
140 |
}
|
|
141 |
return null;
|
|
142 |
}
|
|
135 |
int cont = 0;
|
|
136 |
String[] fieldNames = new String[nFields];
|
|
137 |
for (int i = 0; i < attrs.length; i++) {
|
|
138 |
if (attrs[i].getName().compareTo("GEOMETRY") != 0) {
|
|
139 |
fieldNames[cont] = attrs[i].getName();
|
|
140 |
cont++;
|
|
141 |
}
|
|
142 |
}
|
|
143 |
return fieldNames;
|
|
144 |
} catch (DataException e) {
|
|
145 |
Sextante.addErrorToLog(e);
|
|
146 |
}
|
|
147 |
return null;
|
|
148 |
}
|
|
143 | 149 |
|
144 |
/** |
|
145 |
* Adds a JTS feature to the FeatureStore |
|
146 |
* @param entry |
|
147 |
* @param newGeom |
|
148 |
* @throws CreateGeometryException |
|
149 |
* @throws DataException |
|
150 |
*/ |
|
151 |
public EditableFeature addFeature(Feature feature1, Feature feature2, Geometry newGeom) |
|
152 |
throws CreateGeometryException, DataException { |
|
150 |
/** |
|
151 |
* Adds a JTS feature to the FeatureStore |
|
152 |
* |
|
153 |
* @param entry |
|
154 |
* @param newGeom |
|
155 |
* @throws CreateGeometryException |
|
156 |
* @throws DataException |
|
157 |
*/ |
|
158 |
public EditableFeature addFeature(Feature feature1, Feature feature2, Geometry newGeom) |
|
159 |
throws CreateGeometryException, DataException { |
|
153 | 160 |
|
154 |
int outPutType = getOutputFeatureStore().getDefaultFeatureType()
|
|
155 |
.getDefaultGeometryAttribute().getGeomType().getType();
|
|
161 |
int outPutType = getOutputFeatureStore().getDefaultFeatureType()
|
|
162 |
.getDefaultGeometryAttribute().getGeomType().getType();
|
|
156 | 163 |
|
157 |
//Si el objeto que viene es un GeometryCollection hay que convertirlo a una lista de geometrias
|
|
158 |
//solo del tipo que pueda salvarse en la capa eliminando el resto. Esto sucede sobre todo en la intersecci?n
|
|
159 |
//que devuelve tipos mezclados. Cada uno debe salvarse en el tipo de capa de salida apropiado
|
|
160 |
ArrayList<org.gvsig.fmap.geom.Geometry> dalGeomList = null;
|
|
161 |
try {
|
|
162 |
dalGeomList = convertGeometryCollection2GeometryList(newGeom, outPutType);
|
|
163 |
} catch (GeometryOperationNotSupportedException e1) {
|
|
164 |
Sextante.addErrorToLog(e1);
|
|
165 |
} catch (GeometryOperationException e1) {
|
|
166 |
Sextante.addErrorToLog(e1);
|
|
167 |
}
|
|
168 |
org.gvsig.fmap.geom.Geometry newDalGeom = null;
|
|
164 |
//Si el objeto que viene es un GeometryCollection hay que convertirlo a una lista de geometrias
|
|
165 |
//solo del tipo que pueda salvarse en la capa eliminando el resto. Esto sucede sobre todo en la intersecci?n
|
|
166 |
//que devuelve tipos mezclados. Cada uno debe salvarse en el tipo de capa de salida apropiado
|
|
167 |
ArrayList<org.gvsig.fmap.geom.Geometry> dalGeomList = null;
|
|
168 |
try {
|
|
169 |
dalGeomList = convertGeometryCollection2GeometryList(newGeom, outPutType);
|
|
170 |
} catch (GeometryOperationNotSupportedException e1) {
|
|
171 |
Sextante.addErrorToLog(e1);
|
|
172 |
} catch (GeometryOperationException e1) {
|
|
173 |
Sextante.addErrorToLog(e1);
|
|
174 |
}
|
|
175 |
org.gvsig.fmap.geom.Geometry newDalGeom = null;
|
|
169 | 176 |
|
170 |
//Si lo que venia no era un GeometryCollection se convierte a geometr?a de DAL
|
|
171 |
if(dalGeomList == null) {
|
|
172 |
GeometryOperationContext ctx = new GeometryOperationContext();
|
|
173 |
ctx.setAttribute(FromJTS.PARAM, newGeom);
|
|
174 |
try {
|
|
175 |
newDalGeom = (org.gvsig.fmap.geom.Geometry)geometryManager.invokeOperation(FromJTS.NAME, ctx);
|
|
176 |
} catch (GeometryOperationNotSupportedException e) {
|
|
177 |
Sextante.addErrorToLog(e);
|
|
178 |
return null;
|
|
179 |
} catch (GeometryOperationException e) {
|
|
180 |
Sextante.addErrorToLog(e);
|
|
181 |
return null;
|
|
182 |
}
|
|
183 |
}
|
|
177 |
//Si lo que venia no era un GeometryCollection se convierte a geometr?a de DAL
|
|
178 |
if (dalGeomList == null) {
|
|
179 |
GeometryOperationContext ctx = new GeometryOperationContext();
|
|
180 |
ctx.setAttribute(FromJTS.PARAM, newGeom);
|
|
181 |
try {
|
|
182 |
newDalGeom = (org.gvsig.fmap.geom.Geometry) geometryManager.invokeOperation(FromJTS.NAME, ctx);
|
|
183 |
} catch (GeometryOperationNotSupportedException e) {
|
|
184 |
Sextante.addErrorToLog(e);
|
|
185 |
return null;
|
|
186 |
} catch (GeometryOperationException e) {
|
|
187 |
Sextante.addErrorToLog(e);
|
|
188 |
return null;
|
|
189 |
}
|
|
190 |
}
|
|
184 | 191 |
|
185 |
EditableFeature feat = store.createNewFeature();
|
|
192 |
EditableFeature feat = store.createNewFeature();
|
|
186 | 193 |
|
187 |
|
|
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 |
} |
|
194 |
if (namesTranslator != null) { |
|
195 |
for (FeatureAttributeDescriptor attr1 : feature1.getType().getAttributeDescriptors()) { |
|
196 |
String attrName = attr1.getName(); |
|
197 |
String translation = namesTranslator.getTranslation(attrName); |
|
198 |
Object fValue = feature1.get(attrName); |
|
199 |
if (translation != null && !translation.isEmpty()) { |
|
200 |
feat.set(translation, fValue); |
|
196 | 201 |
} |
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 |
}
|
|
202 |
}
|
|
203 |
for (FeatureAttributeDescriptor attr2 : feature2.getType().getAttributeDescriptors()) {
|
|
204 |
String attrName = attr2.getName();
|
|
205 |
List<String> translation = namesTranslator.getAllTranslations(attrName);
|
|
206 |
Object fValue = feature2.get(attrName);
|
|
207 |
if (translation != null && !translation.isEmpty()) {
|
|
208 |
feat.set(translation.get(translation.size() - 1), fValue);
|
|
204 | 209 |
} |
205 |
} else { |
|
206 |
feat.copyFrom(feature1); |
|
207 |
feat.copyFrom(feature2); |
|
208 | 210 |
} |
211 |
} else { |
|
212 |
feat.copyFrom(feature1); |
|
213 |
feat.copyFrom(feature2); |
|
214 |
} |
|
209 | 215 |
|
210 |
if(newDalGeom != null && acceptType(store, newDalGeom)) {
|
|
216 |
if (newDalGeom != null && acceptType(store, newDalGeom)) {
|
|
211 | 217 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
212 |
if(multiGeometry!=null && acceptType(store, multiGeometry)){
|
|
218 |
if (multiGeometry != null && acceptType(store, multiGeometry)) {
|
|
213 | 219 |
feat.setGeometry("GEOMETRY", multiGeometry); |
214 | 220 |
} else { |
215 | 221 |
feat.setGeometry("GEOMETRY", newDalGeom); |
216 | 222 |
} |
217 |
store.insert(feat);
|
|
218 |
return feat;
|
|
219 |
} else if(dalGeomList != null) {
|
|
220 |
for (int i = 0; i < dalGeomList.size(); i++) {
|
|
221 |
if(acceptType(store, dalGeomList.get(i))) {
|
|
222 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(dalGeomList.get(i));
|
|
223 |
if(multiGeometry!=null && acceptType(store, multiGeometry)){
|
|
224 |
feat.setGeometry("GEOMETRY", multiGeometry);
|
|
225 |
} else {
|
|
226 |
feat.setGeometry("GEOMETRY", dalGeomList.get(i));
|
|
227 |
}
|
|
228 |
store.insert(feat);
|
|
229 |
}
|
|
230 |
}
|
|
231 |
return feat;
|
|
232 |
}
|
|
233 |
return null;
|
|
234 |
}
|
|
223 |
store.insert(feat);
|
|
224 |
return feat;
|
|
225 |
} else if (dalGeomList != null) {
|
|
226 |
for (int i = 0; i < dalGeomList.size(); i++) {
|
|
227 |
if (acceptType(store, dalGeomList.get(i))) {
|
|
228 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(dalGeomList.get(i));
|
|
229 |
if (multiGeometry != null && acceptType(store, multiGeometry)) {
|
|
230 |
feat.setGeometry("GEOMETRY", multiGeometry);
|
|
231 |
} else {
|
|
232 |
feat.setGeometry("GEOMETRY", dalGeomList.get(i));
|
|
233 |
}
|
|
234 |
store.insert(feat);
|
|
235 |
}
|
|
236 |
}
|
|
237 |
return feat;
|
|
238 |
}
|
|
239 |
return null;
|
|
240 |
}
|
|
235 | 241 |
|
236 |
public EditableFeature addFeature(Feature feature1, Feature feature2, org.gvsig.fmap.geom.Geometry newDalGeom)
|
|
237 |
throws CreateGeometryException, DataException {
|
|
238 |
EditableFeature feat = store.createNewFeature();
|
|
242 |
public EditableFeature addFeature(Feature feature1, Feature feature2, org.gvsig.fmap.geom.Geometry newDalGeom)
|
|
243 |
throws CreateGeometryException, DataException {
|
|
244 |
EditableFeature feat = store.createNewFeature();
|
|
239 | 245 |
|
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 |
} |
|
246 |
if (namesTranslator != null) { |
|
247 |
for (FeatureAttributeDescriptor attr1 : feature1.getType().getAttributeDescriptors()) { |
|
248 |
String attrName = attr1.getName(); |
|
249 |
String translation = namesTranslator.getTranslation(attrName); |
|
250 |
Object fValue = feature1.get(attrName); |
|
251 |
if (translation != null && !translation.isEmpty()) { |
|
252 |
feat.set(translation, fValue); |
|
248 | 253 |
} |
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 |
}
|
|
254 |
}
|
|
255 |
for (FeatureAttributeDescriptor attr2 : feature2.getType().getAttributeDescriptors()) {
|
|
256 |
String attrName = attr2.getName();
|
|
257 |
List<String> translation = namesTranslator.getAllTranslations(attrName);
|
|
258 |
Object fValue = feature2.get(attrName);
|
|
259 |
if (translation != null && !translation.isEmpty()) {
|
|
260 |
feat.set(translation.get(translation.size() - 1), fValue);
|
|
256 | 261 |
} |
262 |
} |
|
263 |
} else { |
|
264 |
feat.copyFrom(feature1); |
|
265 |
feat.copyFrom(feature2); |
|
266 |
} |
|
267 |
|
|
268 |
if (newDalGeom != null && acceptType(store, newDalGeom)) { |
|
269 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
|
270 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
271 |
feat.setDefaultGeometry(multiGeometry); |
|
257 | 272 |
} else { |
258 |
feat.copyFrom(feature1); |
|
259 |
feat.copyFrom(feature2); |
|
273 |
feat.setDefaultGeometry(newDalGeom); |
|
260 | 274 |
} |
275 |
store.insert(feat); |
|
276 |
return feat; |
|
277 |
} |
|
278 |
return null; |
|
279 |
} |
|
261 | 280 |
|
262 |
if(newDalGeom != null && acceptType(store, newDalGeom)) { |
|
263 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
|
264 |
if(multiGeometry!=null && acceptType(store, multiGeometry)){ |
|
265 |
feat.setDefaultGeometry(multiGeometry); |
|
266 |
} else { |
|
267 |
feat.setDefaultGeometry(newDalGeom); |
|
268 |
} |
|
269 |
store.insert(feat); |
|
270 |
return feat; |
|
271 |
} |
|
272 |
return null; |
|
273 |
} |
|
281 |
/** |
|
282 |
* Converts a geometry collection from JTS to a list of geometries of the |
|
283 |
* selected type.The GeometryCollection is converted only when it is a |
|
284 |
* heterogeneous collection of geometries |
|
285 |
* |
|
286 |
* @param type |
|
287 |
* @return |
|
288 |
* @throws GeometryOperationException |
|
289 |
* @throws GeometryOperationNotSupportedException |
|
290 |
*/ |
|
291 |
public ArrayList<org.gvsig.fmap.geom.Geometry> convertGeometryCollection2GeometryList(Geometry g, int type) throws GeometryOperationNotSupportedException, GeometryOperationException { |
|
292 |
if (g instanceof GeometryCollection |
|
293 |
&& !(g instanceof com.vividsolutions.jts.geom.MultiLineString) |
|
294 |
&& !(g instanceof com.vividsolutions.jts.geom.MultiPoint) |
|
295 |
&& !(g instanceof com.vividsolutions.jts.geom.MultiPolygon)) { |
|
296 |
GeometryCollection col = (GeometryCollection) g; |
|
297 |
ArrayList<org.gvsig.fmap.geom.Geometry> geometries = new ArrayList<org.gvsig.fmap.geom.Geometry>(); |
|
274 | 298 |
|
275 |
/** |
|
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 |
|
277 |
* @param type |
|
278 |
* @return |
|
279 |
* @throws GeometryOperationException |
|
280 |
* @throws GeometryOperationNotSupportedException |
|
281 |
*/ |
|
282 |
public ArrayList<org.gvsig.fmap.geom.Geometry> convertGeometryCollection2GeometryList(Geometry g, int type) throws GeometryOperationNotSupportedException, GeometryOperationException { |
|
283 |
if( g instanceof GeometryCollection && |
|
284 |
!(g instanceof com.vividsolutions.jts.geom.MultiLineString) && |
|
285 |
!(g instanceof com.vividsolutions.jts.geom.MultiPoint) && |
|
286 |
!(g instanceof com.vividsolutions.jts.geom.MultiPolygon)) { |
|
287 |
GeometryCollection col = (GeometryCollection)g; |
|
288 |
ArrayList<org.gvsig.fmap.geom.Geometry> geometries = new ArrayList<org.gvsig.fmap.geom.Geometry>(); |
|
299 |
if (type == TYPES.MULTIPOINT || type == TYPES.POINT) { |
|
300 |
for (int i = 0; i < col.getNumGeometries(); i++) { |
|
301 |
Geometry gx = col.getGeometryN(i); |
|
302 |
if (gx instanceof com.vividsolutions.jts.geom.Point |
|
303 |
|| gx instanceof com.vividsolutions.jts.geom.MultiPoint) { |
|
304 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
305 |
ctx.setAttribute(FromJTS.PARAM, gx); |
|
306 |
org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry) geometryManager.invokeOperation(FromJTS.NAME, ctx); |
|
307 |
geometries.add(newDalGeom); |
|
308 |
} |
|
309 |
} |
|
310 |
} |
|
289 | 311 |
|
290 |
if(type == TYPES.MULTIPOINT || type == TYPES.POINT) { |
|
291 |
for (int i = 0; i < col.getNumGeometries(); i++) { |
|
292 |
Geometry gx = col.getGeometryN(i); |
|
293 |
if( gx instanceof com.vividsolutions.jts.geom.Point || |
|
294 |
gx instanceof com.vividsolutions.jts.geom.MultiPoint) { |
|
295 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
296 |
ctx.setAttribute(FromJTS.PARAM, gx); |
|
297 |
org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry)geometryManager.invokeOperation(FromJTS.NAME, ctx); |
|
298 |
geometries.add(newDalGeom); |
|
299 |
} |
|
300 |
} |
|
301 |
} |
|
312 |
if (type == TYPES.MULTICURVE || type == TYPES.CURVE) { |
|
313 |
for (int i = 0; i < col.getNumGeometries(); i++) { |
|
314 |
Geometry gx = col.getGeometryN(i); |
|
315 |
if (gx instanceof com.vividsolutions.jts.geom.LineString |
|
316 |
|| gx instanceof com.vividsolutions.jts.geom.MultiLineString) { |
|
317 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
318 |
ctx.setAttribute(FromJTS.PARAM, gx); |
|
319 |
org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry) geometryManager.invokeOperation(FromJTS.NAME, ctx); |
|
320 |
geometries.add(newDalGeom); |
|
321 |
} |
|
322 |
} |
|
323 |
} |
|
324 |
if (type == TYPES.MULTISURFACE || type == TYPES.SURFACE) { |
|
325 |
for (int i = 0; i < col.getNumGeometries(); i++) { |
|
326 |
Geometry gx = col.getGeometryN(i); |
|
327 |
if (gx instanceof com.vividsolutions.jts.geom.Polygon |
|
328 |
|| gx instanceof com.vividsolutions.jts.geom.MultiPolygon) { |
|
329 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
330 |
ctx.setAttribute(FromJTS.PARAM, gx); |
|
331 |
org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry) geometryManager.invokeOperation(FromJTS.NAME, ctx); |
|
332 |
geometries.add(newDalGeom); |
|
333 |
} |
|
334 |
} |
|
335 |
} |
|
336 |
return geometries; |
|
337 |
} |
|
338 |
return null; |
|
339 |
} |
|
302 | 340 |
|
303 |
if(type == TYPES.MULTICURVE || type == TYPES.CURVE) { |
|
304 |
for (int i = 0; i < col.getNumGeometries(); i++) { |
|
305 |
Geometry gx = col.getGeometryN(i); |
|
306 |
if( gx instanceof com.vividsolutions.jts.geom.LineString || |
|
307 |
gx instanceof com.vividsolutions.jts.geom.MultiLineString) { |
|
308 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
309 |
ctx.setAttribute(FromJTS.PARAM, gx); |
|
310 |
org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry)geometryManager.invokeOperation(FromJTS.NAME, ctx); |
|
311 |
geometries.add(newDalGeom); |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
if(type == TYPES.MULTISURFACE || type == TYPES.SURFACE) { |
|
316 |
for (int i = 0; i < col.getNumGeometries(); i++) { |
|
317 |
Geometry gx = col.getGeometryN(i); |
|
318 |
if( gx instanceof com.vividsolutions.jts.geom.Polygon || |
|
319 |
gx instanceof com.vividsolutions.jts.geom.MultiPolygon) { |
|
320 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
321 |
ctx.setAttribute(FromJTS.PARAM, gx); |
|
322 |
org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry)geometryManager.invokeOperation(FromJTS.NAME, ctx); |
|
323 |
geometries.add(newDalGeom); |
|
324 |
} |
|
325 |
} |
|
326 |
} |
|
327 |
return geometries; |
|
328 |
} |
|
329 |
return null; |
|
330 |
} |
|
341 |
/** |
|
342 |
* Converts a geometry into a multigeometry |
|
343 |
* |
|
344 |
* @param g |
|
345 |
* @return |
|
346 |
* @throws CreateGeometryException |
|
347 |
*/ |
|
348 |
private org.gvsig.fmap.geom.Geometry convertGeometryList2MultiGeometry(List<org.gvsig.fmap.geom.Geometry> list) throws CreateGeometryException { |
|
349 |
if (list.size() == 0) { |
|
350 |
return null; |
|
351 |
} |
|
352 |
MultiPrimitive primitive = null; |
|
331 | 353 |
|
332 |
/** |
|
333 |
* Converts a geometry into a multigeometry |
|
334 |
* @param g |
|
335 |
* @return |
|
336 |
* @throws CreateGeometryException |
|
337 |
*/ |
|
338 |
private org.gvsig.fmap.geom.Geometry convertGeometryList2MultiGeometry(List<org.gvsig.fmap.geom.Geometry> list) throws CreateGeometryException { |
|
339 |
if(list.size() == 0) |
|
340 |
return null; |
|
341 |
MultiPrimitive primitive = null; |
|
354 |
if (list.get(0) instanceof Point || list.get(0) instanceof MultiPoint) { |
|
355 |
primitive = (MultiPrimitive) geometryManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D); |
|
356 |
} |
|
357 |
if (list.get(0) instanceof Curve || list.get(0) instanceof MultiCurve) { |
|
358 |
primitive = (MultiPrimitive) geometryManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D); |
|
359 |
} |
|
360 |
if (list.get(0) instanceof Surface || list.get(0) instanceof MultiSurface) { |
|
361 |
primitive = (MultiPrimitive) geometryManager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D); |
|
362 |
} |
|
342 | 363 |
|
343 |
if(list.get(0) instanceof Point || list.get(0) instanceof MultiPoint) { |
|
344 |
primitive = (MultiPrimitive)geometryManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D); |
|
345 |
} |
|
346 |
if(list.get(0) instanceof Curve || list.get(0) instanceof MultiCurve) { |
|
347 |
primitive = (MultiPrimitive)geometryManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D); |
|
348 |
} |
|
349 |
if(list.get(0) instanceof Surface || list.get(0) instanceof MultiSurface) { |
|
350 |
primitive = (MultiPrimitive)geometryManager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D); |
|
351 |
} |
|
364 |
for (int i = 0; i < list.size(); i++) { |
|
365 |
org.gvsig.fmap.geom.Geometry geom = list.get(i); |
|
366 |
if (geom instanceof MultiPrimitive) { |
|
367 |
MultiPrimitive multi = (MultiPrimitive) geom; |
|
368 |
for (int j = 0; j < multi.getPrimitivesNumber(); j++) { |
|
369 |
primitive.addPrimitive((Primitive) multi.getPrimitiveAt(j)); |
|
370 |
} |
|
371 |
} else { |
|
372 |
primitive.addPrimitive((Primitive) list.get(i)); |
|
373 |
} |
|
374 |
} |
|
352 | 375 |
|
353 |
for (int i = 0; i < list.size(); i++) { |
|
354 |
org.gvsig.fmap.geom.Geometry geom = list.get(i); |
|
355 |
if(geom instanceof MultiPrimitive) { |
|
356 |
MultiPrimitive multi = (MultiPrimitive)geom; |
|
357 |
for (int j = 0; j < multi.getPrimitivesNumber(); j++) { |
|
358 |
primitive.addPrimitive((Primitive)multi.getPrimitiveAt(j)); |
|
359 |
} |
|
360 |
} else |
|
361 |
primitive.addPrimitive((Primitive)list.get(i)); |
|
362 |
} |
|
376 |
return primitive; |
|
377 |
} |
|
363 | 378 |
|
364 |
return primitive; |
|
365 |
} |
|
379 |
/** |
|
380 |
* Converts a geometry into a multigeometry |
|
381 |
* |
|
382 |
* @param g |
|
383 |
* @return |
|
384 |
* @throws CreateGeometryException |
|
385 |
*/ |
|
386 |
private org.gvsig.fmap.geom.Geometry convertGeometry2MultiGeometry(org.gvsig.fmap.geom.Geometry g) throws CreateGeometryException { |
|
387 |
if (g instanceof MultiPrimitive) { |
|
388 |
return g; |
|
389 |
} |
|
390 |
if (g instanceof Point) { |
|
391 |
MultiPoint pNew = (MultiPoint) geometryManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D); |
|
392 |
pNew.addPoint((Point) g); |
|
393 |
return pNew; |
|
394 |
} |
|
395 |
if (g instanceof Curve) { |
|
396 |
MultiCurve cNew = (MultiCurve) geometryManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D); |
|
397 |
cNew.addCurve((Curve) g); |
|
398 |
return cNew; |
|
399 |
} |
|
400 |
if (g instanceof Surface) { |
|
401 |
MultiSurface cNew = (MultiSurface) geometryManager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D); |
|
402 |
cNew.addSurface((Surface) g); |
|
403 |
return cNew; |
|
404 |
} |
|
405 |
return g; |
|
406 |
} |
|
366 | 407 |
|
367 |
/** |
|
368 |
* Converts a geometry into a multigeometry |
|
369 |
* @param g |
|
370 |
* @return |
|
371 |
* @throws CreateGeometryException |
|
372 |
*/ |
|
373 |
private org.gvsig.fmap.geom.Geometry convertGeometry2MultiGeometry(org.gvsig.fmap.geom.Geometry g) throws CreateGeometryException { |
|
374 |
if(g instanceof MultiPrimitive) |
|
375 |
return g; |
|
376 |
if(g instanceof Point) { |
|
377 |
MultiPoint pNew = (MultiPoint)geometryManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D); |
|
378 |
pNew.addPoint((Point)g); |
|
379 |
return pNew; |
|
380 |
} |
|
381 |
if(g instanceof Curve) { |
|
382 |
MultiCurve cNew = (MultiCurve)geometryManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D); |
|
383 |
cNew.addCurve((Curve)g); |
|
384 |
return cNew; |
|
385 |
} |
|
386 |
if(g instanceof Surface) { |
|
387 |
MultiSurface cNew = (MultiSurface)geometryManager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D); |
|
388 |
cNew.addSurface((Surface)g); |
|
389 |
return cNew; |
|
390 |
} |
|
391 |
return g; |
|
392 |
} |
|
408 |
/** |
|
409 |
* Checks if the type of the feature store and the geometry are compatibles. |
|
410 |
* |
|
411 |
* @param store |
|
412 |
* @param geom |
|
413 |
* @return |
|
414 |
* @throws ReadException |
|
415 |
*/ |
|
416 |
private boolean acceptType(FeatureStore store, org.gvsig.fmap.geom.Geometry geom) throws ReadException { |
|
417 |
int fType = getShapeType(store); |
|
418 |
GeometryType geomType = geom.getGeometryType(); |
|
419 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
393 | 420 |
|
394 |
/** |
|
395 |
* Checks if the type of the feature store and the geometry are compatibles. |
|
396 |
* @param store |
|
397 |
* @param geom |
|
398 |
* @return |
|
399 |
* @throws ReadException |
|
400 |
*/ |
|
401 |
private boolean acceptType(FeatureStore store, org.gvsig.fmap.geom.Geometry geom) throws ReadException { |
|
402 |
int fType = getShapeType(store); |
|
403 |
GeometryType geomType = geom.getGeometryType(); |
|
404 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
421 |
if (geomManager.isSubtype(fType, geomType.getType())) { |
|
422 |
return true; |
|
423 |
} |
|
405 | 424 |
|
406 |
if(geomManager.isSubtype(fType, geomType.getType())) |
|
407 |
return true; |
|
408 |
|
|
409 |
if( geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTICURVE, fType) && |
|
410 |
geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.CURVE, geomType.getType())) |
|
411 |
return true; |
|
412 |
if( geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTISURFACE, fType) && |
|
413 |
geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.SURFACE, geomType.getType()) ) |
|
414 |
return true; |
|
415 |
if( geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTIPOINT, fType) && |
|
416 |
geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.POINT, geomType.getType())) |
|
417 |
return true; |
|
418 |
if( geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTISOLID, fType) && |
|
419 |
geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.SOLID, geomType.getType())) |
|
420 |
return true; |
|
421 |
return false; |
|
422 |
} |
|
425 |
if (geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTICURVE, fType) |
|
426 |
&& geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.CURVE, geomType.getType())) { |
|
427 |
return true; |
|
428 |
} |
|
429 |
if (geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTISURFACE, fType) |
|
430 |
&& geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.SURFACE, geomType.getType())) { |
|
431 |
return true; |
|
432 |
} |
|
433 |
if (geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTIPOINT, fType) |
|
434 |
&& geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.POINT, geomType.getType())) { |
|
435 |
return true; |
|
436 |
} |
|
437 |
if (geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTISOLID, fType) |
|
438 |
&& geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.SOLID, geomType.getType())) { |
|
439 |
return true; |
|
440 |
} |
|
441 |
return false; |
|
442 |
} |
|
423 | 443 |
|
424 |
/** |
|
425 |
* Adds a JTS feature to the FeatureStore |
|
426 |
* @param entry |
|
427 |
* @param newGeom |
|
428 |
* @throws CreateGeometryException |
|
429 |
* @throws DataException |
|
430 |
*/ |
|
431 |
public EditableFeature addFeature(Feature feature, Geometry newGeom) throws CreateGeometryException, DataException { |
|
432 |
int outPutType = getOutputFeatureStore().getDefaultFeatureType() |
|
433 |
.getDefaultGeometryAttribute().getGeomType().getType(); |
|
434 |
//Si el objeto que viene es un GeometryCollection hay que convertirlo a una lista de geometrias |
|
435 |
//solo del tipo que pueda salvarse en la capa eliminando el resto. Esto sucede sobre todo en la intersecci?n |
|
436 |
//que devuelve tipos mezclados. Cada uno debe salvarse en el tipo de capa de salida apropiado |
|
437 |
ArrayList<org.gvsig.fmap.geom.Geometry> dalGeomList = null; |
|
438 |
try { |
|
439 |
dalGeomList = convertGeometryCollection2GeometryList(newGeom, outPutType); |
|
440 |
} catch (GeometryOperationNotSupportedException e1) { |
|
441 |
Sextante.addErrorToLog(e1); |
|
442 |
} catch (GeometryOperationException e1) { |
|
443 |
Sextante.addErrorToLog(e1); |
|
444 |
} |
|
444 |
/** |
|
445 |
* Adds a JTS feature to the FeatureStore |
|
446 |
* |
|
447 |
* @param entry |
|
448 |
* @param newGeom |
|
449 |
* @throws CreateGeometryException |
|
450 |
* @throws DataException |
|
451 |
*/ |
|
452 |
public EditableFeature addFeature(Feature feature, Geometry newGeom) throws CreateGeometryException, DataException { |
|
453 |
int outPutType = getOutputFeatureStore().getDefaultFeatureType() |
|
454 |
.getDefaultGeometryAttribute().getGeomType().getType(); |
|
455 |
//Si el objeto que viene es un GeometryCollection hay que convertirlo a una lista de geometrias |
|
456 |
//solo del tipo que pueda salvarse en la capa eliminando el resto. Esto sucede sobre todo en la intersecci?n |
|
457 |
//que devuelve tipos mezclados. Cada uno debe salvarse en el tipo de capa de salida apropiado |
|
458 |
ArrayList<org.gvsig.fmap.geom.Geometry> dalGeomList = null; |
|
459 |
try { |
|
460 |
dalGeomList = convertGeometryCollection2GeometryList(newGeom, outPutType); |
|
461 |
} catch (GeometryOperationNotSupportedException e1) { |
|
462 |
Sextante.addErrorToLog(e1); |
|
463 |
} catch (GeometryOperationException e1) { |
|
464 |
Sextante.addErrorToLog(e1); |
|
465 |
} |
|
445 | 466 |
|
446 |
//No era un GeometryCollection
|
|
447 |
if(dalGeomList == null) {
|
|
448 |
org.gvsig.fmap.geom.Geometry newDalGeom = null;
|
|
449 |
GeometryOperationContext ctx = new GeometryOperationContext();
|
|
450 |
ctx.setAttribute(FromJTS.PARAM, newGeom);
|
|
451 |
try {
|
|
452 |
newDalGeom = (org.gvsig.fmap.geom.Geometry)geometryManager.invokeOperation(FromJTS.NAME, ctx);
|
|
453 |
} catch (GeometryOperationNotSupportedException e) {
|
|
454 |
Sextante.addErrorToLog(e);
|
|
455 |
} catch (GeometryOperationException e) {
|
|
456 |
Sextante.addErrorToLog(e);
|
|
457 |
}
|
|
458 |
insertFeatureIntoStore(feature, newDalGeom);
|
|
459 |
} else {
|
|
460 |
for (int i = 0; i < dalGeomList.size(); i++) {
|
|
461 |
insertFeatureIntoStore(feature, dalGeomList.get(i));
|
|
462 |
}
|
|
463 |
}
|
|
464 |
return null;
|
|
465 |
}
|
|
467 |
//No era un GeometryCollection
|
|
468 |
if (dalGeomList == null) {
|
|
469 |
org.gvsig.fmap.geom.Geometry newDalGeom = null;
|
|
470 |
GeometryOperationContext ctx = new GeometryOperationContext();
|
|
471 |
ctx.setAttribute(FromJTS.PARAM, newGeom);
|
|
472 |
try {
|
|
473 |
newDalGeom = (org.gvsig.fmap.geom.Geometry) geometryManager.invokeOperation(FromJTS.NAME, ctx);
|
|
474 |
} catch (GeometryOperationNotSupportedException e) {
|
|
475 |
Sextante.addErrorToLog(e);
|
|
476 |
} catch (GeometryOperationException e) {
|
|
477 |
Sextante.addErrorToLog(e);
|
|
478 |
}
|
|
479 |
insertFeatureIntoStore(feature, newDalGeom);
|
|
480 |
} else {
|
|
481 |
for (int i = 0; i < dalGeomList.size(); i++) {
|
|
482 |
insertFeatureIntoStore(feature, dalGeomList.get(i));
|
|
483 |
}
|
|
484 |
}
|
|
485 |
return null;
|
|
486 |
}
|
|
466 | 487 |
|
467 |
private EditableFeature insertFeatureIntoStore(Feature feature, org.gvsig.fmap.geom.Geometry newDalGeom) throws DataException { |
|
468 |
if (acceptType(store, newDalGeom)) { |
|
469 |
EditableFeature targetFeature = store.createNewFeature(store.getDefaultFeatureType(), true); |
|
470 |
for (FeatureAttributeDescriptor attrdesc : targetFeature.getType()) { |
|
471 |
if (attrdesc.isComputed()) { |
|
472 |
continue; |
|
473 |
} |
|
474 |
if (attrdesc.getType() == DataTypes.GEOMETRY) { |
|
475 |
continue; |
|
476 |
} |
|
477 |
String name = attrdesc.getName(); |
|
478 |
Object value = feature.get(name); |
|
479 |
if (value != null) { |
|
480 |
targetFeature.set(name, value); |
|
481 |
} |
|
488 |
private EditableFeature insertFeatureIntoStore(Feature feature, org.gvsig.fmap.geom.Geometry newDalGeom) throws DataException { |
|
489 |
if (acceptType(store, newDalGeom)) { |
|
490 |
EditableFeature targetFeature = store.createNewFeature(store.getDefaultFeatureType(), true); |
|
491 |
for (FeatureAttributeDescriptor attrdesc : targetFeature.getType()) { |
|
492 |
if (attrdesc.isComputed()) { |
|
493 |
continue; |
|
482 | 494 |
} |
483 |
org.gvsig.fmap.geom.Geometry multiGeometry = null; |
|
484 |
try { |
|
485 |
multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
|
486 |
} catch (CreateGeometryException e) { |
|
487 |
Sextante.addErrorToLog(e); |
|
495 |
if (attrdesc.getType() == DataTypes.GEOMETRY) { |
|
496 |
continue; |
|
488 | 497 |
} |
489 |
|
|
490 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
491 |
targetFeature.setGeometry("GEOMETRY", multiGeometry); |
|
492 |
} else { |
|
493 |
targetFeature.setGeometry("GEOMETRY", newDalGeom); |
|
498 |
String name = attrdesc.getName(); |
|
499 |
Object value = feature.get(name); |
|
500 |
if (value != null) { |
|
501 |
targetFeature.set(name, value); |
|
494 | 502 |
} |
495 |
store.insert(targetFeature); |
|
496 |
return targetFeature; |
|
497 | 503 |
} |
498 |
return null; |
|
504 |
org.gvsig.fmap.geom.Geometry multiGeometry = null; |
|
505 |
try { |
|
506 |
multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
|
507 |
} catch (CreateGeometryException e) { |
|
508 |
Sextante.addErrorToLog(e); |
|
509 |
} |
|
510 |
|
|
511 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
512 |
targetFeature.setGeometry("GEOMETRY", multiGeometry); |
|
513 |
} else { |
|
514 |
targetFeature.setGeometry("GEOMETRY", newDalGeom); |
|
515 |
} |
|
516 |
store.insert(targetFeature); |
|
517 |
return targetFeature; |
|
499 | 518 |
} |
519 |
return null; |
|
520 |
} |
|
500 | 521 |
|
501 |
/** |
|
502 |
* Adds a JTS feature to the FeatureStore |
|
503 |
* @param entry |
|
504 |
* @param newGeom |
|
505 |
* @throws CreateGeometryException |
|
506 |
* @throws DataException |
|
507 |
*/ |
|
508 |
public EditableFeature addFeature(Geometry newGeom, int id, double value) throws CreateGeometryException, DataException { |
|
509 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
522 |
/** |
|
523 |
* Adds a JTS feature to the FeatureStore |
|
524 |
* |
|
525 |
* @param entry |
|
526 |
* @param newGeom |
|
527 |
* @throws CreateGeometryException |
|
528 |
* @throws DataException |
|
529 |
*/ |
|
530 |
public EditableFeature addFeature(Geometry newGeom, int id, double value) throws CreateGeometryException, DataException { |
|
531 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
510 | 532 |
|
511 |
if(newDalGeom != null && acceptType(store, newDalGeom)) {
|
|
512 |
EditableFeature feat = store.createNewFeature();
|
|
513 |
feat.set(0, id);
|
|
514 |
feat.set(1, value);
|
|
515 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom);
|
|
516 |
if(multiGeometry!=null && acceptType(store, multiGeometry)){
|
|
517 |
feat.setGeometry("GEOMETRY", multiGeometry);
|
|
518 |
} else {
|
|
519 |
feat.setGeometry("GEOMETRY", newDalGeom);
|
|
520 |
}
|
|
521 |
store.insert(feat);
|
|
522 |
return feat;
|
|
523 |
}
|
|
524 |
return null;
|
|
525 |
}
|
|
533 |
if (newDalGeom != null && acceptType(store, newDalGeom)) {
|
|
534 |
EditableFeature feat = store.createNewFeature();
|
|
535 |
feat.set(0, id);
|
|
536 |
feat.set(1, value);
|
|
537 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom);
|
|
538 |
if (multiGeometry != null && acceptType(store, multiGeometry)) {
|
|
539 |
feat.setGeometry("GEOMETRY", multiGeometry); |
|
540 |
} else { |
|
541 |
feat.setGeometry("GEOMETRY", newDalGeom); |
|
542 |
} |
|
543 |
store.insert(feat);
|
|
544 |
return feat;
|
|
545 |
}
|
|
546 |
return null;
|
|
547 |
}
|
|
526 | 548 |
|
527 |
/** |
|
528 |
* Adds a JTS feature to the FeatureStore |
|
529 |
* @param entry |
|
530 |
* @param newGeom |
|
531 |
* @throws CreateGeometryException |
|
532 |
* @throws DataException |
|
533 |
*/ |
|
534 |
public EditableFeature addFeature(Feature feature, List<Geometry> newJTSListGeom) throws CreateGeometryException, DataException { |
|
535 |
List<org.gvsig.fmap.geom.Geometry> newDalListGeom = new ArrayList<org.gvsig.fmap.geom.Geometry>(); |
|
549 |
/** |
|
550 |
* Adds a JTS feature to the FeatureStore |
|
551 |
* |
|
552 |
* @param entry |
|
553 |
* @param newGeom |
|
554 |
* @throws CreateGeometryException |
|
555 |
* @throws DataException |
|
556 |
*/ |
|
557 |
public EditableFeature addFeature(Feature feature, List<Geometry> newJTSListGeom) throws CreateGeometryException, DataException { |
|
558 |
List<org.gvsig.fmap.geom.Geometry> newDalListGeom = new ArrayList<org.gvsig.fmap.geom.Geometry>(); |
|
536 | 559 |
|
537 |
for (int i = 0; i < newJTSListGeom.size(); i++) {
|
|
538 |
newDalListGeom.add(GeometryUtil.jtsToGeom(newJTSListGeom.get(i)));
|
|
539 |
}
|
|
560 |
for (int i = 0; i < newJTSListGeom.size(); i++) {
|
|
561 |
newDalListGeom.add(GeometryUtil.jtsToGeom(newJTSListGeom.get(i)));
|
|
562 |
}
|
|
540 | 563 |
|
541 |
org.gvsig.fmap.geom.Geometry newMultiGeom = convertGeometryList2MultiGeometry(newDalListGeom);
|
|
542 |
insertFeatureIntoStore(feature, newMultiGeom);
|
|
543 |
return null;
|
|
544 |
}
|
|
564 |
org.gvsig.fmap.geom.Geometry newMultiGeom = convertGeometryList2MultiGeometry(newDalListGeom);
|
|
565 |
insertFeatureIntoStore(feature, newMultiGeom);
|
|
566 |
return null;
|
|
567 |
}
|
|
545 | 568 |
|
546 |
/** |
|
547 |
* Adds a JTS feature to the FeatureStore |
|
548 |
* @param entry |
|
549 |
* @param newGeom |
|
550 |
* @throws CreateGeometryException |
|
551 |
* @throws DataException |
|
552 |
*/ |
|
553 |
public EditableFeature addFeature(Geometry newGeom, String name, Object value) throws CreateGeometryException, DataException { |
|
554 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
569 |
/** |
|
570 |
* Adds a JTS feature to the FeatureStore |
|
571 |
* |
|
572 |
* @param entry |
|
573 |
* @param newGeom |
|
574 |
* @throws CreateGeometryException |
|
575 |
* @throws DataException |
|
576 |
*/ |
|
577 |
public EditableFeature addFeature(Geometry newGeom, String name, Object value) throws CreateGeometryException, DataException { |
|
578 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
555 | 579 |
|
556 |
if(newDalGeom != null && acceptType(store, newDalGeom)) {
|
|
557 |
EditableFeature feat = store.createNewFeature();
|
|
558 |
feat.set(name, value);
|
|
559 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom);
|
|
560 |
if(multiGeometry!=null && acceptType(store, multiGeometry)){
|
|
561 |
feat.setGeometry("GEOMETRY", multiGeometry);
|
|
562 |
} else {
|
|
563 |
feat.setGeometry("GEOMETRY", newDalGeom);
|
|
564 |
}
|
|
565 |
store.insert(feat);
|
|
566 |
return feat;
|
|
567 |
}
|
|
568 |
return null;
|
|
569 |
}
|
|
580 |
if (newDalGeom != null && acceptType(store, newDalGeom)) {
|
|
581 |
EditableFeature feat = store.createNewFeature();
|
|
582 |
feat.set(name, value);
|
|
583 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom);
|
|
584 |
if (multiGeometry != null && acceptType(store, multiGeometry)) {
|
|
585 |
feat.setGeometry("GEOMETRY", multiGeometry); |
|
586 |
} else { |
|
587 |
feat.setGeometry("GEOMETRY", newDalGeom); |
|
588 |
} |
|
589 |
store.insert(feat);
|
|
590 |
return feat;
|
|
591 |
}
|
|
592 |
return null;
|
|
593 |
}
|
|
570 | 594 |
|
571 |
/** |
|
572 |
* Adds a geometry feature to the FeatureStore |
|
573 |
* @param entry |
|
574 |
* @param newGeom |
|
575 |
* @throws CreateGeometryException |
|
576 |
* @throws DataException |
|
577 |
*/ |
|
578 |
public EditableFeature addFeature(org.gvsig.fmap.geom.Geometry newGeom, String name, Object value) throws CreateGeometryException, DataException { |
|
579 |
if(newGeom != null && acceptType(store, newGeom)) { |
|
580 |
EditableFeature feat = store.createNewFeature(); |
|
581 |
feat.set(name, value); |
|
582 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom); |
|
583 |
if(multiGeometry!=null && acceptType(store, multiGeometry)){ |
|
584 |
feat.setGeometry("GEOMETRY", multiGeometry); |
|
585 |
} else { |
|
586 |
feat.setGeometry("GEOMETRY", newGeom); |
|
587 |
} |
|
588 |
store.insert(feat); |
|
589 |
return feat; |
|
590 |
} |
|
591 |
return null; |
|
592 |
} |
|
595 |
/** |
|
596 |
* Adds a geometry feature to the FeatureStore |
|
597 |
* |
|
598 |
* @param entry |
|
599 |
* @param newGeom |
|
600 |
* @throws CreateGeometryException |
|
601 |
* @throws DataException |
|
602 |
*/ |
|
603 |
public EditableFeature addFeature(org.gvsig.fmap.geom.Geometry newGeom, String name, Object value) throws CreateGeometryException, DataException { |
|
604 |
if (newGeom != null && acceptType(store, newGeom)) { |
|
605 |
EditableFeature feat = store.createNewFeature(); |
|
606 |
feat.set(name, value); |
|
607 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom); |
|
608 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
609 |
feat.setGeometry("GEOMETRY", multiGeometry); |
|
610 |
} else { |
|
611 |
feat.setGeometry("GEOMETRY", newGeom); |
|
612 |
} |
|
613 |
store.insert(feat); |
|
614 |
return feat; |
|
615 |
} |
|
616 |
return null; |
|
617 |
} |
|
593 | 618 |
|
594 |
/** |
|
595 |
* Adds a geometry feature to the FeatureStore |
|
596 |
* @param entry |
|
597 |
* @param newGeom |
|
598 |
* @throws CreateGeometryException |
|
599 |
* @throws DataException |
|
600 |
*/ |
|
601 |
public EditableFeature addFeature(org.gvsig.fmap.geom.Geometry newGeom, ArrayList<String> names, ArrayList<Object> values) throws CreateGeometryException, DataException { |
|
602 |
if(newGeom != null && acceptType(store, newGeom)) { |
|
603 |
EditableFeature feat = store.createNewFeature(); |
|
604 |
for (int i = 0; i < values.size(); i++) { |
|
605 |
feat.set(names.get(i), values.get(i)); |
|
606 |
} |
|
607 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom); |
|
608 |
if(multiGeometry!=null && acceptType(store, multiGeometry)){ |
|
609 |
feat.setGeometry("GEOMETRY", multiGeometry); |
|
610 |
} else { |
|
611 |
feat.setGeometry("GEOMETRY", newGeom); |
|
612 |
} |
|
613 |
store.insert(feat); |
|
614 |
return feat; |
|
615 |
} |
|
616 |
return null; |
|
617 |
} |
|
619 |
/** |
|
620 |
* Adds a geometry feature to the FeatureStore |
|
621 |
* |
|
622 |
* @param entry |
|
623 |
* @param newGeom |
|
624 |
* @throws CreateGeometryException |
|
625 |
* @throws DataException |
|
626 |
*/ |
|
627 |
public EditableFeature addFeature(org.gvsig.fmap.geom.Geometry newGeom, ArrayList<String> names, ArrayList<Object> values) throws CreateGeometryException, DataException { |
|
628 |
if (newGeom != null && acceptType(store, newGeom)) { |
|
629 |
EditableFeature feat = store.createNewFeature(); |
|
630 |
for (int i = 0; i < values.size(); i++) { |
|
631 |
feat.set(names.get(i), values.get(i)); |
|
632 |
} |
|
633 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom); |
|
634 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
635 |
feat.setGeometry("GEOMETRY", multiGeometry); |
|
636 |
} else { |
|
637 |
feat.setGeometry("GEOMETRY", newGeom); |
|
638 |
} |
|
639 |
store.insert(feat); |
|
640 |
return feat; |
|
641 |
} |
|
642 |
return null; |
|
643 |
} |
|
618 | 644 |
|
619 |
/** |
|
620 |
* Adds a JTS feature to the FeatureStore |
|
621 |
* @param entry |
|
622 |
* @param newGeom |
|
623 |
* @throws CreateGeometryException |
|
624 |
* @throws DataException |
|
625 |
*/ |
|
626 |
public EditableFeature addFeature(Geometry newGeom, ArrayList<String> names, ArrayList<Object> values) throws CreateGeometryException, DataException { |
|
627 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
645 |
/** |
|
646 |
* Adds a JTS feature to the FeatureStore |
|
647 |
* |
|
648 |
* @param entry |
|
649 |
* @param newGeom |
|
650 |
* @throws CreateGeometryException |
|
651 |
* @throws DataException |
|
652 |
*/ |
|
653 |
public EditableFeature addFeature(Geometry newGeom, ArrayList<String> names, ArrayList<Object> values) throws CreateGeometryException, DataException { |
|
654 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
628 | 655 |
|
629 |
if(newDalGeom != null && acceptType(store, newDalGeom)) {
|
|
630 |
EditableFeature feat = store.createNewFeature();
|
|
631 |
for (int i = 0; i < values.size(); i++) {
|
|
632 |
feat.set(names.get(i), values.get(i));
|
|
633 |
}
|
|
634 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom);
|
|
635 |
if(multiGeometry!=null && acceptType(store, multiGeometry)){
|
|
636 |
feat.setDefaultGeometry(multiGeometry);
|
|
637 |
} else {
|
|
638 |
feat.setDefaultGeometry(newDalGeom);
|
|
639 |
}
|
|
640 |
store.insert(feat);
|
|
641 |
return feat;
|
|
642 |
}
|
|
643 |
return null;
|
|
644 |
}
|
|
656 |
if (newDalGeom != null && acceptType(store, newDalGeom)) {
|
|
657 |
EditableFeature feat = store.createNewFeature();
|
|
658 |
for (int i = 0; i < values.size(); i++) {
|
|
659 |
feat.set(names.get(i), values.get(i));
|
|
660 |
}
|
|
661 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom);
|
|
662 |
if (multiGeometry != null && acceptType(store, multiGeometry)) {
|
|
663 |
feat.setDefaultGeometry(multiGeometry); |
|
664 |
} else { |
|
665 |
feat.setDefaultGeometry(newDalGeom); |
|
666 |
} |
|
667 |
store.insert(feat);
|
|
668 |
return feat;
|
|
669 |
}
|
|
670 |
return null;
|
|
671 |
}
|
|
645 | 672 |
|
646 |
/** |
|
647 |
* Adds a JTS feature to the FeatureStore |
|
648 |
* @param entry |
|
649 |
* @param newGeom |
|
650 |
* @throws CreateGeometryException |
|
651 |
* @throws DataException |
|
652 |
*/ |
|
653 |
public EditableFeature addFeature(Geometry newGeom, int id, double value1, double value2) throws CreateGeometryException, DataException { |
|
654 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
673 |
/** |
|
674 |
* Adds a JTS feature to the FeatureStore |
|
675 |
* |
|
676 |
* @param entry |
|
677 |
* @param newGeom |
|
678 |
* @throws CreateGeometryException |
|
679 |
* @throws DataException |
|
680 |
*/ |
|
681 |
public EditableFeature addFeature(Geometry newGeom, int id, double value1, double value2) throws CreateGeometryException, DataException { |
|
682 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
655 | 683 |
|
656 |
if(newDalGeom != null && acceptType(store, newDalGeom)) {
|
|
657 |
EditableFeature feat = store.createNewFeature();
|
|
658 |
feat.set(0, id);
|
|
659 |
feat.set(1, value1);
|
|
660 |
feat.set(2, value2);
|
|
661 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom);
|
|
662 |
if(multiGeometry!=null && acceptType(store, multiGeometry)){
|
|
663 |
feat.setDefaultGeometry(multiGeometry);
|
|
664 |
} else {
|
|
665 |
feat.setDefaultGeometry(newDalGeom);
|
|
666 |
}
|
|
667 |
store.insert(feat);
|
|
668 |
return feat;
|
|
669 |
}
|
|
670 |
return null;
|
|
671 |
}
|
|
684 |
if (newDalGeom != null && acceptType(store, newDalGeom)) {
|
|
685 |
EditableFeature feat = store.createNewFeature();
|
|
686 |
feat.set(0, id);
|
|
687 |
feat.set(1, value1);
|
|
688 |
feat.set(2, value2);
|
|
689 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom);
|
|
690 |
if (multiGeometry != null && acceptType(store, multiGeometry)) {
|
|
691 |
feat.setDefaultGeometry(multiGeometry); |
|
692 |
} else { |
|
693 |
feat.setDefaultGeometry(newDalGeom); |
|
694 |
} |
|
695 |
store.insert(feat);
|
|
696 |
return feat;
|
|
697 |
}
|
|
698 |
return null;
|
|
699 |
}
|
|
672 | 700 |
|
673 |
/** |
|
674 |
* Adds a DAL feature to the FeatureStore when the field structure in the new feature |
|
675 |
* is different to the source field structure. |
|
676 |
* @param entry |
|
677 |
* @param newGeom |
|
678 |
* @throws CreateGeometryException |
|
679 |
* @throws DataException |
|
680 |
*/ |
|
681 |
public EditableFeature addDifferentFieldFeature(Feature feature, org.gvsig.fmap.geom.Geometry newGeom) throws CreateGeometryException, DataException { |
|
682 |
if(acceptType(store, newGeom)) { |
|
683 |
//Builds a new empty feature |
|
684 |
EditableFeature feat = store.createNewFeature(store.getDefaultFeatureType(), true); |
|
701 |
/** |
|
702 |
* Adds a DAL feature to the FeatureStore when the field structure in the |
|
703 |
* new feature is different to the source field structure. |
|
704 |
* |
|
705 |
* @param entry |
|
706 |
* @param newGeom |
|
707 |
* @throws CreateGeometryException |
|
708 |
* @throws DataException |
|
709 |
*/ |
|
710 |
public EditableFeature addDifferentFieldFeature(Feature feature, org.gvsig.fmap.geom.Geometry newGeom) throws CreateGeometryException, DataException { |
|
711 |
if (acceptType(store, newGeom)) { |
|
712 |
//Builds a new empty feature |
|
713 |
EditableFeature feat = store.createNewFeature(store.getDefaultFeatureType(), true); |
|
685 | 714 |
|
686 |
//Writes only values with the same name and data type in both features |
|
687 |
for (int i = 0; i < fieldNames.length; i++) { |
|
688 |
if(feature.getType().getIndex(fieldNames[i]) != -1) { |
|
689 |
Object obj1 = feature.get(fieldNames[i]); |
|
690 |
if(feat.getType().getIndex(fieldNames[i]) != -1) { |
|
691 |
Object obj2 = feat.get(fieldNames[i]); |
|
692 |
if(obj1 != null && obj2 != null && obj1.getClass() == obj2.getClass()) |
|
693 |
feat.set(i, obj1); |
|
694 |
} |
|
695 |
} |
|
696 |
} |
|
715 |
//Writes only values with the same name and data type in both features |
|
716 |
for (int i = 0; i < fieldNames.length; i++) { |
|
717 |
if (feature.getType().getIndex(fieldNames[i]) != -1) { |
|
718 |
Object obj1 = feature.get(fieldNames[i]); |
|
719 |
if (feat.getType().getIndex(fieldNames[i]) != -1) { |
|
720 |
Object obj2 = feat.get(fieldNames[i]); |
|
721 |
if (obj1 != null && obj2 != null && obj1.getClass() == obj2.getClass()) { |
|
722 |
feat.set(i, obj1); |
|
723 |
} |
|
724 |
} |
|
725 |
} |
|
726 |
} |
|
697 | 727 |
|
698 |
//Sets the geometry
|
|
699 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom);
|
|
700 |
if(multiGeometry!=null && acceptType(store, multiGeometry)){
|
|
701 |
feat.setDefaultGeometry(multiGeometry);
|
|
702 |
} else {
|
|
703 |
feat.setDefaultGeometry(newGeom);
|
|
704 |
}
|
|
705 |
store.insert(feat);
|
|
706 |
return feat;
|
|
707 |
}
|
|
708 |
return null;
|
|
709 |
}
|
|
728 |
//Sets the geometry
|
|
729 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom);
|
|
730 |
if (multiGeometry != null && acceptType(store, multiGeometry)) {
|
|
731 |
feat.setDefaultGeometry(multiGeometry);
|
|
732 |
} else {
|
|
733 |
feat.setDefaultGeometry(newGeom);
|
|
734 |
}
|
|
735 |
store.insert(feat);
|
|
736 |
return feat;
|
|
737 |
}
|
|
738 |
return null;
|
|
739 |
}
|
|
710 | 740 |
|
711 |
/** |
|
712 |
* Adds a DAL feature to the FeatureStore |
|
713 |
* @param entry |
|
714 |
* @param newGeom |
|
715 |
* @throws CreateGeometryException |
|
716 |
* @throws DataException |
|
717 |
*/ |
|
718 |
public EditableFeature addFeature(Feature feature, org.gvsig.fmap.geom.Geometry newGeom) throws CreateGeometryException, DataException { |
|
719 |
if(acceptType(store, newGeom)) { |
|
720 |
EditableFeature feat = store.createNewFeature(store.getDefaultFeatureType(), feature); |
|
721 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom); |
|
722 |
if (multiGeometry!=null && acceptType(store, multiGeometry)){ |
|
723 |
feat.setDefaultGeometry(multiGeometry); |
|
724 |
} else { |
|
725 |
feat.setDefaultGeometry(newGeom); |
|
726 |
} |
|
727 |
store.insert(feat); |
|
728 |
return feat; |
|
729 |
} |
|
730 |
return null; |
|
731 |
} |
|
741 |
/** |
|
742 |
* Adds a DAL feature to the FeatureStore |
|
743 |
* |
|
744 |
* @param entry |
|
745 |
* @param newGeom |
|
746 |
* @throws CreateGeometryException |
|
747 |
* @throws DataException |
|
748 |
*/ |
|
749 |
public EditableFeature addFeature(Feature feature, org.gvsig.fmap.geom.Geometry newGeom) throws CreateGeometryException, DataException { |
|
750 |
if (acceptType(store, newGeom)) { |
|
751 |
EditableFeature feat = store.createNewFeature(store.getDefaultFeatureType(), feature); |
|
752 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom); |
|
753 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
754 |
feat.setDefaultGeometry(multiGeometry); |
|
755 |
} else { |
|
756 |
feat.setDefaultGeometry(newGeom); |
|
757 |
} |
|
758 |
store.insert(feat); |
|
759 |
return feat; |
|
760 |
} |
|
761 |
return null; |
|
762 |
} |
|
732 | 763 |
|
733 |
/** |
|
734 |
* Adds a DAL feature to the FeatureStore |
|
735 |
* @param entry |
|
736 |
* @param newGeom |
|
737 |
* @throws CreateGeometryException |
|
738 |
* @throws DataException |
|
739 |
*/ |
|
740 |
public EditableFeature addGeometryToExistingFeature(EditableFeature feature, org.gvsig.fmap.geom.Geometry newGeom) throws CreateGeometryException, DataException { |
|
741 |
//Y esto para que c... sirve? |
|
742 |
for (String fieldName : fieldNames) { |
|
743 |
feature.set(fieldName, feature.get(fieldName)); |
|
744 |
} |
|
745 |
if(acceptType(store, newGeom)) { |
|
746 |
feature.setGeometry(fieldNames.length, newGeom); |
|
747 |
store.update(feature); |
|
748 |
return feature; |
|
749 |
} |
|
750 |
return null; |
|
751 |
} |
|
764 |
/** |
|
765 |
* Adds a DAL feature to the FeatureStore |
|
766 |
* |
|
767 |
* @param entry |
|
768 |
* @param newGeom |
|
769 |
* @throws CreateGeometryException |
|
770 |
* @throws DataException |
|
771 |
*/ |
|
772 |
public EditableFeature addGeometryToExistingFeature(EditableFeature feature, org.gvsig.fmap.geom.Geometry newGeom) throws CreateGeometryException, DataException { |
|
773 |
//Y esto para que c... sirve? |
|
774 |
for (String fieldName : fieldNames) { |
|
775 |
feature.set(fieldName, feature.get(fieldName)); |
|
776 |
} |
|
777 |
if (acceptType(store, newGeom)) { |
|
778 |
feature.setGeometry(fieldNames.length, newGeom); |
|
779 |
store.update(feature); |
|
780 |
return feature; |
|
781 |
} |
|
782 |
return null; |
|
783 |
} |
|
752 | 784 |
|
753 |
/**
|
|
754 |
* Ends the edition and closes the FeatureStore
|
|
755 |
*/
|
|
756 |
public void end() {
|
|
757 |
try {
|
|
758 |
store.finishEditing();
|
|
759 |
} catch (DataException e) {
|
|
760 |
Sextante.addErrorToLog(e);
|
|
761 |
}
|
|
785 |
/**
|
|
786 |
* Ends the edition and closes the FeatureStore
|
|
787 |
*/
|
|
788 |
public void end() {
|
|
789 |
try {
|
|
790 |
store.finishEditing();
|
|
791 |
} catch (DataException e) {
|
|
792 |
Sextante.addErrorToLog(e);
|
|
793 |
}
|
|
762 | 794 |
// Si destruimos aqui el store ya no estara disponible en el postprocess, |
763 | 795 |
// donde se usa, y se vuelve a destruir. |
764 | 796 |
// store.dispose(); |
765 |
}
|
|
797 |
}
|
|
766 | 798 |
|
767 |
/** |
|
768 |
* Gets the shape type of the selected feature store |
|
769 |
* @param FeatureStore source |
|
770 |
* @return shape type |
|
771 |
* @throws ReadException |
|
772 |
*/ |
|
773 |
@SuppressWarnings("deprecation") |
|
774 |
public int getShapeType(FeatureStore storeLayer1) throws ReadException { |
|
775 |
FeatureType featureType; |
|
776 |
try { |
|
777 |
featureType = storeLayer1.getDefaultFeatureType(); |
|
778 |
} catch (DataException e) { |
|
779 |
throw new ReadException(storeLayer1.getName(), e); |
|
780 |
} |
|
781 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex(); |
|
782 |
return featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
|
783 |
} |
|
799 |
/** |
|
800 |
* Gets the shape type of the selected feature store |
|
801 |
* |
|
802 |
* @param FeatureStore source |
|
803 |
* @return shape type |
|
804 |
* @throws ReadException |
|
805 |
*/ |
|
806 |
@SuppressWarnings("deprecation") |
|
807 |
public int getShapeType(FeatureStore storeLayer1) throws ReadException { |
|
808 |
FeatureType featureType; |
|
809 |
try { |
|
810 |
featureType = storeLayer1.getDefaultFeatureType(); |
|
811 |
} catch (DataException e) { |
|
812 |
throw new ReadException(storeLayer1.getName(), e); |
|
813 |
} |
|
814 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex(); |
|
815 |
return featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
|
816 |
} |
|
784 | 817 |
|
785 |
@SuppressWarnings("deprecation") |
|
786 |
public int getType() { |
|
787 |
if(store == null) |
|
788 |
return org.gvsig.fmap.geom.Geometry.TYPES.NULL; |
|
789 |
FeatureType featureType; |
|
790 |
try { |
|
791 |
featureType = store.getDefaultFeatureType(); |
|
792 |
} catch (DataException e) { |
|
793 |
return org.gvsig.fmap.geom.Geometry.TYPES.NULL; |
|
794 |
} |
|
795 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex(); |
|
796 |
return featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
|
797 |
} |
|
818 |
@SuppressWarnings("deprecation") |
|
819 |
public int getType() { |
|
820 |
if (store == null) { |
|
821 |
return org.gvsig.fmap.geom.Geometry.TYPES.NULL; |
|
822 |
} |
|
823 |
FeatureType featureType; |
|
824 |
try { |
|
825 |
featureType = store.getDefaultFeatureType(); |
|
826 |
} catch (DataException e) { |
|
827 |
return org.gvsig.fmap.geom.Geometry.TYPES.NULL; |
|
828 |
} |
|
829 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex(); |
|
830 |
return featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
|
831 |
} |
|
798 | 832 |
|
799 |
public boolean isCompatibleType(org.gvsig.fmap.geom.Geometry geom) { |
|
800 |
if(store == null) |
|
801 |
return false; |
|
802 |
try { |
|
803 |
return acceptType(store, geom); |
|
804 |
} catch (ReadException e) { |
|
805 |
return false; |
|
806 |
} |
|
807 |
} |
|
833 |
public boolean isCompatibleType(org.gvsig.fmap.geom.Geometry geom) { |
|
834 |
if (store == null) { |
|
835 |
return false; |
|
836 |
} |
|
837 |
try { |
|
838 |
return acceptType(store, geom); |
|
839 |
} catch (ReadException e) { |
|
840 |
return false; |
|
841 |
} |
|
842 |
} |
|
808 | 843 |
|
809 |
/** |
|
810 |
* Gets the output FeatureStore |
|
811 |
* @return |
|
812 |
*/ |
|
813 |
public FeatureStore getOutputFeatureStore() { |
|
814 |
return store; |
|
815 |
} |
|
844 |
/** |
|
845 |
* Gets the output FeatureStore |
|
846 |
* |
|
847 |
* @return |
|
848 |
*/ |
|
849 |
public FeatureStore getOutputFeatureStore() { |
|
850 |
return store; |
|
851 |
} |
|
816 | 852 |
} |
817 |
|
Also available in: Unified diff