gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.algorithm / org.gvsig.sextante.app.algorithm.merge / src / main / java / org / gvsig / sextante / app / algorithm / merge / MergeAlgorithm.java @ 46
History | View | Annotate | Download (4.5 KB)
1 | 41 | nbrodin | /*
|
---|---|---|---|
2 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
3 | *
|
||
4 | * Copyright (C) 2010 Generalitat Valenciana.
|
||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
19 | *
|
||
20 | */
|
||
21 | 21 | nbrodin | package org.gvsig.sextante.app.algorithm.merge; |
22 | |||
23 | 41 | nbrodin | import java.util.ArrayList; |
24 | |||
25 | 42 | nbrodin | import javax.swing.JOptionPane; |
26 | |||
27 | 41 | nbrodin | import org.gvsig.fmap.dal.exception.DataException; |
28 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
29 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
30 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
31 | import org.gvsig.sextante.app.algorithm.base.core.GeometryOperation; |
||
32 | import org.gvsig.sextante.app.extension.core.gvGeoAlgorithm; |
||
33 | import org.gvsig.sextante.app.extension.core.gvVectorLayer; |
||
34 | |||
35 | import es.unex.sextante.additionalInfo.AdditionalInfoMultipleInput; |
||
36 | 21 | nbrodin | import es.unex.sextante.core.Sextante; |
37 | 41 | nbrodin | import es.unex.sextante.dataObjects.IVectorLayer; |
38 | 21 | nbrodin | import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
39 | import es.unex.sextante.exceptions.RepeatedParameterNameException; |
||
40 | 41 | nbrodin | import es.unex.sextante.outputs.OutputVectorLayer; |
41 | 21 | nbrodin | |
42 | 41 | nbrodin | /**
|
43 | * Merge algorithm
|
||
44 | * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
||
45 | */
|
||
46 | public class MergeAlgorithm extends gvGeoAlgorithm { |
||
47 | public static final String RESULT = "RESULT"; |
||
48 | public static final String LAYERS = "LAYERS"; |
||
49 | public static final String FIELDLAYER = "LAYER"; |
||
50 | |||
51 | /*
|
||
52 | * (non-Javadoc)
|
||
53 | * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
|
||
54 | */
|
||
55 | public void defineCharacteristics() { |
||
56 | setName(Sextante.getText("Merge"));
|
||
57 | setGroup(Sextante.getText("gvSIG_Algorithms"));
|
||
58 | setGeneratesUserDefinedRasterOutput(false);
|
||
59 | |||
60 | try {
|
||
61 | m_Parameters.addMultipleInput(LAYERS, |
||
62 | Sextante.getText("Input_layers"),
|
||
63 | AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_ANY, |
||
64 | true);
|
||
65 | m_Parameters.addInputVectorLayer(FIELDLAYER, |
||
66 | 45 | nbrodin | Sextante.getText("Fields"),
|
67 | 41 | nbrodin | IVectorLayer.SHAPE_TYPE_WRONG, |
68 | true);
|
||
69 | addOutputVectorLayer(RESULT, |
||
70 | Sextante.getText("Merge"),
|
||
71 | OutputVectorLayer.SHAPE_TYPE_UNDEFINED); |
||
72 | } catch (RepeatedParameterNameException e) {
|
||
73 | Sextante.addErrorToLog(e); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | 42 | nbrodin | /*
|
78 | * (non-Javadoc)
|
||
79 | * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
|
||
80 | */
|
||
81 | 41 | nbrodin | @SuppressWarnings("unchecked") |
82 | public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
||
83 | IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(FIELDLAYER); |
||
84 | ArrayList<IVectorLayer> layers = m_Parameters.getParameterValueAsArrayList(LAYERS);
|
||
85 | |||
86 | FeatureStore storeLayer = null;
|
||
87 | if(layer instanceof gvVectorLayer) |
||
88 | storeLayer = ((gvVectorLayer)layer).getFeatureStore(); |
||
89 | else
|
||
90 | return false; |
||
91 | |||
92 | try {
|
||
93 | //Gets the list of FeatureStore
|
||
94 | ArrayList<FeatureStore> featureStoreList = new ArrayList<FeatureStore>(); |
||
95 | for (int i = 0; i < layers.size(); i++) { |
||
96 | IVectorLayer lyr = layers.get(i); |
||
97 | if(lyr instanceof gvVectorLayer && layer.getShapeType() == lyr.getShapeType()) |
||
98 | featureStoreList.add(((gvVectorLayer)lyr).getFeatureStore()); |
||
99 | 42 | nbrodin | else {
|
100 | JOptionPane.showMessageDialog(null, |
||
101 | 45 | nbrodin | Sextante.getText("layers_type_are_different"),
|
102 | 42 | nbrodin | "Error",
|
103 | JOptionPane.WARNING_MESSAGE);
|
||
104 | 41 | nbrodin | return false; |
105 | 42 | nbrodin | } |
106 | 41 | nbrodin | } |
107 | |||
108 | //Builds the output FeatureStore
|
||
109 | FeatureSet features = null;
|
||
110 | features = storeLayer.getFeatureSet(); |
||
111 | FeatureType featureType = features.getDefaultFeatureType(); |
||
112 | FeatureStore outFeatStore = buildOutPutStore(featureType, layer.getShapeType(), Sextante.getText("Merge"), RESULT);
|
||
113 | 21 | nbrodin | |
114 | 41 | nbrodin | //Calls the operation
|
115 | 42 | nbrodin | GeometryOperation operation = new MergeOperation(layer);
|
116 | 41 | nbrodin | operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, false, true); |
117 | } catch (DataException e) {
|
||
118 | Sextante.addErrorToLog(e); |
||
119 | return false; |
||
120 | } |
||
121 | |||
122 | 21 | nbrodin | return true; |
123 | } |
||
124 | |||
125 | } |