Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / vectorizacion / clip / ClipProcess.java @ 29995

History | View | Annotate | Download (4.95 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. 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
package org.gvsig.rastertools.vectorizacion.clip;
20

    
21
import java.awt.geom.AffineTransform;
22
import java.io.File;
23

    
24
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
25
import org.gvsig.raster.IProcessActions;
26
import org.gvsig.raster.RasterLibrary;
27
import org.gvsig.raster.RasterProcess;
28
import org.gvsig.raster.buffer.BufferInterpolation;
29
import org.gvsig.raster.buffer.WriterBufferServer;
30
import org.gvsig.raster.dataset.properties.DatasetColorInterpretation;
31
import org.gvsig.raster.grid.filter.FilterTypeException;
32
import org.gvsig.raster.util.RasterToolsUtil;
33
import org.gvsig.raster.util.process.ClippingProcess;
34

    
35
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
36

    
37
/**
38
 * Procesos necesarios para la funcionalidad de vectorizaci?n.
39
 * 
40
 * 11/07/2008
41
 * @author Nacho Brodin nachobrodin@gmail.com
42
 */
43
public class ClipProcess implements IProcessActions {
44
        private FLyrRasterSE                  sourceLayer       = null;
45
        private IProcessActions               endActions        = null;
46
        
47
        /**
48
         * Asigna la clase IProcessActions para las acciones de
49
         * finalizaci?n.
50
         * @param pa
51
         */
52
        public ClipProcess(IProcessActions endActions) {
53
                this.endActions = endActions;
54
        }
55
        
56
        /**
57
         * Aplica el proceso de recorte sobre el raster inicial
58
         * @throws FilterTypeException
59
         */
60
        public void clip(ClipData data) throws FilterTypeException {
61
                RasterProcess clippingProcess = new ClippingProcess();
62
                clippingProcess.setActions(this);
63
                clippingProcess.addParam("realcoordinates", data.getWCCoordinates());
64
                String tempRaster = RasterLibrary.tempCacheDirectoryPath + File.separator + RasterLibrary.usesOnlyLayerName();
65
                clippingProcess.addParam("filename", tempRaster);
66
                clippingProcess.addParam("datawriter", new WriterBufferServer());
67
                clippingProcess.addParam("layer", sourceLayer);
68
                if(sourceLayer.getBandCount() > 1)
69
                        clippingProcess.addParam("drawablebands", sourceLayer.getRenderBands());
70
                else
71
                        clippingProcess.addParam("drawablebands", new int[]{0});
72
                clippingProcess.addParam("onelayerperband", new Boolean(false));
73
                clippingProcess.addParam("interpolationmethod", new Integer(BufferInterpolation.INTERPOLATION_Undefined));
74
                double newCellSize = sourceLayer.getCellSize() / data.getScaleSelectedValue();
75
                AffineTransform at = new AffineTransform(newCellSize, 0, 0, -newCellSize, data.getWCCoordinates()[0], data.getWCCoordinates()[1]);
76
                clippingProcess.addParam("affinetransform", at);
77
                if(sourceLayer.getBandCount() < 3)
78
                        clippingProcess.addParam("colorInterpretation", DatasetColorInterpretation.createGrayInterpretation());
79
                else
80
                        clippingProcess.addParam("colorInterpretation", DatasetColorInterpretation.createRGBInterpretation());
81
                double w = Math.abs((data.getWCCoordinates()[0] - data.getWCCoordinates()[2]) / sourceLayer.getCellSize());
82
                double h = Math.abs((data.getWCCoordinates()[1] - data.getWCCoordinates()[3]) / sourceLayer.getCellSize());
83
                clippingProcess.addParam("resolution", new int[]{(int) (w * data.getScaleSelectedValue()), (int) (h * data.getScaleSelectedValue())});
84
                clippingProcess.addParam("showenddialog", true);
85
                clippingProcess.start();
86
        }
87
                        
88
        /*
89
         * (non-Javadoc)
90
         * @see org.gvsig.raster.IProcessActions#end(java.lang.Object)
91
         */
92
        public void end(Object param) {
93
                FLyrRasterSE clip = null;
94
                try {
95
                        if(param instanceof Object[] && ((Object[])param).length == 2 && ((Object[])param)[0] instanceof String) {
96
                                clip = FLyrRasterSE.createLayer(RasterLibrary.getOnlyLayerName(), (String)((Object[])param)[0], sourceLayer.getProjection());
97
                        }
98
                } catch (LoadLayerException e) {
99
                        RasterToolsUtil.messageBoxError("error_generating_layer", null, e);
100
                }
101
                if(endActions != null)
102
                        endActions.end(new Object[]{this, clip});
103
        }
104

    
105
        /**
106
         * Asigna la capa fuente
107
         * @param sourceLayer
108
         */
109
        public void setSourceLayer(FLyrRasterSE sourceLayer) {
110
                this.sourceLayer = sourceLayer;
111
        }
112
        
113
        /**
114
         * Asigna el interfaz para que el proceso ejectute las acciones de finalizaci?n
115
         * al acabar.
116
         * @param endActions
117
         */
118
        public void setProcessActions(IProcessActions endActions) {
119
                this.endActions = endActions;
120
        }
121

    
122
        /*
123
         * (non-Javadoc)
124
         * @see org.gvsig.raster.IProcessActions#interrupted(java.lang.Object)
125
         */
126
        public void interrupted() {
127
        }
128
}