Revision 2158 branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/SHP.java
SHP.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.cit.gvsig.fmap.drivers.shp; |
42 | 42 |
|
43 |
import java.io.File; |
|
44 |
import java.util.BitSet; |
|
45 |
|
|
46 |
import com.hardcode.gdbms.engine.values.Value; |
|
47 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
48 |
import com.iver.cit.gvsig.fmap.FMap; |
|
49 | 43 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
50 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.DBFFromSelected; |
|
51 | 44 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiLine; |
52 | 45 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiPoint; |
53 | 46 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPPoint; |
54 | 47 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPPolygon; |
55 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPSHXFromSelectedVisitor; |
|
56 | 48 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPShape; |
57 | 49 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.ShapefileException; |
58 | 50 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
59 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedShapeVisitor; |
|
60 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
|
61 | 51 |
|
52 |
import java.io.File; |
|
62 | 53 |
|
54 |
import java.util.BitSet; |
|
63 | 55 |
|
56 |
|
|
64 | 57 |
/** |
65 | 58 |
* Clase con las constantes que representan los diferentes tipos de Shape y |
66 | 59 |
* m?todos est?ticos relativos a los shapes. |
... | ... | |
85 | 78 |
* |
86 | 79 |
* @return Geometr?a m?s adecuada. |
87 | 80 |
* |
88 |
* @throws ShapefileException Se lanza cuando es causada por la creaci?n del shape. |
|
81 |
* @throws ShapefileException Se lanza cuando es causada por la creaci?n |
|
82 |
* del shape. |
|
89 | 83 |
*/ |
90 | 84 |
public static SHPShape create(int type) throws ShapefileException { |
91 | 85 |
SHPShape shape; |
... | ... | |
126 | 120 |
return shape; |
127 | 121 |
} |
128 | 122 |
|
129 |
public static void SHPFileFromSelected(FMap map,File f){ |
|
130 |
SHPSHXFromSelectedVisitor visitor = new SHPSHXFromSelectedVisitor(); |
|
131 |
visitor.setFile(f); |
|
132 |
//int type=getTypeShape(); |
|
133 |
//visitor.setType(5); |
|
134 |
try { |
|
135 |
map.getLayers().process(visitor); |
|
136 |
} catch (DriverException e1) { |
|
137 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
|
138 |
e1); |
|
139 |
} catch (VisitException e) { |
|
140 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
|
141 |
e); |
|
142 |
} |
|
143 |
|
|
144 |
try { |
|
145 |
DBFFromSelected dbf=new DBFFromSelected(); |
|
146 |
dbf.setFile(f); |
|
147 |
dbf.setGeometries(visitor.getGeometries()); |
|
148 |
dbf.setIsNewDBF(true); |
|
149 |
visitor.getSDS().start(); |
|
150 |
dbf.start(visitor.getSDS()); |
|
151 |
dbf.createdbf(visitor.getBitSet()); |
|
152 |
dbf.stop(); |
|
153 |
visitor.getSDS().stop(); |
|
154 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e2) { |
|
155 |
e2.printStackTrace(); |
|
156 |
} |
|
157 |
|
|
158 |
} |
|
159 |
public static void SHPFileFromGeometries(IGeometry[] fgs,BitSet bitset,SelectableDataSource sds,File f){ |
|
160 |
|
|
161 |
SHPSHXFromGeometries ssfg = new SHPSHXFromGeometries(fgs,f); |
|
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 |
SHPSHXFromGeometries ssfg = new SHPSHXFromGeometries(fgs, f); |
|
162 | 136 |
ssfg.create(); |
163 |
DBFFromGeometries dfg=new DBFFromGeometries(fgs,f); |
|
164 |
dfg.create(sds,bitset); |
|
137 |
|
|
138 |
DBFFromGeometries dfg = new DBFFromGeometries(fgs, f); |
|
139 |
dfg.create(sds, bitset); |
|
165 | 140 |
} |
166 |
public static double[] getZMinMax(double[] zs){ |
|
167 |
if (zs==null)return null; |
|
168 |
double min=Double.MAX_VALUE; |
|
169 |
double max=Double.MIN_VALUE; |
|
170 |
for (int i=0;i<zs.length;i++){ |
|
171 |
if (zs[i]>max)max=zs[i]; |
|
172 |
if (zs[i]<min)min=zs[i]; |
|
141 |
|
|
142 |
/** |
|
143 |
* Devuelve un array con dos doubles, el primero representa el m?nimo valor |
|
144 |
* y el segundo el m?ximo de entre los valores que se pasan como par?metro |
|
145 |
* en forma de array. |
|
146 |
* |
|
147 |
* @param zs Valores a comprobar. |
|
148 |
* |
|
149 |
* @return Array de doubles con el valor m?nimo y el valor m?ximo. |
|
150 |
*/ |
|
151 |
public static double[] getZMinMax(double[] zs) { |
|
152 |
if (zs == null) { |
|
153 |
return null; |
|
173 | 154 |
} |
174 |
return new double[]{min,max}; |
|
155 |
|
|
156 |
double min = Double.MAX_VALUE; |
|
157 |
double max = Double.MIN_VALUE; |
|
158 |
|
|
159 |
for (int i = 0; i < zs.length; i++) { |
|
160 |
if (zs[i] > max) { |
|
161 |
max = zs[i]; |
|
162 |
} |
|
163 |
|
|
164 |
if (zs[i] < min) { |
|
165 |
min = zs[i]; |
|
166 |
} |
|
167 |
} |
|
168 |
|
|
169 |
return new double[] { min, max }; |
|
175 | 170 |
} |
176 | 171 |
} |
Also available in: Unified diff