Statistics
| Revision:

root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / buffer / fmap / AttributeBufferVisitor.java @ 5626

History | View | Annotate | Download (4.56 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 5626 2006-06-02 18:20:33Z azabala $
47
* $Log$
48
* Revision 1.2  2006-06-02 18:20:33  azabala
49
* limpieza de imports
50
*
51
* Revision 1.1  2006/05/24 21:14:41  azabala
52
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
53
*
54
* Revision 1.8  2006/05/01 19:18:09  azabala
55
* revisi?n general del buffer (a?adidos anillos concentricos, buffers interiores y exteriores, etc)
56
*
57
* Revision 1.7  2006/03/28 16:27:16  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.6  2006/03/07 21:01:33  azabala
61
* *** empty log message ***
62
*
63
* Revision 1.5  2006/03/06 19:48:39  azabala
64
* *** empty log message ***
65
*
66
* Revision 1.2  2006/03/05 19:57:05  azabala
67
* *** empty log message ***
68
*
69
* Revision 1.1  2006/02/17 16:31:38  azabala
70
* *** empty log message ***
71
*
72
* Revision 1.3  2006/02/12 21:02:44  azabala
73
* *** empty log message ***
74
*
75
* Revision 1.2  2006/02/09 16:01:06  azabala
76
* First version in CVS
77
*
78
* Revision 1.1  2006/02/02 19:46:01  azabala
79
* First version in CVS
80
*
81
*
82
*/
83
package com.iver.cit.gvsig.geoprocess.buffer.fmap;
84

    
85
import com.hardcode.gdbms.engine.values.NumericValue;
86
import com.iver.cit.gvsig.fmap.DriverException;
87
import com.iver.cit.gvsig.fmap.core.IGeometry;
88
import com.iver.cit.gvsig.fmap.layers.FLayer;
89
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
90
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
91
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
92
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
93
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessingResultsProcessor;
94
/**
95
 * FeatureVisitor that computes buffer geometries from original geometrie
96
 * and an attribute value of IFeature
97
 * @author azabala
98
 *
99
 */
100
public class AttributeBufferVisitor extends BufferVisitor {
101
        /**
102
         * Attribute name from which visitor will get buffer distances
103
         */
104
        private String attributeName;
105
        /**
106
         * It allows visitor to get attribute values link to geometries
107
         */
108
        private SelectableDataSource recordset;
109
        /**
110
         * Processes individual buffer results
111
         * (we could persist them in a datastore, caching them, etc
112
         */
113
        private GeoprocessingResultsProcessor resultProcessor;
114
        
115
        
116
        /**
117
         * Constructor
118
         * @param attributeName
119
         * @param recordset
120
         */
121
        public AttributeBufferVisitor(String attributeName) throws GeoprocessException{
122
                this.attributeName = attributeName;
123
        }
124

    
125
        public void stop(FLayer layer) {
126
                resultProcessor.finish();
127
        }
128

    
129
        public boolean start(FLayer layer) {
130
                if(layer instanceof AlphanumericData && layer instanceof VectorialData){
131
                        try {
132
                                this.recordset = ((AlphanumericData)layer).getRecordset();
133
                        } catch (DriverException e) {
134
                                return false;//must we throw an Exception??
135
                        }
136
                        return true;
137
                }
138
                return false;
139
        }
140

    
141
        public double getBufferDistance(IGeometry g, int index){
142
                NumericValue value = null;
143
                try {
144
                        int fieldIndex = recordset.getFieldIndexByName(attributeName);
145
                        //we could throw an AttributeBufferException, or
146
                        //we could check preconditions in BufferGeoprocess
147
                        //TODO to check attribute is a NUMBER
148
                         value = (NumericValue) recordset.
149
                                         getFieldValue(index, fieldIndex);
150
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
151
                        return -1d;
152
                }
153
                //TODO catch ClassCastException 
154
                return value.doubleValue();
155
        }
156

    
157
        public String getProcessDescription() {
158
                return "Computing buffers applying distances from attribute";
159
        }
160
}
161