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