root / branches / v2_0_0_prep / extensions / extRemoteSensing / src / org / gvsig / remotesensing / scatterplot / listener / RoiFromChartProcess.java @ 31496
History | View | Annotate | Download (8.74 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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 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 |
* 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.scatterplot.listener; |
42 |
|
43 |
import java.util.ArrayList; |
44 |
import java.util.Iterator; |
45 |
|
46 |
import org.gvsig.andami.PluginServices; |
47 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
48 |
import org.gvsig.fmap.geom.Geometry; |
49 |
import org.gvsig.fmap.geom.GeometryLocator; |
50 |
import org.gvsig.fmap.geom.GeometryManager; |
51 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
52 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
53 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
54 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
55 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
56 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
57 |
import org.gvsig.fmap.mapcontrol.MapControl; |
58 |
import org.gvsig.fmap.raster.grid.roi.VectorialROI; |
59 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
60 |
import org.gvsig.raster.RasterProcess; |
61 |
import org.gvsig.raster.buffer.BufferFactory; |
62 |
import org.gvsig.raster.buffer.RasterBuffer; |
63 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
64 |
import org.gvsig.raster.dataset.IBuffer; |
65 |
import org.gvsig.raster.dataset.IRasterDataSource; |
66 |
import org.gvsig.raster.grid.Grid; |
67 |
import org.gvsig.raster.grid.GridException; |
68 |
import org.gvsig.raster.grid.roi.ROI; |
69 |
import org.gvsig.remotesensing.scatterplot.chart.ROIChart; |
70 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
71 |
import org.jfree.data.Range; |
72 |
import org.slf4j.Logger; |
73 |
import org.slf4j.LoggerFactory; |
74 |
|
75 |
|
76 |
/**
|
77 |
* Clase que implementa el proceso de construcci?n de una roi a partir de una
|
78 |
* ROIChart definida en el gr?fico de dispersion.
|
79 |
*
|
80 |
* @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
|
81 |
* @version 11/12/2007
|
82 |
*/
|
83 |
public class RoiFromChartProcess extends RasterProcess { |
84 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
85 |
private static final Logger logger = LoggerFactory.getLogger(RoiFromChartProcess.class); |
86 |
|
87 |
private Grid grid=null; |
88 |
private ROIChart roiToExport= null; |
89 |
private FLyrRasterSE rasterSE =null; |
90 |
private int percent =0; |
91 |
|
92 |
private MapContextManager mapContextManager = MapContextLocator
|
93 |
.getMapContextManager(); |
94 |
|
95 |
/**
|
96 |
* Constructor
|
97 |
* @param roiToExport roiChart que va a ser a exportar
|
98 |
* @grid grid asociado (unicamente dispone de las dos bandas seleccionadas en el grafico)
|
99 |
*
|
100 |
**/
|
101 |
|
102 |
/*public RoiFromChartProcess(ROIChart roiToExport, FLyrRasterSE raster){
|
103 |
this.roiToExport= roiToExport;
|
104 |
this.rasterSE= raster;
|
105 |
}*/
|
106 |
|
107 |
|
108 |
|
109 |
public ROI createRasterRoi(){
|
110 |
// creaccion de la roiRaster
|
111 |
return null; |
112 |
} |
113 |
|
114 |
|
115 |
|
116 |
/***
|
117 |
* Metodo que determina si el valor pasado esta dentro del intervalo
|
118 |
* definido en rango.
|
119 |
* @param valor valor a comprobar
|
120 |
* @rango rango intervalo de tipo double
|
121 |
*
|
122 |
*/
|
123 |
public boolean isInside(double valor, Range rango){ |
124 |
|
125 |
double minValue= rango.getLowerBound();
|
126 |
double maxValue= rango.getUpperBound();
|
127 |
if( ( minValue<= valor) && (maxValue>=valor)) {
|
128 |
return true; |
129 |
} else {
|
130 |
return false; |
131 |
} |
132 |
|
133 |
} |
134 |
|
135 |
|
136 |
/**Esto tiene que cambiar!!!!!!!! Actualmente solo pinta los pixeles que pertenecen a la roi
|
137 |
* Dibujado de la roi
|
138 |
* */
|
139 |
void drawRoi(VectorialROI roi){
|
140 |
|
141 |
VectorialROI vectorialROI = roi; |
142 |
ISymbol symbol = null;
|
143 |
// FGraphic fGraphic = null;
|
144 |
DefaultViewPanel view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
145 |
MapControl mapControl = view.getMapControl(); |
146 |
GraphicLayer graphicLayer =mapControl.getMapContext().getGraphicsLayer(); |
147 |
|
148 |
for (Iterator iterator = vectorialROI.getGeometries() |
149 |
.iterator(); iterator.hasNext();) { |
150 |
Geometry geometry = (Geometry) iterator.next(); |
151 |
switch (geometry.getType()) {
|
152 |
case Geometry.TYPES.POINT:
|
153 |
symbol = |
154 |
mapContextManager.getSymbolManager().createSymbol( |
155 |
IMarkerSymbol.SYMBOL_NAME, roi.getColor()); |
156 |
break;
|
157 |
} |
158 |
// fGraphic = new FGraphic(geometry, graphicLayer.addSymbol(symbol));
|
159 |
// graphicLayer.addGraphic(fGraphic);
|
160 |
graphicLayer.addGraphic(geometry, graphicLayer.addSymbol(symbol)); |
161 |
mapControl.drawGraphics(); |
162 |
} |
163 |
|
164 |
} |
165 |
|
166 |
public void init() { |
167 |
this.roiToExport= (ROIChart)getParam("roi"); |
168 |
this.rasterSE= (FLyrRasterSE)getParam("raster"); |
169 |
} |
170 |
|
171 |
/**
|
172 |
* Proceso que construye la ROI Vectorial a?adiendo un punto por
|
173 |
* cada pixel que se encuentra en el conjunto de rangos especificados.
|
174 |
* Para terminar se pinta la roi en la vista
|
175 |
* */
|
176 |
public void process() throws InterruptedException { |
177 |
|
178 |
IRasterDataSource dsetCopy = null;
|
179 |
dsetCopy = rasterSE.getDataSource().newDataset(); |
180 |
BufferFactory bufferFactory = new BufferFactory(dsetCopy);
|
181 |
if (!RasterBuffer.loadInMemory(dsetCopy)) {
|
182 |
bufferFactory.setReadOnly(true);
|
183 |
} |
184 |
|
185 |
try {
|
186 |
grid=new Grid(bufferFactory);
|
187 |
} catch (RasterBufferInvalidException e1) {
|
188 |
e1.printStackTrace(); |
189 |
} |
190 |
|
191 |
VectorialROI newRoi = new VectorialROI(grid);
|
192 |
newRoi.setColor(roiToExport.getColor()); |
193 |
newRoi.setName(roiToExport.getName()); |
194 |
|
195 |
double valorBandX= 0; |
196 |
double valorBandY=0; |
197 |
Range rango[] = null; |
198 |
int nX = grid.getRasterBuf().getWidth();
|
199 |
int nY = grid.getRasterBuf().getHeight();
|
200 |
IBuffer buffer = grid.getRasterBuf(); |
201 |
ArrayList rangos= roiToExport.getRanges();
|
202 |
double mapX=0; |
203 |
double mapY=0; |
204 |
|
205 |
// Caso de buffer tipo BYTE
|
206 |
if(buffer.getDataType() == RasterBuffer.TYPE_BYTE)
|
207 |
{ |
208 |
for (int j=0; j<nY; j++){ |
209 |
|
210 |
for(int i=0; i<nX; i++) |
211 |
{ |
212 |
try {
|
213 |
grid.setBandToOperate(roiToExport.getBandaX()); |
214 |
valorBandX= grid.getCellValueAsByte(i,j)&0xff;
|
215 |
grid.setBandToOperate(roiToExport.getBandaY()); |
216 |
valorBandY= grid.getCellValueAsByte(i,j)&0xff;
|
217 |
} catch (GridException e) {
|
218 |
e.printStackTrace(); |
219 |
} |
220 |
|
221 |
Iterator iterator =rangos.iterator();
|
222 |
while(iterator.hasNext()){
|
223 |
rango=(Range[]) iterator.next();
|
224 |
if(isInside(valorBandX,rango[0]) && isInside(valorBandY,rango[1])){ |
225 |
mapX = grid.getGridExtent().getMin().getX()+i*grid.getCellSize(); |
226 |
mapY = grid.getGridExtent().getMax().getY()-j*grid.getCellSize(); |
227 |
Geometry geometry; |
228 |
try {
|
229 |
geometry = geomManager.createPoint(mapX, |
230 |
mapY, SUBTYPES.GEOM2D); |
231 |
newRoi.addGeometry(geometry); // Geometria
|
232 |
} catch (CreateGeometryException e) {
|
233 |
logger.error("Error creating a point", e);
|
234 |
} |
235 |
|
236 |
} |
237 |
} |
238 |
} |
239 |
percent=j*100/nY;
|
240 |
} |
241 |
} |
242 |
|
243 |
// Caso de buffer tipo SHORT
|
244 |
if(buffer.getDataType() == RasterBuffer.TYPE_SHORT)
|
245 |
{ |
246 |
for (int j=0; j<nY; j++){ |
247 |
for(int i=0; i<nX; i++) |
248 |
{ |
249 |
try {
|
250 |
grid.setBandToOperate(roiToExport.getBandaX()); |
251 |
valorBandX= grid.getCellValueAsShort(i,j); |
252 |
grid.setBandToOperate(roiToExport.getBandaY()); |
253 |
valorBandY= grid.getCellValueAsShort(i,j); |
254 |
|
255 |
} catch (GridException e) {
|
256 |
// TODO Auto-generated catch block
|
257 |
e.printStackTrace(); |
258 |
} |
259 |
Iterator iterator =rangos.iterator();
|
260 |
while(iterator.hasNext()){
|
261 |
rango=(Range[]) iterator.next();
|
262 |
if(isInside(valorBandX,rango[0]) && isInside(valorBandY,rango[1])){ |
263 |
mapX = grid.getGridExtent().getMin().getX()+i*grid.getCellSize(); |
264 |
mapY = grid.getGridExtent().getMax().getY()-j*grid.getCellSize(); |
265 |
Geometry geometry; |
266 |
try {
|
267 |
geometry = geomManager.createPoint(mapX, |
268 |
mapY, SUBTYPES.GEOM2D); |
269 |
newRoi.addGeometry(geometry); |
270 |
} catch (CreateGeometryException e) {
|
271 |
logger.error("Error creating a point", e);
|
272 |
} |
273 |
} |
274 |
} |
275 |
} |
276 |
} |
277 |
} |
278 |
|
279 |
drawRoi(newRoi); |
280 |
externalActions.end(newRoi); |
281 |
} |
282 |
|
283 |
public String getTitle() { |
284 |
// TODO Auto-generated method stub
|
285 |
return PluginServices.getText(this,"generando_roi"); |
286 |
} |
287 |
|
288 |
public int getPercent() { |
289 |
// TODO Auto-generated method stub
|
290 |
return percent;
|
291 |
} |
292 |
|
293 |
} |