Statistics
| Revision:

root / branches / pilotoDWG / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / prueba.java @ 1634

History | View | Annotate | Download (4.46 KB)

1 1287 vcaballero
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package com.iver.cit.gvsig.fmap.edition;
42
43
import java.io.File;
44
import java.io.IOException;
45 1574 fernando
import java.util.BitSet;
46 1287 vcaballero
47
import org.cresques.cts.IProjection;
48
import org.cresques.cts.ProjectionPool;
49
50
import com.hardcode.driverManager.Driver;
51
import com.hardcode.driverManager.DriverLoadException;
52
import com.hardcode.driverManager.DriverManager;
53
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
54
import com.iver.cit.gvsig.fmap.DriverException;
55
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
56
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
57
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
58
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
59
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
60 1574 fernando
import com.iver.cit.gvsig.fmap.layers.FBitSet;
61 1287 vcaballero
import com.iver.cit.gvsig.fmap.layers.FLayer;
62
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
63
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
64
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter;
65
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
66
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
67
68
69
public class prueba {
70
71
        public FLayer createLayer(String layerName, VectorialFileDriver d,
72
                        File f, IProjection proj) throws DriverException {
73
                        //TODO Comprobar si hay un adaptador ya
74
                        VectorialFileAdapter adapter = new VectorialFileAdapter(f);
75
                        adapter.setDriver((VectorialDriver) d);
76
                        FileEditableFeatureSource fefs=new FileEditableFeatureSource((VectorialFileAdapter)adapter);
77
                        MemoryExpansionFile mef=new MemoryExpansionFile();
78 1574 fernando
                        DefaultEditableFeatureSource defs=new DefaultEditableFeatureSource(mef,fefs, new FBitSet());
79 1287 vcaballero
                        try {
80
                                defs.addGeometry(ShapeFactory.createPoint2D(1,3));
81
                                defs.addGeometry(ShapeFactory.createPoint2D(2,2));
82
                                defs.addGeometry(ShapeFactory.createPoint2D(3,1));
83
                                defs.addGeometry(ShapeFactory.createPoint2D(4,0));
84
                        } catch (DriverIOException e1) {
85
                                e1.printStackTrace();
86
                        } catch (IOException e1) {
87
                                e1.printStackTrace();
88
                        }
89
                        FLyrVect capa = new FLyrVect();
90
                        capa.setName(layerName);
91
92
                        //TODO Meter esto dentro de la comprobaci?n de si hay memoria
93
                        if (false) {
94
                        } else {
95
                                capa.setSource(adapter);
96
                                capa.setProjection(proj);
97
                        }
98
99
                        try {
100
                                // Le asignamos tambi?n una legenda por defecto acorde con
101
                                // el tipo de shape que tenga. Tampoco s? si es aqu? el
102
                                // sitio adecuado, pero en fin....
103
                                if (d instanceof WithDefaultLegend) {
104
                                        WithDefaultLegend aux = (WithDefaultLegend) d;
105
                                        adapter.start();
106
                                        capa.setLegend((VectorialLegend) aux.getDefaultLegend());
107
                                        adapter.stop();
108
                                } else {
109
                                        capa.setLegend(LegendFactory.createSingleSymbolLegend(
110
                                                        capa.getShapeType()));
111
                                }
112
                        } catch (FieldNotFoundException e) {
113
                                //Esta no puede saltar
114
                        } catch (DriverIOException e) {
115
                                throw new DriverException(e);
116
                        }
117
118
                        return capa;
119
                }
120
        public static void main(String[] args) {
121
                DriverManager driverManager = new DriverManager();
122
                driverManager.loadDrivers(new File("../FMap 03/drivers"));
123
                prueba prueba=new prueba();
124
                FLayer layer=null;
125
                try {
126
                        layer=prueba.createLayer("prueba", (VectorialFileDriver)driverManager.getDriver("gvSIG shp driver"),new File("c:/Layers/puntosPrueba.shp"),ProjectionPool.get("EPSG:23030"));
127
                } catch (DriverException e) {
128
                        e.printStackTrace();
129
                } catch (DriverLoadException e) {
130
                        e.printStackTrace();
131
                }
132
133
        }
134
}