svn-gvsig-desktop / tags / v1_0_2_Build_912 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / shp / SHP.java @ 11422
History | View | Annotate | Download (5.15 KB)
1 | 1100 | fjp | /* 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 | 224 | vcaballero | package com.iver.cit.gvsig.fmap.drivers.shp; |
42 | |||
43 | 1270 | vcaballero | import com.iver.cit.gvsig.fmap.core.IGeometry; |
44 | 1132 | vcaballero | 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 | 1270 | vcaballero | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
51 | 1132 | vcaballero | |
52 | 2197 | vcaballero | import java.io.File; |
53 | 1132 | vcaballero | |
54 | 2197 | vcaballero | import java.util.BitSet; |
55 | 1132 | vcaballero | |
56 | 2197 | vcaballero | |
57 | 224 | vcaballero | /**
|
58 | 1132 | vcaballero | * Clase con las constantes que representan los diferentes tipos de Shape y
|
59 | * m?todos est?ticos relativos a los shapes.
|
||
60 | 224 | vcaballero | *
|
61 | * @author Vicente Caballero Navarro
|
||
62 | */
|
||
63 | public class SHP { |
||
64 | 2841 | caballero | 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 | 1132 | vcaballero | |
74 | 2841 | caballero | /**
|
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 | 1132 | vcaballero | |
87 | 2841 | caballero | switch (type) {
|
88 | case 1: |
||
89 | case 11: |
||
90 | case 21: |
||
91 | shape = new SHPPoint(type);
|
||
92 | 1132 | vcaballero | |
93 | 2841 | caballero | break;
|
94 | 1132 | vcaballero | |
95 | 2841 | caballero | case 3: |
96 | case 13: |
||
97 | case 23: |
||
98 | shape = new SHPMultiLine(type);
|
||
99 | 1132 | vcaballero | |
100 | 2841 | caballero | break;
|
101 | 1132 | vcaballero | |
102 | 2841 | caballero | case 5: |
103 | case 15: |
||
104 | case 25: |
||
105 | shape = new SHPPolygon(type);
|
||
106 | 1132 | vcaballero | |
107 | 2841 | caballero | break;
|
108 | 1132 | vcaballero | |
109 | 2841 | caballero | case 8: |
110 | case 18: |
||
111 | case 28: |
||
112 | shape = new SHPMultiPoint(type);
|
||
113 | 1132 | vcaballero | |
114 | 2841 | caballero | break;
|
115 | 1132 | vcaballero | |
116 | 2841 | caballero | default:
|
117 | shape = null;
|
||
118 | } |
||
119 | 1132 | vcaballero | |
120 | 2841 | caballero | return shape;
|
121 | } |
||
122 | 1132 | vcaballero | |
123 | 2841 | caballero | /**
|
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 | 2197 | vcaballero | |
137 | 2841 | caballero | DBFFromGeometries dfg = new DBFFromGeometries(fgs, f);
|
138 | dfg.create(sds, bitset); |
||
139 | } |
||
140 | 2197 | vcaballero | |
141 | 2841 | caballero | /**
|
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 | 2197 | vcaballero | |
153 | 2841 | caballero | /**
|
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 | 2197 | vcaballero | |
167 | 2841 | caballero | double min = Double.MAX_VALUE; |
168 | 11226 | caballero | double max = Double.NEGATIVE_INFINITY; |
169 | 2197 | vcaballero | |
170 | 2841 | caballero | for (int i = 0; i < zs.length; i++) { |
171 | if (zs[i] > max) {
|
||
172 | max = zs[i]; |
||
173 | } |
||
174 | 2197 | vcaballero | |
175 | 2841 | caballero | if (zs[i] < min) {
|
176 | min = zs[i]; |
||
177 | } |
||
178 | } |
||
179 | |||
180 | return new double[] { min, max }; |
||
181 | } |
||
182 | 224 | vcaballero | } |