svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / dissolve / fmap / AlphanumericDissolveVisitor.java @ 10626
History | View | Annotate | Download (5.52 KB)
1 |
/*
|
---|---|
2 |
* Created on 26-abr-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: AlphanumericDissolveVisitor.java 10626 2007-03-06 16:55:54Z caballero $
|
47 |
* $Log$
|
48 |
* Revision 1.2 2007-03-06 16:47:58 caballero
|
49 |
* Exceptions
|
50 |
*
|
51 |
* Revision 1.1 2006/06/20 18:20:45 azabala
|
52 |
* first version in cvs
|
53 |
*
|
54 |
* Revision 1.2 2006/06/02 18:21:28 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.1 2006/05/24 21:11:14 azabala
|
58 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
59 |
*
|
60 |
* Revision 1.2 2006/05/08 15:37:26 azabala
|
61 |
* added alphanumeric dissolve
|
62 |
*
|
63 |
* Revision 1.1 2006/05/01 19:21:50 azabala
|
64 |
* primera version en cvs (todav?a no funciona)
|
65 |
*
|
66 |
*
|
67 |
*/
|
68 |
package com.iver.cit.gvsig.geoprocess.impl.dissolve.fmap; |
69 |
|
70 |
import java.util.List; |
71 |
import java.util.Map; |
72 |
import java.util.Stack; |
73 |
|
74 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
75 |
import com.hardcode.gdbms.engine.values.Value; |
76 |
import com.iver.cit.gvsig.exceptions.visitors.ProcessVisitorException; |
77 |
import com.iver.cit.gvsig.exceptions.visitors.StartVisitorException; |
78 |
import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
79 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
80 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
81 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
82 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeatureProcessor; |
83 |
import com.vividsolutions.jts.geom.Geometry; |
84 |
|
85 |
/**
|
86 |
* <p>
|
87 |
* This Visitor generates a dissolve of input layer based
|
88 |
* in alphanumeric criteria: it dissolves two polygons with the same
|
89 |
* dissolve attribute value, and doesnt care if they are adjacent or not.
|
90 |
* </p>
|
91 |
* @author azabala
|
92 |
*
|
93 |
*/
|
94 |
public class AlphanumericDissolveVisitor extends DissolveVisitor { |
95 |
|
96 |
public AlphanumericDissolveVisitor(String dissolveField, |
97 |
FeatureProcessor processor) { |
98 |
super(dissolveField, processor);
|
99 |
} |
100 |
|
101 |
protected boolean verifyIfDissolve(DissolvedFeature f1, DissolvedFeature f2) { |
102 |
// dissolveField is the last
|
103 |
int fieldIndex = 0; |
104 |
if(numericField_sumarizeFunction != null) |
105 |
fieldIndex = numericField_sumarizeFunction.keySet().size(); |
106 |
Value adjacentVal = f1.getAttribute(fieldIndex); |
107 |
Value val = f2.getAttribute(fieldIndex); |
108 |
if (adjacentVal.doEquals(val)) {
|
109 |
return true; |
110 |
}// if val equals
|
111 |
|
112 |
return false; |
113 |
} |
114 |
|
115 |
class IndividualAlphaVisitor extends IndividualGeometryDissolveVisitor{ |
116 |
protected IndividualAlphaVisitor(DissolvedFeature feature, FBitSet dissolvedFeatures, Stack featuresToDissolve, Map fields_sumarize) { |
117 |
super(feature, dissolvedFeatures, featuresToDissolve, fields_sumarize);
|
118 |
} |
119 |
|
120 |
public void visit(IGeometry g, int index) throws VisitorException, ProcessVisitorException { |
121 |
if(g == null) |
122 |
return;
|
123 |
if (index == feature.getIndex())
|
124 |
return;
|
125 |
// have we dissolved this feature yet?
|
126 |
if (dissolvedFeatures.get(index))
|
127 |
return;
|
128 |
try {
|
129 |
DissolvedFeature adjacentFeature = createFeature(g, index); |
130 |
Geometry jtsGeo = g.toJTSGeometry(); |
131 |
adjacentFeature.setJtsGeometry(jtsGeo); |
132 |
if (verifyIfDissolve(feature, adjacentFeature)) {
|
133 |
dissolvedFeatures.set(index); |
134 |
// we actualize geometry by unioning
|
135 |
featuresToDissolve.push(adjacentFeature); |
136 |
applySumarizeFunction(index); |
137 |
} |
138 |
} catch (ReadDriverException e) {
|
139 |
throw new ProcessVisitorException(recordset.getName(),e, |
140 |
"Error al cargar los pol?gonos adyacentes durante un dissolve");
|
141 |
} |
142 |
} |
143 |
public String getProcessDescription() { |
144 |
return ""; |
145 |
} |
146 |
public void stop(FLayer layer) throws VisitorException { |
147 |
} |
148 |
public boolean start(FLayer layer) throws StartVisitorException { |
149 |
return true; |
150 |
} |
151 |
} |
152 |
|
153 |
protected Value[] dissolveGeometries(Stack toDissol, |
154 |
List geometries) throws ReadDriverException, VisitorException { |
155 |
IndividualAlphaVisitor visitor = null;
|
156 |
DissolvedFeature feature = null;
|
157 |
while (toDissol.size() != 0) { |
158 |
feature = (DissolvedFeature) toDissol.pop(); |
159 |
// flags this idx (to not to process in future)
|
160 |
dissolvedGeometries.set(feature.getIndex()); |
161 |
if (visitor == null) { |
162 |
visitor = new IndividualAlphaVisitor(feature,
|
163 |
dissolvedGeometries, toDissol, |
164 |
numericField_sumarizeFunction); |
165 |
visitor.setDissolveField(this.dissolveField);
|
166 |
} else {
|
167 |
visitor.setProcessedFeature(feature); |
168 |
} |
169 |
strategy.process(visitor); |
170 |
//al final de toda la pila de llamadas recursivas,
|
171 |
//geometries tendr? todas las geometrias que debemos dissolver
|
172 |
geometries.add(feature.getJtsGeometry()); |
173 |
}// while
|
174 |
Value[] values = visitor.getSumarizedValues2();
|
175 |
return values;
|
176 |
} |
177 |
|
178 |
} |