root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / spatialjoin / fmap / IntersectsFinderFeatureVisitor.java @ 5628
History | View | Annotate | Download (5.61 KB)
1 |
/*
|
---|---|
2 |
* Created on 01-mar-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: IntersectsFinderFeatureVisitor.java 5628 2006-06-02 18:21:28Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.2 2006-06-02 18:21:28 azabala
|
49 |
* *** empty log message ***
|
50 |
*
|
51 |
* Revision 1.1 2006/05/24 21:09:47 azabala
|
52 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
53 |
*
|
54 |
* Revision 1.2 2006/03/07 21:01:33 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.1 2006/03/06 19:48:39 azabala
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
* Revision 1.1 2006/03/05 19:59:47 azabala
|
61 |
* *** empty log message ***
|
62 |
*
|
63 |
*
|
64 |
*/
|
65 |
package com.iver.cit.gvsig.geoprocess.spatialjoin.fmap; |
66 |
|
67 |
import java.util.ArrayList; |
68 |
import java.util.Iterator; |
69 |
import java.util.List; |
70 |
import java.util.Map; |
71 |
|
72 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
73 |
import com.hardcode.gdbms.engine.values.NumericValue; |
74 |
import com.hardcode.gdbms.engine.values.Value; |
75 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
76 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
77 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
78 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
79 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
80 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
81 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
82 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
83 |
import com.iver.cit.gvsig.geoprocess.core.fmap.SummarizationFunction; |
84 |
import com.vividsolutions.jts.geom.Geometry; |
85 |
/**
|
86 |
* Given a feature of JOIN source layer,
|
87 |
* it looks for intersecting geometries of JOIN target layer and applies
|
88 |
* a sumarization function to its numeric fields.
|
89 |
*
|
90 |
* @author azabala
|
91 |
*
|
92 |
*/
|
93 |
public class IntersectsFinderFeatureVisitor implements FeatureVisitor { |
94 |
/**
|
95 |
* Reads atributes of target layer
|
96 |
*/
|
97 |
SelectableDataSource targetRecordset; |
98 |
/**
|
99 |
* Geometry of layer A whose intersections of layer B
|
100 |
* we are looking for
|
101 |
*/
|
102 |
private Geometry queryGeometry;
|
103 |
/**
|
104 |
* It has indexes of intersections
|
105 |
*/
|
106 |
private List intersectIndexes = null; |
107 |
/**
|
108 |
* Relates a set of sumarization functions with a numeric field
|
109 |
* name
|
110 |
*/
|
111 |
Map fields_sumarizationFun = null; |
112 |
|
113 |
private FBitSet selection;
|
114 |
|
115 |
public IntersectsFinderFeatureVisitor(Geometry geometry, Map functions) { |
116 |
this.queryGeometry = geometry;
|
117 |
this.fields_sumarizationFun = functions;
|
118 |
intersectIndexes = new ArrayList(); |
119 |
} |
120 |
|
121 |
public IntersectsFinderFeatureVisitor(Map functions) { |
122 |
this.fields_sumarizationFun = functions;
|
123 |
intersectIndexes = new ArrayList(); |
124 |
} |
125 |
|
126 |
public void visit(IGeometry g, int index) throws VisitException { |
127 |
if(g == null) |
128 |
return;
|
129 |
if(selection != null){ |
130 |
if(! selection.get(index)){
|
131 |
//dont process feature because is not selected
|
132 |
return;
|
133 |
} |
134 |
} |
135 |
Geometry jtsGeo = g.toJTSGeometry(); |
136 |
if (queryGeometry.intersects(jtsGeo)) {
|
137 |
intersectIndexes.add(new Integer(index)); |
138 |
try {
|
139 |
applySumarizeFunction(index); |
140 |
} catch (DriverException e) {
|
141 |
throw new VisitException("Error al acceder a los atributos de la capa destino en un spatial join"); |
142 |
} |
143 |
} |
144 |
} |
145 |
|
146 |
public String getProcessDescription() { |
147 |
return "Looking intersects and sumarizing for a spatial join"; |
148 |
} |
149 |
|
150 |
private void applySumarizeFunction(int recordIndex) throws DriverException { |
151 |
Iterator fieldsIt = fields_sumarizationFun.keySet().iterator();
|
152 |
while (fieldsIt.hasNext()) {
|
153 |
String field = (String) fieldsIt.next(); |
154 |
int fieldIndex = targetRecordset.getFieldIndexByName(field);
|
155 |
Value valToSumarize = targetRecordset.getFieldValue(recordIndex, |
156 |
fieldIndex); |
157 |
SummarizationFunction[] functions =
|
158 |
(SummarizationFunction[]) fields_sumarizationFun.get(field);
|
159 |
for (int i = 0; i < functions.length; i++) { |
160 |
functions[i].process((NumericValue) valToSumarize); |
161 |
}// for
|
162 |
}// while
|
163 |
} |
164 |
|
165 |
public List getIntersectIndexes() { |
166 |
return intersectIndexes;
|
167 |
} |
168 |
|
169 |
public int getNumIntersections() { |
170 |
return intersectIndexes.size();
|
171 |
} |
172 |
|
173 |
public boolean hasFoundIntersections() { |
174 |
return intersectIndexes.size() > 0; |
175 |
} |
176 |
|
177 |
public void stop(FLayer layer) { |
178 |
} |
179 |
|
180 |
public boolean start(FLayer layer) { |
181 |
if (layer instanceof AlphanumericData && layer instanceof VectorialData) { |
182 |
try {
|
183 |
targetRecordset = ((AlphanumericData) layer).getRecordset(); |
184 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) {
|
185 |
return false; |
186 |
} |
187 |
return true; |
188 |
} |
189 |
return false; |
190 |
} |
191 |
|
192 |
public void setQueryGeometry(Geometry queryGeometry) { |
193 |
this.queryGeometry = queryGeometry;
|
194 |
} |
195 |
|
196 |
public void setSelection(FBitSet selection) { |
197 |
this.selection = selection;
|
198 |
} |
199 |
|
200 |
} |