Revision 23231
branches/v10/extensions/extLidar/src/com/dielmo/gvsig/lidar/extensions/LidarExtension.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
LidarExtension.java |
|
3 |
Copyright (C) 2008 by DIELMO 3D S.L. |
|
4 |
|
|
5 |
This program is free software; you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU General Public License as published by |
|
7 |
the Free Software Foundation; either version 2 of the License, or |
|
8 |
(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 |
|
|
20 |
package com.dielmo.gvsig.lidar.extensions; |
|
21 |
|
|
22 |
import java.awt.Color; |
|
23 |
import java.awt.Component; |
|
24 |
import java.awt.geom.Rectangle2D; |
|
25 |
import java.io.File; |
|
26 |
import java.io.FileInputStream; |
|
27 |
import java.io.FileNotFoundException; |
|
28 |
import java.io.InputStreamReader; |
|
29 |
import java.io.Reader; |
|
30 |
import java.io.UnsupportedEncodingException; |
|
31 |
import java.text.NumberFormat; |
|
32 |
|
|
33 |
import javax.swing.JOptionPane; |
|
34 |
|
|
35 |
import org.exolab.castor.xml.ValidationException; |
|
36 |
|
|
37 |
import com.dielmo.gvsig.lidar.LidarHeader; |
|
38 |
import com.dielmo.gvsig.lidar.Strategies.LidarWatcher; |
|
39 |
import com.dielmo.gvsig.lidar.drivers.LiDARDriver; |
|
40 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
|
41 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
42 |
import com.hardcode.gdbms.engine.values.ValueWriter; |
|
43 |
import com.iver.andami.PluginServices; |
|
44 |
import com.iver.andami.plugins.Extension; |
|
45 |
import com.iver.andami.preferences.IPreference; |
|
46 |
import com.iver.andami.preferences.IPreferenceExtension; |
|
47 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
48 |
import com.iver.cit.gvsig.fmap.MapContext; |
|
49 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
50 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
51 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
52 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
|
53 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
54 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
55 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
56 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
57 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
|
58 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
59 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
60 |
import com.iver.cit.gvsig.fmap.rendering.FInterval; |
|
61 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
|
62 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
|
63 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
|
64 |
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend; |
|
65 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
|
66 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
|
67 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
|
68 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
69 |
import com.iver.utiles.XMLEntity; |
|
70 |
import com.iver.utiles.xml.XMLEncodingUtils; |
|
71 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
|
72 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
|
73 |
|
|
74 |
|
|
75 |
public class LidarExtension extends Extension implements IPreferenceExtension{ |
|
76 |
|
|
77 |
private static final IPreference thePreferencePage = new Lidar_Preferences(); |
|
78 |
|
|
79 |
public void initialize() { |
|
80 |
|
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
public void execute(String actionCommand) { |
|
85 |
|
|
86 |
if(actionCommand.equalsIgnoreCase("Z_LEGEND")) { |
|
87 |
zLegend(); |
|
88 |
} |
|
89 |
else if (actionCommand.equalsIgnoreCase("CLASIFICACION_LEGEND")) { |
|
90 |
clasificationLegend(); |
|
91 |
} |
|
92 |
else if (actionCommand.equalsIgnoreCase("INTENSITY_LEGEND")) { |
|
93 |
intensityLegend(); |
|
94 |
} |
|
95 |
else if (actionCommand.equalsIgnoreCase("PREFER_LEGEND")) { |
|
96 |
PreferenceLegend(); |
|
97 |
} |
|
98 |
else if(actionCommand.equalsIgnoreCase("DEFAULT_LEGEND")) { |
|
99 |
defaultLegend(); |
|
100 |
} |
|
101 |
return; |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Aplica la leyenda por intervalos para el valor de la tabla intensidad |
|
106 |
*/ |
|
107 |
private void intensityLegend() { |
|
108 |
FilterByName("Intensity"); |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Aplica la leyenda por intervalos para el valor de la tabla z |
|
113 |
*/ |
|
114 |
private void zLegend() { |
|
115 |
FilterByName("Z"); |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* Aplica la leyenda por defecto que aplicaria gvSIG, es decir, aplica |
|
120 |
* la leyenda para simbolos con colores aleatorios para cada capa. |
|
121 |
*/ |
|
122 |
private void defaultLegend() { |
|
123 |
// Cogemos todas las capas de la vista |
|
124 |
View vista = (View)PluginServices.getMDIManager().getActiveWindow(); |
|
125 |
MapContext mapContext = vista.getModel().getMapContext(); |
|
126 |
MapControl mc = vista.getMapControl(); |
|
127 |
FLayers Layers = mapContext.getLayers(); |
|
128 |
|
|
129 |
AplyDefaultLeyend(Layers, mapContext); |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Recorre todas las capas que contiene el FLayers de entrada |
|
134 |
* y le aplica la leyenda por defecto (colores aleatorios para cada capa) |
|
135 |
* |
|
136 |
* @param layers, capas en las que aplicaremos la leyenda |
|
137 |
*/ |
|
138 |
private void AplyDefaultLeyend(FLayers layers, MapContext mc) { |
|
139 |
SingleSymbolLegend legend; |
|
140 |
FSymbol s; |
|
141 |
FLayer lyr; |
|
142 |
|
|
143 |
SingleLayerIterator it = new SingleLayerIterator(layers); |
|
144 |
|
|
145 |
mc.beginAtomicEvent(); |
|
146 |
|
|
147 |
while (it.hasNext()) { |
|
148 |
lyr = it.next(); |
|
149 |
if (lyr instanceof FLyrVect) { |
|
150 |
try { |
|
151 |
FLyrVect lyrVect = (FLyrVect) lyr; |
|
152 |
s = new FSymbol(FShape.POINT); |
|
153 |
s.setSize(5); |
|
154 |
legend = new SingleSymbolLegend(s); |
|
155 |
lyrVect.setLegend((VectorialLegend) legend); |
|
156 |
|
|
157 |
} catch (FieldNotFoundException e) { |
|
158 |
// TODO Auto-generated catch block |
|
159 |
e.printStackTrace(); |
|
160 |
} catch (DriverException e) { |
|
161 |
// TODO Auto-generated catch block |
|
162 |
e.printStackTrace(); |
|
163 |
} |
|
164 |
} |
|
165 |
} // while |
|
166 |
|
|
167 |
mc.endAtomicEvent(); |
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* Aplica la leyenda predefinida en Preferencias->Preferencias Lidar |
|
172 |
*/ |
|
173 |
private void PreferenceLegend() { |
|
174 |
Legend legend = null; |
|
175 |
int i; |
|
176 |
|
|
177 |
LiDAR_Mapping lm = new LiDAR_Mapping(); |
|
178 |
|
|
179 |
String preferLegend = lm.getPathLegend(); |
|
180 |
|
|
181 |
File file=new File(preferLegend); |
|
182 |
|
|
183 |
if(!file.isFile()) |
|
184 |
return; |
|
185 |
|
|
186 |
// Cogemos todas las capas de la vista |
|
187 |
View vista = (View)PluginServices.getMDIManager().getActiveWindow(); |
|
188 |
MapContext mapContext = vista.getModel().getMapContext(); |
|
189 |
MapControl mc = vista.getMapControl(); |
|
190 |
FLayers Layers = mapContext.getLayers(); |
|
191 |
int LayerCount; |
|
192 |
|
|
193 |
Layers = extractLayers(Layers, mapContext); |
|
194 |
LayerCount = Layers.getLayersCount(); |
|
195 |
mc.cancelDrawing(); |
|
196 |
|
|
197 |
if ((file.getPath().endsWith(".gvl") || file.getPath().endsWith(".GVL"))) { |
|
198 |
legend = readLegend(file); |
|
199 |
|
|
200 |
// le asignamos la leyenda a todas las capas lidar |
|
201 |
for (i = 0; i < LayerCount; i++) { |
|
202 |
try { |
|
203 |
Legend cloneLegend = legend.cloneLegend(); |
|
204 |
Layers = mapContext.getLayers(); |
|
205 |
aplyLegend(Layers,cloneLegend, mapContext); |
|
206 |
} catch (XMLException e) { |
|
207 |
// TODO Auto-generated catch block |
|
208 |
e.printStackTrace(); |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
/** |
|
215 |
* Aplica la leyenda para las clasificaciones. |
|
216 |
* |
|
217 |
* La clasificacion se corresponde con la definicion que la especificacion |
|
218 |
* del LAS 1.1 se da sobre el tema. Por esta causa no se usa actualmente, ya |
|
219 |
* que cada lidar puede tener un tipo de clasificacion. |
|
220 |
*/ |
|
221 |
private void clasificationLegend() { |
|
222 |
|
|
223 |
String filtername = "Classification"; |
|
224 |
VectorialUniqueValueLegend legend = null; |
|
225 |
FSymbol mySymbol; |
|
226 |
// Cogemos todas las capas de la vista |
|
227 |
View vista = (View)PluginServices.getMDIManager().getActiveWindow(); |
|
228 |
MapContext mapContext = vista.getModel().getMapContext(); |
|
229 |
FLayers Layers = mapContext.getLayers(); |
|
230 |
FLyrVect lyr = null; |
|
231 |
int i; |
|
232 |
|
|
233 |
legend = LegendFactory.createVectorialUniqueValueLegend(FShape.POINT); |
|
234 |
legend.clear(); |
|
235 |
legend.setFieldName(filtername); |
|
236 |
|
|
237 |
mySymbol = setSymbol(PluginServices.getText(null, "Class0"), new Color(0,0,0)); |
|
238 |
legend.addSymbol(ValueFactory.createValue(0), mySymbol); |
|
239 |
|
|
240 |
mySymbol = setSymbol(PluginServices.getText(null, "Class1"), new Color(0,0,0)); |
|
241 |
legend.addSymbol(ValueFactory.createValue(1), mySymbol); |
|
242 |
|
|
243 |
mySymbol = setSymbol(PluginServices.getText(null, "Class2"), new Color(153,0,0)); |
|
244 |
legend.addSymbol(ValueFactory.createValue(2), mySymbol); |
|
245 |
|
|
246 |
mySymbol = setSymbol(PluginServices.getText(null, "Class3"), new Color(153,255,153)); |
|
247 |
legend.addSymbol(ValueFactory.createValue(3), mySymbol); |
|
248 |
|
|
249 |
mySymbol = setSymbol(PluginServices.getText(null, "Class4"), new Color(0,204,0)); |
|
250 |
legend.addSymbol(ValueFactory.createValue(4), mySymbol); |
|
251 |
|
|
252 |
mySymbol = setSymbol(PluginServices.getText(null, "Class5"), new Color(0,153,0)); |
|
253 |
legend.addSymbol(ValueFactory.createValue(5), mySymbol); |
|
254 |
|
|
255 |
mySymbol = setSymbol(PluginServices.getText(null, "Class6"), new Color(255,0,0)); |
|
256 |
legend.addSymbol(ValueFactory.createValue(6), mySymbol); |
|
257 |
|
|
258 |
mySymbol = setSymbol(PluginServices.getText(null, "Class7"), new Color(102,0,102)); |
|
259 |
legend.addSymbol(ValueFactory.createValue(7), mySymbol); |
|
260 |
|
|
261 |
mySymbol = setSymbol(PluginServices.getText(null, "Class8"), new Color(255,0,204)); |
|
262 |
legend.addSymbol(ValueFactory.createValue(8), mySymbol); |
|
263 |
|
|
264 |
mySymbol = setSymbol(PluginServices.getText(null, "Class9"), new Color(51,102,255)); |
|
265 |
legend.addSymbol(ValueFactory.createValue(9), mySymbol); |
|
266 |
|
|
267 |
mySymbol = setSymbol(PluginServices.getText(null, "Class12"), new Color(153,255,204)); |
|
268 |
legend.addSymbol(ValueFactory.createValue(12), mySymbol); |
|
269 |
|
|
270 |
// le asignamos la leyenda a todas las capas lidar |
|
271 |
for (i = 0; i < Layers.getLayersCount(); i++) { |
|
272 |
|
|
273 |
if (LiDARDriver.isLidarLayer(Layers.getLayer(i))) { |
|
274 |
|
|
275 |
try { |
|
276 |
lyr = ((FLyrVect) Layers.getLayer(i)); |
|
277 |
VectorialUniqueValueLegend cloneLegend = (VectorialUniqueValueLegend) legend.cloneLegend(); |
|
278 |
lyr.setLegend(cloneLegend); |
|
279 |
} catch (FieldNotFoundException e) { |
|
280 |
// TODO Auto-generated catch block |
|
281 |
e.printStackTrace(); |
|
282 |
} catch (DriverException e) { |
|
283 |
// TODO Auto-generated catch block |
|
284 |
e.printStackTrace(); |
|
285 |
} catch (XMLException e) { |
|
286 |
// TODO Auto-generated catch block |
|
287 |
e.printStackTrace(); |
|
288 |
} |
|
289 |
} |
|
290 |
} |
|
291 |
} |
|
292 |
|
|
293 |
|
|
294 |
/** |
|
295 |
* Obtiene las capas internas de las agrupaciones y las devuelve en un |
|
296 |
* solo FLayers |
|
297 |
*/ |
|
298 |
private FLayers extractLayers(FLayers layers, MapContext mc) { |
|
299 |
|
|
300 |
FLayers capas = new FLayers(mc, null); |
|
301 |
FLayer lyr; |
|
302 |
|
|
303 |
SingleLayerIterator it = new SingleLayerIterator(layers); |
|
304 |
|
|
305 |
while (it.hasNext()) { |
|
306 |
|
|
307 |
lyr = it.next(); |
|
308 |
if (lyr instanceof FLyrVect) { |
|
309 |
|
|
310 |
try { |
|
311 |
capas.addLayer(lyr.cloneLayer()); |
|
312 |
} catch (Exception e) { |
|
313 |
// TODO Auto-generated catch block |
|
314 |
e.printStackTrace(); |
|
315 |
} |
|
316 |
} |
|
317 |
} // while |
|
318 |
|
|
319 |
return capas; |
|
320 |
} |
|
321 |
|
|
322 |
/** |
|
323 |
* Aplica las leyendas a todas las capas del FLayers, incluida |
|
324 |
* las agrupaciones. |
|
325 |
* |
|
326 |
* @param layers capas a las que aplicarle la leyenda. |
|
327 |
* @param leyenda, leyenda a aplicar |
|
328 |
*/ |
|
329 |
private void aplyLegend(FLayers layers, Legend leyenda, MapContext mc) { |
|
330 |
|
|
331 |
FLayer lyr; |
|
332 |
|
|
333 |
SingleLayerIterator it = new SingleLayerIterator(layers); |
|
334 |
|
|
335 |
mc.beginAtomicEvent(); |
|
336 |
|
|
337 |
while (it.hasNext()) { |
|
338 |
lyr = it.next(); |
|
339 |
if (lyr instanceof FLyrVect) { |
|
340 |
|
|
341 |
try { |
|
342 |
FLyrVect lyrVect = (FLyrVect) lyr; |
|
343 |
lyrVect.setLegend((VectorialLegend) leyenda.cloneLegend()); |
|
344 |
mc.redraw(); |
|
345 |
|
|
346 |
} catch (FieldNotFoundException e) { |
|
347 |
// TODO Auto-generated catch block |
|
348 |
e.printStackTrace(); |
|
349 |
} catch (DriverException e) { |
|
350 |
// TODO Auto-generated catch block |
|
351 |
e.printStackTrace(); |
|
352 |
} catch (XMLException e) { |
|
353 |
// TODO Auto-generated catch block |
|
354 |
e.printStackTrace(); |
|
355 |
} |
|
356 |
} |
|
357 |
} // while |
|
358 |
|
|
359 |
mc.endAtomicEvent(); |
|
360 |
} |
|
361 |
|
|
362 |
/** |
|
363 |
* Aplica la leyenda por intervalos del campo filtername pasado por entrada. |
|
364 |
* |
|
365 |
* @param filtername, campo por el que filtrar |
|
366 |
*/ |
|
367 |
private void FilterByName(String filtername) { |
|
368 |
|
|
369 |
VectorialIntervalLegend legend = null; |
|
370 |
FInterval[] arrayIntervalos = null; |
|
371 |
FSymbol myDefaultSymbol; |
|
372 |
ReadableVectorial rv; |
|
373 |
SelectableDataSource ds; |
|
374 |
int i,campo,LidarLayerCount=0; |
|
375 |
long NumPointsByLayer, inc=1, j; |
|
376 |
double MaxValue=Double.NEGATIVE_INFINITY, MinValue=Double.MAX_VALUE, value; |
|
377 |
|
|
378 |
// Cogemos todas las capas de la vista |
|
379 |
View vista = (View)PluginServices.getMDIManager().getActiveWindow(); |
|
380 |
MapContext mapContext = vista.getModel().getMapContext(); |
|
381 |
MapControl mc = vista.getMapControl(); |
|
382 |
FLayers layers = mapContext.getLayers(); |
|
383 |
IGeometry geom; |
|
384 |
int layerCount; |
|
385 |
|
|
386 |
layers = extractLayers(layers, mapContext); |
|
387 |
layerCount = layers.getLayersCount(); |
|
388 |
|
|
389 |
Rectangle2D extentView = mapContext.getViewPort().getAdjustedExtent(); |
|
390 |
Rectangle2D extentLayer; |
|
391 |
|
|
392 |
FLyrVect lyr = null; |
|
393 |
mc.cancelDrawing(); |
|
394 |
|
|
395 |
// Calculamos el n?mero de capas que intersectan con la vista |
|
396 |
for (i = 0; i < layerCount; i++) { |
|
397 |
|
|
398 |
if (LiDARDriver.isLidarLayer(layers.getLayer(i))) { |
|
399 |
|
|
400 |
try { |
|
401 |
lyr = ((FLyrVect) layers.getLayer(i)); |
|
402 |
extentLayer = lyr.getFullExtent(); |
|
403 |
|
|
404 |
if(extentLayer.intersects(extentView)) |
|
405 |
{ |
|
406 |
LidarLayerCount++; |
|
407 |
} |
|
408 |
|
|
409 |
}catch (DriverException e) { |
|
410 |
// TODO Auto-generated catch block |
|
411 |
e.printStackTrace(); |
|
412 |
} |
|
413 |
} |
|
414 |
} |
|
415 |
|
|
416 |
// si ninguna capa intersecta con el fullextent dejamos de operar |
|
417 |
if(LidarLayerCount == 0) |
|
418 |
return; |
|
419 |
|
|
420 |
NumPointsByLayer = 20000 / LidarLayerCount; |
|
421 |
|
|
422 |
// Cogemos los valores max y min del campo por el que se filtra de todas las capas. |
|
423 |
for (i = 0; i < layerCount; i++) { |
|
424 |
|
|
425 |
if (LiDARDriver.isLidarLayer(layers.getLayer(i))) { |
|
426 |
|
|
427 |
try { |
|
428 |
|
|
429 |
|
|
430 |
lyr = ((FLyrVect) layers.getLayer(i)); |
|
431 |
rv = lyr.getSource(); |
|
432 |
ds = rv.getRecordset(); |
|
433 |
extentLayer = lyr.getFullExtent(); |
|
434 |
|
|
435 |
/* if(extentView.contains(extentLayer) && filtername == "Z") |
|
436 |
{ |
|
437 |
// si el campo por el que se filtra es Z y ademas el fullextent de la capa |
|
438 |
// esta completamente denro de la vista, cogemos los valores Z de la cabecera |
|
439 |
// proporcionada por el driver que maneja la capa |
|
440 |
LiDARDriver ld = (LiDARDriver) rv.getDriver(); |
|
441 |
|
|
442 |
value = ld.getLidarHeader().getMinZ(); |
|
443 |
if (MinValue > value) |
|
444 |
MinValue = value; |
|
445 |
|
|
446 |
value = ld.getLidarHeader().getMaxZ(); |
|
447 |
if (MaxValue < value) |
|
448 |
MaxValue = value; |
|
449 |
} |
|
450 |
else |
|
451 |
{ */ |
|
452 |
campo = ds.getFieldIndexByName(filtername); |
|
453 |
|
|
454 |
inc = ds.getRowCount() / NumPointsByLayer; |
|
455 |
if (inc < 1) |
|
456 |
inc = 1; |
|
457 |
|
|
458 |
if(extentLayer.intersects(extentView)) { |
|
459 |
|
|
460 |
for (j=0 ; j<ds.getRowCount(); j+=inc) { |
|
461 |
|
|
462 |
geom=rv.getShape((int)j); |
|
463 |
|
|
464 |
// if (geom.intersects(extentView)) { |
|
465 |
if (geom.fastIntersects(extentView.getMinX(), extentView.getMinY(), extentView.getWidth(), extentView.getHeight())) { |
|
466 |
|
|
467 |
value=Double.parseDouble(ds.getFieldValue(j, campo).getStringValue(ValueWriter.internalValueWriter)); |
|
468 |
if (MinValue > value) |
|
469 |
MinValue = value; |
|
470 |
|
|
471 |
if (MaxValue < value) |
|
472 |
MaxValue = value; |
|
473 |
} |
|
474 |
} |
|
475 |
} |
|
476 |
// } |
|
477 |
|
|
478 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
|
479 |
// TODO Auto-generated catch block |
|
480 |
e.printStackTrace(); |
|
481 |
} catch (DriverIOException e) { |
|
482 |
// TODO Auto-generated catch block |
|
483 |
e.printStackTrace(); |
|
484 |
} catch (DriverException e) { |
|
485 |
// TODO Auto-generated catch block |
|
486 |
e.printStackTrace(); |
|
487 |
} |
|
488 |
} |
|
489 |
} |
|
490 |
|
|
491 |
legend = LegendFactory.createVectorialIntervalLegend(FShape.POINT); |
|
492 |
legend.clear(); |
|
493 |
legend.setFieldName(filtername); |
|
494 |
|
|
495 |
// Creamos el primer y ?ltimo color. |
|
496 |
Color startColor = new Color(0,0,0); |
|
497 |
Color endColor = new Color(230,230,230); |
|
498 |
|
|
499 |
arrayIntervalos = calculateEqualIntervals(100, MinValue, MaxValue, filtername); |
|
500 |
FInterval elIntervalo; |
|
501 |
NumberFormat.getInstance().setMaximumFractionDigits(2); |
|
502 |
|
|
503 |
int r; |
|
504 |
int g; |
|
505 |
int b; |
|
506 |
int stepR; |
|
507 |
int stepG; |
|
508 |
int stepB; |
|
509 |
r = startColor.getRed(); |
|
510 |
g = startColor.getGreen(); |
|
511 |
b = startColor.getBlue(); |
|
512 |
stepR = (endColor.getRed() - r) / arrayIntervalos.length; |
|
513 |
stepG = (endColor.getGreen() - g) / arrayIntervalos.length; |
|
514 |
stepB = (endColor.getBlue() - b) / arrayIntervalos.length; |
|
515 |
|
|
516 |
|
|
517 |
for (int k = 0; k < arrayIntervalos.length; k++) { |
|
518 |
elIntervalo = arrayIntervalos[k]; |
|
519 |
|
|
520 |
Color c = new Color(r, g, b); |
|
521 |
//si no esta creado el simbolo se crea |
|
522 |
myDefaultSymbol = new FSymbol(FShape.POINT, c); |
|
523 |
myDefaultSymbol.setDescription(NumberFormat.getInstance().format(elIntervalo.getMin()) + |
|
524 |
" - " + |
|
525 |
NumberFormat.getInstance().format(elIntervalo.getMax())); |
|
526 |
|
|
527 |
// myDefaultSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE); |
|
528 |
myDefaultSymbol.setSize(3); |
|
529 |
myDefaultSymbol.setSizeInPixels(true); |
|
530 |
|
|
531 |
|
|
532 |
////////////////////////////////////// |
|
533 |
// CALCULAMOS UN COLOR APROPIADO |
|
534 |
r = r + stepR; |
|
535 |
g = g + stepG; |
|
536 |
b = b + stepB; |
|
537 |
|
|
538 |
///////////////////////////////// |
|
539 |
|
|
540 |
legend.addSymbol(elIntervalo, myDefaultSymbol); |
|
541 |
} |
|
542 |
|
|
543 |
// le asignamos la leyenda a todas las capas lidar |
|
544 |
try { |
|
545 |
VectorialIntervalLegend cloneLegend = (VectorialIntervalLegend) legend.cloneLegend(); |
|
546 |
layers = mapContext.getLayers(); |
|
547 |
aplyLegend(layers,cloneLegend, mapContext); |
|
548 |
} catch (XMLException e) { |
|
549 |
// TODO Auto-generated catch block |
|
550 |
e.printStackTrace(); |
|
551 |
} |
|
552 |
} |
|
553 |
|
|
554 |
/** |
|
555 |
* EQUAL INTERVAL Devuelve un Array con el n?mero de intervalos que se |
|
556 |
* quieren crear. Los intervalos se crean con un tama?o igual entre ellos. |
|
557 |
* |
|
558 |
* @param numIntervals n?mero de intervalos |
|
559 |
* @param minValue Valor m?nimo. |
|
560 |
* @param maxValue Valor m?ximo. |
|
561 |
* @param fieldName Nombre del campo |
|
562 |
* |
|
563 |
* @return Array con los intervalos. |
|
564 |
* @see com.iver.cit.gvsig.project.documents.view.legend.gui; |
|
565 |
*/ |
|
566 |
public static FInterval[] calculateEqualIntervals(int numIntervals, double minValue, |
|
567 |
double maxValue, String fieldName) { |
|
568 |
|
|
569 |
FInterval[] theIntervalArray = new FInterval[numIntervals]; |
|
570 |
double step = (maxValue - minValue) / numIntervals; |
|
571 |
|
|
572 |
if (numIntervals > 1) { |
|
573 |
theIntervalArray[0] = new FInterval(minValue, minValue + step); |
|
574 |
|
|
575 |
for (int i = 1; i < (numIntervals - 1); i++) { |
|
576 |
theIntervalArray[i] = new FInterval(minValue + (i * step) + |
|
577 |
0.01, minValue + ((i + 1) * step)); |
|
578 |
} |
|
579 |
|
|
580 |
theIntervalArray[numIntervals - 1] = new FInterval(minValue + |
|
581 |
((numIntervals - 1) * step) + 0.01, maxValue); |
|
582 |
} else { |
|
583 |
theIntervalArray[0] = new FInterval(minValue, maxValue); |
|
584 |
} |
|
585 |
|
|
586 |
return theIntervalArray; |
|
587 |
} |
|
588 |
|
|
589 |
/** |
|
590 |
* Set a new Symbol with a name and color. |
|
591 |
* |
|
592 |
* @param nameSymbol name of symbol |
|
593 |
* @param c color of symbol |
|
594 |
* @return the symbol with name and color predefined |
|
595 |
*/ |
|
596 |
private FSymbol setSymbol(String nameSymbol, Color c) { |
|
597 |
|
|
598 |
FSymbol mySymbol; |
|
599 |
mySymbol = new FSymbol(FShape.POINT, c); |
|
600 |
|
|
601 |
mySymbol.setDescription(nameSymbol); |
|
602 |
mySymbol.setSize(3); |
|
603 |
mySymbol.setSizeInPixels(true); |
|
604 |
|
|
605 |
return mySymbol; |
|
606 |
} |
|
607 |
|
|
608 |
public boolean isEnabled() { |
|
609 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
|
610 |
.getActiveWindow(); |
|
611 |
if (f == null) { |
|
612 |
return false; |
|
613 |
} |
|
614 |
if (f instanceof View) { |
|
615 |
View vista = (View) f; |
|
616 |
IProjectView model = vista.getModel(); |
|
617 |
FLayers layers = model.getMapContext().getLayers(); |
|
618 |
|
|
619 |
|
|
620 |
layers = extractLayers(layers, model.getMapContext()); |
|
621 |
|
|
622 |
int numLayers = layers.getLayersCount(); |
|
623 |
for(int i = 0; i < numLayers; i++){ |
|
624 |
FLayer layer = layers.getLayer(i); |
|
625 |
if(LiDARDriver.isLidarLayer(layer) && layer.isAvailable()) |
|
626 |
return true; |
|
627 |
} |
|
628 |
} |
|
629 |
return false; |
|
630 |
} |
|
631 |
|
|
632 |
public boolean isVisible() { |
|
633 |
|
|
634 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
|
635 |
.getActiveWindow(); |
|
636 |
if (f == null) { |
|
637 |
return false; |
|
638 |
} |
|
639 |
|
|
640 |
if (f instanceof View) { |
|
641 |
|
|
642 |
View vista = (View) f; |
|
643 |
IProjectView model = vista.getModel(); |
|
644 |
|
|
645 |
setLidarListener(vista); |
|
646 |
|
|
647 |
FLayers layers = model.getMapContext().getLayers(); |
|
648 |
|
|
649 |
// layers = extractLayers(layers, model.getMapContext()); |
|
650 |
|
|
651 |
int numLayers = layers.getLayersCount(); |
|
652 |
for(int i = 0; i < numLayers; i++){ |
|
653 |
FLayer layer = layers.getLayer(i); |
|
654 |
if(LiDARDriver.isLidarLayer(layer)) { |
|
655 |
// return true; |
|
656 |
} |
|
657 |
} |
|
658 |
return false; |
|
659 |
} |
|
660 |
|
|
661 |
return false; |
|
662 |
} |
|
663 |
|
|
664 |
/** |
|
665 |
* Nos registramos como escucha de los mapcontext del MapOverview |
|
666 |
* y del MapControl para que nos avisen cuando se a?ade una capa. |
|
667 |
* Si es de tipo Lidar, le cambiamos la estregia. |
|
668 |
* @param vista |
|
669 |
*/ |
|
670 |
private void setLidarListener(View vista) { |
|
671 |
FLayers layers = vista.getMapControl().getMapContext().getLayers(); |
|
672 |
layers.addLayerCollectionListener(LidarWatcher.getInstance()); |
|
673 |
|
|
674 |
} |
|
675 |
|
|
676 |
/** |
|
677 |
* Lee la leyenda del fichero file y devuelve la leyenda cargada. |
|
678 |
* |
|
679 |
* @param file, fichero donde buscar la leyenda |
|
680 |
* @return la leyenda leida. |
|
681 |
*/ |
|
682 |
public Legend readLegend(File file) { |
|
683 |
|
|
684 |
Legend renderer = null; |
|
685 |
File xmlFile = new File(file.getAbsolutePath()); |
|
686 |
try { |
|
687 |
String encoding = XMLEncodingUtils.getEncoding(new FileInputStream(xmlFile)); |
|
688 |
InputStreamReader reader=null; |
|
689 |
if (encoding!=null) { |
|
690 |
try { |
|
691 |
reader = new InputStreamReader(new FileInputStream(xmlFile), encoding); |
|
692 |
renderer= readLegend(reader, true); |
|
693 |
} catch (UnsupportedEncodingException e) { |
|
694 |
reader = new InputStreamReader(new FileInputStream(xmlFile),"ISO-8859-1"); |
|
695 |
try { |
|
696 |
renderer= readLegend(reader, false); |
|
697 |
} catch (UnsupportedEncodingException e1) { |
|
698 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, e1.getLocalizedMessage())); |
|
699 |
return null; |
|
700 |
} |
|
701 |
} |
|
702 |
} |
|
703 |
else { |
|
704 |
reader = new InputStreamReader(new FileInputStream(xmlFile),"UTF-8"); |
|
705 |
try { |
|
706 |
renderer= readLegend(reader, false); |
|
707 |
} catch (UnsupportedEncodingException e1) { |
|
708 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, e1.getLocalizedMessage())); |
|
709 |
return null; |
|
710 |
} |
|
711 |
} |
|
712 |
} catch (FileNotFoundException e) { |
|
713 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "fichero_incorrecto")); |
|
714 |
return null; |
|
715 |
} catch (UnsupportedEncodingException e) { |
|
716 |
e.printStackTrace(); |
|
717 |
} |
|
718 |
|
|
719 |
return renderer; |
|
720 |
} |
|
721 |
public Legend readLegend(Reader reader, boolean encodingFollowed) throws UnsupportedEncodingException { |
|
722 |
Legend legend = null; |
|
723 |
|
|
724 |
try { |
|
725 |
XmlTag tag = (XmlTag) XmlTag.unmarshal(reader); |
|
726 |
XMLEntity xml=new XMLEntity(tag); |
|
727 |
if (encodingFollowed) { |
|
728 |
if (xml.contains("followHeaderEncoding")) { |
|
729 |
boolean useEncoding = xml.getBooleanProperty("followHeaderEncoding"); |
|
730 |
if (!useEncoding) { |
|
731 |
throw new UnsupportedEncodingException("the encoding specified in the xml header is not safe"); |
|
732 |
} |
|
733 |
} |
|
734 |
else { |
|
735 |
// Old projects didn't contain followHeaderEncoding and they were |
|
736 |
// not correctly encoded. We throw an exception now, and we'll try |
|
737 |
// to reopen the project |
|
738 |
// using the default system encoding. |
|
739 |
throw new UnsupportedEncodingException("the encoding specified in the xml header is not safe"); |
|
740 |
} |
|
741 |
} |
|
742 |
|
|
743 |
legend = LegendFactory.createFromXML(xml); |
|
744 |
return legend; |
|
745 |
} catch (ValidationException e) { |
|
746 |
PluginServices.getLogger().error(PluginServices.getText(this, "formato_incorrecto"),e); |
|
747 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "formato_incorrecto")); |
|
748 |
//NotificationManager.addError("Al leer el proyecto", e); |
|
749 |
} catch (XMLException e) { |
|
750 |
PluginServices.getLogger().error(PluginServices.getText(this, "formato_incorrecto"),e); |
|
751 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "formato_incorrecto")); |
|
752 |
//NotificationManager.addError("Al leer el proyecto", e); |
|
753 |
} catch (org.exolab.castor.xml.MarshalException e) { |
|
754 |
// TODO Auto-generated catch block |
|
755 |
e.printStackTrace(); |
|
756 |
} |
|
757 |
return null; |
|
758 |
} |
|
759 |
|
|
760 |
/** |
|
761 |
* Usada para recuperar las preferencias Lidar |
|
762 |
*/ |
|
763 |
public IPreference getPreferencesPage() { |
|
764 |
return thePreferencePage; |
|
765 |
} |
|
766 |
} |
Also available in: Unified diff