svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / shp / SHP.java @ 1828
History | View | Annotate | Download (4.6 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.drivers.shp; |
42 |
|
43 |
import java.io.File; |
44 |
import java.util.BitSet; |
45 |
|
46 |
import com.hardcode.gdbms.engine.values.Value; |
47 |
import com.iver.cit.gvsig.fmap.DriverException; |
48 |
import com.iver.cit.gvsig.fmap.FMap; |
49 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
50 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.DBFFromSelected; |
51 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiLine; |
52 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiPoint; |
53 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPPoint; |
54 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPPolygon; |
55 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPSHXFromSelectedVisitor; |
56 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPShape; |
57 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.ShapefileException; |
58 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
59 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedShapeVisitor; |
60 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
61 |
|
62 |
|
63 |
|
64 |
/**
|
65 |
* Clase con las constantes que representan los diferentes tipos de Shape y
|
66 |
* m?todos est?ticos relativos a los shapes.
|
67 |
*
|
68 |
* @author Vicente Caballero Navarro
|
69 |
*/
|
70 |
public class SHP { |
71 |
public static final int NULL = 0; |
72 |
public static final int POINT2D = 1; |
73 |
public static final int POLYLINE2D = 3; |
74 |
public static final int POLYGON2D = 5; |
75 |
public static final int MULTIPOINT2D = 8; |
76 |
public static final int POINT3D = 11; |
77 |
public static final int POLYLINE3D = 13; |
78 |
public static final int POLYGON3D = 15; |
79 |
public static final int MULTIPOINT3D = 18; |
80 |
|
81 |
/**
|
82 |
* Crea a partir del tipo de geometr?a un shape del tipo m?s adecuado.
|
83 |
*
|
84 |
* @param type Tipo de geometr?a.
|
85 |
*
|
86 |
* @return Geometr?a m?s adecuada.
|
87 |
*
|
88 |
* @throws ShapefileException Se lanza cuando es causada por la creaci?n del shape.
|
89 |
*/
|
90 |
public static SHPShape create(int type) throws ShapefileException { |
91 |
SHPShape shape; |
92 |
|
93 |
switch (type) {
|
94 |
case 1: |
95 |
case 11: |
96 |
case 21: |
97 |
shape = new SHPPoint(type);
|
98 |
|
99 |
break;
|
100 |
|
101 |
case 3: |
102 |
case 13: |
103 |
case 23: |
104 |
shape = new SHPMultiLine(type);
|
105 |
|
106 |
break;
|
107 |
|
108 |
case 5: |
109 |
case 15: |
110 |
case 25: |
111 |
shape = new SHPPolygon(type);
|
112 |
|
113 |
break;
|
114 |
|
115 |
case 8: |
116 |
case 18: |
117 |
case 28: |
118 |
shape = new SHPMultiPoint(type);
|
119 |
|
120 |
break;
|
121 |
|
122 |
default:
|
123 |
shape = null;
|
124 |
} |
125 |
|
126 |
return shape;
|
127 |
} |
128 |
|
129 |
public static void SHPFileFromSelected(FMap map,File f){ |
130 |
SHPSHXFromSelectedVisitor visitor = new SHPSHXFromSelectedVisitor();
|
131 |
visitor.setFile(f); |
132 |
//int type=getTypeShape();
|
133 |
//visitor.setType(5);
|
134 |
try {
|
135 |
map.getLayers().process(visitor); |
136 |
} catch (DriverException e1) {
|
137 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
138 |
e1); |
139 |
} catch (VisitException e) {
|
140 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
141 |
e); |
142 |
} |
143 |
|
144 |
try {
|
145 |
DBFFromSelected dbf=new DBFFromSelected();
|
146 |
dbf.setFile(f); |
147 |
dbf.setGeometries(visitor.getGeometries()); |
148 |
dbf.setIsNewDBF(true);
|
149 |
visitor.getSDS().start(); |
150 |
dbf.start(visitor.getSDS()); |
151 |
dbf.createdbf(visitor.getBitSet()); |
152 |
dbf.stop(); |
153 |
visitor.getSDS().stop(); |
154 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e2) {
|
155 |
e2.printStackTrace(); |
156 |
} |
157 |
|
158 |
} |
159 |
public static void SHPFileFromGeometries(IGeometry[] fgs,BitSet bitset,SelectableDataSource sds,File f){ |
160 |
|
161 |
SHPSHXFromGeometries ssfg = new SHPSHXFromGeometries(fgs,f);
|
162 |
ssfg.create(); |
163 |
DBFFromGeometries dfg=new DBFFromGeometries(fgs,f);
|
164 |
dfg.create(sds,bitset); |
165 |
} |
166 |
} |