svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libFMap_mobile_shp_driver / src-file / org / gvsig / data / datastores / vectorial / file / shp / utils / SHP.java @ 21865
History | View | Annotate | Download (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 org.gvsig.data.datastores.vectorial.file.shp.utils; |
42 |
|
43 |
import java.io.File; |
44 |
|
45 |
/**
|
46 |
* Clase con las constantes que representan los diferentes tipos de Shape y
|
47 |
* m?todos est?ticos relativos a los shapes.
|
48 |
*
|
49 |
* @author Vicente Caballero Navarro
|
50 |
*/
|
51 |
public class SHP { |
52 |
public static final int NULL = 0; |
53 |
|
54 |
public static final int POINT2D = 1; |
55 |
|
56 |
public static final int POLYLINE2D = 3; |
57 |
|
58 |
public static final int POLYGON2D = 5; |
59 |
|
60 |
public static final int MULTIPOINT2D = 8; |
61 |
|
62 |
public static final int POINT3D = 11; |
63 |
|
64 |
public static final int POLYLINE3D = 13; |
65 |
|
66 |
public static final int POLYGON3D = 15; |
67 |
|
68 |
public static final int MULTIPOINT3D = 18; |
69 |
|
70 |
public final static int POINTM = 21; |
71 |
|
72 |
public final static int POLYLINEM = 23; |
73 |
public final static int POLYGONM = 25; |
74 |
public final static int MULTIPOINTM = 28; |
75 |
|
76 |
/**
|
77 |
* Crea a partir del tipo de geometr?a un shape del tipo m?s adecuado.
|
78 |
*
|
79 |
* @param type
|
80 |
* Tipo de geometr?a.
|
81 |
*
|
82 |
* @return Geometr?a m?s adecuada.
|
83 |
*
|
84 |
* @throws ShapefileException
|
85 |
* Se lanza cuando es causada por la creaci?n del shape.
|
86 |
*/
|
87 |
public static SHPShape create(int type) { |
88 |
SHPShape shape; |
89 |
|
90 |
switch (type) {
|
91 |
case 0: |
92 |
shape = new SHPNull(type);
|
93 |
break;
|
94 |
|
95 |
case 1: |
96 |
case 11: |
97 |
case 21: |
98 |
shape = new SHPPoint(type);
|
99 |
|
100 |
break;
|
101 |
|
102 |
case 3: |
103 |
case 13: |
104 |
case 23: |
105 |
shape = new SHPMultiLine(type);
|
106 |
|
107 |
break;
|
108 |
|
109 |
case 5: |
110 |
case 15: |
111 |
case 25: |
112 |
shape = new SHPPolygon(type);
|
113 |
|
114 |
break;
|
115 |
|
116 |
case 8: |
117 |
case 18: |
118 |
case 28: |
119 |
shape = new SHPMultiPoint(type);
|
120 |
|
121 |
break;
|
122 |
|
123 |
default:
|
124 |
shape = null;
|
125 |
} |
126 |
|
127 |
return shape;
|
128 |
} |
129 |
|
130 |
/**
|
131 |
* Devuelve un array con dos doubles, el primero representa el m?nimo valor
|
132 |
* y el segundo el m?ximo de entre los valores que se pasan como par?metro
|
133 |
* en forma de array.
|
134 |
*
|
135 |
* @param zs
|
136 |
* Valores a comprobar.
|
137 |
*
|
138 |
* @return Array de doubles con el valor m?nimo y el valor m?ximo.
|
139 |
*/
|
140 |
public static double[] getZMinMax(double[] zs) { |
141 |
if (zs == null) { |
142 |
return null; |
143 |
} |
144 |
|
145 |
double min = Double.MAX_VALUE; |
146 |
double max = Double.NEGATIVE_INFINITY; |
147 |
|
148 |
for (int i = 0; i < zs.length; i++) { |
149 |
if (zs[i] > max) {
|
150 |
max = zs[i]; |
151 |
} |
152 |
|
153 |
if (zs[i] < min) {
|
154 |
min = zs[i]; |
155 |
} |
156 |
} |
157 |
|
158 |
return new double[] { min, max }; |
159 |
} |
160 |
|
161 |
public static File getDbfFile(File shpFile) { |
162 |
String str = shpFile.getAbsolutePath();
|
163 |
File directory = shpFile.getParentFile();
|
164 |
File[] files = new File[0]; |
165 |
if (directory != null) { |
166 |
MyFileFilter myFileFilter = new MyFileFilter(str);
|
167 |
files = directory.listFiles(myFileFilter); |
168 |
} |
169 |
String[] ends = new String[] { "dbf", "DBF", "Dbf", "dBf", "DBf", |
170 |
"dbF", "DbF", "dBF" }; |
171 |
File dbfFile = findEnd(str, files, ends);
|
172 |
return dbfFile;
|
173 |
} |
174 |
|
175 |
public static File getShpFile(File dbfFile) { |
176 |
String str = dbfFile.getAbsolutePath();
|
177 |
File directory = dbfFile.getParentFile();
|
178 |
File[] files = new File[0]; |
179 |
if (directory != null) { |
180 |
MyFileFilter myFileFilter = new MyFileFilter(str);
|
181 |
files = directory.listFiles(myFileFilter); |
182 |
} |
183 |
String[] ends = new String[] { "shp", "SHP", "Shp", "sHp", "SHp", |
184 |
"shP", "ShP", "sHP" }; |
185 |
File shpFile = findEnd(str, files, ends);
|
186 |
return dbfFile;
|
187 |
} |
188 |
|
189 |
public static File getShxFile(File shpFile) { |
190 |
String str = shpFile.getAbsolutePath();
|
191 |
File directory = shpFile.getParentFile();
|
192 |
File[] files = new File[0]; |
193 |
if (directory != null) { |
194 |
MyFileFilter myFileFilter = new MyFileFilter(str);
|
195 |
files = directory.listFiles(myFileFilter); |
196 |
} |
197 |
String[] ends = new String[] { "shx", "SHX", "Shx", "sHx", "SHx", |
198 |
"shX", "ShX", "sHX" }; |
199 |
File shxFile = findEnd(str, files, ends);
|
200 |
return shxFile;
|
201 |
} |
202 |
|
203 |
private static File findEnd(String str, File[] files, String[] ends) { |
204 |
for (int i = 0; i < files.length; i++) { |
205 |
File dbfFile = files[i];
|
206 |
if (dbfFile.getAbsolutePath().endsWith(ends[0])) |
207 |
return dbfFile;
|
208 |
} |
209 |
for (int i = 0; i < files.length; i++) { |
210 |
File dbfFile = files[i];
|
211 |
if (dbfFile.getAbsolutePath().endsWith(ends[1])) |
212 |
return dbfFile;
|
213 |
} |
214 |
for (int i = 0; i < files.length; i++) { |
215 |
File dbfFile = files[i];
|
216 |
if (dbfFile.getAbsolutePath().endsWith(ends[2])) |
217 |
return dbfFile;
|
218 |
} |
219 |
for (int i = 0; i < files.length; i++) { |
220 |
File dbfFile = files[i];
|
221 |
if (dbfFile.getAbsolutePath().endsWith(ends[3])) |
222 |
return dbfFile;
|
223 |
} |
224 |
for (int i = 0; i < files.length; i++) { |
225 |
File dbfFile = files[i];
|
226 |
if (dbfFile.getAbsolutePath().endsWith(ends[4])) |
227 |
return dbfFile;
|
228 |
} |
229 |
for (int i = 0; i < files.length; i++) { |
230 |
File dbfFile = files[i];
|
231 |
if (dbfFile.getAbsolutePath().endsWith(ends[5])) |
232 |
return dbfFile;
|
233 |
} |
234 |
for (int i = 0; i < files.length; i++) { |
235 |
File dbfFile = files[i];
|
236 |
if (dbfFile.getAbsolutePath().endsWith(ends[6])) |
237 |
return dbfFile;
|
238 |
} |
239 |
for (int i = 0; i < files.length; i++) { |
240 |
File dbfFile = files[i];
|
241 |
if (dbfFile.getAbsolutePath().endsWith(ends[7])) |
242 |
return dbfFile;
|
243 |
} |
244 |
return new File(str.substring(0, str.length() - 3) + ends[0]); |
245 |
} |
246 |
|
247 |
} |