root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / buffer / fmap / AttributeBufferVisitor.java @ 5412
History | View | Annotate | Download (4.6 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 5412 2006-05-24 21:15:07Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.1 2006-05-24 21:14:41 azabala
|
49 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
50 |
*
|
51 |
* Revision 1.8 2006/05/01 19:18:09 azabala
|
52 |
* revisi?n general del buffer (a?adidos anillos concentricos, buffers interiores y exteriores, etc)
|
53 |
*
|
54 |
* Revision 1.7 2006/03/28 16:27:16 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.6 2006/03/07 21:01:33 azabala
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
* Revision 1.5 2006/03/06 19:48:39 azabala
|
61 |
* *** empty log message ***
|
62 |
*
|
63 |
* Revision 1.2 2006/03/05 19:57:05 azabala
|
64 |
* *** empty log message ***
|
65 |
*
|
66 |
* Revision 1.1 2006/02/17 16:31:38 azabala
|
67 |
* *** empty log message ***
|
68 |
*
|
69 |
* Revision 1.3 2006/02/12 21:02:44 azabala
|
70 |
* *** empty log message ***
|
71 |
*
|
72 |
* Revision 1.2 2006/02/09 16:01:06 azabala
|
73 |
* First version in CVS
|
74 |
*
|
75 |
* Revision 1.1 2006/02/02 19:46:01 azabala
|
76 |
* First version in CVS
|
77 |
*
|
78 |
*
|
79 |
*/
|
80 |
package com.iver.cit.gvsig.geoprocess.buffer.fmap; |
81 |
|
82 |
import com.hardcode.gdbms.engine.values.NumericValue; |
83 |
import com.iver.cit.gvsig.fmap.DriverException; |
84 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
85 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
86 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
87 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
88 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
89 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
90 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
91 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessingResultsProcessor; |
92 |
import com.vividsolutions.jts.geom.Geometry; |
93 |
/**
|
94 |
* FeatureVisitor that computes buffer geometries from original geometrie
|
95 |
* and an attribute value of IFeature
|
96 |
* @author azabala
|
97 |
*
|
98 |
*/
|
99 |
public class AttributeBufferVisitor extends BufferVisitor { |
100 |
/**
|
101 |
* Attribute name from which visitor will get buffer distances
|
102 |
*/
|
103 |
private String attributeName; |
104 |
/**
|
105 |
* It allows visitor to get attribute values link to geometries
|
106 |
*/
|
107 |
private SelectableDataSource recordset;
|
108 |
/**
|
109 |
* Processes individual buffer results
|
110 |
* (we could persist them in a datastore, caching them, etc
|
111 |
*/
|
112 |
private GeoprocessingResultsProcessor resultProcessor;
|
113 |
|
114 |
|
115 |
/**
|
116 |
* Constructor
|
117 |
* @param attributeName
|
118 |
* @param recordset
|
119 |
*/
|
120 |
public AttributeBufferVisitor(String attributeName) throws GeoprocessException{ |
121 |
this.attributeName = attributeName;
|
122 |
} |
123 |
|
124 |
public void stop(FLayer layer) { |
125 |
resultProcessor.finish(); |
126 |
} |
127 |
|
128 |
public boolean start(FLayer layer) { |
129 |
if(layer instanceof AlphanumericData && layer instanceof VectorialData){ |
130 |
try {
|
131 |
this.recordset = ((AlphanumericData)layer).getRecordset();
|
132 |
} catch (DriverException e) {
|
133 |
return false;//must we throw an Exception?? |
134 |
} |
135 |
return true; |
136 |
} |
137 |
return false; |
138 |
} |
139 |
|
140 |
public double getBufferDistance(IGeometry g, int index){ |
141 |
NumericValue value = null;
|
142 |
try {
|
143 |
int fieldIndex = recordset.getFieldIndexByName(attributeName);
|
144 |
//we could throw an AttributeBufferException, or
|
145 |
//we could check preconditions in BufferGeoprocess
|
146 |
//TODO to check attribute is a NUMBER
|
147 |
value = (NumericValue) recordset. |
148 |
getFieldValue(index, fieldIndex); |
149 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
150 |
return -1d; |
151 |
} |
152 |
//TODO catch ClassCastException
|
153 |
return value.doubleValue();
|
154 |
} |
155 |
|
156 |
public String getProcessDescription() { |
157 |
return "Computing buffers applying distances from attribute"; |
158 |
} |
159 |
} |
160 |
|