svn-gvsig-desktop / tags / v1_1_Build_1005 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / shp / SHP.java @ 12355
History | View | Annotate | Download (5.15 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 com.iver.cit.gvsig.fmap.core.IGeometry; |
44 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiLine; |
45 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiPoint; |
46 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPPoint; |
47 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPPolygon; |
48 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPShape; |
49 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.ShapefileException; |
50 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
51 |
|
52 |
import java.io.File; |
53 |
|
54 |
import java.util.BitSet; |
55 |
|
56 |
|
57 |
/**
|
58 |
* Clase con las constantes que representan los diferentes tipos de Shape y
|
59 |
* m?todos est?ticos relativos a los shapes.
|
60 |
*
|
61 |
* @author Vicente Caballero Navarro
|
62 |
*/
|
63 |
public class SHP { |
64 |
public static final int NULL = 0; |
65 |
public static final int POINT2D = 1; |
66 |
public static final int POLYLINE2D = 3; |
67 |
public static final int POLYGON2D = 5; |
68 |
public static final int MULTIPOINT2D = 8; |
69 |
public static final int POINT3D = 11; |
70 |
public static final int POLYLINE3D = 13; |
71 |
public static final int POLYGON3D = 15; |
72 |
public static final int MULTIPOINT3D = 18; |
73 |
|
74 |
/**
|
75 |
* Crea a partir del tipo de geometr?a un shape del tipo m?s adecuado.
|
76 |
*
|
77 |
* @param type Tipo de geometr?a.
|
78 |
*
|
79 |
* @return Geometr?a m?s adecuada.
|
80 |
*
|
81 |
* @throws ShapefileException Se lanza cuando es causada por la creaci?n
|
82 |
* del shape.
|
83 |
*/
|
84 |
public static SHPShape create(int type) throws ShapefileException { |
85 |
SHPShape shape; |
86 |
|
87 |
switch (type) {
|
88 |
case 1: |
89 |
case 11: |
90 |
case 21: |
91 |
shape = new SHPPoint(type);
|
92 |
|
93 |
break;
|
94 |
|
95 |
case 3: |
96 |
case 13: |
97 |
case 23: |
98 |
shape = new SHPMultiLine(type);
|
99 |
|
100 |
break;
|
101 |
|
102 |
case 5: |
103 |
case 15: |
104 |
case 25: |
105 |
shape = new SHPPolygon(type);
|
106 |
|
107 |
break;
|
108 |
|
109 |
case 8: |
110 |
case 18: |
111 |
case 28: |
112 |
shape = new SHPMultiPoint(type);
|
113 |
|
114 |
break;
|
115 |
|
116 |
default:
|
117 |
shape = null;
|
118 |
} |
119 |
|
120 |
return shape;
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Crea un fichero en formato shape con las geometr?as que se pasan como
|
125 |
* par?metro en forma de array, un bitset para saber las seleccionadas, un
|
126 |
* SelectableDataSource para obtener los valores y el fichero a crear.
|
127 |
*
|
128 |
* @param fgs Array de geometr?as.
|
129 |
* @param bitset Bitset con la selecci?n.
|
130 |
* @param sds SelectableDataSource.
|
131 |
* @param f Fichero a crear o modificar.
|
132 |
*/
|
133 |
public static void SHPFileFromGeometries(IGeometry[] fgs, BitSet bitset, |
134 |
SelectableDataSource sds, File f) {
|
135 |
SHPOnlyFromGeometries(fgs, f); |
136 |
|
137 |
DBFFromGeometries dfg = new DBFFromGeometries(fgs, f);
|
138 |
dfg.create(sds, bitset); |
139 |
} |
140 |
|
141 |
/**
|
142 |
* Obtiene un fichero shape con las geometr?as que se pasan como par?metro,
|
143 |
* sin crear un dbf.
|
144 |
*
|
145 |
* @param fgs Array de IGeometries.
|
146 |
* @param f Fichero que hay que crear.
|
147 |
*/
|
148 |
public static void SHPOnlyFromGeometries(IGeometry[] fgs, File f) { |
149 |
SHPSHXFromGeometries ssfg = new SHPSHXFromGeometries(fgs, f);
|
150 |
ssfg.create(); |
151 |
} |
152 |
|
153 |
/**
|
154 |
* Devuelve un array con dos doubles, el primero representa el m?nimo valor
|
155 |
* y el segundo el m?ximo de entre los valores que se pasan como par?metro
|
156 |
* en forma de array.
|
157 |
*
|
158 |
* @param zs Valores a comprobar.
|
159 |
*
|
160 |
* @return Array de doubles con el valor m?nimo y el valor m?ximo.
|
161 |
*/
|
162 |
public static double[] getZMinMax(double[] zs) { |
163 |
if (zs == null) { |
164 |
return null; |
165 |
} |
166 |
|
167 |
double min = Double.MAX_VALUE; |
168 |
double max = Double.NEGATIVE_INFINITY; |
169 |
|
170 |
for (int i = 0; i < zs.length; i++) { |
171 |
if (zs[i] > max) {
|
172 |
max = zs[i]; |
173 |
} |
174 |
|
175 |
if (zs[i] < min) {
|
176 |
min = zs[i]; |
177 |
} |
178 |
} |
179 |
|
180 |
return new double[] { min, max }; |
181 |
} |
182 |
} |