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