root / trunk / libraries / libDataSourceBaseDrivers / src-test / org / gvsig / data / datastores / vectorial / driver / shp / SHPTest.java @ 19736
History | View | Annotate | Download (3.85 KB)
1 |
package org.gvsig.data.datastores.vectorial.driver.shp; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.Iterator; |
5 |
|
6 |
import junit.framework.TestCase; |
7 |
|
8 |
import org.gvsig.data.datastores.vectorial.driver.DataStoreTest; |
9 |
import org.gvsig.data.datastores.vectorial.driver.shp.fileshp.SHP; |
10 |
import org.gvsig.data.exception.CloseException; |
11 |
import org.gvsig.data.exception.InitializeException; |
12 |
import org.gvsig.data.exception.OpenException; |
13 |
import org.gvsig.data.exception.ReadException; |
14 |
import org.gvsig.data.vectorial.IFeature; |
15 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
16 |
import org.gvsig.data.vectorial.IFeatureCollection; |
17 |
import org.gvsig.data.vectorial.IFeatureType; |
18 |
import org.gvsig.data.vectorial.expansionadapter.FeatureManager; |
19 |
import org.gvsig.data.vectorial.expansionadapter.MemoryExpansionAdapter; |
20 |
|
21 |
import com.iver.cit.gvsig.fmap.drivers.dbf.TestDbf; |
22 |
|
23 |
public class SHPTest extends TestCase { |
24 |
SHPStore store = new SHPStore();
|
25 |
private File file = new File(DataStoreTest.class.getResource("data/prueba.shp").getFile()); |
26 |
|
27 |
|
28 |
public static void main(String[] args) { |
29 |
junit.textui.TestRunner.run(TestDbf.class); |
30 |
} |
31 |
|
32 |
protected void setUp() throws Exception { |
33 |
super.setUp();
|
34 |
} |
35 |
|
36 |
/*
|
37 |
* Test method for 'com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver.initialize()'
|
38 |
*/
|
39 |
public void testInitialize() { |
40 |
Register.selfRegister(); |
41 |
SHPStoreParameters shpParameters=new SHPStoreParameters();
|
42 |
shpParameters.setSHPFile(file); |
43 |
shpParameters.setDBFFile(SHP.getDbfFile(file)); |
44 |
shpParameters.setSHXFile(SHP.getShxFile(file)); |
45 |
try {
|
46 |
store.init(shpParameters); |
47 |
} catch (InitializeException e) {
|
48 |
// TODO Auto-generated catch block
|
49 |
e.printStackTrace(); |
50 |
} |
51 |
try {
|
52 |
store.open(); |
53 |
} catch (OpenException e2) {
|
54 |
// TODO Auto-generated catch block
|
55 |
e2.printStackTrace(); |
56 |
} |
57 |
|
58 |
IFeatureType ft=store.getDefaultFeatureType(); |
59 |
FeatureManager featureManager=new FeatureManager(new MemoryExpansionAdapter()); |
60 |
IFeatureCollection featureCollection=null;
|
61 |
try {
|
62 |
featureCollection = (IFeatureCollection)store.getDataCollection(ft,null,null); |
63 |
} catch (ReadException e1) {
|
64 |
// TODO Auto-generated catch block
|
65 |
e1.printStackTrace(); |
66 |
} |
67 |
Iterator iter = featureCollection.iterator();
|
68 |
while (iter.hasNext()) {
|
69 |
IFeature feature = (IFeature)iter.next(); |
70 |
System.out.println("SHP Feature ------------------- "); |
71 |
for (int i=0;i<ft.size();i++){ |
72 |
|
73 |
IFeatureAttributeDescriptor descriptor=(IFeatureAttributeDescriptor)ft.get(i); |
74 |
String type=descriptor.getDataType();
|
75 |
if (type.equals(IFeatureAttributeDescriptor.TYPE_BOOLEAN)){
|
76 |
System.out.println("Boolean ----- "+ feature.getBoolean(i)); |
77 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_BYTE)){ |
78 |
System.out.println("Byte ----- "+ feature.getByte(i)); |
79 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_DATE)){ |
80 |
System.out.println("Date ----- "+ feature.getDate(i)); |
81 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_DOUBLE)){ |
82 |
System.out.println("Double ----- "+ feature.getDouble(i)); |
83 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_FLOAT)){ |
84 |
System.out.println("Float ----- "+ feature.getFloat(i)); |
85 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_INT)){ |
86 |
System.out.println("Integer ----- "+ feature.getInt(i)); |
87 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_LONG)){ |
88 |
System.out.println("Long ----- "+ feature.getLong(i)); |
89 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_STRING)){ |
90 |
System.out.println("String ----- "+ feature.getString(i)); |
91 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)){ |
92 |
|
93 |
System.out.println("Geometry ----- "+ feature.getGeometry(i)); |
94 |
} |
95 |
} |
96 |
} |
97 |
|
98 |
try {
|
99 |
store.close(); |
100 |
} catch (CloseException e) {
|
101 |
// TODO Auto-generated catch block
|
102 |
e.printStackTrace(); |
103 |
} |
104 |
store.dispose(); |
105 |
} |
106 |
} |