svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / writers / shp / testWriter.java @ 4440
History | View | Annotate | Download (2.89 KB)
1 |
package com.iver.cit.gvsig.fmap.edition.writers.shp; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
|
5 |
import javax.swing.JFileChooser; |
6 |
|
7 |
import org.cresques.cts.IProjection; |
8 |
import org.cresques.cts.ProjectionPool; |
9 |
|
10 |
import com.hardcode.driverManager.DriverLoadException; |
11 |
import com.hardcode.driverManager.DriverManager; |
12 |
import com.iver.cit.gvsig.fmap.DriverException; |
13 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
14 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
15 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
16 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
17 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
18 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
19 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
20 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
21 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
22 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
23 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
24 |
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter; |
25 |
|
26 |
public class testWriter { |
27 |
|
28 |
public FLayer createLayer(String layerName, VectorialFileDriver d, |
29 |
File f, IProjection proj) throws DriverException { |
30 |
//TODO Comprobar si hay un adaptador ya
|
31 |
VectorialFileAdapter adapter = new VectorialFileAdapter(f);
|
32 |
adapter.setDriver(d); |
33 |
FLyrVect capa = new FLyrVect();
|
34 |
capa.setName(layerName); |
35 |
|
36 |
capa.setSource(adapter); |
37 |
capa.setProjection(proj); |
38 |
|
39 |
|
40 |
return capa;
|
41 |
} |
42 |
|
43 |
/**
|
44 |
* @param args
|
45 |
*/
|
46 |
public static void main(String[] args) { |
47 |
// LayerFactory.setDriversPath("D:/java/eclipse30/eclipse/workspace/FMap 03/driversDebug");
|
48 |
LayerFactory.setDriversPath("d:/eclipse/workspace/fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
|
49 |
DriverManager driverManager = LayerFactory.getDM();
|
50 |
// DriverManager driverManager = new DriverManager();
|
51 |
// driverManager.loadDrivers(new File("../fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers"));
|
52 |
testWriter test=new testWriter();
|
53 |
|
54 |
try {
|
55 |
JFileChooser jfc = new JFileChooser(); |
56 |
if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) |
57 |
{ |
58 |
File original = jfc.getSelectedFile();
|
59 |
FLyrVect layer= (FLyrVect) test.createLayer("prueba",
|
60 |
(VectorialFileDriver)driverManager.getDriver("gvSIG shp driver"),
|
61 |
original, |
62 |
ProjectionPool.get("EPSG:23030"));
|
63 |
|
64 |
|
65 |
if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) |
66 |
{ |
67 |
File newFile = jfc.getSelectedFile();
|
68 |
|
69 |
ShpWriter writer = (ShpWriter)LayerFactory.getWM().getWriter("Shape Writer");
|
70 |
writer.initialize(layer); |
71 |
writer.preProcess(); |
72 |
ReadableVectorial adapter = layer.getSource(); |
73 |
for (int i=0; i < adapter.getShapeCount(); i++) |
74 |
{ |
75 |
IFeature feat = adapter.getFeature(i); |
76 |
IRowEdited editFeat = new DefaultRowEdited(feat, IRowEdited.STATUS_MODIFIED, i);
|
77 |
writer.process(editFeat); |
78 |
} |
79 |
writer.postProcess(); |
80 |
} |
81 |
} |
82 |
} catch (Exception e) { |
83 |
e.printStackTrace(); |
84 |
System.exit(0); |
85 |
} |
86 |
System.exit(0); |
87 |
} |
88 |
|
89 |
} |