Revision 1261 org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.merge/src/main/java/org/gvsig/geoprocess/algorithm/merge/MergeAlgorithm.java
MergeAlgorithm.java | ||
---|---|---|
45 | 45 |
|
46 | 46 |
/** |
47 | 47 |
* Merge algorithm |
48 |
* |
|
48 | 49 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
49 | 50 |
*/ |
50 | 51 |
public class MergeAlgorithm extends AbstractSextanteGeoProcess { |
51 |
public static final String RESULT_POL = "RESULT_POL"; |
|
52 |
public static final String RESULT_POINT = "RESULT_POINT"; |
|
53 |
public static final String RESULT_LINE = "RESULT_LINE"; |
|
54 |
public static final String LAYERS = "LAYERS"; |
|
55 |
public static final String FIELDLAYER = "LAYER"; |
|
56 |
|
|
57 |
/* |
|
52 |
|
|
53 |
public static final String RESULT_POL = "RESULT_POL"; |
|
54 |
public static final String RESULT_POINT = "RESULT_POINT"; |
|
55 |
public static final String RESULT_LINE = "RESULT_LINE"; |
|
56 |
public static final String LAYERS = "LAYERS"; |
|
57 |
public static final String FIELDLAYER = "LAYER"; |
|
58 |
|
|
59 |
/* |
|
58 | 60 |
* (non-Javadoc) |
59 | 61 |
* @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics() |
60 |
*/
|
|
61 |
public void defineCharacteristics() {
|
|
62 |
*/
|
|
63 |
public void defineCharacteristics() {
|
|
62 | 64 |
setName(getTranslation("Merge")); |
63 | 65 |
setGroup(getTranslation("basic_vect_algorithms")); |
64 | 66 |
// setGeneratesUserDefinedRasterOutput(false); |
65 |
|
|
66 |
try {
|
|
67 |
m_Parameters.addMultipleInput(LAYERS,
|
|
68 |
getTranslation("Input_layers"), |
|
69 |
AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_ANY,
|
|
70 |
true);
|
|
71 |
m_Parameters.addInputVectorLayer(FIELDLAYER,
|
|
72 |
getTranslation("Fields"), |
|
73 |
IVectorLayer.SHAPE_TYPE_WRONG,
|
|
74 |
true);
|
|
75 |
|
|
76 |
addOutputVectorLayer(RESULT_POL, getTranslation("Merge_polygon"),
|
|
77 |
OutputVectorLayer.SHAPE_TYPE_POLYGON);
|
|
78 |
addOutputVectorLayer(RESULT_LINE, getTranslation("Merge_line"),
|
|
79 |
OutputVectorLayer.SHAPE_TYPE_LINE);
|
|
80 |
addOutputVectorLayer(RESULT_POINT, getTranslation("Merge_point"),
|
|
81 |
OutputVectorLayer.SHAPE_TYPE_POINT);
|
|
82 |
|
|
83 |
} catch (RepeatedParameterNameException e) {
|
|
84 |
Sextante.addErrorToLog(e);
|
|
85 |
}
|
|
86 |
}
|
|
87 |
|
|
88 |
/*
|
|
67 |
|
|
68 |
try {
|
|
69 |
m_Parameters.addMultipleInput(LAYERS,
|
|
70 |
getTranslation("Input_layers"),
|
|
71 |
AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_ANY,
|
|
72 |
true);
|
|
73 |
m_Parameters.addInputVectorLayer(FIELDLAYER,
|
|
74 |
getTranslation("Fields"),
|
|
75 |
IVectorLayer.SHAPE_TYPE_WRONG,
|
|
76 |
true);
|
|
77 |
|
|
78 |
addOutputVectorLayer(RESULT_POL, getTranslation("Merge_polygon"),
|
|
79 |
OutputVectorLayer.SHAPE_TYPE_POLYGON);
|
|
80 |
addOutputVectorLayer(RESULT_LINE, getTranslation("Merge_line"),
|
|
81 |
OutputVectorLayer.SHAPE_TYPE_LINE);
|
|
82 |
addOutputVectorLayer(RESULT_POINT, getTranslation("Merge_point"),
|
|
83 |
OutputVectorLayer.SHAPE_TYPE_POINT);
|
|
84 |
|
|
85 |
} catch (RepeatedParameterNameException e) {
|
|
86 |
Sextante.addErrorToLog(e);
|
|
87 |
}
|
|
88 |
}
|
|
89 |
|
|
90 |
/*
|
|
89 | 91 |
* (non-Javadoc) |
90 | 92 |
* @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm() |
91 |
*/ |
|
92 |
@SuppressWarnings("unchecked") |
|
93 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
|
94 |
if(existsOutPutFile(RESULT_POL, 0) || |
|
95 |
existsOutPutFile(RESULT_LINE, 0) || |
|
96 |
existsOutPutFile(RESULT_POINT, 0)) { |
|
97 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
|
98 |
} |
|
99 |
IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(FIELDLAYER); |
|
100 |
ArrayList<IVectorLayer> layers = m_Parameters.getParameterValueAsArrayList(LAYERS); |
|
101 |
|
|
102 |
FeatureStore storeLayer = null; |
|
103 |
if(layer instanceof FlyrVectIVectorLayer) |
|
104 |
storeLayer = ((FlyrVectIVectorLayer)layer).getFeatureStore(); |
|
105 |
else |
|
106 |
return false; |
|
107 |
|
|
108 |
try { |
|
109 |
//Gets the list of FeatureStore |
|
110 |
ArrayList<FeatureStore> featureStoreList = new ArrayList<FeatureStore>(); |
|
111 |
for (int i = 0; i < layers.size(); i++) { |
|
112 |
IVectorLayer lyr = layers.get(i); |
|
113 |
if(lyr instanceof FlyrVectIVectorLayer && layer.getShapeType() == lyr.getShapeType()) |
|
114 |
featureStoreList.add(((FlyrVectIVectorLayer)lyr).getFeatureStore()); |
|
115 |
else { |
|
116 |
JOptionPane.showMessageDialog(null, |
|
117 |
getTranslation("layers_type_are_different"), |
|
118 |
"Error", |
|
119 |
JOptionPane.WARNING_MESSAGE); |
|
120 |
return false; |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
//Builds the output FeatureStore |
|
125 |
FeatureSet features = null; |
|
126 |
features = storeLayer.getFeatureSet(); |
|
127 |
FeatureType featureType = features.getDefaultFeatureType(); |
|
128 |
/* FeatureStore outFeatStore = |
|
93 |
*/ |
|
94 |
@SuppressWarnings("unchecked") |
|
95 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
|
96 |
if (existsOutPutFile(RESULT_POL, 0) |
|
97 |
|| existsOutPutFile(RESULT_LINE, 0) |
|
98 |
|| existsOutPutFile(RESULT_POINT, 0)) { |
|
99 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
|
100 |
} |
|
101 |
IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(FIELDLAYER); |
|
102 |
ArrayList<IVectorLayer> layers = m_Parameters.getParameterValueAsArrayList(LAYERS); |
|
103 |
|
|
104 |
FeatureStore storeLayer = null; |
|
105 |
if (layer instanceof FlyrVectIVectorLayer) { |
|
106 |
storeLayer = ((FlyrVectIVectorLayer) layer).getFeatureStore(); |
|
107 |
} else { |
|
108 |
return false; |
|
109 |
} |
|
110 |
|
|
111 |
try { |
|
112 |
//Gets the list of FeatureStore |
|
113 |
ArrayList<FeatureStore> featureStoreList = new ArrayList<FeatureStore>(); |
|
114 |
for (int i = 0; i < layers.size(); i++) { |
|
115 |
IVectorLayer lyr = layers.get(i); |
|
116 |
if (lyr instanceof FlyrVectIVectorLayer && layer.getShapeType() == lyr.getShapeType()) { |
|
117 |
featureStoreList.add(((FlyrVectIVectorLayer) lyr).getFeatureStore()); |
|
118 |
} else { |
|
119 |
JOptionPane.showMessageDialog(null, |
|
120 |
getTranslation("layers_type_are_different"), |
|
121 |
"Error", |
|
122 |
JOptionPane.WARNING_MESSAGE); |
|
123 |
return false; |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
127 |
//Builds the output FeatureStore |
|
128 |
FeatureSet features = null; |
|
129 |
features = storeLayer.getFeatureSet(); |
|
130 |
FeatureType featureType = features.getDefaultFeatureType(); |
|
131 |
/* FeatureStore outFeatStore = |
|
129 | 132 |
buildOutPutStore(featureType, layer.getShapeType(), |
130 | 133 |
getTranslation("Merge"), RESULT); |
131 | 134 |
|
... | ... | |
133 | 136 |
GeometryOperation operation = new MergeOperation(layer, this); |
134 | 137 |
operation.setTaskStatus(getStatus()); |
135 | 138 |
operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, false, true); |
136 |
*/
|
|
137 |
GeometryOperation operation = new MergeOperation(layer, this);
|
|
139 |
*/
|
|
140 |
GeometryOperation operation = new MergeOperation(layer, this);
|
|
138 | 141 |
operation.setTaskStatus(getStatus()); |
139 |
|
|
140 |
if (isPolygon(storeLayer) || isUndefined(storeLayer)) { |
|
141 |
FeatureStore outFeatStore = |
|
142 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON, |
|
143 |
getTranslation("Merge_polygon"), RESULT_POL); |
|
144 | 142 |
|
145 |
operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, |
|
146 |
false, false, true); |
|
147 |
} else { |
|
148 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON, |
|
149 |
getTranslation("Null_polygon"), RESULT_POL); |
|
150 |
} |
|
151 |
|
|
152 |
if (isLine(storeLayer) || isUndefined(storeLayer)) { |
|
153 |
FeatureStore outFeatStore = |
|
154 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_LINE, |
|
155 |
getTranslation("Merge_line"), RESULT_LINE); |
|
143 |
if (isPolygon(storeLayer) || isUndefined(storeLayer)) { |
|
144 |
FeatureStore outFeatStore |
|
145 |
= buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON, |
|
146 |
getTranslation("Merge_polygon"), RESULT_POL); |
|
156 | 147 |
|
157 |
operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, |
|
158 |
false, false, true); |
|
159 |
} else { |
|
160 |
buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_LINE, |
|
161 |
getTranslation("Null_line"), RESULT_LINE); |
|
162 |
} |
|
163 |
|
|
164 |
if (isPoint(storeLayer) || isUndefined(storeLayer)) { |
|
165 |
FeatureStore outFeatStore = |
|
166 |
buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT, |
|
167 |
getTranslation("Merge_point"), RESULT_POINT); |
|
148 |
operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, |
|
149 |
false, false, true); |
|
150 |
} else { |
|
151 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON, |
|
152 |
getTranslation("Null_polygon"), RESULT_POL); |
|
153 |
} |
|
168 | 154 |
|
169 |
operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, |
|
170 |
false, false, true); |
|
171 |
} else { |
|
172 |
buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT, |
|
173 |
getTranslation("Null_point"), RESULT_POINT); |
|
174 |
} |
|
175 |
|
|
176 |
} catch (DataException e) { |
|
177 |
Sextante.addErrorToLog(e); |
|
178 |
return false; |
|
179 |
} |
|
180 |
|
|
181 |
if(getTaskMonitor().isCanceled()) |
|
182 |
return false; |
|
183 |
|
|
184 |
return true; |
|
185 |
} |
|
155 |
if (isLine(storeLayer) || isUndefined(storeLayer)) { |
|
156 |
FeatureStore outFeatStore |
|
157 |
= buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_LINE, |
|
158 |
getTranslation("Merge_line"), RESULT_LINE); |
|
186 | 159 |
|
160 |
operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, |
|
161 |
false, false, true); |
|
162 |
} else { |
|
163 |
buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_LINE, |
|
164 |
getTranslation("Null_line"), RESULT_LINE); |
|
165 |
} |
|
166 |
|
|
167 |
if (isPoint(storeLayer) || isUndefined(storeLayer)) { |
|
168 |
FeatureStore outFeatStore |
|
169 |
= buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT, |
|
170 |
getTranslation("Merge_point"), RESULT_POINT); |
|
171 |
|
|
172 |
operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, |
|
173 |
false, false, true); |
|
174 |
} else { |
|
175 |
buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT, |
|
176 |
getTranslation("Null_point"), RESULT_POINT); |
|
177 |
} |
|
178 |
|
|
179 |
} catch (DataException e) { |
|
180 |
Sextante.addErrorToLog(e); |
|
181 |
return false; |
|
182 |
} |
|
183 |
|
|
184 |
if (getTaskMonitor().isCanceled()) { |
|
185 |
return false; |
|
186 |
} |
|
187 |
|
|
188 |
return true; |
|
189 |
} |
|
190 |
|
|
187 | 191 |
@Override |
188 | 192 |
public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() { |
189 | 193 |
return MergeParametersPanel.class; |
Also available in: Unified diff