Statistics
| Revision:

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

History | View | Annotate | Download (4.63 KB)

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

    
3
import java.io.File;
4
import java.io.IOException;
5

    
6
import org.cresques.cts.IProjection;
7

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

    
31

    
32
public class Prueba {
33

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

    
45
                                //vea.start();
46

    
47

    
48

    
49

    
50

    
51
                        FLyrVect capa = new FLyrVect();
52
                        capa.setName(layerName);
53

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

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

    
127
        }
128
}