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