Statistics
| Revision:

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 @ 1260

History | View | Annotate | Download (6.79 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
    public static final String USESIMPLIFIEDGEOMETRIES = "USESIMPLIFIEDGEOMETRIES";
54
    
55
    public static final int    LEFT          = 0;
56
    public static final int    RIGHT         = 1;
57
    
58
    private int                lateral       = LEFT;
59
    
60
        public void defineCharacteristics() {
61
        setName(getTranslation("lateral_buffer"));
62
        setGroup(getTranslation("basic_vect_algorithms"));
63
        // setGeneratesUserDefinedRasterOutput(false);
64
                
65
        try {
66
            m_Parameters.addInputVectorLayer(LAYER, getTranslation("Input_layer"), 
67
                    IVectorLayer.SHAPE_TYPE_WRONG, true);
68
            m_Parameters.addBoolean(SELECTED_GEOM, getTranslation("Selected_geometries"), false);
69
            m_Parameters.addNumericalValue(DISTANCE, getTranslation("area_distance"), 0,
70
                AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE);
71
            m_Parameters.addTableField(FIELD, getTranslation("area_field"), "LAYER");
72
            m_Parameters.addBoolean(DISSOLVE, getTranslation("Dissolve_entities"), false);
73
            m_Parameters.addSelection(RING_NUMBER, getTranslation("Number_of_rings"),
74
                new String[] { "1", "2", "3","4" });
75
            m_Parameters.addBoolean(ROUND_BORDER, getTranslation("Round_border"), true);
76
            m_Parameters.addBoolean(IGNOREINVALIDLINES, getTranslation("ignore_invalid_lines"), true);
77
            m_Parameters.addBoolean(USESIMPLIFIEDGEOMETRIES, getTranslation("Use_simplified_geometries"), true);
78
            m_Parameters.addNumericalValue(LATERAL, getTranslation("select_lateral"), 0,
79
                    AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
80
        } catch (RepeatedParameterNameException e) {
81
            Sextante.addErrorToLog(e);
82
        } catch (UndefinedParentParameterNameException e) {
83
            Sextante.addErrorToLog(e);
84
        } catch (OptionalParentParameterException e) {
85
            Sextante.addErrorToLog(e);
86
        }
87
        addOutputVectorLayer(RESULT, getTranslation("lateral_buffer"),
88
            OutputVectorLayer.SHAPE_TYPE_POLYGON);
89
        }
90
        
91
        /*
92
         * (non-Javadoc)
93
         * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
94
         */
95
        public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
96
                if(existsOutPutFile(LateralBufferAlgorithm.RESULT, 0)) {
97
                    throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
98
            }
99
                
100
                int attributePosition = m_Parameters.getParameterValueAsInt(FIELD);
101
                double distanceValue = m_Parameters.getParameter(DISTANCE).getParameterValueAsDouble();
102
                lateral = m_Parameters.getParameterValueAsInt(LATERAL); //0:left 1:right
103
                boolean ignoreInvalidLines = m_Parameters.getParameterValueAsBoolean(IGNOREINVALIDLINES);
104
                boolean useSimplifiedGeometries = m_Parameters.getParameterValueAsBoolean(USESIMPLIFIEDGEOMETRIES);
105
                //Default inflArea BUFFER_OUTSIDE_POLY
106
                readParameters();
107
                
108
        if (sextanteInputLayer instanceof FlyrVectIVectorLayer)
109
                inputStore = ((FlyrVectIVectorLayer) sextanteInputLayer).getFeatureStore();
110
        else
111
            return false;
112
        
113
        try {
114
            // Object to compute the distance
115
            IDistance distance = null;
116
            if (distanceValue == 0)
117
                distance = new FieldDistance(sextanteInputLayer.getFieldName(attributePosition));
118
            else
119
                distance = new ConstantDistance(distanceValue);
120
            
121
            BufferOperation operation = new LateralBufferOperation(distance, inputStore, this, getTableFieldsStructure(), lateral, ignoreInvalidLines, useSimplifiedGeometries);
122
            
123
            operation.setTypeOfCap(round_border ? BufferOperation.CAP_ROUND : BufferOperation.CAP_SQUARE);
124
            operation.setNumberOfRadialBuffers(rings + 1);
125
            operation.setGeoProcess(this, 100);
126
            
127
                // Builds the output FeatureStore
128
            outputStore = buildOutPutStore(IVectorLayer.SHAPE_TYPE_POLYGON,
129
                                        getTranslation("lateral_buffer"), RESULT);
130
            
131
            if(!dissolve) {
132
                        computesBufferAlgWithoutDissolve(operation);
133
                } else {
134
                        computesBufferAlgWithDissolve(operation);
135
                }
136

    
137
        } catch (DataException e) {
138
            Sextante.addErrorToLog(e);
139
            return false;
140
        }
141
                
142
                return true;
143
        }
144
        
145
        
146
    @Override
147
    public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() {
148
        return LateralBufferParametersPanel.class;
149
    }
150
        
151
}