Revision 2034
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.274/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.base/src/main/java/org/gvsig/geoprocess/algorithm/base/core/GeometryOperation.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify it under |
|
7 |
* the terms of the GNU General Public License as published by the Free Software |
|
8 |
* Foundation; either version 2 of the License, or (at your option) any later |
|
9 |
* version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
14 |
* details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us at info AT |
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.geoprocess.algorithm.base.core; |
|
24 |
|
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.Iterator; |
|
27 |
import java.util.List; |
|
28 |
|
|
29 |
import org.gvsig.fmap.dal.DataSet; |
|
30 |
import org.gvsig.fmap.dal.exception.DataException; |
|
31 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
32 |
import org.gvsig.fmap.dal.feature.Feature; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
import org.gvsig.geoprocess.core.IProgressModel; |
|
37 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
|
38 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
39 |
import org.gvsig.tools.namestranslator.NamesTranslator; |
|
40 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
41 |
|
|
42 |
/** |
|
43 |
* Each geometry operation have to inherit from this class. |
|
44 |
* |
|
45 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
46 |
*/ |
|
47 |
@SuppressWarnings("deprecation") |
|
48 |
public abstract class GeometryOperation { |
|
49 |
|
|
50 |
protected DALFeaturePersister persister = null; |
|
51 |
protected FeatureStore inFeatureStore = null; |
|
52 |
protected ArrayList<FeatureStore> inFeatureStoreList = null; |
|
53 |
protected int numberOfFeatures = 0; |
|
54 |
protected EditableFeature lastEditFeature = null; |
|
55 |
protected SimpleTaskStatus status = null; |
|
56 |
protected AbstractSextanteGeoProcess process = null; |
|
57 |
protected boolean selectedGeomInput = false; |
|
58 |
protected boolean selectedGeomOverlay = false; |
|
59 |
protected int procesSize = 0; |
|
60 |
|
|
61 |
public GeometryOperation(AbstractSextanteGeoProcess process) { |
|
62 |
this.process = process; |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* Assigns the flag to use only the selected geometries in the overlay layer |
|
67 |
*/ |
|
68 |
public void setSelectedGeomOverlayLayer(boolean setSelected) { |
|
69 |
this.selectedGeomOverlay = setSelected; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Invokes this operation and returns an EditableFeature |
|
74 |
* |
|
75 |
* @param g |
|
76 |
* @param featureInput |
|
77 |
* @return |
|
78 |
*/ |
|
79 |
public abstract EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature featureInput); |
|
80 |
|
|
81 |
/** |
|
82 |
* Invokes this operation |
|
83 |
* |
|
84 |
* @param g |
|
85 |
* @param featureInput |
|
86 |
*/ |
|
87 |
public abstract void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput); |
|
88 |
|
|
89 |
/** |
|
90 |
* Sets the output FeatureType and the input attributes for this feature |
|
91 |
* |
|
92 |
* @param out |
|
93 |
* @throws DataException |
|
94 |
*/ |
|
95 |
public void setFeatureStore(FeatureStore out, String[] attrNames) throws DataException { |
|
96 |
persister = new DALFeaturePersister(out, attrNames, this.process.getNamesTranslator()); |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Gets the last result of this operation |
|
101 |
* |
|
102 |
* @return |
|
103 |
*/ |
|
104 |
public Object getResult() { |
|
105 |
return lastEditFeature; |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Computes a complete operation over the input FeatureStore. The result of |
|
110 |
* this operation is stored in the output FeatureStore. This method will |
|
111 |
* call once for each geometry. |
|
112 |
* |
|
113 |
* @param inFeatStore Input FeatureStore |
|
114 |
* @param outFeatStore Output FeatureStore |
|
115 |
* @param attrNames List of attributes to build the output feature store |
|
116 |
* @param selectedGeom If it is true only the selected geometries will be |
|
117 |
* processed |
|
118 |
* @throws DataException |
|
119 |
*/ |
|
120 |
@SuppressWarnings({"unchecked"}) |
|
121 |
public void computesGeometryOperation(FeatureStore inFeatStore, |
|
122 |
FeatureStore outFeatStore, |
|
123 |
String[] attrNames, |
|
124 |
boolean selectedGeomInput, |
|
125 |
boolean selectedGeomOverlay, |
|
126 |
boolean closeOutStore) throws DataException { |
|
127 |
this.inFeatureStore = inFeatStore; |
|
128 |
FeatureSet featuresSet = null; |
|
129 |
this.selectedGeomInput = selectedGeomInput; |
|
130 |
this.selectedGeomOverlay = selectedGeomOverlay; |
|
131 |
if (outFeatStore != null) { |
|
132 |
setFeatureStore(outFeatStore, attrNames); |
|
133 |
} |
|
134 |
Iterator it = null; |
|
135 |
|
|
136 |
if (this.selectedGeomInput) { |
|
137 |
featuresSet = (FeatureSet) inFeatStore.getSelection(); |
|
138 |
} else { |
|
139 |
featuresSet = inFeatStore.getFeatureSet(); |
|
140 |
} |
|
141 |
|
|
142 |
it = featuresSet.iterator(); |
|
143 |
numberOfFeatures = (int) featuresSet.getSize(); |
|
144 |
if (status != null && process != null) { |
|
145 |
status.setRangeOfValues(0, numberOfFeatures); |
|
146 |
process.setProgress(0, numberOfFeatures); |
|
147 |
} |
|
148 |
|
|
149 |
int iCount = 0; |
|
150 |
while (it.hasNext() && !process.getTaskMonitor().isCanceled()) { |
|
151 |
Feature feature = (Feature) it.next(); |
|
152 |
List geomList = feature.getGeometries(); |
|
153 |
|
|
154 |
if (status != null && process != null) { |
|
155 |
status.setCurValue(iCount); |
|
156 |
process.setProgress(iCount, numberOfFeatures); |
|
157 |
} |
|
158 |
iCount++; |
|
159 |
|
|
160 |
if (geomList == null) { |
|
161 |
org.gvsig.fmap.geom.Geometry geom = feature.getDefaultGeometry(); |
|
162 |
if(geom!=null){ |
|
163 |
invoke(geom, feature); |
|
164 |
} |
|
165 |
continue; |
|
166 |
} |
|
167 |
|
|
168 |
Iterator<org.gvsig.fmap.geom.Geometry> itGeom = geomList.iterator(); |
|
169 |
boolean first = true; |
|
170 |
EditableFeature editFeat = null; |
|
171 |
while (itGeom.hasNext() && !process.getTaskMonitor().isCanceled()) { |
|
172 |
org.gvsig.fmap.geom.Geometry g = itGeom.next(); |
|
173 |
if (first) { |
|
174 |
editFeat = invoke(g, feature); |
|
175 |
first = false; |
|
176 |
} else { |
|
177 |
invoke(g, editFeat); |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
process.setProgress(iCount, numberOfFeatures); |
|
182 |
|
|
183 |
if (closeOutStore && persister != null) { |
|
184 |
persister.end(); |
|
185 |
} |
|
186 |
|
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
190 |
* Computes a complete operation over the input FeatureStore. The result of |
|
191 |
* this operation is stored in the output FeatureStore. This method will |
|
192 |
* call once for each feature. |
|
193 |
* |
|
194 |
* @param inFeatStore Input FeatureStore |
|
195 |
* @param outFeatStore Output FeatureStore |
|
196 |
* @param attrNames List of attributes to build the output feature store |
|
197 |
* @param selectedGeom If it is true only the selected geometries will be |
|
198 |
* processed |
|
199 |
* @throws DataException |
|
200 |
*/ |
|
201 |
public void computesFeatureOperation(FeatureStore inFeatStore, |
|
202 |
FeatureStore outFeatStore, |
|
203 |
String[] attrNames, |
|
204 |
boolean selectedGeomInput, |
|
205 |
boolean selectedGeomOverlay, |
|
206 |
boolean closeOutStore) throws DataException { |
|
207 |
this.inFeatureStore = inFeatStore; |
|
208 |
FeatureSet featuresSet = null; |
|
209 |
featuresSet = inFeatStore.getFeatureSet(); |
|
210 |
this.selectedGeomInput = selectedGeomInput; |
|
211 |
this.selectedGeomOverlay = selectedGeomOverlay; |
|
212 |
|
|
213 |
if (outFeatStore != null) { |
|
214 |
setFeatureStore(outFeatStore, attrNames); |
|
215 |
} |
|
216 |
DisposableIterator it = null; |
|
217 |
|
|
218 |
if (this.selectedGeomInput) { |
|
219 |
DataSet ds = inFeatStore.getSelection(); |
|
220 |
it = ((FeatureSelection) ds).fastIterator(); |
|
221 |
} else { |
|
222 |
it = featuresSet.fastIterator(); |
|
223 |
} |
|
224 |
numberOfFeatures = (int) featuresSet.getSize(); |
|
225 |
|
|
226 |
if (status != null && process != null) { |
|
227 |
status.setRangeOfValues(0, numberOfFeatures); |
|
228 |
process.setProgress(0, numberOfFeatures); |
|
229 |
} |
|
230 |
|
|
231 |
int iCount = 0; |
|
232 |
while (it.hasNext() && !process.getTaskMonitor().isCanceled()) { |
|
233 |
Feature feature = (Feature) it.next(); |
|
234 |
invoke(null, feature); |
|
235 |
if (status != null && process != null) { |
|
236 |
status.setCurValue(iCount); |
|
237 |
process.setProgress(iCount, numberOfFeatures); |
|
238 |
} |
|
239 |
iCount++; |
|
240 |
} |
|
241 |
|
|
242 |
if (closeOutStore && persister != null) { |
|
243 |
persister.end(); |
|
244 |
} |
|
245 |
} |
|
246 |
|
|
247 |
/** |
|
248 |
* Computes a complete operation over the input list of FeatureStore. The |
|
249 |
* result of this operation is stored in the output FeatureStore. This |
|
250 |
* method will call once for each geometry. |
|
251 |
* |
|
252 |
* @param inFeatStoreList Input FeatureStore list |
|
253 |
* @param outFeatStore Output FeatureStore |
|
254 |
* @param attrNames List of attributes to build the output feature store |
|
255 |
* @param selectedGeom If it is true only the selected geometries will be |
|
256 |
* processed |
|
257 |
* @throws DataException |
|
258 |
*/ |
|
259 |
public void computesGeometryOperationInAList(ArrayList<FeatureStore> inFeatStoreList, |
|
260 |
FeatureStore outFeatStore, |
|
261 |
String[] attrNames, |
|
262 |
boolean selectedGeomInput, |
|
263 |
boolean selectedGeomOverlay, |
|
264 |
boolean closeOutStore) throws DataException { |
|
265 |
this.inFeatureStoreList = inFeatStoreList; |
|
266 |
this.selectedGeomInput = selectedGeomInput; |
|
267 |
this.selectedGeomOverlay = selectedGeomOverlay; |
|
268 |
|
|
269 |
if (status != null && process != null) { |
|
270 |
status.setRangeOfValues(0, inFeatStoreList.size()); |
|
271 |
process.setProgress(0, inFeatStoreList.size()); |
|
272 |
} |
|
273 |
|
|
274 |
int iCount = 0; |
|
275 |
for (int i = 0; i < inFeatStoreList.size(); i++) { |
|
276 |
if (status != null && process != null) { |
|
277 |
status.setCurValue(iCount); |
|
278 |
process.setProgress(iCount, numberOfFeatures); |
|
279 |
} |
|
280 |
iCount++; |
|
281 |
computesGeometryOperation(inFeatStoreList.get(i), |
|
282 |
i == 0 ? outFeatStore : null, |
|
283 |
attrNames, |
|
284 |
selectedGeomInput, |
|
285 |
selectedGeomOverlay, |
|
286 |
false); |
|
287 |
if (process.getTaskMonitor().isCanceled()) { |
|
288 |
return; |
|
289 |
} |
|
290 |
} |
|
291 |
|
|
292 |
if (closeOutStore && persister != null) { |
|
293 |
persister.end(); |
|
294 |
} |
|
295 |
} |
|
296 |
|
|
297 |
/** |
|
298 |
* Ends the edition and closes the FeatureStore |
|
299 |
* |
|
300 |
* @deprecated |
|
301 |
*/ |
|
302 |
public void end() { |
|
303 |
persister.end(); |
|
304 |
} |
|
305 |
|
|
306 |
/** |
|
307 |
* @deprecated use {@link #setTaskStatus(SimpleTaskStatus)} instead. |
|
308 |
*/ |
|
309 |
public void setProgressModel(IProgressModel pModel) { |
|
310 |
// Ignore |
|
311 |
} |
|
312 |
|
|
313 |
public void setTaskStatus(SimpleTaskStatus status) { |
|
314 |
this.status = status; |
|
315 |
} |
|
316 |
|
|
317 |
public void setGeoProcess(AbstractSextanteGeoProcess geoprocess, int size) { |
|
318 |
this.process = geoprocess; |
|
319 |
this.procesSize = size; |
|
320 |
} |
|
321 |
|
|
322 |
} |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.274/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.base/src/main/java/org/gvsig/geoprocess/algorithm/base/core/DALFeaturePersister.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 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 |
package org.gvsig.geoprocess.algorithm.base.core; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.List; |
|
28 |
|
|
29 |
import org.gvsig.fmap.dal.exception.DataException; |
|
30 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
31 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
32 |
import org.gvsig.fmap.dal.feature.Feature; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
36 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
37 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
38 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
39 |
import org.gvsig.fmap.geom.GeometryManager; |
|
40 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
41 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
42 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
|
43 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
44 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
45 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
|
46 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
47 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
48 |
import org.gvsig.fmap.geom.operation.fromjts.FromJTS; |
|
49 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
50 |
import org.gvsig.fmap.geom.primitive.Point; |
|
51 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
52 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
53 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
54 |
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil; |
|
55 |
|
|
56 |
import com.vividsolutions.jts.geom.Geometry; |
|
57 |
import com.vividsolutions.jts.geom.GeometryCollection; |
|
58 |
|
|
59 |
import es.unex.sextante.core.Sextante; |
|
60 |
import org.gvsig.fmap.dal.DataStore; |
|
61 |
import org.gvsig.fmap.dal.DataTypes; |
|
62 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
63 |
import org.gvsig.tools.namestranslator.NamesTranslator; |
|
64 |
import org.slf4j.Logger; |
|
65 |
import org.slf4j.LoggerFactory; |
|
66 |
|
|
67 |
/** |
|
68 |
* Writes features in a FeatureStore |
|
69 |
* |
|
70 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
71 |
*/ |
|
72 |
public class DALFeaturePersister { |
|
73 |
|
|
74 |
private FeatureStore store = null; |
|
75 |
private String[] fieldNames = null; |
|
76 |
private GeometryManager geometryManager = null; |
|
77 |
private NamesTranslator namesTranslator = null; |
|
78 |
|
|
79 |
private static final Logger LOGGER = LoggerFactory.getLogger(DALFeaturePersister.class); |
|
80 |
|
|
81 |
/** |
|
82 |
* Sets the output FeatureType |
|
83 |
* |
|
84 |
* @param out |
|
85 |
* @throws DataException |
|
86 |
*/ |
|
87 |
public DALFeaturePersister(FeatureStore out, String[] fieldNames, NamesTranslator namesTranslator) { |
|
88 |
this(out, fieldNames); |
|
89 |
this.namesTranslator = namesTranslator; |
|
90 |
} |
|
91 |
|
|
92 |
public DALFeaturePersister(FeatureStore out, String[] fieldNames) { |
|
93 |
this.store = out; |
|
94 |
this.fieldNames = fieldNames; |
|
95 |
this.namesTranslator = null; |
|
96 |
try { |
|
97 |
if (store.getMode() == FeatureStore.MODE_QUERY) { |
|
98 |
store.edit(); |
|
99 |
} |
|
100 |
} catch (Exception e) { |
|
101 |
LOGGER.warn("Can't enter in edit mode. store = "+DataStore.getFullNameQuietly(store)); |
|
102 |
} |
|
103 |
geometryManager = GeometryLocator.getGeometryManager(); |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* Gets the list of field names |
|
108 |
* |
|
109 |
* @return |
|
110 |
*/ |
|
111 |
public String[] getFieldNames() { |
|
112 |
try { |
|
113 |
FeatureAttributeDescriptor[] attrs = store.getDefaultFeatureType().getAttributeDescriptors(); |
|
114 |
String[] fieldNames = new String[attrs.length]; |
|
115 |
for (int i = 0; i < attrs.length; i++) { |
|
116 |
fieldNames[i] = attrs[i].getName(); |
|
117 |
} |
|
118 |
return fieldNames; |
|
119 |
} catch (DataException e) { |
|
120 |
Sextante.addErrorToLog(e); |
|
121 |
} |
|
122 |
return null; |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Gets the list of field names |
|
127 |
* |
|
128 |
* @return |
|
129 |
*/ |
|
130 |
public String[] getFieldNamesWithoutGeom() { |
|
131 |
try { |
|
132 |
FeatureAttributeDescriptor[] attrs = store.getDefaultFeatureType().getAttributeDescriptors(); |
|
133 |
int nFields = attrs.length; |
|
134 |
for (int j = 0; j < nFields; j++) { |
|
135 |
if (attrs[j].getName().compareTo("GEOMETRY") == 0) { |
|
136 |
nFields--; |
|
137 |
break; |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
int cont = 0; |
|
142 |
String[] fieldNames = new String[nFields]; |
|
143 |
for (int i = 0; i < attrs.length; i++) { |
|
144 |
if (attrs[i].getName().compareTo("GEOMETRY") != 0) { |
|
145 |
fieldNames[cont] = attrs[i].getName(); |
|
146 |
cont++; |
|
147 |
} |
|
148 |
} |
|
149 |
return fieldNames; |
|
150 |
} catch (DataException e) { |
|
151 |
Sextante.addErrorToLog(e); |
|
152 |
} |
|
153 |
return null; |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* Adds a JTS feature to the FeatureStore |
|
158 |
* |
|
159 |
* @param entry |
|
160 |
* @param newGeom |
|
161 |
* @throws CreateGeometryException |
|
162 |
* @throws DataException |
|
163 |
*/ |
|
164 |
public EditableFeature addFeature(Feature feature1, Feature feature2, Geometry newGeom) |
|
165 |
throws CreateGeometryException, DataException { |
|
166 |
|
|
167 |
int outPutType = getOutputFeatureStore().getDefaultFeatureType() |
|
168 |
.getDefaultGeometryAttribute().getGeomType().getType(); |
|
169 |
|
|
170 |
//Si el objeto que viene es un GeometryCollection hay que convertirlo a una lista de geometrias |
|
171 |
//solo del tipo que pueda salvarse en la capa eliminando el resto. Esto sucede sobre todo en la intersecci?n |
|
172 |
//que devuelve tipos mezclados. Cada uno debe salvarse en el tipo de capa de salida apropiado |
|
173 |
ArrayList<org.gvsig.fmap.geom.Geometry> dalGeomList = null; |
|
174 |
try { |
|
175 |
dalGeomList = convertGeometryCollection2GeometryList(newGeom, outPutType); |
|
176 |
} catch (GeometryOperationNotSupportedException e1) { |
|
177 |
Sextante.addErrorToLog(e1); |
|
178 |
} catch (GeometryOperationException e1) { |
|
179 |
Sextante.addErrorToLog(e1); |
|
180 |
} |
|
181 |
org.gvsig.fmap.geom.Geometry newDalGeom = null; |
|
182 |
|
|
183 |
//Si lo que venia no era un GeometryCollection se convierte a geometr?a de DAL |
|
184 |
if (dalGeomList == null) { |
|
185 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
186 |
ctx.setAttribute(FromJTS.PARAM, newGeom); |
|
187 |
try { |
|
188 |
newDalGeom = (org.gvsig.fmap.geom.Geometry) geometryManager.invokeOperation(FromJTS.NAME, ctx); |
|
189 |
} catch (GeometryOperationNotSupportedException e) { |
|
190 |
Sextante.addErrorToLog(e); |
|
191 |
return null; |
|
192 |
} catch (GeometryOperationException e) { |
|
193 |
Sextante.addErrorToLog(e); |
|
194 |
return null; |
|
195 |
} |
|
196 |
} |
|
197 |
|
|
198 |
EditableFeature feat = store.createNewFeature(); |
|
199 |
|
|
200 |
if (namesTranslator != null) { |
|
201 |
for (FeatureAttributeDescriptor attr1 : feature1.getType().getAttributeDescriptors()) { |
|
202 |
String attrName = attr1.getName(); |
|
203 |
String translation = namesTranslator.getTranslation(attrName); |
|
204 |
Object fValue = feature1.get(attrName); |
|
205 |
if (translation != null && !translation.isEmpty()) { |
|
206 |
feat.set(translation, fValue); |
|
207 |
} |
|
208 |
} |
|
209 |
for (FeatureAttributeDescriptor attr2 : feature2.getType().getAttributeDescriptors()) { |
|
210 |
String attrName = attr2.getName(); |
|
211 |
List<String> translation = namesTranslator.getAllTranslations(attrName); |
|
212 |
Object fValue = feature2.get(attrName); |
|
213 |
if (translation != null && !translation.isEmpty()) { |
|
214 |
feat.set(translation.get(translation.size() - 1), fValue); |
|
215 |
} |
|
216 |
} |
|
217 |
} else { |
|
218 |
feat.copyFrom(feature1); |
|
219 |
feat.copyFrom(feature2); |
|
220 |
} |
|
221 |
|
|
222 |
if (newDalGeom != null && acceptType(store, newDalGeom)) { |
|
223 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
|
224 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
225 |
feat.setDefaultGeometry(multiGeometry); |
|
226 |
} else { |
|
227 |
feat.setDefaultGeometry(newDalGeom); |
|
228 |
} |
|
229 |
store.insert(feat); |
|
230 |
return feat; |
|
231 |
} else if (dalGeomList != null) { |
|
232 |
for (int i = 0; i < dalGeomList.size(); i++) { |
|
233 |
if (acceptType(store, dalGeomList.get(i))) { |
|
234 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(dalGeomList.get(i)); |
|
235 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
236 |
feat.setDefaultGeometry(multiGeometry); |
|
237 |
} else { |
|
238 |
feat.setDefaultGeometry(dalGeomList.get(i)); |
|
239 |
} |
|
240 |
store.insert(feat); |
|
241 |
} |
|
242 |
} |
|
243 |
return feat; |
|
244 |
} |
|
245 |
return null; |
|
246 |
} |
|
247 |
|
|
248 |
public EditableFeature addFeature(Feature feature1, Feature feature2, org.gvsig.fmap.geom.Geometry newDalGeom) |
|
249 |
throws CreateGeometryException, DataException { |
|
250 |
EditableFeature feat = store.createNewFeature(); |
|
251 |
|
|
252 |
if (namesTranslator != null) { |
|
253 |
for (FeatureAttributeDescriptor attr1 : feature1.getType().getAttributeDescriptors()) { |
|
254 |
String attrName = attr1.getName(); |
|
255 |
String translation = namesTranslator.getTranslation(attrName); |
|
256 |
Object fValue = feature1.get(attrName); |
|
257 |
if (translation != null && !translation.isEmpty()) { |
|
258 |
feat.set(translation, fValue); |
|
259 |
} |
|
260 |
} |
|
261 |
for (FeatureAttributeDescriptor attr2 : feature2.getType().getAttributeDescriptors()) { |
|
262 |
String attrName = attr2.getName(); |
|
263 |
List<String> translation = namesTranslator.getAllTranslations(attrName); |
|
264 |
Object fValue = feature2.get(attrName); |
|
265 |
if (translation != null && !translation.isEmpty()) { |
|
266 |
feat.set(translation.get(translation.size() - 1), fValue); |
|
267 |
} |
|
268 |
} |
|
269 |
} else { |
|
270 |
feat.copyFrom(feature1); |
|
271 |
feat.copyFrom(feature2); |
|
272 |
} |
|
273 |
|
|
274 |
if (newDalGeom != null && acceptType(store, newDalGeom)) { |
|
275 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
|
276 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
277 |
feat.setDefaultGeometry(multiGeometry); |
|
278 |
} else { |
|
279 |
feat.setDefaultGeometry(newDalGeom); |
|
280 |
} |
|
281 |
store.insert(feat); |
|
282 |
return feat; |
|
283 |
} |
|
284 |
return null; |
|
285 |
} |
|
286 |
|
|
287 |
/** |
|
288 |
* Converts a geometry collection from JTS to a list of geometries of the |
|
289 |
* selected type.The GeometryCollection is converted only when it is a |
|
290 |
* heterogeneous collection of geometries |
|
291 |
* |
|
292 |
* @param type |
|
293 |
* @return |
|
294 |
* @throws GeometryOperationException |
|
295 |
* @throws GeometryOperationNotSupportedException |
|
296 |
*/ |
|
297 |
public ArrayList<org.gvsig.fmap.geom.Geometry> convertGeometryCollection2GeometryList(Geometry g, int type) throws GeometryOperationNotSupportedException, GeometryOperationException { |
|
298 |
if (g instanceof GeometryCollection |
|
299 |
&& !(g instanceof com.vividsolutions.jts.geom.MultiLineString) |
|
300 |
&& !(g instanceof com.vividsolutions.jts.geom.MultiPoint) |
|
301 |
&& !(g instanceof com.vividsolutions.jts.geom.MultiPolygon)) { |
|
302 |
GeometryCollection col = (GeometryCollection) g; |
|
303 |
ArrayList<org.gvsig.fmap.geom.Geometry> geometries = new ArrayList<org.gvsig.fmap.geom.Geometry>(); |
|
304 |
|
|
305 |
if (GeometryUtils.isSubtype(TYPES.POINT, type) || GeometryUtils.isSubtype(TYPES.MULTIPOINT, type)) { |
|
306 |
for (int i = 0; i < col.getNumGeometries(); i++) { |
|
307 |
Geometry gx = col.getGeometryN(i); |
|
308 |
if (gx instanceof com.vividsolutions.jts.geom.Point |
|
309 |
|| gx instanceof com.vividsolutions.jts.geom.MultiPoint) { |
|
310 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
311 |
ctx.setAttribute(FromJTS.PARAM, gx); |
|
312 |
org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry) geometryManager.invokeOperation(FromJTS.NAME, ctx); |
|
313 |
geometries.add(newDalGeom); |
|
314 |
} |
|
315 |
} |
|
316 |
} |
|
317 |
|
|
318 |
if (GeometryUtils.isSubtype(TYPES.CURVE, type) || GeometryUtils.isSubtype(TYPES.MULTICURVE, type)) { |
|
319 |
for (int i = 0; i < col.getNumGeometries(); i++) { |
|
320 |
Geometry gx = col.getGeometryN(i); |
|
321 |
if (gx instanceof com.vividsolutions.jts.geom.LineString |
|
322 |
|| gx instanceof com.vividsolutions.jts.geom.MultiLineString) { |
|
323 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
324 |
ctx.setAttribute(FromJTS.PARAM, gx); |
|
325 |
org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry) geometryManager.invokeOperation(FromJTS.NAME, ctx); |
|
326 |
geometries.add(newDalGeom); |
|
327 |
} |
|
328 |
} |
|
329 |
} |
|
330 |
if (GeometryUtils.isSubtype(TYPES.SURFACE, type) || GeometryUtils.isSubtype(TYPES.MULTISURFACE, type)) { |
|
331 |
for (int i = 0; i < col.getNumGeometries(); i++) { |
|
332 |
Geometry gx = col.getGeometryN(i); |
|
333 |
if (gx instanceof com.vividsolutions.jts.geom.Polygon |
|
334 |
|| gx instanceof com.vividsolutions.jts.geom.MultiPolygon) { |
|
335 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
336 |
ctx.setAttribute(FromJTS.PARAM, gx); |
|
337 |
org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry) geometryManager.invokeOperation(FromJTS.NAME, ctx); |
|
338 |
geometries.add(newDalGeom); |
|
339 |
} |
|
340 |
} |
|
341 |
} |
|
342 |
return geometries; |
|
343 |
} |
|
344 |
return null; |
|
345 |
} |
|
346 |
|
|
347 |
/** |
|
348 |
* Converts a geometry into a multigeometry |
|
349 |
* |
|
350 |
* @param g |
|
351 |
* @return |
|
352 |
* @throws CreateGeometryException |
|
353 |
*/ |
|
354 |
private org.gvsig.fmap.geom.Geometry convertGeometryList2MultiGeometry(List<org.gvsig.fmap.geom.Geometry> list) throws CreateGeometryException { |
|
355 |
if (list.size() == 0) { |
|
356 |
return null; |
|
357 |
} |
|
358 |
MultiPrimitive primitive = null; |
|
359 |
|
|
360 |
if (list.get(0) instanceof Point || list.get(0) instanceof MultiPoint) { |
|
361 |
primitive = (MultiPrimitive) geometryManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D); |
|
362 |
} |
|
363 |
if (list.get(0) instanceof Curve || list.get(0) instanceof MultiCurve) { |
|
364 |
primitive = (MultiPrimitive) geometryManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D); |
|
365 |
} |
|
366 |
if (list.get(0) instanceof Surface || list.get(0) instanceof MultiSurface) { |
|
367 |
primitive = (MultiPrimitive) geometryManager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D); |
|
368 |
} |
|
369 |
|
|
370 |
for (int i = 0; i < list.size(); i++) { |
|
371 |
org.gvsig.fmap.geom.Geometry geom = list.get(i); |
|
372 |
if (geom instanceof MultiPrimitive) { |
|
373 |
MultiPrimitive multi = (MultiPrimitive) geom; |
|
374 |
for (int j = 0; j < multi.getPrimitivesNumber(); j++) { |
|
375 |
primitive.addPrimitive((Primitive) multi.getPrimitiveAt(j)); |
|
376 |
} |
|
377 |
} else { |
|
378 |
primitive.addPrimitive((Primitive) list.get(i)); |
|
379 |
} |
|
380 |
} |
|
381 |
|
|
382 |
return primitive; |
|
383 |
} |
|
384 |
|
|
385 |
/** |
|
386 |
* Converts a geometry into a multigeometry |
|
387 |
* |
|
388 |
* @param g |
|
389 |
* @return |
|
390 |
* @throws CreateGeometryException |
|
391 |
*/ |
|
392 |
private org.gvsig.fmap.geom.Geometry convertGeometry2MultiGeometry(org.gvsig.fmap.geom.Geometry g) throws CreateGeometryException { |
|
393 |
if (g instanceof MultiPrimitive) { |
|
394 |
return g; |
|
395 |
} |
|
396 |
if (g instanceof Point) { |
|
397 |
MultiPoint pNew = (MultiPoint) geometryManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D); |
|
398 |
pNew.addPoint((Point) g); |
|
399 |
return pNew; |
|
400 |
} |
|
401 |
if (g instanceof Curve) { |
|
402 |
MultiCurve cNew = (MultiCurve) geometryManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D); |
|
403 |
cNew.addCurve((Curve) g); |
|
404 |
return cNew; |
|
405 |
} |
|
406 |
if (g instanceof Surface) { |
|
407 |
MultiSurface cNew = (MultiSurface) geometryManager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D); |
|
408 |
cNew.addSurface((Surface) g); |
|
409 |
return cNew; |
|
410 |
} |
|
411 |
return g; |
|
412 |
} |
|
413 |
|
|
414 |
/** |
|
415 |
* Checks if the type of the feature store and the geometry are compatibles. |
|
416 |
* |
|
417 |
* @param store |
|
418 |
* @param geom |
|
419 |
* @return |
|
420 |
* @throws ReadException |
|
421 |
*/ |
|
422 |
private boolean acceptType(FeatureStore store, org.gvsig.fmap.geom.Geometry geom) throws ReadException { |
|
423 |
int fType = getShapeType(store); |
|
424 |
GeometryType geomType = geom.getGeometryType(); |
|
425 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
426 |
|
|
427 |
if (geomManager.isSubtype(fType, geomType.getType())) { |
|
428 |
return true; |
|
429 |
} |
|
430 |
|
|
431 |
if (geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTICURVE, fType) |
|
432 |
&& geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.CURVE, geomType.getType())) { |
|
433 |
return true; |
|
434 |
} |
|
435 |
if (geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTISURFACE, fType) |
|
436 |
&& geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.SURFACE, geomType.getType())) { |
|
437 |
return true; |
|
438 |
} |
|
439 |
if (geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTIPOINT, fType) |
|
440 |
&& geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.POINT, geomType.getType())) { |
|
441 |
return true; |
|
442 |
} |
|
443 |
if (geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTISOLID, fType) |
|
444 |
&& geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.SOLID, geomType.getType())) { |
|
445 |
return true; |
|
446 |
} |
|
447 |
return false; |
|
448 |
} |
|
449 |
|
|
450 |
/** |
|
451 |
* Adds a JTS feature to the FeatureStore |
|
452 |
* |
|
453 |
* @param entry |
|
454 |
* @param newGeom |
|
455 |
* @throws CreateGeometryException |
|
456 |
* @throws DataException |
|
457 |
*/ |
|
458 |
public EditableFeature addFeature(Feature feature, Geometry newGeom) throws CreateGeometryException, DataException { |
|
459 |
int outPutType = getOutputFeatureStore().getDefaultFeatureType() |
|
460 |
.getDefaultGeometryAttribute().getGeomType().getType(); |
|
461 |
//Si el objeto que viene es un GeometryCollection hay que convertirlo a una lista de geometrias |
|
462 |
//solo del tipo que pueda salvarse en la capa eliminando el resto. Esto sucede sobre todo en la intersecci?n |
|
463 |
//que devuelve tipos mezclados. Cada uno debe salvarse en el tipo de capa de salida apropiado |
|
464 |
ArrayList<org.gvsig.fmap.geom.Geometry> dalGeomList = null; |
|
465 |
try { |
|
466 |
dalGeomList = convertGeometryCollection2GeometryList(newGeom, outPutType); |
|
467 |
} catch (GeometryOperationNotSupportedException e1) { |
|
468 |
Sextante.addErrorToLog(e1); |
|
469 |
} catch (GeometryOperationException e1) { |
|
470 |
Sextante.addErrorToLog(e1); |
|
471 |
} |
|
472 |
|
|
473 |
//No era un GeometryCollection |
|
474 |
if (dalGeomList == null) { |
|
475 |
org.gvsig.fmap.geom.Geometry newDalGeom = null; |
|
476 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
477 |
ctx.setAttribute(FromJTS.PARAM, newGeom); |
|
478 |
try { |
|
479 |
newDalGeom = (org.gvsig.fmap.geom.Geometry) geometryManager.invokeOperation(FromJTS.NAME, ctx); |
|
480 |
} catch (GeometryOperationNotSupportedException e) { |
|
481 |
Sextante.addErrorToLog(e); |
|
482 |
} catch (GeometryOperationException e) { |
|
483 |
Sextante.addErrorToLog(e); |
|
484 |
} |
|
485 |
insertFeatureIntoStore(feature, newDalGeom); |
|
486 |
} else { |
|
487 |
for (int i = 0; i < dalGeomList.size(); i++) { |
|
488 |
insertFeatureIntoStore(feature, dalGeomList.get(i)); |
|
489 |
} |
|
490 |
} |
|
491 |
return null; |
|
492 |
} |
|
493 |
|
|
494 |
private EditableFeature insertFeatureIntoStore(Feature feature, org.gvsig.fmap.geom.Geometry newDalGeom) throws DataException { |
|
495 |
if (acceptType(store, newDalGeom)) { |
|
496 |
EditableFeature targetFeature = store.createNewFeature(store.getDefaultFeatureType(), true); |
|
497 |
for (FeatureAttributeDescriptor attrdesc : targetFeature.getType()) { |
|
498 |
if (attrdesc.isComputed()) { |
|
499 |
continue; |
|
500 |
} |
|
501 |
if (attrdesc.getType() == DataTypes.GEOMETRY) { |
|
502 |
continue; |
|
503 |
} |
|
504 |
String name = attrdesc.getName(); |
|
505 |
if (feature.getType().getAttributeDescriptor(name)!=null) { |
|
506 |
Object value = feature.get(name); |
|
507 |
if (value != null) { |
|
508 |
targetFeature.set(name, value); |
|
509 |
} |
|
510 |
} |
|
511 |
} |
|
512 |
org.gvsig.fmap.geom.Geometry multiGeometry = null; |
|
513 |
try { |
|
514 |
multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
|
515 |
} catch (CreateGeometryException e) { |
|
516 |
Sextante.addErrorToLog(e); |
|
517 |
} |
|
518 |
|
|
519 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
520 |
targetFeature.setDefaultGeometry(multiGeometry); |
|
521 |
} else { |
|
522 |
targetFeature.setDefaultGeometry(newDalGeom); |
|
523 |
} |
|
524 |
store.insert(targetFeature); |
|
525 |
return targetFeature; |
|
526 |
} |
|
527 |
return null; |
|
528 |
} |
|
529 |
|
|
530 |
/** |
|
531 |
* Adds a JTS feature to the FeatureStore |
|
532 |
* |
|
533 |
* @param entry |
|
534 |
* @param newGeom |
|
535 |
* @throws CreateGeometryException |
|
536 |
* @throws DataException |
|
537 |
*/ |
|
538 |
public EditableFeature addFeature(Geometry newGeom, int id, double value) throws CreateGeometryException, DataException { |
|
539 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
540 |
|
|
541 |
if (newDalGeom != null && acceptType(store, newDalGeom)) { |
|
542 |
EditableFeature feat = store.createNewFeature(); |
|
543 |
feat.set(0, id); |
|
544 |
feat.set(1, value); |
|
545 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
|
546 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
547 |
feat.setDefaultGeometry(multiGeometry); |
|
548 |
} else { |
|
549 |
feat.setDefaultGeometry(newDalGeom); |
|
550 |
} |
|
551 |
store.insert(feat); |
|
552 |
return feat; |
|
553 |
} |
|
554 |
return null; |
|
555 |
} |
|
556 |
|
|
557 |
/** |
|
558 |
* Adds a JTS feature to the FeatureStore |
|
559 |
* |
|
560 |
* @param entry |
|
561 |
* @param newGeom |
|
562 |
* @throws CreateGeometryException |
|
563 |
* @throws DataException |
|
564 |
*/ |
|
565 |
public EditableFeature addFeature(Feature feature, List<Geometry> newJTSListGeom) throws CreateGeometryException, DataException { |
|
566 |
List<org.gvsig.fmap.geom.Geometry> newDalListGeom = new ArrayList<org.gvsig.fmap.geom.Geometry>(); |
|
567 |
|
|
568 |
for (int i = 0; i < newJTSListGeom.size(); i++) { |
|
569 |
newDalListGeom.add(GeometryUtil.jtsToGeom(newJTSListGeom.get(i))); |
|
570 |
} |
|
571 |
|
|
572 |
org.gvsig.fmap.geom.Geometry newMultiGeom = convertGeometryList2MultiGeometry(newDalListGeom); |
|
573 |
insertFeatureIntoStore(feature, newMultiGeom); |
|
574 |
return null; |
|
575 |
} |
|
576 |
|
|
577 |
/** |
|
578 |
* Adds a JTS feature to the FeatureStore |
|
579 |
* |
|
580 |
* @param entry |
|
581 |
* @param newGeom |
|
582 |
* @throws CreateGeometryException |
|
583 |
* @throws DataException |
|
584 |
*/ |
|
585 |
public EditableFeature addFeature(Geometry newGeom, String name, Object value) throws CreateGeometryException, DataException { |
|
586 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
587 |
|
|
588 |
if (newDalGeom != null && acceptType(store, newDalGeom)) { |
|
589 |
EditableFeature feat = store.createNewFeature(); |
|
590 |
feat.set(name, value); |
|
591 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
|
592 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
593 |
feat.setDefaultGeometry(multiGeometry); |
|
594 |
} else { |
|
595 |
feat.setDefaultGeometry(newDalGeom); |
|
596 |
} |
|
597 |
store.insert(feat); |
|
598 |
return feat; |
|
599 |
} |
|
600 |
return null; |
|
601 |
} |
|
602 |
|
|
603 |
/** |
|
604 |
* Adds a geometry feature to the FeatureStore |
|
605 |
* |
|
606 |
* @param entry |
|
607 |
* @param newGeom |
|
608 |
* @throws CreateGeometryException |
|
609 |
* @throws DataException |
|
610 |
*/ |
|
611 |
public EditableFeature addFeature(org.gvsig.fmap.geom.Geometry newGeom, String name, Object value) throws CreateGeometryException, DataException { |
|
612 |
if (newGeom != null && acceptType(store, newGeom)) { |
|
613 |
EditableFeature feat = store.createNewFeature(); |
|
614 |
feat.set(name, value); |
|
615 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom); |
|
616 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
617 |
feat.setDefaultGeometry(multiGeometry); |
|
618 |
} else { |
|
619 |
feat.setDefaultGeometry(newGeom); |
|
620 |
} |
|
621 |
store.insert(feat); |
|
622 |
return feat; |
|
623 |
} |
|
624 |
return null; |
|
625 |
} |
|
626 |
|
|
627 |
/** |
|
628 |
* Adds a geometry feature to the FeatureStore |
|
629 |
* |
|
630 |
* @param entry |
|
631 |
* @param newGeom |
|
632 |
* @throws CreateGeometryException |
|
633 |
* @throws DataException |
|
634 |
*/ |
|
635 |
public EditableFeature addFeature(org.gvsig.fmap.geom.Geometry newGeom, ArrayList<String> names, ArrayList<Object> values) throws CreateGeometryException, DataException { |
|
636 |
if (newGeom != null && acceptType(store, newGeom)) { |
|
637 |
EditableFeature feat = store.createNewFeature(); |
|
638 |
for (int i = 0; i < values.size(); i++) { |
|
639 |
feat.set(names.get(i), values.get(i)); |
|
640 |
} |
|
641 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom); |
|
642 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
643 |
feat.setDefaultGeometry(multiGeometry); |
|
644 |
} else { |
|
645 |
feat.setDefaultGeometry(newGeom); |
|
646 |
} |
|
647 |
store.insert(feat); |
|
648 |
return feat; |
|
649 |
} |
|
650 |
return null; |
|
651 |
} |
|
652 |
|
|
653 |
/** |
|
654 |
* Adds a JTS feature to the FeatureStore |
|
655 |
* |
|
656 |
* @param entry |
|
657 |
* @param newGeom |
|
658 |
* @throws CreateGeometryException |
|
659 |
* @throws DataException |
|
660 |
*/ |
|
661 |
public EditableFeature addFeature(Geometry newGeom, ArrayList<String> names, ArrayList<Object> values) throws CreateGeometryException, DataException { |
|
662 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
663 |
|
|
664 |
if (newDalGeom != null && acceptType(store, newDalGeom)) { |
|
665 |
EditableFeature feat = store.createNewFeature(); |
|
666 |
for (int i = 0; i < values.size(); i++) { |
|
667 |
feat.set(names.get(i), values.get(i)); |
|
668 |
} |
|
669 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
|
670 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
671 |
feat.setDefaultGeometry(multiGeometry); |
|
672 |
} else { |
|
673 |
feat.setDefaultGeometry(newDalGeom); |
|
674 |
} |
|
675 |
store.insert(feat); |
|
676 |
return feat; |
|
677 |
} |
|
678 |
return null; |
|
679 |
} |
|
680 |
|
|
681 |
/** |
|
682 |
* Adds a JTS feature to the FeatureStore |
|
683 |
* |
|
684 |
* @param entry |
|
685 |
* @param newGeom |
|
686 |
* @throws CreateGeometryException |
|
687 |
* @throws DataException |
|
688 |
*/ |
|
689 |
public EditableFeature addFeature(Geometry newGeom, int id, double value1, double value2) throws CreateGeometryException, DataException { |
|
690 |
org.gvsig.fmap.geom.Geometry newDalGeom = GeometryUtil.jtsToGeom(newGeom); |
|
691 |
|
|
692 |
if (newDalGeom != null && acceptType(store, newDalGeom)) { |
|
693 |
EditableFeature feat = store.createNewFeature(); |
|
694 |
feat.set(0, id); |
|
695 |
feat.set(1, value1); |
|
696 |
feat.set(2, value2); |
|
697 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newDalGeom); |
|
698 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
699 |
feat.setDefaultGeometry(multiGeometry); |
|
700 |
} else { |
|
701 |
feat.setDefaultGeometry(newDalGeom); |
|
702 |
} |
|
703 |
store.insert(feat); |
|
704 |
return feat; |
|
705 |
} |
|
706 |
return null; |
|
707 |
} |
|
708 |
|
|
709 |
/** |
|
710 |
* Adds a DAL feature to the FeatureStore when the field structure in the |
|
711 |
* new feature is different to the source field structure. |
|
712 |
* |
|
713 |
* @param entry |
|
714 |
* @param newGeom |
|
715 |
* @throws CreateGeometryException |
|
716 |
* @throws DataException |
|
717 |
*/ |
|
718 |
public EditableFeature addDifferentFieldFeature(Feature feature, org.gvsig.fmap.geom.Geometry newGeom) throws CreateGeometryException, DataException { |
|
719 |
if (acceptType(store, newGeom)) { |
|
720 |
//Builds a new empty feature |
|
721 |
EditableFeature feat = store.createNewFeature(store.getDefaultFeatureType(), true); |
|
722 |
|
|
723 |
feat.copyFrom(feature); |
|
724 |
|
|
725 |
//Sets the geometry |
|
726 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom); |
|
727 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
728 |
feat.setDefaultGeometry(multiGeometry); |
|
729 |
} else { |
|
730 |
feat.setDefaultGeometry(newGeom); |
|
731 |
} |
|
732 |
store.insert(feat); |
|
733 |
return feat; |
|
734 |
} |
|
735 |
return null; |
|
736 |
} |
|
737 |
|
|
738 |
/** |
|
739 |
* Adds a DAL feature to the FeatureStore |
|
740 |
* |
|
741 |
* @param entry |
|
742 |
* @param newGeom |
|
743 |
* @throws CreateGeometryException |
|
744 |
* @throws DataException |
|
745 |
*/ |
|
746 |
public EditableFeature addFeature(Feature feature, org.gvsig.fmap.geom.Geometry newGeom) throws CreateGeometryException, DataException { |
|
747 |
if (acceptType(store, newGeom)) { |
|
748 |
EditableFeature feat = store.createNewFeature(store.getDefaultFeatureType(), feature); |
|
749 |
org.gvsig.fmap.geom.Geometry multiGeometry = convertGeometry2MultiGeometry(newGeom); |
|
750 |
if (multiGeometry != null && acceptType(store, multiGeometry)) { |
|
751 |
feat.setDefaultGeometry(multiGeometry); |
|
752 |
} else { |
|
753 |
feat.setDefaultGeometry(newGeom); |
|
754 |
} |
|
755 |
store.insert(feat); |
|
756 |
return feat; |
|
757 |
} |
|
758 |
return null; |
|
759 |
} |
|
760 |
|
|
761 |
/** |
|
762 |
* Adds a DAL feature to the FeatureStore |
|
763 |
* |
|
764 |
* @param entry |
|
765 |
* @param newGeom |
|
766 |
* @throws CreateGeometryException |
|
767 |
* @throws DataException |
|
768 |
*/ |
|
769 |
public EditableFeature addGeometryToExistingFeature(EditableFeature feature, org.gvsig.fmap.geom.Geometry newGeom) throws CreateGeometryException, DataException { |
|
770 |
//Y esto para que c... sirve? |
|
771 |
for (String fieldName : fieldNames) { |
|
772 |
feature.set(fieldName, feature.get(fieldName)); |
|
773 |
} |
|
774 |
if (acceptType(store, newGeom)) { |
|
775 |
feature.setDefaultGeometry(newGeom); |
|
776 |
store.update(feature); |
|
777 |
return feature; |
|
778 |
} |
|
779 |
return null; |
|
780 |
} |
|
781 |
|
|
782 |
/** |
|
783 |
* Ends the edition and closes the FeatureStore |
|
784 |
*/ |
|
785 |
public void end() { |
|
786 |
try { |
|
787 |
store.finishEditing(); |
|
788 |
} catch (DataException e) { |
|
789 |
Sextante.addErrorToLog(e); |
|
790 |
} |
|
791 |
// Si destruimos aqui el store ya no estara disponible en el postprocess, |
|
792 |
// donde se usa, y se vuelve a destruir. |
|
793 |
// store.dispose(); |
|
794 |
} |
|
795 |
|
|
796 |
/** |
|
797 |
* Gets the shape type of the selected feature store |
|
798 |
* |
|
799 |
* @param FeatureStore source |
|
800 |
* @return shape type |
|
801 |
* @throws ReadException |
|
802 |
*/ |
|
803 |
@SuppressWarnings("deprecation") |
|
804 |
public int getShapeType(FeatureStore storeLayer1) throws ReadException { |
|
805 |
FeatureType featureType; |
|
806 |
try { |
|
807 |
featureType = storeLayer1.getDefaultFeatureType(); |
|
808 |
} catch (DataException e) { |
|
809 |
throw new ReadException(storeLayer1.getName(), e); |
|
810 |
} |
|
811 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex(); |
|
812 |
return featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
|
813 |
} |
|
814 |
|
|
815 |
@SuppressWarnings("deprecation") |
|
816 |
public int getType() { |
|
817 |
if (store == null) { |
|
818 |
return org.gvsig.fmap.geom.Geometry.TYPES.NULL; |
|
819 |
} |
|
820 |
FeatureType featureType; |
|
821 |
try { |
|
822 |
featureType = store.getDefaultFeatureType(); |
|
823 |
} catch (DataException e) { |
|
824 |
return org.gvsig.fmap.geom.Geometry.TYPES.NULL; |
|
825 |
} |
|
826 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex(); |
|
827 |
return featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
|
828 |
} |
|
829 |
|
|
830 |
public boolean isCompatibleType(org.gvsig.fmap.geom.Geometry geom) { |
|
831 |
if (store == null) { |
|
832 |
return false; |
|
833 |
} |
|
834 |
try { |
|
835 |
return acceptType(store, geom); |
|
836 |
} catch (ReadException e) { |
|
837 |
return false; |
|
838 |
} |
|
839 |
} |
|
840 |
|
|
841 |
/** |
|
842 |
* Gets the output FeatureStore |
|
843 |
* |
|
844 |
* @return |
|
845 |
*/ |
|
846 |
public FeatureStore getOutputFeatureStore() { |
|
847 |
return store; |
|
848 |
} |
|
849 |
} |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.274/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.base/src/main/java/org/gvsig/geoprocess/algorithm/base/core/AlgorithmAbstractLibrary.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 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 |
package org.gvsig.geoprocess.algorithm.base.core; |
|
25 |
|
|
26 |
import java.util.Enumeration; |
|
27 |
import java.util.HashMap; |
|
28 |
import java.util.Locale; |
|
29 |
import java.util.Map; |
|
30 |
import java.util.MissingResourceException; |
|
31 |
import java.util.ResourceBundle; |
|
32 |
|
|
33 |
import org.gvsig.geoprocess.lib.api.GeoProcess; |
|
34 |
import org.gvsig.geoprocess.lib.api.GeoProcessLibrary; |
|
35 |
import org.gvsig.geoprocess.lib.api.GeoProcessLocator; |
|
36 |
import org.gvsig.tools.library.AbstractLibrary; |
|
37 |
|
|
38 |
/** |
|
39 |
* Base class for the entry point of an algorithm |
|
40 |
* |
|
41 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
42 |
* @author gvSIG team |
|
43 |
*/ |
|
44 |
public abstract class AlgorithmAbstractLibrary extends AbstractLibrary { |
|
45 |
|
|
46 |
/** |
|
47 |
* @deprecated Use {@link #getLanguageStrings(String)} instead. |
|
48 |
*/ |
|
49 |
protected HashMap<String, String> text = new HashMap<String, String>(); |
|
50 |
|
|
51 |
@Override |
|
52 |
public void doRegistration() { |
|
53 |
registerAsServiceOf(GeoProcessLibrary.class); |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* @deprecated Use {@link #getLanguageStrings(String)} instead. |
|
58 |
*/ |
|
59 |
protected void setLanguageStrings(String algorithmName) { |
|
60 |
this.text = |
|
61 |
new HashMap<String, String>(getLanguageStrings(algorithmName)); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Returns the translations. |
|
66 |
* |
|
67 |
* @param algorithmName |
|
68 |
*/ |
|
69 |
protected Map<String, String> getLanguageStrings(String algorithmName) { |
|
70 |
Map<String, String> text = new HashMap<String, String>(); |
|
71 |
String defaultFile = algorithmName; |
|
72 |
String file = algorithmName + "_" + Locale.getDefault().getLanguage(); |
|
73 |
ResourceBundle labels = null; |
|
74 |
|
|
75 |
try { |
|
76 |
labels = ResourceBundle.getBundle(file, Locale.getDefault()); |
|
77 |
} catch (final MissingResourceException e) { |
|
78 |
file = defaultFile; |
|
79 |
} |
|
80 |
|
|
81 |
try { |
|
82 |
if (labels == null) { |
|
83 |
labels = ResourceBundle.getBundle(file, Locale.getDefault()); |
|
84 |
} |
|
85 |
Enumeration<String> bundleKeys = labels.getKeys(); |
|
86 |
|
|
87 |
while (bundleKeys.hasMoreElements()) { |
|
88 |
final String key = bundleKeys.nextElement(); |
|
89 |
final String value = labels.getString(key); |
|
90 |
text.put(key, value); |
|
91 |
} |
|
92 |
} catch (final MissingResourceException e) { |
|
93 |
file = defaultFile; |
|
94 |
} |
|
95 |
|
|
96 |
return text; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Registers a new {@link GeoProcess}. |
|
101 |
* |
|
102 |
* @param geoProcessClazz |
|
103 |
* implementation of the {@link GeoProcess} to register |
|
104 |
*/ |
|
105 |
protected void registerGeoProcess(GeoProcess geoProcess) { |
|
106 |
GeoProcessLocator.getGeoProcessManager().registerGeoProcess(geoProcess); |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* @deprecated use {@link #registerGeoProcess(Class)} instead |
|
111 |
*/ |
|
112 |
protected void registerGeoProcess( |
|
113 |
Class<? extends GeoProcess> geoProcessClazz, |
|
114 |
Map<String, String> localeStrings) { |
|
115 |
GeoProcessLocator.getGeoProcessManager().registerGeoProcess( |
|
116 |
geoProcessClazz, localeStrings); |
|
117 |
} |
|
118 |
|
|
119 |
} |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.274/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.base/src/main/java/org/gvsig/geoprocess/algorithm/base/core/ScalableUnionOperation.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify it under |
|
7 |
* the terms of the GNU General Public License as published by the Free Software |
|
8 |
* Foundation; either version 2 of the License, or (at your option) any later |
|
9 |
* version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
14 |
* details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us at info AT |
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.geoprocess.algorithm.base.core; |
|
24 |
|
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.Date; |
|
27 |
import java.util.Iterator; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import com.vividsolutions.jts.geom.Geometry; |
|
31 |
|
|
32 |
import es.unex.sextante.core.Sextante; |
|
33 |
import es.unex.sextante.dataObjects.IVectorLayer; |
|
34 |
import es.unex.sextante.exceptions.NullParameterValueException; |
|
35 |
import es.unex.sextante.exceptions.WrongParameterIDException; |
|
36 |
import es.unex.sextante.exceptions.WrongParameterTypeException; |
|
37 |
|
|
38 |
import org.slf4j.Logger; |
|
39 |
import org.slf4j.LoggerFactory; |
|
40 |
|
|
41 |
import org.gvsig.fmap.dal.exception.DataException; |
|
42 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
43 |
import org.gvsig.fmap.dal.feature.Feature; |
|
44 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
45 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
46 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
47 |
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil; |
|
48 |
import org.gvsig.geoprocess.algorithm.base.util.JTSFacade; |
|
49 |
import org.gvsig.geoprocess.algorithm.base.visitor.exception.VisitorException; |
|
50 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
|
51 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer; |
|
52 |
|
|
53 |
/** |
|
54 |
* Joins all geometries in a layer |
|
55 |
* |
|
56 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
57 |
*/ |
|
58 |
public class ScalableUnionOperation extends GeometryOperation { |
|
59 |
|
|
60 |
private static final Logger LOG = LoggerFactory |
|
61 |
.getLogger(ScalableUnionOperation.class); |
|
62 |
//geometry type of the layer whose features we are going to fussion |
|
63 |
//(polygon features are optimized in jts with buffer(0) trick, the |
|
64 |
//nor the rest |
|
65 |
private Geometry geometry = null; |
|
66 |
|
|
67 |
public ScalableUnionOperation() { |
|
68 |
super(null); |
|
69 |
} |
|
70 |
|
|
71 |
public ScalableUnionOperation(AbstractSextanteGeoProcess p) { |
|
72 |
super(p); |
|
73 |
} |
|
74 |
|
|
75 |
/* |
|
76 |
* (non-Javadoc) |
|
77 |
* @see org.gvsig.geoprocess.algorithm.base.core.IOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.Feature) |
|
78 |
*/ |
|
79 |
public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature featureInput) { |
|
80 |
if (g == null) { |
|
81 |
return null; |
|
82 |
} |
|
83 |
|
|
84 |
if (g.getGeometryType().getType() != TYPES.SURFACE) { |
|
85 |
return null; |
|
86 |
} |
|
87 |
|
|
88 |
com.vividsolutions.jts.geom.Geometry actualGeometry = GeometryUtil.geomToJTS(g); |
|
89 |
|
|
90 |
if (geometry == null) { |
|
91 |
geometry = actualGeometry; |
|
92 |
} else { |
|
93 |
Geometry[] geoms = new Geometry[2]; |
|
94 |
geoms[0] = geometry; |
|
95 |
geoms[1] = actualGeometry; |
|
96 |
|
|
97 |
geometry = JTSFacade.union(geoms, g.getType()); |
|
98 |
} |
|
99 |
return null; |
|
100 |
} |
|
101 |
|
|
102 |
/* |
|
103 |
* (non-Javadoc) |
|
104 |
* @see org.gvsig.geoprocess.algorithm.base.core.IOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.EditableFeature) |
|
105 |
*/ |
|
106 |
public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput) { |
|
107 |
invoke(g, featureInput); |
|
108 |
} |
|
109 |
|
|
110 |
public void setFeatureStore(FeatureStore out, String[] attrNames) |
|
111 |
throws DataException { |
|
112 |
} |
|
113 |
|
|
114 |
/* |
|
115 |
* (non-Javadoc) |
|
116 |
* @see org.gvsig.geoprocess.algorithm.base.core.IOperation#getResult() |
|
117 |
*/ |
|
118 |
public Object getResult() { |
|
119 |
return getGeometry(); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* Returns FMap convex hull geometry. |
|
124 |
* |
|
125 |
* @return |
|
126 |
*/ |
|
127 |
private org.gvsig.fmap.geom.Geometry getGeometry() { |
|
128 |
return GeometryUtil.jtsToGeom(geometry); |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* Joins two geometries |
|
133 |
* |
|
134 |
* @param g |
|
135 |
* @param geometryType |
|
136 |
* @return |
|
137 |
*/ |
|
138 |
private void union(org.gvsig.fmap.geom.Geometry g, int geometryType) { |
|
139 |
Date time1 = new Date(); |
|
140 |
if (g == null) { |
|
141 |
return; |
|
142 |
} |
|
143 |
|
|
144 |
if (!g.getGeometryType().isTypeOf(TYPES.SURFACE) && !g.getGeometryType().isTypeOf(TYPES.MULTISURFACE)) { |
|
145 |
return; |
|
146 |
} |
|
147 |
|
|
148 |
com.vividsolutions.jts.geom.Geometry actualGeometry = GeometryUtil.geomToJTS(g); |
|
149 |
|
|
150 |
if (geometry == null) { |
|
151 |
geometry = actualGeometry; |
|
152 |
} else { |
|
153 |
Geometry[] geoms = new Geometry[2]; |
|
154 |
geoms[0] = geometry; |
|
155 |
geoms[1] = actualGeometry; |
|
156 |
|
|
157 |
geometry = JTSFacade.union(geoms, geometryType); |
|
158 |
} |
|
159 |
Date time2 = new Date(); |
|
160 |
LOG.info("scalableUnion time = " + (time2.getTime() - time1.getTime() + " ms")); |
|
161 |
|
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* Joins an array of surface geometries |
|
166 |
* |
|
167 |
* @param geoms |
|
168 |
* @param geometryType |
|
169 |
* @return |
|
170 |
*/ |
|
171 |
private void union(org.gvsig.fmap.geom.Geometry[] geoms) { |
|
172 |
Date time1 = new Date(); |
|
173 |
if (geoms == null) { |
|
174 |
|
|
175 |
return; |
|
176 |
} |
|
177 |
|
|
178 |
ArrayList<Geometry> geometries = new ArrayList<Geometry>(); |
|
179 |
|
|
180 |
if (geometry != null) { |
|
181 |
geometries.add(geometry); |
|
182 |
} |
|
183 |
for (int i = 0; i < geoms.length; i++) { |
|
184 |
org.gvsig.fmap.geom.Geometry geom = geoms[i]; |
|
185 |
if (geom.getGeometryType().isTypeOf(TYPES.SURFACE) || geom.getGeometryType().isTypeOf(TYPES.MULTISURFACE)) { |
|
186 |
geometries.add(GeometryUtil.geomToJTS(geom)); |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
geometry = JTSFacade.union((Geometry[]) geometries.toArray(new Geometry[0]), TYPES.SURFACE); |
|
191 |
|
Also available in: Unified diff