svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / writers / shp / Prueba.java @ 10665
History | View | Annotate | Download (5.51 KB)
1 |
package com.iver.cit.gvsig.fmap.edition.writers.shp; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
|
5 |
import org.cresques.cts.IProjection; |
6 |
|
7 |
import com.hardcode.driverManager.DriverLoadException; |
8 |
import com.hardcode.driverManager.DriverManager; |
9 |
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException; |
10 |
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException; |
11 |
import com.hardcode.gdbms.driver.exceptions.OpenDriverException; |
12 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
13 |
import com.hardcode.gdbms.engine.values.Value; |
14 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
15 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileWriteException; |
16 |
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
17 |
import com.iver.cit.gvsig.exceptions.layers.StartEditionLayerException; |
18 |
import com.iver.cit.gvsig.exceptions.layers.StopEditionLayerException; |
19 |
import com.iver.cit.gvsig.exceptions.validate.ValidateRowException; |
20 |
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException; |
21 |
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException; |
22 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
23 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
24 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
25 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
26 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
27 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
28 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
29 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
30 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
31 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
32 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
33 |
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter; |
34 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
35 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
36 |
|
37 |
|
38 |
public class Prueba { |
39 |
|
40 |
public FLayer createLayer(String layerName, VectorialFileDriver d, |
41 |
File f, IProjection proj) throws ReadDriverException { |
42 |
VectorialFileAdapter adapter = new VectorialFileAdapter(f);
|
43 |
adapter.setDriver((VectorialDriver) d); |
44 |
VectorialEditableAdapter vea=new VectorialEditableAdapter();
|
45 |
vea.setOriginalVectorialAdapter(adapter); |
46 |
//FileEditableFeatureSource fefs=new FileEditableFeatureSource((VectorialFileAdapter)adapter);
|
47 |
//MemoryExpansionFile mef=new MemoryExpansionFile();
|
48 |
//DefaultEditableFeatureSource defs=new DefaultEditableFeatureSource(mef,fefs, new FBitSet());
|
49 |
|
50 |
//vea.start();
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
FLyrVect capa = new FLyrVect();
|
57 |
capa.setName(layerName); |
58 |
|
59 |
//TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
60 |
if (false) { |
61 |
} else {
|
62 |
capa.setSource(adapter); |
63 |
capa.setProjection(proj); |
64 |
} |
65 |
|
66 |
try {
|
67 |
// Le asignamos tambi?n una legenda por defecto acorde con
|
68 |
// el tipo de shape que tenga. Tampoco s? si es aqu? el
|
69 |
// sitio adecuado, pero en fin....
|
70 |
if (d instanceof WithDefaultLegend) { |
71 |
WithDefaultLegend aux = (WithDefaultLegend) d; |
72 |
adapter.start(); |
73 |
capa.setLegend((VectorialLegend) aux.getDefaultLegend()); |
74 |
adapter.stop(); |
75 |
} else {
|
76 |
capa.setLegend(LegendFactory.createSingleSymbolLegend( |
77 |
capa.getShapeType())); |
78 |
} |
79 |
} catch (ReadDriverException e) {
|
80 |
e.printStackTrace(); |
81 |
} catch (LegendLayerException e) {
|
82 |
// TODO Auto-generated catch block
|
83 |
e.printStackTrace(); |
84 |
} |
85 |
try {
|
86 |
vea.startEdition(EditionEvent.GRAPHIC); |
87 |
} catch (StartWriterVisitorException e2) {
|
88 |
e2.printStackTrace(); |
89 |
} |
90 |
try {
|
91 |
Value[] values=new Value[5]; |
92 |
values[0]=ValueFactory.createValue("hola0"); |
93 |
values[1]=ValueFactory.createValue("hola1"); |
94 |
values[2]=ValueFactory.createValue("hola2"); |
95 |
values[3]=ValueFactory.createValue(300d); |
96 |
values[4]=ValueFactory.createValue(1d); |
97 |
DefaultFeature df0=new DefaultFeature(ShapeFactory.createPoint2D(1,3),values); |
98 |
vea.addRow(df0,"",EditionEvent.GRAPHIC);
|
99 |
DefaultFeature df1=new DefaultFeature(ShapeFactory.createPoint2D(2,4),values); |
100 |
vea.addRow(df1,"",EditionEvent.GRAPHIC);
|
101 |
DefaultFeature df2=new DefaultFeature(ShapeFactory.createPoint2D(3,5),values); |
102 |
vea.addRow(df2,"", EditionEvent.GRAPHIC);
|
103 |
DefaultFeature df3=new DefaultFeature(ShapeFactory.createPoint2D(4,6),values); |
104 |
vea.addRow(df3,"", EditionEvent.GRAPHIC);
|
105 |
} catch (ValidateRowException e) {
|
106 |
e.printStackTrace(); |
107 |
} catch (ReadDriverException e) {
|
108 |
// TODO Auto-generated catch block
|
109 |
e.printStackTrace(); |
110 |
} catch (ExpansionFileWriteException e) {
|
111 |
// TODO Auto-generated catch block
|
112 |
e.printStackTrace(); |
113 |
} |
114 |
ShpWriter writer=null;
|
115 |
try {
|
116 |
writer = (ShpWriter)LayerFactory.getWM().getWriter("Shape Writer");
|
117 |
} catch (DriverLoadException e1) {
|
118 |
// TODO Auto-generated catch block
|
119 |
e1.printStackTrace(); |
120 |
} |
121 |
try {
|
122 |
writer.initialize(capa); |
123 |
} catch (InitializeWriterException e) {
|
124 |
e.printStackTrace(); |
125 |
} |
126 |
try {
|
127 |
vea.stopEdition(writer,EditionEvent.GRAPHIC); |
128 |
} catch (StopWriterVisitorException e) {
|
129 |
e.printStackTrace(); |
130 |
} |
131 |
return null; |
132 |
} |
133 |
public static void main(String[] args) { |
134 |
DriverManager driverManager = LayerFactory.getDM();
|
135 |
driverManager.loadDrivers(new File("d:/eclipse/workspace/fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers")); |
136 |
Prueba prueba=new Prueba();
|
137 |
FLayer layer=null;
|
138 |
try {
|
139 |
layer=prueba.createLayer("prueba", (VectorialFileDriver)LayerFactory.getDM().getDriver("gvSIG shp driver"),new File("c:/Layers/puntosPrueba.shp"),CRSFactory.getCRS("EPSG:23030")); |
140 |
} catch (ReadDriverException e) {
|
141 |
e.printStackTrace(); |
142 |
} catch (DriverLoadException e) {
|
143 |
e.printStackTrace(); |
144 |
} |
145 |
|
146 |
} |
147 |
} |