Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / buffer / fmap / AttributeBufferVisitor.java @ 10626

History | View | Annotate | Download (4.74 KB)

1
/*
2
 * Created on 02-feb-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: AttributeBufferVisitor.java 10626 2007-03-06 16:55:54Z caballero $
47
* $Log$
48
* Revision 1.3  2007-03-06 16:47:58  caballero
49
* Exceptions
50
*
51
* Revision 1.2  2006/07/21 11:22:52  azabala
52
* fixed bug 654: AttributeBufferVisitor overwrited result processor of BufferVisitor (and always was null)
53
*
54
* Revision 1.1  2006/06/20 18:20:45  azabala
55
* first version in cvs
56
*
57
* Revision 1.2  2006/06/02 18:20:33  azabala
58
* limpieza de imports
59
*
60
* Revision 1.1  2006/05/24 21:14:41  azabala
61
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
62
*
63
* Revision 1.8  2006/05/01 19:18:09  azabala
64
* revisi?n general del buffer (a?adidos anillos concentricos, buffers interiores y exteriores, etc)
65
*
66
* Revision 1.7  2006/03/28 16:27:16  azabala
67
* *** empty log message ***
68
*
69
* Revision 1.6  2006/03/07 21:01:33  azabala
70
* *** empty log message ***
71
*
72
* Revision 1.5  2006/03/06 19:48:39  azabala
73
* *** empty log message ***
74
*
75
* Revision 1.2  2006/03/05 19:57:05  azabala
76
* *** empty log message ***
77
*
78
* Revision 1.1  2006/02/17 16:31:38  azabala
79
* *** empty log message ***
80
*
81
* Revision 1.3  2006/02/12 21:02:44  azabala
82
* *** empty log message ***
83
*
84
* Revision 1.2  2006/02/09 16:01:06  azabala
85
* First version in CVS
86
*
87
* Revision 1.1  2006/02/02 19:46:01  azabala
88
* First version in CVS
89
*
90
*
91
*/
92
package com.iver.cit.gvsig.geoprocess.impl.buffer.fmap;
93

    
94
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
95
import com.hardcode.gdbms.engine.values.NumericValue;
96
import com.iver.cit.gvsig.exceptions.visitors.StartVisitorException;
97
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
98
import com.iver.cit.gvsig.fmap.core.IGeometry;
99
import com.iver.cit.gvsig.fmap.layers.FLayer;
100
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
101
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
102
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
103
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
104
/**
105
 * FeatureVisitor that computes buffer geometries from original geometrie
106
 * and an attribute value of IFeature
107
 * @author azabala
108
 *
109
 */
110
public class AttributeBufferVisitor extends BufferVisitor {
111
        /**
112
         * Attribute name from which visitor will get buffer distances
113
         */
114
        private String attributeName;
115
        /**
116
         * It allows visitor to get attribute values link to geometries
117
         */
118
        private SelectableDataSource recordset;
119

    
120

    
121
        /**
122
         * Constructor
123
         * @param attributeName
124
         * @param recordset
125
         */
126
        public AttributeBufferVisitor(String attributeName) throws GeoprocessException{
127
                this.attributeName = attributeName;
128
        }
129

    
130
        public void stop(FLayer layer) throws VisitorException {
131
                resultsProcessor.finish();
132
        }
133

    
134
        public boolean start(FLayer layer) throws StartVisitorException {
135
                if(layer instanceof AlphanumericData && layer instanceof VectorialData){
136
                        try {
137
                                this.recordset = ((AlphanumericData)layer).getRecordset();
138
                        } catch (ReadDriverException e) {
139
                                return false;
140
                        }
141
                        return true;
142
                }
143
                return false;
144
        }
145

    
146
        public double getBufferDistance(IGeometry g, int index){
147
                NumericValue value = null;
148
                try {
149
                        int fieldIndex = recordset.getFieldIndexByName(attributeName);
150
                        //we could throw an AttributeBufferException, or
151
                        //we could check preconditions in BufferGeoprocess
152
                        //TODO to check attribute is a NUMBER
153
                         value = (NumericValue) recordset.
154
                                         getFieldValue(index, fieldIndex);
155
                } catch (ReadDriverException e) {
156
                        return -1d;
157
                }
158
                //TODO catch ClassCastException
159
                return value.doubleValue();
160
        }
161

    
162
        public String getProcessDescription() {
163
                return "Computing buffers applying distances from attribute";
164
        }
165
}
166