svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libFMap_dataFile / src-test / org / gvsig / data / datastores / vectorial / file / dxf / DXFTest.java @ 22125
History | View | Annotate | Download (4.1 KB)
1 |
package org.gvsig.data.datastores.vectorial.file.dxf; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.Iterator; |
5 |
|
6 |
import junit.framework.TestCase; |
7 |
|
8 |
import org.gvsig.projection.cts.IProjection; |
9 |
import org.gvsig.data.CloseException; |
10 |
import org.gvsig.data.DataManager; |
11 |
import org.gvsig.data.InitializeException; |
12 |
import org.gvsig.data.OpenException; |
13 |
import org.gvsig.data.ReadException; |
14 |
import org.gvsig.data.datastores.vectorial.file.DataStoreTest; |
15 |
import org.gvsig.data.vectorial.Feature; |
16 |
import org.gvsig.data.vectorial.FeatureAttributeDescriptor; |
17 |
import org.gvsig.data.vectorial.FeatureCollection; |
18 |
import org.gvsig.data.vectorial.FeatureType; |
19 |
import org.gvsig.fmap.crs.CRSFactory; |
20 |
|
21 |
public class DXFTest extends TestCase { |
22 |
private File file = new File(DataStoreTest.class.getResource("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 = DataManager.getManager(); |
35 |
DXFStore store =null;
|
36 |
|
37 |
DXFStoreParameters dxfParameters=null;
|
38 |
dxfParameters=(DXFStoreParameters)manager.createDataStoreParameters(DXFStore.DATASTORE_NAME); |
39 |
dxfParameters.setFile(file); |
40 |
IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
41 |
dxfParameters.setProjection(proj); |
42 |
try {
|
43 |
store=(DXFStore)manager.createDataStore(dxfParameters); |
44 |
} catch (InitializeException e) {
|
45 |
// TODO Auto-generated catch block
|
46 |
e.printStackTrace(); |
47 |
} |
48 |
try {
|
49 |
store.open(); |
50 |
} catch (OpenException e1) {
|
51 |
// TODO Auto-generated catch block
|
52 |
e1.printStackTrace(); |
53 |
} |
54 |
|
55 |
FeatureType ft=store.getDefaultFeatureType(); |
56 |
FeatureCollection featureCollection=null;
|
57 |
try {
|
58 |
featureCollection = (FeatureCollection)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.TYPE_BOOLEAN)){
|
74 |
System.out.println("Boolean ----- "+ feature.getBoolean(i)); |
75 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_BYTE)){ |
76 |
System.out.println("Byte ----- "+ feature.getByte(i)); |
77 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_DATE)){ |
78 |
System.out.println("Date ----- "+ feature.getDate(i)); |
79 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_DOUBLE)){ |
80 |
System.out.println("Double ----- "+ feature.getDouble(i)); |
81 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_FLOAT)){ |
82 |
System.out.println("Float ----- "+ feature.getFloat(i)); |
83 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_INT)){ |
84 |
System.out.println("Integer ----- "+ feature.getInt(i)); |
85 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_LONG)){ |
86 |
System.out.println("Long ----- "+ feature.getLong(i)); |
87 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_STRING)){ |
88 |
System.out.println("String ----- "+ feature.getString(i)); |
89 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_GEOMETRY)){ |
90 |
|
91 |
System.out.println("Geometry ----- "+ feature.getGeometry(i)); |
92 |
} |
93 |
} |
94 |
} |
95 |
iter = null;
|
96 |
featureCollection.dispose(); |
97 |
|
98 |
try {
|
99 |
store.close(); |
100 |
|
101 |
store.dispose(); |
102 |
} catch (CloseException e) {
|
103 |
// TODO Auto-generated catch block
|
104 |
e.printStackTrace(); |
105 |
} |
106 |
} |
107 |
|
108 |
public void test_Resources(){ |
109 |
|
110 |
DataManager manager = DataManager.getManager(); |
111 |
Register.selfRegister(); |
112 |
|
113 |
DXFStoreParameters parameters; |
114 |
|
115 |
parameters=(DXFStoreParameters)manager.createDataStoreParameters(DXFStore.DATASTORE_NAME); |
116 |
parameters.setFile(file); |
117 |
IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
118 |
parameters.setProjection(proj); |
119 |
|
120 |
|
121 |
DataStoreTest.doFileResourceTest(parameters); |
122 |
} |
123 |
|
124 |
} |