gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.lateralbuffer / src / main / java / org / gvsig / geoprocess / algorithm / lateralbuffer / LateralBufferAlgorithm.java @ 1082
History | View | Annotate | Download (6.42 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.lateralbuffer; |
25 |
|
26 |
import org.gvsig.fmap.dal.exception.DataException; |
27 |
import org.gvsig.geoprocess.algorithm.buffer.BufferAlgorithm; |
28 |
import org.gvsig.geoprocess.algorithm.buffer.BufferOperation; |
29 |
import org.gvsig.geoprocess.algorithm.buffer.ConstantDistance; |
30 |
import org.gvsig.geoprocess.algorithm.buffer.FieldDistance; |
31 |
import org.gvsig.geoprocess.algorithm.buffer.IDistance; |
32 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer; |
33 |
|
34 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
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.OptionalParentParameterException; |
39 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
40 |
import es.unex.sextante.exceptions.UndefinedParentParameterNameException; |
41 |
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel; |
42 |
import es.unex.sextante.outputs.OutputVectorLayer; |
43 |
|
44 |
/**
|
45 |
* Lateral buffer algorithm
|
46 |
*
|
47 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
48 |
*/
|
49 |
public class LateralBufferAlgorithm extends BufferAlgorithm { |
50 |
|
51 |
public static final String LATERAL = "LATERAL"; |
52 |
public static final String IGNOREINVALIDLINES = "IGNORENOTVALIDLINES"; |
53 |
|
54 |
public static final int LEFT = 0; |
55 |
public static final int RIGHT = 1; |
56 |
|
57 |
private int lateral = LEFT; |
58 |
|
59 |
public void defineCharacteristics() { |
60 |
setName(getTranslation("lateral_buffer"));
|
61 |
setGroup(getTranslation("basic_vect_algorithms"));
|
62 |
// setGeneratesUserDefinedRasterOutput(false);
|
63 |
|
64 |
try {
|
65 |
m_Parameters.addInputVectorLayer(LAYER, getTranslation("Input_layer"),
|
66 |
IVectorLayer.SHAPE_TYPE_WRONG, true);
|
67 |
m_Parameters.addBoolean(SELECTED_GEOM, getTranslation("Selected_geometries"), false); |
68 |
m_Parameters.addNumericalValue(DISTANCE, getTranslation("area_distance"), 0, |
69 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE); |
70 |
m_Parameters.addTableField(FIELD, getTranslation("area_field"), "LAYER"); |
71 |
m_Parameters.addBoolean(DISSOLVE, getTranslation("Dissolve_entities"), false); |
72 |
m_Parameters.addSelection(RING_NUMBER, getTranslation("Number_of_rings"),
|
73 |
new String[] { "1", "2", "3" }); |
74 |
m_Parameters.addBoolean(ROUND_BORDER, getTranslation("Round_border"), true); |
75 |
m_Parameters.addBoolean(IGNOREINVALIDLINES, getTranslation("ignore_invalid_lines"), true); |
76 |
m_Parameters.addNumericalValue(LATERAL, getTranslation("select_lateral"), 0, |
77 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER); |
78 |
} catch (RepeatedParameterNameException e) {
|
79 |
Sextante.addErrorToLog(e); |
80 |
} catch (UndefinedParentParameterNameException e) {
|
81 |
Sextante.addErrorToLog(e); |
82 |
} catch (OptionalParentParameterException e) {
|
83 |
Sextante.addErrorToLog(e); |
84 |
} |
85 |
addOutputVectorLayer(RESULT, getTranslation("lateral_buffer"),
|
86 |
OutputVectorLayer.SHAPE_TYPE_POLYGON); |
87 |
} |
88 |
|
89 |
/*
|
90 |
* (non-Javadoc)
|
91 |
* @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
|
92 |
*/
|
93 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
94 |
if(existsOutPutFile(LateralBufferAlgorithm.RESULT, 0)) { |
95 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
96 |
} |
97 |
|
98 |
int attributePosition = m_Parameters.getParameterValueAsInt(FIELD);
|
99 |
double distanceValue = m_Parameters.getParameter(DISTANCE).getParameterValueAsDouble();
|
100 |
lateral = m_Parameters.getParameterValueAsInt(LATERAL); //0:left 1:right
|
101 |
boolean ignoreInvalidLines = m_Parameters.getParameterValueAsBoolean(IGNOREINVALIDLINES);
|
102 |
//Default inflArea BUFFER_OUTSIDE_POLY
|
103 |
readParameters(); |
104 |
|
105 |
if (sextanteInputLayer instanceof FlyrVectIVectorLayer) |
106 |
inputStore = ((FlyrVectIVectorLayer) sextanteInputLayer).getFeatureStore(); |
107 |
else
|
108 |
return false; |
109 |
|
110 |
try {
|
111 |
// Object to compute the distance
|
112 |
IDistance distance = null;
|
113 |
if (distanceValue == 0) |
114 |
distance = new FieldDistance(attributePosition);
|
115 |
else
|
116 |
distance = new ConstantDistance(distanceValue);
|
117 |
|
118 |
BufferOperation operation = new LateralBufferOperation(distance, inputStore, this, getTableFieldsStructure(), lateral, ignoreInvalidLines); |
119 |
|
120 |
operation.setTypeOfCap(round_border ? BufferOperation.CAP_ROUND : BufferOperation.CAP_SQUARE); |
121 |
operation.setNumberOfRadialBuffers(rings + 1);
|
122 |
operation.setGeoProcess(this, 100); |
123 |
|
124 |
// Builds the output FeatureStore
|
125 |
outputStore = buildOutPutStore(IVectorLayer.SHAPE_TYPE_POLYGON, |
126 |
getTranslation("lateral_buffer"), RESULT);
|
127 |
|
128 |
if(!dissolve) {
|
129 |
computesBufferAlgWithoutDissolve(operation); |
130 |
} else {
|
131 |
computesBufferAlgWithDissolve(operation); |
132 |
} |
133 |
|
134 |
} catch (DataException e) {
|
135 |
Sextante.addErrorToLog(e); |
136 |
return false; |
137 |
} |
138 |
|
139 |
return true; |
140 |
} |
141 |
|
142 |
|
143 |
@Override
|
144 |
public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() { |
145 |
return LateralBufferParametersPanel.class;
|
146 |
} |
147 |
|
148 |
} |