svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / featureiterators / IndexedSptQueryFeatureIterator.java @ 30109
History | View | Annotate | Download (5.43 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 30109 2009-07-23 10:34:02Z jpiera $
|
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 |
/**
|
87 |
* Spatial index to resolve the spatial query
|
88 |
*/
|
89 |
private ISpatialIndex spatialIndex;
|
90 |
|
91 |
/**
|
92 |
* List of indexes returned by te spatial index as result
|
93 |
* of the query, over iterator is going to iterate
|
94 |
*/
|
95 |
List<Integer> resultIdx; |
96 |
|
97 |
/**
|
98 |
* flag that marks if the iterator is doing a fast iteration
|
99 |
*/
|
100 |
boolean fastIteration;
|
101 |
|
102 |
/**
|
103 |
* Constructor.
|
104 |
*
|
105 |
* @param source
|
106 |
* @param sourceProj
|
107 |
* @param targetProj
|
108 |
* @param fieldNames
|
109 |
* @param spatialQuery
|
110 |
* @param spatialIndex
|
111 |
* @param fastIteration
|
112 |
* @throws ReadDriverException
|
113 |
*/
|
114 |
public IndexedSptQueryFeatureIterator(ReadableVectorial source,
|
115 |
IProjection sourceProj, |
116 |
IProjection targetProj, |
117 |
String[] fieldNames, |
118 |
Rectangle2D spatialQuery,
|
119 |
ISpatialIndex spatialIndex, |
120 |
boolean fastIteration)throws ReadDriverException { |
121 |
super(source, sourceProj, targetProj, fieldNames, spatialQuery,
|
122 |
fastIteration); |
123 |
this.spatialIndex = spatialIndex;
|
124 |
this.fastIteration = fastIteration;
|
125 |
//the query is in the source projection, not in the targetProj
|
126 |
//(in super() spatialQuery is reprojected)
|
127 |
this.resultIdx = this.spatialIndex.query(this.rect); |
128 |
} |
129 |
|
130 |
// public boolean hasNext() {
|
131 |
// if (fastIteration) {
|
132 |
// if (resultIdx != null && currentFeature < resultIdx.size())
|
133 |
// return true;
|
134 |
// else
|
135 |
// return false;
|
136 |
// } else {
|
137 |
// try {
|
138 |
// while (true) {
|
139 |
// if (currentFeature >= resultIdx.size())
|
140 |
// return false;
|
141 |
// if (spatialChecker.intersects(rect,
|
142 |
// ((Integer) resultIdx.get(currentFeature)).intValue()))
|
143 |
// return true;
|
144 |
// currentFeature++;
|
145 |
// }// while
|
146 |
// } catch (ExpansionFileReadException e) {
|
147 |
// e.printStackTrace();
|
148 |
// return false;
|
149 |
// } catch (ReadDriverException e) {
|
150 |
// e.printStackTrace();
|
151 |
// return false;
|
152 |
// }
|
153 |
//
|
154 |
// }
|
155 |
// }
|
156 |
|
157 |
public boolean hasNext(){ |
158 |
try {
|
159 |
while (true) { |
160 |
if (currentFeature >= resultIdx.size())
|
161 |
return false; |
162 |
Integer indexObj = resultIdx.get(currentFeature);
|
163 |
if(indexObj != null){ |
164 |
if (spatialChecker.intersects(rect,indexObj.intValue()))//((Integer) resultIdx.get(currentFeature)).intValue())) |
165 |
return true; |
166 |
}else{
|
167 |
return false; |
168 |
} |
169 |
currentFeature++; |
170 |
}// while
|
171 |
} catch (ExpansionFileReadException e) {
|
172 |
e.printStackTrace(); |
173 |
return false; |
174 |
} catch (ReadDriverException e) {
|
175 |
e.printStackTrace(); |
176 |
return false; |
177 |
} |
178 |
} |
179 |
|
180 |
public IFeature next() throws ReadDriverException { |
181 |
IGeometry geom; |
182 |
if (fastIteration) {
|
183 |
try {
|
184 |
geom = chekIfCloned(source.getShape(spatialChecker.getIndexOfLast())); |
185 |
reprojectIfNecessary(geom); |
186 |
} catch (ExpansionFileReadException e) {
|
187 |
throw new ReadDriverException("Error accediendo al driver", e); |
188 |
} |
189 |
} else {
|
190 |
//we dont check if spatialChecker.returnShapes because when fastIteration = false,
|
191 |
//spatialChecker is PrecisseSpatialChecker (always return shapes)
|
192 |
geom = spatialChecker.getLastGeometry(); |
193 |
} |
194 |
Value[] regAtt = getValues(spatialChecker.getIndexOfLast());
|
195 |
DefaultFeature feat = new DefaultFeature(geom, regAtt, spatialChecker.getIndexOfLast() + ""); |
196 |
currentFeature++; |
197 |
return feat;
|
198 |
} |
199 |
|
200 |
} |