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