Revision 19654

View differences:

trunk/libraries/libDataSourceBaseDrivers/src-test/org/gvsig/data/datastores/vectorial/driver/dxf/DXFTest.java
52 52
		Iterator iter = featureCollection.iterator();
53 53
		while (iter.hasNext()) {
54 54
			IFeature feature = (IFeature)iter.next();
55
			System.out.println("SHP Feature ------------------- ");
55
			System.out.println("DXF Feature ------------------- ");
56 56
			for (int i=0;i<ft.size();i++){
57 57

  
58 58
				IFeatureAttributeDescriptor descriptor=(IFeatureAttributeDescriptor)ft.get(i);
trunk/libraries/libDataSourceBaseDrivers/src-test/org/gvsig/data/datastores/vectorial/driver/DataStoreTest.java
9 9
import org.gvsig.data.DataSourceManager;
10 10
import org.gvsig.data.IDataStoreParameters;
11 11
import org.gvsig.data.datastores.vectorial.driver.dbf.DBFDriverParameters;
12
import org.gvsig.data.datastores.vectorial.driver.dgn.DGNDriverParameters;
12 13
import org.gvsig.data.datastores.vectorial.driver.dxf.DXFDriverParameters;
13 14
import org.gvsig.data.datastores.vectorial.driver.shp.ShpDriverParameters;
14 15
import org.gvsig.data.datastores.vectorial.driver.shp.fileshp.SHP;
......
18 19
import org.gvsig.data.exception.ReadException;
19 20
import org.gvsig.data.exception.WriteException;
20 21
import org.gvsig.data.vectorial.IFeature;
21
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor;
22 22
import org.gvsig.data.vectorial.IFeatureCollection;
23 23
import org.gvsig.data.vectorial.IFeatureStore;
24 24
import org.gvsig.data.vectorial.IFeatureType;
25 25
import org.gvsig.data.vectorial.visitor.PrintlnFeaturesVisitor;
26
import org.gvsig.data.visitor.IVisitor;
27 26
import org.gvsig.exceptions.BaseException;
28 27

  
29 28
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
30
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
31 29

  
32 30
public class DataStoreTest extends TestCase {
33 31

  
34 32
	private File dbffile = new File(DataStoreTest.class.getResource("data/prueba.dbf").getFile());
35 33
	private File shpfile = new File(DataStoreTest.class.getResource("data/prueba.shp").getFile());
36 34
	private File dxffile = new File(DataStoreTest.class.getResource("data/prueba.dxf").getFile());
35
	private File dgnfile = new File(DataStoreTest.class.getResource("data/cv_300_todo.dgn").getFile());
37 36

  
38 37
	public static void main(String[] args) {
39 38
		junit.textui.TestRunner.run(DataStoreTest.class);
......
483 482

  
484 483
	}
485 484

  
485
	public void testDGN() {
486
		System.out.println("======= DGN ==============");
487
		org.gvsig.data.datastores.vectorial.driver.dgn.Register.selfRegister();
488
		org.gvsig.data.datastores.vectorial.driver.Register.selfRegister();
486 489

  
490
		DataSourceManager dsm=DataSourceManager.getManager();
487 491

  
488 492

  
493
		IDriverParameters dp=dsm.createDriverParameters("dgn");
494
		((DGNDriverParameters)dp).setDGNFile(dgnfile);
495
		driverTest(dp,null,null,true);
489 496

  
497
		IFeatureStore fs = createFeatureStore(dp);
498
		assertNotNull("Can't create Feature Store", fs);
490 499

  
500
		try {
501
			fs.open();
502
		} catch (OpenException e1) {
503
			e1.printStackTrace();
504
			fail();
505
		}
506

  
507
		Iterator it;
508
		IFeatureCollection fc;
509
		Comparable v1,v2;
510
		IFeature feature,pfeature;
511
		long count;
512

  
513

  
514
		fc = (IFeatureCollection)fs.getDataCollection();
515

  
516
		assertEquals(14646, fc.size());
517

  
518
		fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'",null);
519

  
520
		assertEquals(14614, fc.size());
521

  
522
		it = fc.iterator();
523
		count=0;
524
		while (it.hasNext()){
525
			feature = (IFeature)it.next();
526
			assertTrue("Filter error",feature.getInt("Color")>7);
527
			count++;
528
		}
529
		assertEquals("Iteration error",14614,count);
530

  
531

  
532
		fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer ASC");
533
		assertEquals(14646, fc.size());
534
		it = fc.iterator();
535
		count=0;
536
		pfeature = (IFeature)it.next();
537
		count++;
538
		while (it.hasNext()){
539
			feature = (IFeature)it.next();
540
			v1 = (Comparable)pfeature.get("Layer");
541
			v2 = (Comparable)feature.get("Layer");
542
			pfeature=feature;
543
			assertTrue("Short error", (v1.compareTo(v1) <= 0));
544
			count++;
545
		}
546
		assertEquals("Iteration error",10,count);
547

  
548

  
549
		fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer DESC");
550
		assertEquals(14646, fc.size());
551
		it = fc.iterator();
552

  
553
		count=0;
554
		pfeature = (IFeature)it.next();
555
		count++;
556
		while (it.hasNext()){
557
			feature = (IFeature)it.next();
558
			v1 = (Comparable)pfeature.get("Layer");
559
			v2 = (Comparable)feature.get("Layer");
560
			pfeature=feature;
561
			assertTrue("Short error", (v1.compareTo(v1) >= 0));
562
			count++;
563
		}
564
		assertEquals("Iteration error",14646,count);
565

  
566

  
567
		fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'","Layer ASC");
568

  
569
		assertEquals(2, fc.size());
570

  
571
		it = fc.iterator();
572

  
573
		count=0;
574
		pfeature = (IFeature)it.next();
575
		assertTrue(pfeature.getInt("Color")>7);
576
		count++;
577
		while (it.hasNext()){
578
			feature = (IFeature)it.next();
579
			assertTrue("Filter error",feature.getInt("Color")>7);
580
			v1 = (Comparable)pfeature.get("Color");
581
			v2 = (Comparable)feature.get("Color");
582
			pfeature=feature;
583
			Integer i1=(Integer)v1;
584
			Integer i2=(Integer)v2;
585
			assertTrue("Short error", (i1.intValue()>i2.intValue()));
586
			count++;
587
		}
588
		assertEquals("Iteration error",14614,count);
589

  
590

  
591

  
592
//		fc = (IFeatureCollection)fs.getDataCollection(null,null,"Color,Layer Desc");
593
//		assertEquals(10, fc.size());
594
//		it = fc.iterator();
595
//		count=0;
596
//		pfeature = (IFeature)it.next();
597
//		System.out.println(pfeature.getString("Layer"));
598
//		count++;
599
//		while (it.hasNext()){
600
//			feature = (IFeature)it.next();
601
//			v1 = (Comparable)((String)pfeature.get("Layer")).toLowerCase();
602
//			v2 = (Comparable)((String)feature.get("Layer")).toLowerCase();
603
//			pfeature=feature;
604
//			assertTrue("Short error", (v1.compareTo(v2) >= 0));
605
//			System.out.println(pfeature.getString("Layer"));
606
//			count++;
607
//		}
608
//		assertEquals("Iteration error",10,count);
609

  
610

  
611
		try {
612
			fs.close();
613
		} catch (CloseException e) {
614
			e.printStackTrace();
615
			fail("Exception:" + e);
616
		}
617

  
618

  
619
		System.out.println("======= /DGN ==============");
620

  
621
	}
622

  
623

  
624

  
625

  
626

  
627

  
491 628
	private IFeatureStore createFeatureStore(IDriverParameters dp){
492 629
		DataSourceManager dsm=DataSourceManager.getManager();
493 630

  
trunk/libraries/libDataSourceBaseDrivers/src-test/org/gvsig/data/datastores/vectorial/driver/dgn/DGNTest.java
1
package org.gvsig.data.datastores.vectorial.driver.dgn;
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.datastores.vectorial.driver.DataStoreTest;
10
import org.gvsig.data.exception.InitializeException;
11
import org.gvsig.data.exception.OpenException;
12
import org.gvsig.data.vectorial.IFeature;
13
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor;
14
import org.gvsig.data.vectorial.IFeatureCollection;
15
import org.gvsig.data.vectorial.IFeatureType;
16
import org.gvsig.data.vectorial.expansionadapter.FeatureManager;
17
import org.gvsig.data.vectorial.expansionadapter.MemoryExpansionAdapter;
18

  
19
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
20

  
21
public class DGNTest extends TestCase {
22
	DGNDriver driver = new DGNDriver();
23
	private File file = new File(DataStoreTest.class.getResource("data/cv_300_todo.dgn").getFile());
24

  
25

  
26
	public static void main(String[] args) {
27
	}
28

  
29
	protected void setUp() throws Exception {
30
		super.setUp();
31
	}
32

  
33
	/*
34
	 * Test method for 'com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver.initialize()'
35
	 */
36
	public void testInitialize() {
37
		Register.selfRegister();
38
		DGNDriverParameters dgnParameters=new DGNDriverParameters();
39
		dgnParameters.setDGNFile(file);
40
		try {
41
			driver.init(dgnParameters);
42
		} catch (InitializeException e) {
43
			// TODO Auto-generated catch block
44
			e.printStackTrace();
45
		}
46
		try {
47
			driver.open();
48
		} catch (OpenException e) {
49
			// TODO Auto-generated catch block
50
			e.printStackTrace();
51
		}
52

  
53
		IFeatureType ft=driver.getFeatureType();
54
		FeatureManager featureManager=new FeatureManager(new MemoryExpansionAdapter());
55
		IFeatureCollection featureCollection = driver.getDataCollection(featureManager,ft,null,null);
56
		Iterator iter = featureCollection.iterator();
57
		while (iter.hasNext()) {
58
			IFeature feature = (IFeature)iter.next();
59
			System.out.println("DGN Feature ------------------- ");
60
			for (int i=0;i<ft.size();i++){
61

  
62
				IFeatureAttributeDescriptor descriptor=(IFeatureAttributeDescriptor)ft.get(i);
63
				String type=descriptor.getDataType();
64
				if (type.equals(IFeatureAttributeDescriptor.TYPE_BOOLEAN)){
65
					System.out.println("Boolean ----- "+ feature.getBoolean(i));
66
				}else if (type.equals(IFeatureAttributeDescriptor.TYPE_BYTE)){
67
					System.out.println("Byte ----- "+ feature.getByte(i));
68
				}else if (type.equals(IFeatureAttributeDescriptor.TYPE_DATE)){
69
					System.out.println("Date ----- "+ feature.getDate(i));
70
				}else if (type.equals(IFeatureAttributeDescriptor.TYPE_DOUBLE)){
71
					System.out.println("Double ----- "+ feature.getDouble(i));
72
				}else if (type.equals(IFeatureAttributeDescriptor.TYPE_FLOAT)){
73
					System.out.println("Float ----- "+ feature.getFloat(i));
74
				}else if (type.equals(IFeatureAttributeDescriptor.TYPE_INT)){
75
					System.out.println("Integer ----- "+ feature.getInt(i));
76
				}else if (type.equals(IFeatureAttributeDescriptor.TYPE_LONG)){
77
					System.out.println("Long ----- "+ feature.getLong(i));
78
				}else if (type.equals(IFeatureAttributeDescriptor.TYPE_STRING)){
79
					System.out.println("String ----- "+ feature.getString(i));
80
				}else if (type.equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)){
81

  
82
					System.out.println("Geometry ----- "+ feature.getGeometry(i));
83
				}
84
			}
85
		}
86

  
87
		driver.close();
88
		driver.dispose();
89
	}
90
}
trunk/libraries/libDataSourceBaseDrivers/src-test/org/gvsig/data/datastores/vectorial/driver/AllTests.java
5 5
import junit.framework.TestSuite;
6 6

  
7 7
import org.gvsig.data.datastores.vectorial.driver.dbf.DBFTest;
8
import org.gvsig.data.datastores.vectorial.driver.dgn.DGNTest;
8 9
import org.gvsig.data.datastores.vectorial.driver.dxf.DXFTest;
9 10
import org.gvsig.data.datastores.vectorial.driver.shp.SHPTest;
10 11

  
......
15 16
		suite.addTestSuite(DBFTest.class);
16 17
		suite.addTestSuite(SHPTest.class);
17 18
		suite.addTestSuite(DXFTest.class);
19
		suite.addTestSuite(DGNTest.class);
18 20
		suite.addTestSuite(DataStoreTest.class);
19 21
		//$JUnit-END$
20 22
		return suite;
trunk/libraries/libDataSourceBaseDrivers/src/org/gvsig/data/datastores/vectorial/driver/dgn/DGNDriver.java
85 85
		featureType.add(descriptorEntity);
86 86

  
87 87
		DefaultAttributeDescriptor descriptorLayer = new DefaultAttributeDescriptor();
88
		descriptorLayer.setType(IFeatureAttributeDescriptor.TYPE_STRING);
88
		descriptorLayer.setType(IFeatureAttributeDescriptor.TYPE_INT);
89 89
		descriptorLayer.setName("Layer");
90
		descriptorLayer.setDefaultValue("default");
90
		descriptorLayer.setDefaultValue(new Integer(0));
91 91
		featureType.add(descriptorLayer);
92 92

  
93 93
		DefaultAttributeDescriptor descriptorColor = new DefaultAttributeDescriptor();
......
108 108
//		descriptorThickness.setDefaultValue(new Double(0));
109 109
//		featureType.add(descriptorThickness);
110 110

  
111
		DefaultAttributeDescriptor descriptorText = new DefaultAttributeDescriptor();
112
		descriptorText.setType(IFeatureAttributeDescriptor.TYPE_STRING);
113
		descriptorText.setName("Text");
114
		descriptorText.setDefaultValue("");
115
		featureType.add(descriptorText);
116

  
117 111
		DefaultAttributeDescriptor descriptorHeightText = new DefaultAttributeDescriptor();
118 112
		descriptorHeightText.setType(IFeatureAttributeDescriptor.TYPE_FLOAT);
119 113
		descriptorHeightText.setName("HeightText");
......
126 120
		descriptorRotationText.setDefaultValue(new Double(0));
127 121
		featureType.add(descriptorRotationText);
128 122

  
123
		DefaultAttributeDescriptor descriptorText = new DefaultAttributeDescriptor();
124
		descriptorText.setType(IFeatureAttributeDescriptor.TYPE_STRING);
125
		descriptorText.setName("Text");
126
		descriptorText.setDefaultValue("");
127
		featureType.add(descriptorText);
128

  
129

  
130

  
131

  
132

  
129 133
		DefaultAttributeDescriptor descriptorShape = new DefaultAttributeDescriptor();
130 134
		descriptorShape.setType(IFeatureAttributeDescriptor.TYPE_GEOMETRY);
131 135
		descriptorShape.setName("GEOMETRY");
......
136 140
	public void open() throws OpenException {
137 141
		float heightText = 10;
138 142
//		attr.setLoadedInMemory(true);
139

  
143
		initializeFeatureType();
140 144
		try {
141 145
			m_DgnReader = new DGNReader(dgnFile.getAbsolutePath());
142 146
		} catch (ReadException e) {
......
602 606
			}
603 607
		}
604 608

  
605
		defaultLegend = LegendFactory.createVectorialUniqueValueLegend(featureType.getGeometryTypes()[0]);
609
		defaultLegend = LegendFactory.createVectorialUniqueValueLegend(FShape.MULTI);
606 610
		defaultLegend.setClassifyingFieldNames(new String[] {"Color"} );
607 611
		defaultLegend.setClassifyingFieldTypes(new int[]{Types.INTEGER,Types.VARCHAR,Types.INTEGER,Types.INTEGER,Types.FLOAT,Types.DOUBLE,Types.VARCHAR});
608 612

  
609 613

  
610 614
		ISymbol myDefaultSymbol = SymbologyFactory.
611
			createDefaultSymbolByShapeType(featureType.getGeometryTypes()[0]);
615
			createDefaultSymbolByShapeType(FShape.MULTI);
612 616

  
613 617
		defaultLegend.setDefaultSymbol(myDefaultSymbol);
614 618

  
trunk/libraries/libDataSourceBaseDrivers/src/org/gvsig/data/datastores/vectorial/driver/dgn/DGNDriverParameters.java
6 6
import org.gvsig.data.datastores.vectorial.driver.IDriverParameters;
7 7

  
8 8
public class DGNDriverParameters implements IDriverParameters {
9
	private File dxfFile;
10
	private IProjection projection;
9
	private File dgnFile;
11 10
	public File getDGNFile() {
12
		return dxfFile;
11
		return dgnFile;
13 12
	}
14
	public void setDXFFile(File file){
15
		dxfFile=file;
13
	public void setDGNFile(File file){
14
		dgnFile=file;
16 15
	}
17
	public IProjection getProjection() {
18
		return projection;
19
	}
20
	public void setProjection(IProjection projection){
21
		this.projection=projection;
22
	}
23

  
24 16
}

Also available in: Unified diff