svn-gvsig-desktop / branches / v10 / extensions / DielmoOpenLidar / src-test / com / dielmo / gvsig / lidar / test / ObjectToLASVariableLengthRecord.java @ 25419
History | View | Annotate | Download (6.64 KB)
1 |
/* DielmoOpenLiDAR
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2008 DIELMO 3D S.L. (DIELMO) and Infrastructures
|
4 |
* and Transports Department of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For more information, contact:
|
22 |
*
|
23 |
* DIELMO 3D S.L.
|
24 |
* Plaza Vicente Andr?s Estell?s 1 Bajo E
|
25 |
* 46950 Xirivella, Valencia
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963137212
|
29 |
* dielmo@dielmo.com
|
30 |
* www.dielmo.com
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* Generalitat Valenciana
|
35 |
* Conselleria d'Infraestructures i Transport
|
36 |
* Av. Blasco Ib??ez, 50
|
37 |
* 46010 VALENCIA
|
38 |
* SPAIN
|
39 |
*
|
40 |
* +34 963862235
|
41 |
* gvsig@gva.es
|
42 |
* www.gvsig.gva.es
|
43 |
*/
|
44 |
|
45 |
/*
|
46 |
* AUTHORS (In addition to DIELMO and CIT):
|
47 |
*
|
48 |
*/
|
49 |
|
50 |
package com.dielmo.gvsig.lidar.test; |
51 |
|
52 |
import java.io.ByteArrayInputStream; |
53 |
import java.io.ByteArrayOutputStream; |
54 |
import java.io.File; |
55 |
import java.io.FileNotFoundException; |
56 |
import java.io.IOException; |
57 |
import java.io.ObjectInputStream; |
58 |
import java.io.ObjectOutputStream; |
59 |
|
60 |
import javax.swing.JFileChooser; |
61 |
import javax.swing.JOptionPane; |
62 |
|
63 |
import com.dielmo.gvsig.lidar.drivers.LiDARDriver; |
64 |
import com.dielmo.lidar.LASHeader_1X; |
65 |
import com.dielmo.lidar.LASVariableLengthRecord_1X; |
66 |
import com.dielmo.lidar.LASVariableLengthRecord_V10; |
67 |
import com.dielmo.lidar.LASVariableLengthRecord_V11; |
68 |
import com.dielmo.lidar.LidarHeader; |
69 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
70 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
71 |
import com.iver.utiles.GenericFileFilter; |
72 |
|
73 |
public class ObjectToLASVariableLengthRecord { |
74 |
|
75 |
public static void main(String[] args){ |
76 |
|
77 |
JFileChooser fileChooserLAS = new JFileChooser(); |
78 |
fileChooserLAS.addChoosableFileFilter(new GenericFileFilter("LAS Files", "*.las")); |
79 |
File fileLAS;
|
80 |
|
81 |
int resultLAS = fileChooserLAS.showOpenDialog(null); |
82 |
|
83 |
if (resultLAS == JFileChooser.APPROVE_OPTION && (fileLAS = fileChooserLAS.getSelectedFile()) != null) { |
84 |
|
85 |
if(fileLAS.getAbsolutePath().toUpperCase().endsWith("LAS")){ |
86 |
try {
|
87 |
|
88 |
LiDARDriver lidarDriver = new LiDARDriver();
|
89 |
lidarDriver.open(fileLAS); |
90 |
lidarDriver.initialize(); |
91 |
|
92 |
LASHeader_1X lasHeader = (LASHeader_1X) lidarDriver.getLidarHeader(); |
93 |
LASVariableLengthRecord_1X vlrLAS[] = lasHeader.getLASHeaderVLR();
|
94 |
LASVariableLengthRecord_1X newVlrLAS[] = new LASVariableLengthRecord_1X[vlrLAS.length+1]; |
95 |
int i;
|
96 |
for(i=0;i<vlrLAS.length;i++){ |
97 |
newVlrLAS[i] = vlrLAS[i]; |
98 |
} |
99 |
|
100 |
// cualquier objeto serializable y que no pese mas de 8 megas es posible integrarlo en una VLR
|
101 |
DoubleValue dd = ValueFactory.createValue(19.44);
|
102 |
// convertimos el Objeto shpLayer en un vector de bytes
|
103 |
ByteArrayOutputStream bsOut= new ByteArrayOutputStream(); |
104 |
ObjectOutputStream os = new ObjectOutputStream (bsOut); |
105 |
os.writeObject(dd); // solo acepta objetos serializables
|
106 |
os.close(); |
107 |
byte[] byteVal = bsOut.toByteArray(); // devuelve byte[] |
108 |
|
109 |
|
110 |
// escribimos los datos en las varialbes length record
|
111 |
int versionLAS = lasHeader.getVersion();
|
112 |
if(versionLAS==LidarHeader.LAS11F0 || versionLAS == LidarHeader.LAS11F1) {
|
113 |
|
114 |
LASVariableLengthRecord_V11 vlrAux11; |
115 |
vlrAux11 = new LASVariableLengthRecord_V11();
|
116 |
vlrAux11.setUserID("Shp");
|
117 |
vlrAux11.setReserved(0);
|
118 |
vlrAux11.setRecordID(1);
|
119 |
vlrAux11.setDescription("Shp del area de interes de la zona de estudio");
|
120 |
vlrAux11.setRecordLengthAfterHeader(byteVal.length); |
121 |
vlrAux11.setData(byteVal); |
122 |
newVlrLAS[i] = vlrAux11; |
123 |
lasHeader.setLASHeaderVLR(newVlrLAS); |
124 |
|
125 |
} else if(versionLAS==LidarHeader.LAS10F0 || versionLAS == LidarHeader.LAS10F1) { |
126 |
|
127 |
LASVariableLengthRecord_V10 vlrAux10; |
128 |
vlrAux10 = new LASVariableLengthRecord_V10();
|
129 |
|
130 |
vlrAux10.setUserID("Shp");
|
131 |
vlrAux10.setRecordID(1);
|
132 |
vlrAux10.setDescription("Shp del area de interes de la zona de estudio");
|
133 |
vlrAux10.setRecordLengthAfterHeader(byteVal.length); |
134 |
vlrAux10.setData(byteVal); |
135 |
newVlrLAS[i] = vlrAux10; |
136 |
|
137 |
lasHeader.setLASHeaderVLR(newVlrLAS); |
138 |
} |
139 |
|
140 |
// obtenemos la VLR que acabamos de guardar.
|
141 |
LASVariableLengthRecord_1X vlrAux2; |
142 |
vlrAux2 = lasHeader.getLASHeaderVLRByIndex(i); |
143 |
|
144 |
try {
|
145 |
byte bytes[] = vlrAux2.getData(); |
146 |
ByteArrayInputStream bsIn = new ByteArrayInputStream(bytes); // bytes es el byte[] |
147 |
ObjectInputStream is = new ObjectInputStream(bsIn); |
148 |
|
149 |
DoubleValue unObjetoSerializable = (DoubleValue)is.readObject(); |
150 |
is.close(); |
151 |
|
152 |
System.out.println(unObjetoSerializable.getValue());
|
153 |
|
154 |
} catch (ClassNotFoundException e) { |
155 |
// TODO Auto-generated catch block
|
156 |
e.printStackTrace(); |
157 |
} |
158 |
|
159 |
|
160 |
} catch (FileNotFoundException e) { |
161 |
// TODO Auto-generated catch block
|
162 |
e.printStackTrace(); |
163 |
} catch (IOException e) { |
164 |
// TODO Auto-generated catch block
|
165 |
e.printStackTrace(); |
166 |
} |
167 |
} |
168 |
|
169 |
} else {
|
170 |
|
171 |
// si no se eligio fichero LAS correctamente.
|
172 |
if(resultLAS == JFileChooser.APPROVE_OPTION ) |
173 |
JOptionPane.showMessageDialog(null, "Selecciona un fichero Lidar en formato LAS"); |
174 |
} |
175 |
} |
176 |
|
177 |
} |