svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extRemoteSensing / src / org / gvsig / remotesensing / ROIFromFeaturesExtension.java @ 26348
History | View | Annotate | Download (5.1 KB)
1 |
/* gvSIG. Sistema de Informacin Geogrfica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional 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 Ibez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing; |
42 |
|
43 |
import javax.swing.JOptionPane; |
44 |
|
45 |
import org.gvsig.fmap.raster.grid.roi.VectorialROI; |
46 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
47 |
import org.gvsig.raster.buffer.BufferFactory; |
48 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
49 |
import org.gvsig.raster.grid.Grid; |
50 |
import org.gvsig.raster.grid.GridException; |
51 |
import org.gvsig.raster.util.RasterToolsUtil; |
52 |
|
53 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
54 |
import com.iver.andami.PluginServices; |
55 |
import com.iver.andami.plugins.Extension; |
56 |
import com.iver.cit.gvsig.fmap.MapContext; |
57 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
60 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
61 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
62 |
|
63 |
/**
|
64 |
* Extensi?n para el C?lculo de Raster (Band Math)
|
65 |
*
|
66 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
67 |
*
|
68 |
*/
|
69 |
public class ROIFromFeaturesExtension extends Extension { |
70 |
|
71 |
public void initialize() { |
72 |
|
73 |
} |
74 |
|
75 |
public void execute(String actionCommand) { |
76 |
if (actionCommand.equals("roi_from_features")){ |
77 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
78 |
|
79 |
//si la ventana activa es de tipo Vista
|
80 |
if (activeWindow instanceof View) { |
81 |
View view = (View) activeWindow; |
82 |
MapContext mapContext = view.getModel().getMapContext(); |
83 |
FLyrVect flyrVect = null;
|
84 |
FLyrRasterSE flyrRaster = null;
|
85 |
for (int i = 0; i < mapContext.getLayers().getActives().length; i++){ |
86 |
if (mapContext.getLayers().getActives()[i] instanceof FLyrVect) |
87 |
flyrVect = (FLyrVect) mapContext.getLayers().getActives()[i]; |
88 |
if (mapContext.getLayers().getActives()[i] instanceof FLyrRasterSE) |
89 |
flyrRaster = (FLyrRasterSE) mapContext.getLayers().getActives()[i]; |
90 |
} |
91 |
|
92 |
if (flyrRaster != null && flyrVect != null){ |
93 |
Grid grid = null;
|
94 |
BufferFactory dataSource = flyrRaster.getBufferFactory(); |
95 |
|
96 |
int bands[]=null; |
97 |
bands = new int [flyrRaster.getBandCount()]; |
98 |
for(int i=0; i<flyrRaster.getBandCount();i++) |
99 |
bands[i]=i; |
100 |
try {
|
101 |
grid = new Grid(dataSource, bands);
|
102 |
} catch (RasterBufferInvalidException e) {
|
103 |
e.printStackTrace(); |
104 |
} |
105 |
VectorialROI roi = new VectorialROI(grid);
|
106 |
try {
|
107 |
FBitSet fbs = flyrVect.getRecordset().getSelection(); |
108 |
if(fbs.cardinality()>0){ |
109 |
for(int i=fbs.nextSetBit(0); i>=0; i=fbs.nextSetBit(i+1)) { |
110 |
roi.addGeometry(flyrVect.getSource().getFeature(i).getGeometry()); |
111 |
} |
112 |
JOptionPane.showMessageDialog(null, |
113 |
"Mean: "+roi.getMeanValue()+"Max: "+roi.getMaxValue()+"Min: "+roi.getMinValue(), "ROI Statistics", |
114 |
JOptionPane.WARNING_MESSAGE);
|
115 |
} |
116 |
} catch (ReadDriverException e) {
|
117 |
e.printStackTrace(); |
118 |
}catch (GridException e) {
|
119 |
RasterToolsUtil.messageBoxError("error_cargar_capa", this, e); |
120 |
} |
121 |
|
122 |
} |
123 |
else{
|
124 |
|
125 |
} |
126 |
} |
127 |
} |
128 |
} |
129 |
|
130 |
public boolean isEnabled() { |
131 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
132 |
if (f == null) { |
133 |
return false; |
134 |
} |
135 |
if (f.getClass() == View.class) { |
136 |
View vista = (View) f; |
137 |
IProjectView model = vista.getModel(); |
138 |
MapContext mapa = model.getMapContext(); |
139 |
FLayers layers = mapa.getLayers(); |
140 |
for (int i = 0; i < layers.getLayersCount(); i++) |
141 |
if (layers.getLayer(i) instanceof FLyrRasterSE) |
142 |
return true; |
143 |
} |
144 |
return false; |
145 |
} |
146 |
|
147 |
public boolean isVisible() { |
148 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
149 |
if (f == null) { |
150 |
return false; |
151 |
} |
152 |
if (f instanceof View) { |
153 |
View vista = (View) f; |
154 |
IProjectView model = vista.getModel(); |
155 |
MapContext mapa = model.getMapContext(); |
156 |
return mapa.getLayers().getLayersCount() > 0; |
157 |
} else {
|
158 |
return false; |
159 |
} |
160 |
} |
161 |
} |