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