svn-gvsig-desktop / trunk / extensions / extGraph / src / org / gvsig / graph / core / DefaultFeatureExtractor.java @ 30840
History | View | Annotate | Download (2.89 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 Software Colaborativo (www.scolab.es) development
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.graph.core; |
29 |
|
30 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
31 |
import com.hardcode.gdbms.engine.values.Value; |
32 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
33 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
34 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
35 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
36 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
37 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
38 |
|
39 |
public class DefaultFeatureExtractor implements IFeatureExtractor { |
40 |
|
41 |
private FLyrVect lyr;
|
42 |
|
43 |
public DefaultFeatureExtractor(FLyrVect lyr) {
|
44 |
this.lyr = lyr;
|
45 |
} |
46 |
|
47 |
public IFeature getFeature(long i) { |
48 |
ReadableVectorial va = lyr.getSource(); |
49 |
IFeature f = null;
|
50 |
try {
|
51 |
va.start(); |
52 |
f = va.getFeature((int) i);
|
53 |
va.stop(); |
54 |
} catch (ExpansionFileReadException e) {
|
55 |
// TODO Auto-generated catch block
|
56 |
e.printStackTrace(); |
57 |
} catch (ReadDriverException e) {
|
58 |
// TODO Auto-generated catch block
|
59 |
e.printStackTrace(); |
60 |
} |
61 |
return f;
|
62 |
} |
63 |
|
64 |
public Value getFieldValue(long i, int idField) { |
65 |
|
66 |
Value f = null;
|
67 |
try {
|
68 |
SelectableDataSource rs = lyr.getSource().getRecordset(); |
69 |
rs.start(); |
70 |
f = rs.getFieldValue(i, idField); |
71 |
rs.stop(); |
72 |
} catch (ExpansionFileReadException e) {
|
73 |
// TODO Auto-generated catch block
|
74 |
e.printStackTrace(); |
75 |
} catch (ReadDriverException e) {
|
76 |
// TODO Auto-generated catch block
|
77 |
e.printStackTrace(); |
78 |
} |
79 |
return f;
|
80 |
|
81 |
} |
82 |
|
83 |
public IGeometry getGeometry(long i) { |
84 |
ReadableVectorial va = lyr.getSource(); |
85 |
IGeometry f = null;
|
86 |
try {
|
87 |
va.start(); |
88 |
f = va.getShape((int) i);
|
89 |
va.stop(); |
90 |
} catch (ExpansionFileReadException e) {
|
91 |
// TODO Auto-generated catch block
|
92 |
e.printStackTrace(); |
93 |
} catch (ReadDriverException e) {
|
94 |
// TODO Auto-generated catch block
|
95 |
e.printStackTrace(); |
96 |
} |
97 |
return f;
|
98 |
|
99 |
} |
100 |
|
101 |
} |
102 |
|