svn-gvsig-desktop / trunk / libraries / libFMap_dataFile / src-test / org / gvsig / data / datastores / vectorial / file / dxf / DXFTest.java @ 20692
History | View | Annotate | Download (4.67 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.cresques.cts.IProjection; |
9 |
import org.gvsig.data.DataManager; |
10 |
import org.gvsig.data.datastores.vectorial.file.DataStoreTest; |
11 |
import org.gvsig.data.datastores.vectorial.file.dxf.DXFStore; |
12 |
import org.gvsig.data.datastores.vectorial.file.dxf.DXFStoreParameters; |
13 |
import org.gvsig.data.datastores.vectorial.file.dxf.Register; |
14 |
import org.gvsig.data.datastores.vectorial.file.shp.SHPStore; |
15 |
import org.gvsig.data.datastores.vectorial.file.shp.SHPStoreParameters; |
16 |
import org.gvsig.data.exception.CloseException; |
17 |
import org.gvsig.data.exception.InitializeException; |
18 |
import org.gvsig.data.exception.OpenException; |
19 |
import org.gvsig.data.exception.ReadException; |
20 |
import org.gvsig.data.vectorial.FeatureManager; |
21 |
import org.gvsig.data.vectorial.IFeature; |
22 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
23 |
import org.gvsig.data.vectorial.IFeatureCollection; |
24 |
import org.gvsig.data.vectorial.IFeatureType; |
25 |
import org.gvsig.data.vectorial.IsNotFeatureSettingException; |
26 |
import org.gvsig.data.vectorial.expansionadapter.MemoryExpansionAdapter; |
27 |
|
28 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
29 |
|
30 |
public class DXFTest extends TestCase { |
31 |
private File file = new File(DataStoreTest.class.getResource("data/prueba.dxf").getFile()); |
32 |
|
33 |
|
34 |
public static void main(String[] args) { |
35 |
} |
36 |
|
37 |
protected void setUp() throws Exception { |
38 |
super.setUp();
|
39 |
} |
40 |
|
41 |
public void testInitialize() { |
42 |
Register.selfRegister(); |
43 |
DataManager manager = DataManager.getManager(); |
44 |
DXFStore store =null;
|
45 |
|
46 |
DXFStoreParameters dxfParameters=null;
|
47 |
dxfParameters=(DXFStoreParameters)manager.createDataStoreParameters(DXFStore.DATASTORE_NAME); |
48 |
dxfParameters.setFile(file); |
49 |
IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
50 |
dxfParameters.setProjection(proj); |
51 |
try {
|
52 |
store=(DXFStore)manager.createDataStore(dxfParameters); |
53 |
} catch (InitializeException e) {
|
54 |
// TODO Auto-generated catch block
|
55 |
e.printStackTrace(); |
56 |
} |
57 |
try {
|
58 |
store.open(); |
59 |
} catch (OpenException e1) {
|
60 |
// TODO Auto-generated catch block
|
61 |
e1.printStackTrace(); |
62 |
} |
63 |
|
64 |
IFeatureType ft=store.getDefaultFeatureType(); |
65 |
IFeatureCollection featureCollection=null;
|
66 |
try {
|
67 |
featureCollection = (IFeatureCollection)store.getDataCollection(ft,null,null); |
68 |
|
69 |
} catch (ReadException e) {
|
70 |
// TODO Auto-generated catch block
|
71 |
e.printStackTrace(); |
72 |
} |
73 |
Iterator iter = featureCollection.iterator();
|
74 |
while (iter.hasNext()) {
|
75 |
IFeature feature = (IFeature)iter.next(); |
76 |
System.out.println("DXF Feature ------------------- "); |
77 |
Iterator iterator=ft.iterator();
|
78 |
while (iterator.hasNext()) {
|
79 |
IFeatureAttributeDescriptor descriptor = (IFeatureAttributeDescriptor) iterator.next(); |
80 |
int i=descriptor.ordinal();
|
81 |
String type=descriptor.getDataType();
|
82 |
if (type.equals(IFeatureAttributeDescriptor.TYPE_BOOLEAN)){
|
83 |
System.out.println("Boolean ----- "+ feature.getBoolean(i)); |
84 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_BYTE)){ |
85 |
System.out.println("Byte ----- "+ feature.getByte(i)); |
86 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_DATE)){ |
87 |
System.out.println("Date ----- "+ feature.getDate(i)); |
88 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_DOUBLE)){ |
89 |
System.out.println("Double ----- "+ feature.getDouble(i)); |
90 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_FLOAT)){ |
91 |
System.out.println("Float ----- "+ feature.getFloat(i)); |
92 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_INT)){ |
93 |
System.out.println("Integer ----- "+ feature.getInt(i)); |
94 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_LONG)){ |
95 |
System.out.println("Long ----- "+ feature.getLong(i)); |
96 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_STRING)){ |
97 |
System.out.println("String ----- "+ feature.getString(i)); |
98 |
}else if (type.equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)){ |
99 |
|
100 |
System.out.println("Geometry ----- "+ feature.getGeometry(i)); |
101 |
} |
102 |
} |
103 |
} |
104 |
iter = null;
|
105 |
featureCollection.dispose(); |
106 |
|
107 |
try {
|
108 |
store.close(); |
109 |
|
110 |
store.dispose(); |
111 |
} catch (CloseException e) {
|
112 |
// TODO Auto-generated catch block
|
113 |
e.printStackTrace(); |
114 |
} |
115 |
} |
116 |
|
117 |
public void test_Resources(){ |
118 |
|
119 |
DataManager manager = DataManager.getManager(); |
120 |
Register.selfRegister(); |
121 |
|
122 |
DXFStoreParameters parameters; |
123 |
|
124 |
parameters=(DXFStoreParameters)manager.createDataStoreParameters(DXFStore.DATASTORE_NAME); |
125 |
parameters.setFile(file); |
126 |
IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
127 |
parameters.setProjection(proj); |
128 |
|
129 |
|
130 |
DataStoreTest.doFileResourceTest(parameters); |
131 |
} |
132 |
|
133 |
} |