gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.reproject / src / main / java / org / gvsig / geoprocess / algorithm / reproject / ReprojectAlgorithm.java @ 325
History | View | Annotate | Download (4.74 KB)
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.reproject; |
25 |
|
26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.fmap.crs.CRSFactory; |
28 |
import org.gvsig.fmap.dal.exception.DataException; |
29 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
30 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
31 |
import org.gvsig.fmap.dal.feature.FeatureType; |
32 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
33 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer; |
34 |
|
35 |
import es.unex.sextante.core.Sextante; |
36 |
import es.unex.sextante.dataObjects.IVectorLayer; |
37 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
38 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
39 |
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel; |
40 |
import es.unex.sextante.outputs.OutputVectorLayer; |
41 |
|
42 |
/**
|
43 |
* Reproject algorithm
|
44 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
45 |
*/
|
46 |
public class ReprojectAlgorithm extends AbstractSextanteGeoProcess { |
47 |
|
48 |
public static final String RESULT = "RESULT"; |
49 |
public static final String LAYER = "LAYER"; |
50 |
public static final String SELECTED_GEOM = "SELECTED_GEOM"; |
51 |
public static final String DST_PROJECTION = "DST_PROJECTION"; |
52 |
|
53 |
/*
|
54 |
* (non-Javadoc)
|
55 |
* @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
|
56 |
*/
|
57 |
public void defineCharacteristics() { |
58 |
setName(getTranslation("Reproject"));
|
59 |
setGroup(getTranslation("basic_vect_algorithms"));
|
60 |
// setGeneratesUserDefinedRasterOutput(false);
|
61 |
|
62 |
try {
|
63 |
m_Parameters.addInputVectorLayer(LAYER, |
64 |
getTranslation("Input_layer"),
|
65 |
IVectorLayer.SHAPE_TYPE_WRONG, |
66 |
true);
|
67 |
m_Parameters.addBoolean(SELECTED_GEOM, |
68 |
getTranslation("Selected_geometries"),
|
69 |
false);
|
70 |
m_Parameters |
71 |
.addString(DST_PROJECTION, getTranslation("Projection"));
|
72 |
addOutputVectorLayer(RESULT, |
73 |
getTranslation("Reproject"),
|
74 |
OutputVectorLayer.SHAPE_TYPE_UNDEFINED); |
75 |
} catch (RepeatedParameterNameException e) {
|
76 |
Sextante.addErrorToLog(e); |
77 |
} |
78 |
} |
79 |
|
80 |
/*
|
81 |
* (non-Javadoc)
|
82 |
* @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
|
83 |
*/
|
84 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
85 |
if(existsOutPutFile(ReprojectAlgorithm.RESULT, 0)) { |
86 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
87 |
} |
88 |
IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
89 |
boolean selectedGeom = m_Parameters.getParameterValueAsBoolean(SELECTED_GEOM);
|
90 |
String dstProj = m_Parameters.getParameterValueAsString(DST_PROJECTION);
|
91 |
|
92 |
FeatureStore storeLayer = null;
|
93 |
if(layer instanceof FlyrVectIVectorLayer) |
94 |
storeLayer = ((FlyrVectIVectorLayer)layer).getFeatureStore(); |
95 |
else
|
96 |
return false; |
97 |
|
98 |
try {
|
99 |
FeatureSet features = null;
|
100 |
features = storeLayer.getFeatureSet(); |
101 |
FeatureType featureType = features.getDefaultFeatureType(); |
102 |
FeatureStore outFeatStore = |
103 |
buildOutPutStore(featureType, layer.getShapeType(), |
104 |
getTranslation("Reproject"), RESULT);
|
105 |
IProjection projOutput = CRSFactory.getCRS(dstProj); |
106 |
ReprojectOperation operation = new ReprojectOperation(((IProjection)layer.getCRS()), projOutput, this); |
107 |
operation.setTaskStatus(getStatus()); |
108 |
operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
|
109 |
} catch (DataException e) {
|
110 |
Sextante.addErrorToLog(e); |
111 |
return false; |
112 |
} |
113 |
|
114 |
if(getTaskMonitor().isCanceled())
|
115 |
return false; |
116 |
|
117 |
return true; |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() { |
122 |
return ReprojectParametersPanel.class;
|
123 |
} |
124 |
} |