svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / featureiterators / IndexedSptQueryFeatureIterator.java @ 11906
History | View | Annotate | Download (5.5 KB)
1 |
/*
|
---|---|
2 |
* Created on 12-abr-2007
|
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: IndexedSptQueryFeatureIterator.java 11906 2007-05-30 20:12:41Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.2 2007-05-30 20:12:20 azabala
|
49 |
* fastIteration = true optimized.
|
50 |
*
|
51 |
* Revision 1.1 2007/05/29 19:08:11 azabala
|
52 |
* first version in cvs
|
53 |
*
|
54 |
* Revision 1.1 2007/04/19 17:27:58 azabala
|
55 |
* first version in cvs
|
56 |
*
|
57 |
*
|
58 |
*/
|
59 |
package com.iver.cit.gvsig.fmap.drivers.featureiterators; |
60 |
|
61 |
import java.awt.geom.Rectangle2D; |
62 |
import java.util.List; |
63 |
|
64 |
import org.cresques.cts.IProjection; |
65 |
import org.geotools.resources.geometry.XRectangle2D; |
66 |
|
67 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
68 |
import com.hardcode.gdbms.engine.values.Value; |
69 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
70 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
71 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
72 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
73 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
74 |
import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex; |
75 |
|
76 |
/**
|
77 |
* Feature iterator for a spatial query resolved with an spatial index.
|
78 |
*
|
79 |
* @author azabala
|
80 |
*
|
81 |
*/
|
82 |
public class IndexedSptQueryFeatureIterator extends SpatialQueryFeatureIterator { |
83 |
|
84 |
/**
|
85 |
* Spatial index to resolve the spatial query
|
86 |
*/
|
87 |
private ISpatialIndex spatialIndex;
|
88 |
|
89 |
/**
|
90 |
* List of indexes returned by te spatial index as result
|
91 |
* of the query, over iterator is going to iterate
|
92 |
*/
|
93 |
List resultIdx;
|
94 |
|
95 |
/**
|
96 |
* flag that marks if the iterator is doing a fast iteration
|
97 |
*/
|
98 |
boolean fastIteration;
|
99 |
|
100 |
/**
|
101 |
* Constructor.
|
102 |
*
|
103 |
* @param source
|
104 |
* @param sourceProj
|
105 |
* @param targetProj
|
106 |
* @param fieldNames
|
107 |
* @param spatialQuery
|
108 |
* @param spatialIndex
|
109 |
* @param fastIteration
|
110 |
* @throws ReadDriverException
|
111 |
*/
|
112 |
public IndexedSptQueryFeatureIterator(ReadableVectorial source,
|
113 |
IProjection sourceProj, |
114 |
IProjection targetProj, |
115 |
String[] fieldNames, |
116 |
Rectangle2D spatialQuery,
|
117 |
ISpatialIndex spatialIndex, |
118 |
boolean fastIteration)throws ReadDriverException { |
119 |
super(source, sourceProj, targetProj, fieldNames, spatialQuery,
|
120 |
fastIteration); |
121 |
this.spatialIndex = spatialIndex;
|
122 |
this.fastIteration = fastIteration;
|
123 |
//the query is in the source projection, not in the targetProj
|
124 |
//(in super() spatialQuery is reprojected)
|
125 |
this.resultIdx = this.spatialIndex.query(this.rect); |
126 |
} |
127 |
|
128 |
// public boolean hasNext() {
|
129 |
// if (fastIteration) {
|
130 |
// if (resultIdx != null && currentFeature < resultIdx.size())
|
131 |
// return true;
|
132 |
// else
|
133 |
// return false;
|
134 |
// } else {
|
135 |
// try {
|
136 |
// while (true) {
|
137 |
// if (currentFeature >= resultIdx.size())
|
138 |
// return false;
|
139 |
// if (spatialChecker.intersects(rect,
|
140 |
// ((Integer) resultIdx.get(currentFeature)).intValue()))
|
141 |
// return true;
|
142 |
// currentFeature++;
|
143 |
// }// while
|
144 |
// } catch (ExpansionFileReadException e) {
|
145 |
// e.printStackTrace();
|
146 |
// return false;
|
147 |
// } catch (ReadDriverException e) {
|
148 |
// e.printStackTrace();
|
149 |
// return false;
|
150 |
// }
|
151 |
//
|
152 |
// }
|
153 |
// }
|
154 |
|
155 |
public boolean hasNext(){ |
156 |
try {
|
157 |
while (true) { |
158 |
if (currentFeature >= resultIdx.size())
|
159 |
return false; |
160 |
// if(fastIteration){
|
161 |
|
162 |
// IGeometry geom = source.getShape(((Integer) resultIdx.get(currentFeature)).intValue());
|
163 |
// if(XRectangle2D.intersectInclusive(geom, rect))
|
164 |
// return true;
|
165 |
|
166 |
// }else{
|
167 |
if (spatialChecker.intersects(rect,
|
168 |
((Integer) resultIdx.get(currentFeature)).intValue()))
|
169 |
return true; |
170 |
// }//if fastIteration
|
171 |
|
172 |
currentFeature++; |
173 |
}// while
|
174 |
} catch (ExpansionFileReadException e) {
|
175 |
e.printStackTrace(); |
176 |
return false; |
177 |
} catch (ReadDriverException e) {
|
178 |
e.printStackTrace(); |
179 |
return false; |
180 |
} |
181 |
} |
182 |
|
183 |
public IFeature next() throws ReadDriverException { |
184 |
IGeometry geom; |
185 |
if (fastIteration) {
|
186 |
try {
|
187 |
geom = source.getShape(spatialChecker.getIndexOfLast()); |
188 |
reprojectIfNecessary(geom); |
189 |
} catch (ExpansionFileReadException e) {
|
190 |
throw new ReadDriverException("Error accediendo al driver", e); |
191 |
} |
192 |
} else {
|
193 |
//we dont check if spatialChecker.returnShapes because when fastIteration = false,
|
194 |
//spatialChecker is PrecisseSpatialChecker (always return shapes)
|
195 |
geom = spatialChecker.getLastGeometry(); |
196 |
} |
197 |
Value[] regAtt = getValues(spatialChecker.getIndexOfLast());
|
198 |
DefaultFeature feat = new DefaultFeature(geom, regAtt, currentFeature
|
199 |
+ "");
|
200 |
currentFeature++; |
201 |
return feat;
|
202 |
} |
203 |
|
204 |
} |