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