svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / featureiterators / RandomAccessFeatureIterator.java @ 13074
History | View | Annotate | Download (1.94 KB)
1 |
package com.iver.cit.gvsig.fmap.drivers.featureiterators; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
|
5 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
6 |
import com.hardcode.gdbms.engine.values.Value; |
7 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
8 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
9 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
10 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
11 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
12 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
13 |
|
14 |
public class RandomAccessFeatureIterator implements IFeatureIterator { |
15 |
VectorialDriver drv; |
16 |
SelectableDataSource ds; |
17 |
Rectangle2D r = null; |
18 |
String epsg;
|
19 |
int numRec = 0; |
20 |
public RandomAccessFeatureIterator(VectorialDriver driver, SelectableDataSource sds, Rectangle2D r, String strEPSG) { |
21 |
this.drv = driver;
|
22 |
this.ds = sds;
|
23 |
this.r = r;
|
24 |
this.epsg = strEPSG;
|
25 |
} |
26 |
public RandomAccessFeatureIterator(VectorialDriver driver, SelectableDataSource sds, String strEPSG) { |
27 |
this.drv = driver;
|
28 |
this.ds = sds;
|
29 |
this.epsg = strEPSG;
|
30 |
} |
31 |
|
32 |
public boolean hasNext() throws ReadDriverException { |
33 |
boolean bMore = (numRec < drv.getShapeCount());
|
34 |
return bMore;
|
35 |
} |
36 |
|
37 |
public IFeature next() throws ReadDriverException { |
38 |
IGeometry geom; |
39 |
IFeature feat = null;
|
40 |
geom = drv.getShape(numRec); |
41 |
// Si pedimos solo las que entran en un rect?ngulo....
|
42 |
// ?QUE PASA SI TENEMOS UN ?NDICE ESPACIAL?
|
43 |
if (r != null){ |
44 |
while (!(geom.fastIntersects(r.getMinX(), r.getMinY(),
|
45 |
r.getWidth(), r.getHeight()))){ |
46 |
numRec++; |
47 |
if (numRec < drv.getShapeCount())
|
48 |
geom = drv.getShape(numRec); |
49 |
else
|
50 |
return null; |
51 |
} |
52 |
} |
53 |
Value[] regAtt = new Value[ds.getFieldCount()]; |
54 |
for (int fieldId = 0; fieldId < ds.getFieldCount(); fieldId++) { |
55 |
regAtt[fieldId] = ds.getFieldValue(numRec, fieldId); |
56 |
} |
57 |
feat = new DefaultFeature(geom, regAtt, numRec + ""); |
58 |
numRec++; |
59 |
return feat;
|
60 |
} |
61 |
|
62 |
public void closeIterator() throws ReadDriverException { |
63 |
|
64 |
} |
65 |
|
66 |
|
67 |
} |