Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / writers / shp / Prueba.java @ 4440

History | View | Annotate | Download (4.56 KB)

1
package com.iver.cit.gvsig.fmap.edition.writers.shp;
2

    
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.BitSet;
6

    
7
import org.cresques.cts.IProjection;
8
import org.cresques.cts.ProjectionPool;
9

    
10
import com.hardcode.driverManager.Driver;
11
import com.hardcode.driverManager.DriverLoadException;
12
import com.hardcode.driverManager.DriverManager;
13
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
14
import com.hardcode.gdbms.engine.values.Value;
15
import com.hardcode.gdbms.engine.values.ValueFactory;
16
import com.iver.cit.gvsig.fmap.DriverException;
17
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
18
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
19
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
20
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
21
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
22
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
23
import com.iver.cit.gvsig.fmap.edition.EditionException;
24
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
25
import com.iver.cit.gvsig.fmap.layers.FBitSet;
26
import com.iver.cit.gvsig.fmap.layers.FLayer;
27
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
28
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
29
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter;
30
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
31
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
32

    
33

    
34
public class Prueba {
35

    
36
        public FLayer createLayer(String layerName, VectorialFileDriver d,
37
                        File f, IProjection proj) throws DriverException {
38
                try {
39
                        VectorialFileAdapter adapter = new VectorialFileAdapter(f);
40
                        adapter.setDriver((VectorialDriver) d);
41
                        VectorialEditableAdapter vea=new VectorialEditableAdapter();
42
                        vea.setOriginalVectorialAdapter(adapter);
43
                        //FileEditableFeatureSource fefs=new FileEditableFeatureSource((VectorialFileAdapter)adapter);
44
                        //MemoryExpansionFile mef=new MemoryExpansionFile();
45
                        //DefaultEditableFeatureSource defs=new DefaultEditableFeatureSource(mef,fefs, new FBitSet());
46

    
47
                                //vea.start();
48

    
49

    
50

    
51

    
52

    
53
                        FLyrVect capa = new FLyrVect();
54
                        capa.setName(layerName);
55

    
56
                        //TODO Meter esto dentro de la comprobaci?n de si hay memoria
57
                        if (false) {
58
                        } else {
59
                                capa.setSource(adapter);
60
                                capa.setProjection(proj);
61
                        }
62

    
63
                        try {
64
                                // Le asignamos tambi?n una legenda por defecto acorde con
65
                                // el tipo de shape que tenga. Tampoco s? si es aqu? el
66
                                // sitio adecuado, pero en fin....
67
                                if (d instanceof WithDefaultLegend) {
68
                                        WithDefaultLegend aux = (WithDefaultLegend) d;
69
                                        adapter.start();
70
                                        capa.setLegend((VectorialLegend) aux.getDefaultLegend());
71
                                        adapter.stop();
72
                                } else {
73
                                        capa.setLegend(LegendFactory.createSingleSymbolLegend(
74
                                                        capa.getShapeType()));
75
                                }
76
                        } catch (FieldNotFoundException e) {
77
                                //Esta no puede saltar
78
                        } catch (DriverIOException e) {
79
                                throw new DriverException(e);
80
                        }
81
                        vea.startEdition();
82
                        try {
83
                        Value[] values=new Value[5];
84
                        values[0]=ValueFactory.createValue("hola0");
85
                        values[1]=ValueFactory.createValue("hola1");
86
                        values[2]=ValueFactory.createValue("hola2");
87
                        values[3]=ValueFactory.createValue(300d);
88
                        values[4]=ValueFactory.createValue(1d);
89
                        DefaultFeature df0=new DefaultFeature(ShapeFactory.createPoint2D(1,3),values);
90
                        vea.addRow(df0,"");
91
                        DefaultFeature df1=new DefaultFeature(ShapeFactory.createPoint2D(2,4),values);
92
                        vea.addRow(df1,"");
93
                        DefaultFeature df2=new DefaultFeature(ShapeFactory.createPoint2D(3,5),values);
94
                        vea.addRow(df2,"");
95
                        DefaultFeature df3=new DefaultFeature(ShapeFactory.createPoint2D(4,6),values);
96
                        vea.addRow(df3,"");
97
                        } catch (DriverIOException e1) {
98
                                e1.printStackTrace();
99
                        } catch (IOException e1) {
100
                                e1.printStackTrace();
101
                        }
102
                        try {
103
                                ShpWriter writer=(ShpWriter)LayerFactory.getWM().getWriter("Shape Writer");
104
                                writer.initialize(capa);
105
                                vea.stopEdition(writer);
106
                        } catch (EditionException e) {
107
                                // TODO Auto-generated catch block
108
                                e.printStackTrace();
109
                        }
110
                } catch (EditionException e) {
111
                        // TODO Auto-generated catch block
112
                        e.printStackTrace();
113
                }
114
                        return null;
115
                }
116
        public static void main(String[] args) {
117
                DriverManager driverManager = LayerFactory.getDM();
118
                driverManager.loadDrivers(new File("d:/eclipse/workspace/fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers"));
119
                Prueba prueba=new Prueba();
120
                FLayer layer=null;
121
                try {
122
                        layer=prueba.createLayer("prueba", (VectorialFileDriver)LayerFactory.getDM().getDriver("gvSIG shp driver"),new File("c:/Layers/puntosPrueba.shp"),ProjectionPool.get("EPSG:23030"));
123
                } catch (DriverException e) {
124
                        e.printStackTrace();
125
                } catch (DriverLoadException e) {
126
                        e.printStackTrace();
127
                }
128

    
129
        }
130
}