svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataFile / src-test / org / gvsig / fmap / data / feature / file / dxf / DXFTest.java @ 24081
History | View | Annotate | Download (4.18 KB)
1 |
package org.gvsig.fmap.data.feature.file.dxf; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.Iterator; |
5 |
|
6 |
import junit.framework.TestCase; |
7 |
|
8 |
import org.gvsig.fmap.data.DataManager; |
9 |
import org.gvsig.fmap.data.exceptions.CloseException; |
10 |
import org.gvsig.fmap.data.exceptions.InitializeException; |
11 |
import org.gvsig.fmap.data.exceptions.ReadException; |
12 |
import org.gvsig.fmap.data.feature.Feature; |
13 |
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor; |
14 |
import org.gvsig.fmap.data.feature.FeatureSet; |
15 |
import org.gvsig.fmap.data.feature.FeatureStore; |
16 |
import org.gvsig.fmap.data.feature.FeatureType; |
17 |
import org.gvsig.fmap.data.feature.file.DataStoreTest; |
18 |
import org.gvsig.fmap.data.impl.DefaultDataManager; |
19 |
|
20 |
public class DXFTest extends TestCase { |
21 |
public static final File file = new File(DataStoreTest.class.getResource( |
22 |
"data/prueba.dxf").getFile());
|
23 |
|
24 |
|
25 |
public static void main(String[] args) { |
26 |
} |
27 |
|
28 |
protected void setUp() throws Exception { |
29 |
super.setUp();
|
30 |
} |
31 |
|
32 |
public void testInitialize() { |
33 |
Register.selfRegister(); |
34 |
DataManager manager = DefaultDataManager.getManager(); |
35 |
FeatureStore store =null;
|
36 |
|
37 |
DXFStoreParameters dxfParameters=null;
|
38 |
try {
|
39 |
dxfParameters=(DXFStoreParameters)manager.createStoreParameters(DXFStore.DATASTORE_NAME); |
40 |
} catch (InitializeException e2) {
|
41 |
e2.printStackTrace(); |
42 |
fail(); |
43 |
} |
44 |
dxfParameters.setFile(file); |
45 |
// IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
46 |
// dxfParameters.setSRSID(proj);
|
47 |
dxfParameters.setSRSID("EPSG:23030");
|
48 |
try {
|
49 |
store=(FeatureStore)manager.createStore(dxfParameters); |
50 |
} catch (InitializeException e) {
|
51 |
// TODO Auto-generated catch block
|
52 |
e.printStackTrace(); |
53 |
} |
54 |
|
55 |
FeatureType ft=store.getDefaultFeatureType(); |
56 |
FeatureSet featureCollection=null;
|
57 |
try {
|
58 |
featureCollection = (FeatureSet)store.getDataCollection(ft,null,null); |
59 |
|
60 |
} catch (ReadException e) {
|
61 |
// TODO Auto-generated catch block
|
62 |
e.printStackTrace(); |
63 |
} |
64 |
Iterator iter = featureCollection.iterator();
|
65 |
while (iter.hasNext()) {
|
66 |
Feature feature = (Feature)iter.next(); |
67 |
System.out.println("DXF Feature ------------------- "); |
68 |
Iterator iterator=ft.iterator();
|
69 |
while (iterator.hasNext()) {
|
70 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next(); |
71 |
int i=descriptor.ordinal();
|
72 |
String type=descriptor.getDataType();
|
73 |
if (type.equals(FeatureAttributeDescriptor.BOOLEAN)){
|
74 |
System.out.println("Boolean ----- "+ feature.getBoolean(i)); |
75 |
}else if (type.equals(FeatureAttributeDescriptor.BYTE)){ |
76 |
System.out.println("Byte ----- "+ feature.getByte(i)); |
77 |
}else if (type.equals(FeatureAttributeDescriptor.DATE)){ |
78 |
System.out.println("Date ----- "+ feature.getDate(i)); |
79 |
}else if (type.equals(FeatureAttributeDescriptor.DOUBLE)){ |
80 |
System.out.println("Double ----- "+ feature.getDouble(i)); |
81 |
}else if (type.equals(FeatureAttributeDescriptor.FLOAT)){ |
82 |
System.out.println("Float ----- "+ feature.getFloat(i)); |
83 |
}else if (type.equals(FeatureAttributeDescriptor.INT)){ |
84 |
System.out.println("Integer ----- "+ feature.getInt(i)); |
85 |
}else if (type.equals(FeatureAttributeDescriptor.LONG)){ |
86 |
System.out.println("Long ----- "+ feature.getLong(i)); |
87 |
}else if (type.equals(FeatureAttributeDescriptor.STRING)){ |
88 |
System.out.println("String ----- "+ feature.getString(i)); |
89 |
}else if (type.equals(FeatureAttributeDescriptor.GEOMETRY)){ |
90 |
|
91 |
System.out.println("Geometry ----- "+ feature.getGeometry(i)); |
92 |
} |
93 |
} |
94 |
} |
95 |
iter = null;
|
96 |
featureCollection.dispose(); |
97 |
|
98 |
try {
|
99 |
|
100 |
store.dispose(); |
101 |
} catch (CloseException e) {
|
102 |
// TODO Auto-generated catch block
|
103 |
e.printStackTrace(); |
104 |
} |
105 |
} |
106 |
|
107 |
public void test_Resources(){ |
108 |
|
109 |
DataManager manager = DefaultDataManager.getManager(); |
110 |
Register.selfRegister(); |
111 |
|
112 |
DXFStoreParameters parameters=null;
|
113 |
|
114 |
try {
|
115 |
parameters=(DXFStoreParameters)manager.createStoreParameters(DXFStore.DATASTORE_NAME); |
116 |
} catch (InitializeException e) {
|
117 |
e.printStackTrace(); |
118 |
fail(); |
119 |
} |
120 |
parameters.setFile(file); |
121 |
// IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
122 |
parameters.setSRSID("EPSG:23030");
|
123 |
|
124 |
|
125 |
DataStoreTest.doFileResourceTest(parameters); |
126 |
} |
127 |
|
128 |
} |