Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / RemoteSensingUtils.java @ 25523

History | View | Annotate | Download (4.27 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica 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 Iba?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;
42

    
43
import java.util.ArrayList;
44

    
45
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
46
import org.gvsig.raster.buffer.RasterBuffer;
47
import org.gvsig.raster.dataset.IBuffer;
48
import org.gvsig.raster.datastruct.ColorTable;
49
import org.gvsig.raster.grid.GridPalette;
50
import org.gvsig.raster.grid.filter.FilterTypeException;
51
import org.gvsig.raster.grid.filter.RasterFilterList;
52
import org.gvsig.raster.grid.filter.RasterFilterListManager;
53
import org.gvsig.raster.grid.filter.bands.ColorTableFilter;
54
import org.gvsig.raster.grid.filter.bands.ColorTableListManager;
55
import org.gvsig.raster.grid.filter.enhancement.LinearEnhancementFilter;
56
import org.gvsig.raster.grid.filter.statistics.TailTrimFilter;
57
import org.gvsig.raster.hierarchy.IRasterRendering;
58

    
59
import com.iver.cit.gvsig.fmap.layers.FLayer;
60

    
61
/**
62
 * Herramientas de usa general para la extensi?n extRemoteSensing.
63
 * 
64
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
65
 *
66
 */
67
public class RemoteSensingUtils {
68

    
69
        /**
70
        * Asigna a la capa <code>lyr</code> una leyenda construida a partir
71
        * de un <code>ArrayList</code> de <code>ColorItem</code>.
72
        * 
73
        * @param lyr capa a la que se asigna la leyenda
74
        * @param colorItems ColorItems con los que se contruye la leyenda
75
        * 
76
        * @throws FilterTypeException 
77
        */
78
        public  static void setLeyend(FLayer lyr, ArrayList colorItems) throws FilterTypeException {
79
                if(lyr instanceof IRasterRendering) {
80
                        IRasterRendering rendering = (IRasterRendering) lyr;
81
                        
82
                        ColorTable colorTable = new ColorTable();
83
                        colorTable.createPaletteFromColorItems(colorItems, false);
84
        
85
                        RasterFilterList filterList = rendering.getRenderFilterList();
86
                        RasterFilterListManager manager = new RasterFilterListManager(filterList);
87
                        ColorTableListManager cManager = (ColorTableListManager) manager.getManagerByClass(ColorTableListManager.class);
88
                        try {
89
                                filterList.remove(ColorTableFilter.class);
90
        
91
                                ((FLyrRasterSE)lyr).setLastLegend(null);
92
        
93
                                filterList.remove(LinearEnhancementFilter.class);
94
                                filterList.remove(TailTrimFilter.class);
95
                                GridPalette gridPalette = new GridPalette(colorTable);
96
                                cManager.addColorTableFilter(gridPalette);
97
                                ((FLyrRasterSE)lyr).setLastLegend(gridPalette);
98
                        } catch (FilterTypeException e) {
99
                                throw e;
100
                        }
101
                        
102
                        rendering.setRenderFilterList(filterList);
103
                }
104
        }
105
        
106
        public static double getCellValueInLayerCoords(IBuffer buffer, int x, int y, int band) {
107
                int iType = buffer.getDataType();
108

    
109
                if (iType == RasterBuffer.TYPE_DOUBLE) {
110
                        return  buffer.getElemDouble(y, x, band);
111
                } else if (iType == RasterBuffer.TYPE_INT) {
112
                        return (double)  buffer.getElemInt(y, x, band);
113
                } else if (iType == RasterBuffer.TYPE_FLOAT) {
114
                        return (double)  buffer.getElemFloat(y, x, band);
115
                } else if (iType == RasterBuffer.TYPE_BYTE) {
116
                        return (double) (buffer.getElemByte(y, x, band) & 0xff);
117
                } else if ((iType == RasterBuffer.TYPE_SHORT) | (iType == RasterBuffer.TYPE_USHORT)) {
118
                        return (double)  buffer.getElemShort(y, x, band);
119
                }
120

    
121
                return buffer.getNoDataValue();
122
        }
123
}