root / branches / FMap_CAD / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / Prueba2.java @ 3513
History | View | Annotate | Download (6.13 KB)
1 |
/* 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 com.hardcode.driverManager.Driver; |
44 |
import com.hardcode.driverManager.DriverLoadException; |
45 |
import com.hardcode.driverManager.DriverManager; |
46 |
|
47 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
48 |
|
49 |
import com.iver.cit.gvsig.fmap.DriverException; |
50 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
51 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
52 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
53 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
54 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
55 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
56 |
import com.iver.cit.gvsig.fmap.drivers.shp.SHP; |
57 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
60 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
61 |
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter; |
62 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
63 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
64 |
|
65 |
import org.cresques.cts.IProjection; |
66 |
import org.cresques.cts.ProjectionPool; |
67 |
|
68 |
import java.io.File; |
69 |
import java.io.IOException; |
70 |
|
71 |
|
72 |
/**
|
73 |
* DOCUMENT ME!
|
74 |
*
|
75 |
* @author Fernando Gonz?lez Cort?s
|
76 |
*/
|
77 |
public class Prueba2 { |
78 |
/*public FLayer createLayer(String layerName, VectorialFileDriver d,
|
79 |
File f, IProjection proj) throws DriverException {
|
80 |
//TODO Comprobar si hay un adaptador ya
|
81 |
VectorialFileAdapter adapter = new VectorialFileAdapter(f);
|
82 |
adapter.setDriver((VectorialDriver) d);
|
83 |
FileEditableFeatureSource fefs=new FileEditableFeatureSource((VectorialFileAdapter)adapter);
|
84 |
MemoryExpansionFile mef=new MemoryExpansionFile();
|
85 |
DefaultEditableFeatureSource defs=new DefaultEditableFeatureSource(mef,fefs);
|
86 |
try {
|
87 |
defs.addGeometry(ShapeFactory.createPoint2D(1,3));
|
88 |
defs.addGeometry(ShapeFactory.createPoint2D(2,2));
|
89 |
defs.addGeometry(ShapeFactory.createPoint2D(3,1));
|
90 |
defs.addGeometry(ShapeFactory.createPoint2D(4,0));
|
91 |
} catch (DriverIOException e1) {
|
92 |
e1.printStackTrace();
|
93 |
} catch (IOException e1) {
|
94 |
e1.printStackTrace();
|
95 |
}
|
96 |
FLyrVect capa = new FLyrVect();
|
97 |
capa.setName(layerName);
|
98 |
//TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
99 |
if (false) {
|
100 |
} else {
|
101 |
capa.setSource(adapter);
|
102 |
capa.setProjection(proj);
|
103 |
}
|
104 |
try {
|
105 |
// Le asignamos tambi?n una legenda por defecto acorde con
|
106 |
// el tipo de shape que tenga. Tampoco s? si es aqu? el
|
107 |
// sitio adecuado, pero en fin....
|
108 |
if (d instanceof WithDefaultLegend) {
|
109 |
WithDefaultLegend aux = (WithDefaultLegend) d;
|
110 |
adapter.start();
|
111 |
capa.setLegend((VectorialLegend) aux.getDefaultLegend());
|
112 |
adapter.stop();
|
113 |
} else {
|
114 |
capa.setLegend(LegendFactory.createSingleSymbolLegend(
|
115 |
capa.getShapeType()));
|
116 |
}
|
117 |
} catch (FieldNotFoundException e) {
|
118 |
//Esta no puede saltar
|
119 |
} catch (DriverIOException e) {
|
120 |
throw new DriverException(e);
|
121 |
}
|
122 |
return capa;
|
123 |
}
|
124 |
*/
|
125 |
public static void main(String[] args) { |
126 |
File f = new File("C:/tirar/borraprueba5.shp"); |
127 |
VectorialFileAdapter adapter = new VectorialFileAdapter(f);
|
128 |
DriverManager driverManager = new DriverManager(); |
129 |
driverManager.loadDrivers(new File( |
130 |
"C:\\eclipse3\\workspace\\Andami\\gvSIG\\extensiones\\com.iver.cit.gvsig\\drivers"));
|
131 |
|
132 |
try {
|
133 |
adapter.setDriver((VectorialFileDriver) driverManager.getDriver( |
134 |
"gvSIG shp driver"));
|
135 |
} catch (DriverLoadException e2) {
|
136 |
e2.printStackTrace(); |
137 |
} |
138 |
|
139 |
FileEditableFeatureSource fefs = new FileEditableFeatureSource((VectorialFileAdapter) adapter);
|
140 |
MemoryExpansionFile mef = new MemoryExpansionFile();
|
141 |
DefaultEditableFeatureSource defs = new DefaultEditableFeatureSource(mef,
|
142 |
fefs, new FBitSet());
|
143 |
|
144 |
try {
|
145 |
defs.startEdition(); |
146 |
|
147 |
defs.addGeometry(ShapeFactory.createPoint2D(1, 1)); |
148 |
defs.addGeometry(ShapeFactory.createPoint2D(2, 2)); |
149 |
defs.addGeometry(ShapeFactory.createPoint2D(3, 3)); |
150 |
defs.removeGeometry(1);
|
151 |
defs.compact(); |
152 |
defs.addGeometry(ShapeFactory.createPoint2D(4, 4)); |
153 |
defs.modifyGeometry(0, ShapeFactory.createPoint2D(10, 10)); |
154 |
//defs.addGeometry(ShapeFactory.createPoint2D(1,1));
|
155 |
//defs.addGeometry(ShapeFactory.createPoint2D(1,0));
|
156 |
//defs.removeGeometry(0);
|
157 |
//defs.removeGeometry(1);
|
158 |
defs.stopEdition(null);
|
159 |
} catch (DriverIOException e1) {
|
160 |
e1.printStackTrace(); |
161 |
} catch (IOException e1) { |
162 |
e1.printStackTrace(); |
163 |
} catch (EditionException e) {
|
164 |
e.printStackTrace(); |
165 |
} |
166 |
|
167 |
try {
|
168 |
|
169 |
IGeometry[] fgs = new IGeometry[defs.getGeometryCount()]; |
170 |
|
171 |
for (int i = 0; i < fgs.length; i++) { |
172 |
fgs[i] = defs.getGeometry(i); |
173 |
} |
174 |
SHP.SHPFileFromGeometries(fgs, null, null, f); |
175 |
} catch (IOException e) { |
176 |
e.printStackTrace(); |
177 |
} catch (DriverIOException e) {
|
178 |
e.printStackTrace(); |
179 |
} |
180 |
|
181 |
} |
182 |
} |