Revision 9432

View differences:

org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.76/org.gvsig.raster.tools.main/src/main/java/org/gvsig/raster/tools/algorithm/TestMaskthreholdOutPutLayerReplicate.java
1
package org.gvsig.raster.tools.algorithm;
2
/* gvSIG. Geographic Information System of the Valencian Government
3
 *
4
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
5
 * of the Valencian Government (CIT)
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 * MA  02110-1301, USA.
21
 *
22
 */
23

  
24

  
25
import java.io.File;
26

  
27
import org.gvsig.fmap.dal.DALLocator;
28
import org.gvsig.fmap.dal.DataManager;
29
import org.gvsig.fmap.dal.DataStore;
30
import org.gvsig.fmap.dal.coverage.RasterLocator;
31
import org.gvsig.fmap.dal.coverage.RasterManager;
32
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
33
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
34
import org.gvsig.fmap.dal.coverage.util.ProviderServices;
35
import org.gvsig.fmap.dal.exception.InitializeException;
36
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
37
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
38
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
39
import org.gvsig.raster.cache.tile.impl.TileCacheDefaultImplLibrary;
40
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
41
import org.gvsig.raster.fmap.layers.FLyrRaster;
42
import org.gvsig.raster.gdal.io.DefaultGdalIOLibrary;
43
import org.gvsig.raster.impl.RasterDefaultImplLibrary;
44
import org.gvsig.raster.tools.algorithm.base.RasterBaseAlgorithmLibrary;
45
import org.gvsig.raster.tools.algorithm.base.process.ProcessException;
46
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess;
47
import org.gvsig.raster.tools.algorithm.maskthreshold.MaskthresholdAlgorithmLibrary;
48
import org.gvsig.raster.tools.algorithm.maskthreshold.MaskthresholdProcess;
49
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
50

  
51
/**
52
 * @author gvSIG Team
53
 * @version $Id$
54
 *
55
 */
56
@SuppressWarnings("unused")
57
public class TestMaskthreholdOutPutLayerReplicate {
58
	private static int pos = 5;
59
	
60
	private static String file1 = "/home/nacho/images/PNOA/PNOA06-08/2006_clip.tif";
61
	private static String file2 = "/home/nacho/images/PNOA/PNOA06-08/2006_NDVI.tif";
62
    public static DataManager datamanager = DALLocator.getDataManager();
63
    public FLyrRaster lyr = null;
64
    private RasterManager rManager = RasterLocator.getManager();
65
    private int[] drawableBands = { 0, 1, 2 };
66

  
67
    public static void main(String[] args) {
68
    	try {
69
    		new DefaultLibrariesInitializer().fullInitialize(true);
70
    	} catch(Exception e) {
71
    		e.printStackTrace();
72
    	}
73
    	new TileCacheDefaultImplLibrary();
74
		new RasterDefaultImplLibrary();
75
		new DefaultGdalIOLibrary();
76
		new MaskthresholdAlgorithmLibrary().doPostInitialize();
77
    	new TestMaskthreholdOutPutLayerReplicate().start();
78
    }
79
    
80
    public void start() {
81
        FLyrRaster lyr1 = null;
82
        FLyrRaster lyr2 = null;
83
        FLyrRaster lyr3 = null;
84
		try {
85
			lyr1 = createLayerRaster("Input1", new File(file1));
86
			lyr2 = createLayerRaster("Input2", new File(file2));
87
			lyr3 = createLayerRaster("Input3", new File(file1));
88
	        
89
			RasterProcess task;
90
			try {
91
				task = RasterBaseAlgorithmLibrary.getManager().createRasterTask("MaskthresholdProcess");
92
			} catch (ProcessException e1) {
93
				e1.printStackTrace();
94
				return;
95
			}
96
			
97
	        task.addParam(MaskthresholdProcess.RASTER_STORE1, lyr1.getDataStore());
98
	        task.addParam(MaskthresholdProcess.RASTER_STORE2, lyr2.getDataStore());
99
	        task.addParam(MaskthresholdProcess.RASTER_STORE3, lyr3.getDataStore());
100
	        task.addParam(MaskthresholdProcess.PATH, "/tmp/MaskthreholdTest.tif");
101
	        task.addParam(MaskthresholdProcess.THRESHOLD, 0);
102
	        task.addParam(MaskthresholdProcess.BAND1, 0);
103
	        task.addParam(MaskthresholdProcess.BAND2, 0);
104
	        task.addParam(MaskthresholdProcess.BAND3, -1); //Las salida ser? de todas las bandas del datastore 3
105
	        task.addParam(MaskthresholdProcess.OPERATION, 0);
106
	        task.addParam(MaskthresholdProcess.SATISFY_METHOD, 4);
107
	        task.execute();
108
		} catch (LoadLayerException e) {
109
			e.printStackTrace();
110
		} catch (ProcessException e) {
111
			e.printStackTrace();
112
		} catch (ProcessInterruptedException e) {
113
			e.printStackTrace();
114
		}
115
    }
116

  
117
    @SuppressWarnings("deprecation")
118
	public FLyrRaster createLayerRaster(String layerName, File file)
119
        throws LoadLayerException {
120
        ProviderServices provServ =
121
            RasterLocator.getManager().getProviderServices();
122
        RasterDataParameters storeParameters =
123
            provServ.createParameters(file.getName());
124
        storeParameters.setURI(file.getPath());
125

  
126
        DataManager dataManager = DALLocator.getDataManager();
127
        DataStore dataStore = null;
128
        try {
129
            dataStore = dataManager.createStore(storeParameters);
130
        } catch (ValidateDataParametersException e) {
131
            throw new LoadLayerException("Error al cargar la capa.");
132
        } catch (InitializeException e) {
133
            throw new LoadLayerException("Error al cargar la capa.");
134
        } catch (ProviderNotRegisteredException e) {
135
            throw new LoadLayerException("Error al cargar la capa.");
136
        }
137

  
138
        DefaultFLyrRaster lyr = new DefaultFLyrRaster();
139
        lyr.setName(layerName);
140
        lyr.setDataStore(dataStore);
141
        return lyr;
142
    }
143

  
144
}
0 145

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.76/org.gvsig.raster.tools.main/src/main/java/org/gvsig/raster/tools/algorithm/TestMaskthreholdOutPutLayerThreshold.java
1
package org.gvsig.raster.tools.algorithm;
2
/* gvSIG. Geographic Information System of the Valencian Government
3
 *
4
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
5
 * of the Valencian Government (CIT)
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 * MA  02110-1301, USA.
21
 *
22
 */
23

  
24

  
25
import java.io.File;
26

  
27
import org.gvsig.fmap.dal.DALLocator;
28
import org.gvsig.fmap.dal.DataManager;
29
import org.gvsig.fmap.dal.DataStore;
30
import org.gvsig.fmap.dal.coverage.RasterLocator;
31
import org.gvsig.fmap.dal.coverage.RasterManager;
32
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
33
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
34
import org.gvsig.fmap.dal.coverage.util.ProviderServices;
35
import org.gvsig.fmap.dal.exception.InitializeException;
36
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
37
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
38
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
39
import org.gvsig.raster.cache.tile.impl.TileCacheDefaultImplLibrary;
40
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
41
import org.gvsig.raster.fmap.layers.FLyrRaster;
42
import org.gvsig.raster.gdal.io.DefaultGdalIOLibrary;
43
import org.gvsig.raster.impl.RasterDefaultImplLibrary;
44
import org.gvsig.raster.tools.algorithm.base.RasterBaseAlgorithmLibrary;
45
import org.gvsig.raster.tools.algorithm.base.process.ProcessException;
46
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess;
47
import org.gvsig.raster.tools.algorithm.maskthreshold.MaskthresholdAlgorithmLibrary;
48
import org.gvsig.raster.tools.algorithm.maskthreshold.MaskthresholdProcess;
49
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
50

  
51
/**
52
 * Extracts vegetation using NDVI
53
 */
54
@SuppressWarnings("unused")
55
public class TestMaskthreholdOutPutLayerThreshold {
56
	private static int pos = 5;
57
	
58
	private static String file1 = "/home/nacho/images/PNOA/PNOA06-08/2006_clip.tif";
59
	private static String file2 = "/home/nacho/images/PNOA/PNOA06-08/2006_NDVI.tif";
60
    public static DataManager datamanager = DALLocator.getDataManager();
61
    public FLyrRaster lyr = null;
62
    private RasterManager rManager = RasterLocator.getManager();
63
    private int[] drawableBands = { 0, 1, 2 };
64

  
65
    public static void main(String[] args) {
66
    	try {
67
    		new DefaultLibrariesInitializer().fullInitialize(true);
68
    	} catch(Exception e) {
69
    		e.printStackTrace();
70
    	}
71
    	new TileCacheDefaultImplLibrary();
72
		new RasterDefaultImplLibrary();
73
		new DefaultGdalIOLibrary();
74
		new MaskthresholdAlgorithmLibrary().doPostInitialize();
75
    	new TestMaskthreholdOutPutLayerThreshold().start();
76
    }
77
    
78
    public void start() {
79
        FLyrRaster lyr1 = null;
80
        FLyrRaster lyr2 = null;
81
        FLyrRaster lyr3 = null;
82
		try {
83
			lyr1 = createLayerRaster("Input1", new File(file1));
84
			lyr2 = createLayerRaster("Input2", new File(file2));
85
			lyr3 = createLayerRaster("Input3", new File(file1));
86
	        
87
			RasterProcess task;
88
			try {
89
				task = RasterBaseAlgorithmLibrary.getManager().createRasterTask("MaskthresholdProcess");
90
			} catch (ProcessException e1) {
91
				e1.printStackTrace();
92
				return;
93
			}
94
			
95
	        task.addParam(MaskthresholdProcess.RASTER_STORE1, lyr2.getDataStore());
96
	        task.addParam(MaskthresholdProcess.RASTER_STORE3, lyr3.getDataStore());
97
	        task.addParam(MaskthresholdProcess.PATH, "/tmp/MaskthreholdTest.tif");
98
	        task.addParam(MaskthresholdProcess.THRESHOLD, 0.0);
99
	        task.addParam(MaskthresholdProcess.BAND1, 0);
100
	        task.addParam(MaskthresholdProcess.BAND3, -1); //Las salida ser? de todas las bandas del datastore 3
101
	        task.addParam(MaskthresholdProcess.OPERATION, 1);
102
	        task.addParam(MaskthresholdProcess.SATISFY_METHOD, 4);
103
	        task.execute();
104
		} catch (LoadLayerException e) {
105
			e.printStackTrace();
106
		} catch (ProcessException e) {
107
			e.printStackTrace();
108
		} catch (ProcessInterruptedException e) {
109
			e.printStackTrace();
110
		}
111
    }
112

  
113
    @SuppressWarnings("deprecation")
114
	public FLyrRaster createLayerRaster(String layerName, File file)
115
        throws LoadLayerException {
116
        ProviderServices provServ =
117
            RasterLocator.getManager().getProviderServices();
118
        RasterDataParameters storeParameters =
119
            provServ.createParameters(file.getName());
120
        storeParameters.setURI(file.getPath());
121

  
122
        DataManager dataManager = DALLocator.getDataManager();
123
        DataStore dataStore = null;
124
        try {
125
            dataStore = dataManager.createStore(storeParameters);
126
        } catch (ValidateDataParametersException e) {
127
            throw new LoadLayerException("Error al cargar la capa.");
128
        } catch (InitializeException e) {
129
            throw new LoadLayerException("Error al cargar la capa.");
130
        } catch (ProviderNotRegisteredException e) {
131
            throw new LoadLayerException("Error al cargar la capa.");
132
        }
133

  
134
        DefaultFLyrRaster lyr = new DefaultFLyrRaster();
135
        lyr.setName(layerName);
136
        lyr.setDataStore(dataStore);
137
        return lyr;
138
    }
139

  
140
}
0 141

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.76/org.gvsig.raster.tools.main/src/main/java/org/gvsig/raster/tools/algorithm/TestMaskthreholdFixedValue.java
1
package org.gvsig.raster.tools.algorithm;
2
/* gvSIG. Geographic Information System of the Valencian Government
3
 *
4
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
5
 * of the Valencian Government (CIT)
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 * MA  02110-1301, USA.
21
 *
22
 */
23

  
24

  
25
import java.io.File;
26

  
27
import org.gvsig.fmap.dal.DALLocator;
28
import org.gvsig.fmap.dal.DataManager;
29
import org.gvsig.fmap.dal.DataStore;
30
import org.gvsig.fmap.dal.coverage.RasterLocator;
31
import org.gvsig.fmap.dal.coverage.RasterManager;
32
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
33
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
34
import org.gvsig.fmap.dal.coverage.util.ProviderServices;
35
import org.gvsig.fmap.dal.exception.InitializeException;
36
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
37
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
38
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
39
import org.gvsig.raster.cache.tile.impl.TileCacheDefaultImplLibrary;
40
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
41
import org.gvsig.raster.fmap.layers.FLyrRaster;
42
import org.gvsig.raster.gdal.io.DefaultGdalIOLibrary;
43
import org.gvsig.raster.impl.RasterDefaultImplLibrary;
44
import org.gvsig.raster.tools.algorithm.base.RasterBaseAlgorithmLibrary;
45
import org.gvsig.raster.tools.algorithm.base.process.ProcessException;
46
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess;
47
import org.gvsig.raster.tools.algorithm.maskthreshold.MaskthresholdAlgorithmLibrary;
48
import org.gvsig.raster.tools.algorithm.maskthreshold.MaskthresholdProcess;
49
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
50

  
51
/**
52
 * @author gvSIG Team
53
 * @version $Id$
54
 *
55
 */
56
@SuppressWarnings("unused")
57
public class TestMaskthreholdFixedValue {
58
	private static int pos = 5;
59
	
60
	private static String file1 = "/home/nacho/images/PNOA/PNOA06-08/2006_clip.tif";
61
	private static String file2 = "/home/nacho/images/PNOA/PNOA06-08/2006_NDVI.tif";
62
    public static DataManager datamanager = DALLocator.getDataManager();
63
    public FLyrRaster lyr = null;
64
    private RasterManager rManager = RasterLocator.getManager();
65
    private int[] drawableBands = { 0, 1, 2 };
66

  
67
    public static void main(String[] args) {
68
    	try {
69
    		new DefaultLibrariesInitializer().fullInitialize(true);
70
    	} catch(Exception e) {
71
    		e.printStackTrace();
72
    	}
73
    	new TileCacheDefaultImplLibrary();
74
		new RasterDefaultImplLibrary();
75
		new DefaultGdalIOLibrary();
76
		new MaskthresholdAlgorithmLibrary().doPostInitialize();
77
    	new TestMaskthreholdFixedValue().start();
78
    }
79
    
80
    public void start() {
81
        FLyrRaster lyr1 = null;
82
        FLyrRaster lyr2 = null;
83
		try {
84
			lyr1 = createLayerRaster("Input1", new File(file1));
85
			lyr2 = createLayerRaster("Input2", new File(file2));
86
	        
87
			RasterProcess task;
88
			try {
89
				task = RasterBaseAlgorithmLibrary.getManager().createRasterTask("MaskthresholdProcess");
90
			} catch (ProcessException e1) {
91
				e1.printStackTrace();
92
				return;
93
			}
94
			
95
	        task.addParam(MaskthresholdProcess.RASTER_STORE1, lyr1.getDataStore());
96
	        task.addParam(MaskthresholdProcess.RASTER_STORE2, lyr2.getDataStore());
97
	        task.addParam(MaskthresholdProcess.PATH, "/tmp/MaskthreholdTest.tif");
98
	        task.addParam(MaskthresholdProcess.BAND1, 0);
99
	        task.addParam(MaskthresholdProcess.BAND2, 0);
100
	        task.addParam(MaskthresholdProcess.FIXED_VALUE, 80.0);
101
	        task.addParam(MaskthresholdProcess.OPERATION, 0);
102
	        task.addParam(MaskthresholdProcess.SATISFY_METHOD, 1);
103
	        task.execute();
104
		} catch (LoadLayerException e) {
105
			e.printStackTrace();
106
		} catch (ProcessException e) {
107
			e.printStackTrace();
108
		} catch (ProcessInterruptedException e) {
109
			e.printStackTrace();
110
		}
111
    }
112

  
113
    @SuppressWarnings("deprecation")
114
	public FLyrRaster createLayerRaster(String layerName, File file)
115
        throws LoadLayerException {
116
        ProviderServices provServ =
117
            RasterLocator.getManager().getProviderServices();
118
        RasterDataParameters storeParameters =
119
            provServ.createParameters(file.getName());
120
        storeParameters.setURI(file.getPath());
121

  
122
        DataManager dataManager = DALLocator.getDataManager();
123
        DataStore dataStore = null;
124
        try {
125
            dataStore = dataManager.createStore(storeParameters);
126
        } catch (ValidateDataParametersException e) {
127
            throw new LoadLayerException("Error al cargar la capa.");
128
        } catch (InitializeException e) {
129
            throw new LoadLayerException("Error al cargar la capa.");
130
        } catch (ProviderNotRegisteredException e) {
131
            throw new LoadLayerException("Error al cargar la capa.");
132
        }
133

  
134
        DefaultFLyrRaster lyr = new DefaultFLyrRaster();
135
        lyr.setName(layerName);
136
        lyr.setDataStore(dataStore);
137
        return lyr;
138
    }
139

  
140
}
0 141

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.76/org.gvsig.raster.tools.main/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.raster.tools.main</artifactId>
6
	<packaging>jar</packaging>
7
	<name>Raster tools Main</name>
8
	<version>2.2.0-SNAPSHOT</version>
9
	<description />
10
	<parent>
11
      <groupId>org.gvsig</groupId>
12
      <artifactId>org.gvsig.desktop.plugin</artifactId>
13
      <version>2.0.12-SNAPSHOT</version>
14
    </parent>
15
     <scm>
16
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.main</connection>
17
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.main</developerConnection>
18
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.main</url>
19
    </scm>
20
    <dependencyManagement>
21
		<dependencies>
22
	        <dependency>
23
				<groupId>org.gvsig</groupId>
24
				<artifactId>org.gvsig.raster.tools</artifactId>
25
				<version>2.1.0-SNAPSHOT</version>
26
				<type>pom</type>
27
				<scope>import</scope>
28
			</dependency>
29
    	</dependencies>
30
    </dependencyManagement>
31
	<dependencies>
32
		<dependency>
33
			<groupId>org.gvsig</groupId>
34
			<artifactId>org.gvsig.raster.swing.api</artifactId>
35
            <scope>compile</scope>
36
		</dependency>
37
		<dependency>
38
			<groupId>org.gvsig</groupId>
39
			<artifactId>org.gvsig.raster.swing.impl</artifactId>
40
            <scope>runtime</scope>
41
		</dependency>
42
		<dependency>
43
			<groupId>org.gvsig</groupId>
44
			<artifactId>org.gvsig.app.mainplugin</artifactId>
45
            <scope>compile</scope>
46
		</dependency>
47
		<dependency>
48
            <groupId>org.gvsig</groupId>
49
            <artifactId>org.gvsig.app.document.table.app.mainplugin</artifactId>
50
            <scope>compile</scope>
51
        </dependency>		
52
		<dependency>
53
			<groupId>org.gvsig</groupId>
54
			<artifactId>org.gvsig.raster.lib.api</artifactId>
55
            <scope>compile</scope>
56
		</dependency>
57
		<dependency>
58
			<groupId>org.gvsig</groupId>
59
			<artifactId>org.gvsig.raster.fmap</artifactId>
60
            <scope>compile</scope>
61
		</dependency>
62
		<dependency>
63
			<groupId>org.gvsig</groupId>
64
			<artifactId>org.gvsig.raster.lib.impl</artifactId>
65
			<scope>compile</scope>
66
		</dependency>
67
        <dependency>
68
            <groupId>org.gvsig</groupId>
69
            <artifactId>org.gvsig.fmap.geometry</artifactId>
70
            <scope>compile</scope>
71
        </dependency>
72
        <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.fmap.dal</artifactId>
75
            <scope>compile</scope>
76
        </dependency>
77
        <dependency>
78
            <groupId>org.gvsig</groupId>
79
            <artifactId>org.gvsig.fmap.dal.file</artifactId>
80
            <scope>compile</scope>
81
        </dependency>
82
        <dependency>
83
            <groupId>org.gvsig</groupId>
84
            <artifactId>org.gvsig.fmap.dal</artifactId>
85
            <classifier>spi</classifier>
86
            <scope>compile</scope>
87
        </dependency>
88
        <dependency>
89
            <groupId>org.gvsig</groupId>
90
            <artifactId>org.gvsig.fmap.mapcontext</artifactId>
91
            <scope>compile</scope>
92
        </dependency>
93
        <dependency>
94
            <groupId>org.gvsig</groupId>
95
            <artifactId>org.gvsig.fmap.control</artifactId>
96
            <scope>compile</scope>
97
        </dependency>
98
        <dependency>
99
            <groupId>org.gvsig</groupId>
100
            <artifactId>org.gvsig.utils</artifactId>
101
            <scope>compile</scope>
102
        </dependency>
103
        <dependency>
104
            <groupId>org.gvsig</groupId>
105
            <artifactId>org.gvsig.ui</artifactId>
106
            <scope>compile</scope>
107
        </dependency>
108
        <dependency>
109
            <groupId>org.gvsig</groupId>
110
            <artifactId>org.gvsig.symbology.lib.api</artifactId>
111
            <scope>compile</scope>
112
        </dependency>
113
        <dependency>
114
            <groupId>org.gvsig</groupId>
115
            <artifactId>org.gvsig.symbology.lib.impl</artifactId>
116
            <scope>compile</scope>
117
        </dependency>
118
        <dependency>
119
            <groupId>org.gvsig</groupId>
120
            <artifactId>org.gvsig.projection</artifactId>
121
            <scope>compile</scope>
122
        </dependency>
123
        <dependency>
124
            <groupId>org.gvsig</groupId>
125
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
126
            <scope>compile</scope>
127
        </dependency>
128
        	<dependency>
129
                <groupId>org.gvsig</groupId>
130
                <artifactId>org.gvsig.raster.tools.algorithm.maskthreshold</artifactId>
131
            </dependency>
132
            <dependency>
133
                <groupId>org.gvsig</groupId>
134
                <artifactId>org.gvsig.raster.gdal.io</artifactId>
135
            </dependency>
136
            <dependency>
137
                <groupId>org.gvsig</groupId>
138
                <artifactId>org.gvsig.raster.cache.lib.api</artifactId>
139
            </dependency>
140
             <dependency>
141
                <groupId>org.gvsig</groupId>
142
                <artifactId>org.gvsig.raster.cache.lib.impl</artifactId>
143
            </dependency>
144
            <dependency>
145
				<groupId>org.gvsig</groupId>
146
				<artifactId>org.gvsig.tools.lib</artifactId>
147
            	<scope>compile</scope>
148
			</dependency>
149
	</dependencies>
150
</project>
0 151

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.76/org.gvsig.raster.tools.main/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Mon Jun 25 09:20:23 CEST 2012
3
buildNumber=5
0 4

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.76/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.raster.tools.algorithm.saveraster</artifactId>
5
	<packaging>jar</packaging>
6
	<name>org.gvsig.raster.tools.algorithm.saveraster</name>
7
	<parent>
8
		<groupId>org.gvsig</groupId>
9
		<artifactId>org.gvsig.raster.tools.algorithm</artifactId>
10
		<version>2.2.76</version>
11
	</parent>
12
    <dependencies>
13
		<dependency>
14
			<groupId>org.gvsig</groupId>
15
			<artifactId>org.gvsig.raster.algorithm</artifactId>
16
            <scope>compile</scope>
17
		</dependency>
18
		<!--Dependencia debido a que este algoritmo rasteriza capas de gvSIG.-->
19
		<dependency>
20
			<groupId>org.gvsig</groupId>
21
			<artifactId>org.gvsig.raster.fmap</artifactId>
22
            <scope>compile</scope>
23
		</dependency>
24
	</dependencies>
25
</project>
0 26

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.76/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.tools.algorithm.saveraster.SaveRasterAlgorithmLibrary
0 2

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.76/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/src/main/java/org/gvsig/raster/tools/algorithm/saveraster/ExternalCancellable.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.algorithm.saveraster;
23

  
24
import org.gvsig.raster.algorithm.gui.IncrementableTask;
25

  
26

  
27
public class ExternalCancellable implements org.gvsig.fmap.dal.coverage.store.ExternalCancellable {
28
	private IncrementableTask task = null;
29
	
30
	public ExternalCancellable(IncrementableTask task) {
31
		this.task = task;
32
	}
33
	
34
	/*
35
	 * (non-Javadoc)
36
	 * @see org.gvsig.raster.dataset.io.IExternalCancellable#processFinalize()
37
	 */
38
	public void processFinalize() {
39
		if(task != null)
40
			task.processFinalize();
41
	}
42
}
0 43

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.76/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/src/main/java/org/gvsig/raster/tools/algorithm/saveraster/SaveRasterAlgorithmLibrary.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.raster.tools.algorithm.saveraster;
25

  
26
import org.gvsig.i18n.Messages;
27
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary;
28
import org.gvsig.tools.library.AbstractLibrary;
29
import org.gvsig.tools.library.LibraryException;
30

  
31
/**
32
 * Initialization of SaveRasterAlgorithmLibrary library.
33
 * 
34
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
35
 */
36
public class SaveRasterAlgorithmLibrary extends AbstractLibrary {
37
	public static final String         PROCESS_LABEL   = "SaveRasterProcess";
38
	
39
    @Override
40
    protected void doInitialize() throws LibraryException {
41
        // Nothing to do
42
    }
43

  
44
    @Override
45
    protected void doPostInitialize() throws LibraryException {
46
    	//Registers the process and its parameters
47
    	RasterBaseAlgorithmLibrary.register(PROCESS_LABEL, SaveRasterProcess.class);
48
    	SaveRasterProcess.registerParameters();
49
    	
50
        Messages.addResourceFamily(
51
            "org.gvsig.raster.tools.algorithm.saveraster", 
52
            SaveRasterAlgorithmLibrary.class.getClassLoader(), 
53
            SaveRasterAlgorithmLibrary.class.getClass().getName());
54
        //registerGeoProcess(new SaveRasterAlgorithmLibrary());
55
    }
56
}
0 57

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.76/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/src/main/java/org/gvsig/raster/tools/algorithm/saveraster/RasterizeFLayers.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.algorithm.saveraster;
23

  
24
import java.awt.Color;
25
import java.awt.Dimension;
26
import java.awt.Graphics2D;
27
import java.awt.geom.Rectangle2D;
28
import java.awt.image.BufferedImage;
29

  
30
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
31
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
32
import org.gvsig.fmap.dal.coverage.store.DataServerWriter;
33
import org.gvsig.fmap.dal.exception.ReadException;
34
import org.gvsig.fmap.geom.GeometryLocator;
35
import org.gvsig.fmap.geom.GeometryManager;
36
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
37
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
38
import org.gvsig.fmap.geom.primitive.Envelope;
39
import org.gvsig.fmap.mapcontext.ViewPort;
40
import org.gvsig.fmap.mapcontext.impl.DefaultMapContextDrawer;
41
import org.gvsig.fmap.mapcontext.layers.FLayers;
42
import org.gvsig.gui.beans.incrementabletask.IIncrementable;
43
import org.gvsig.i18n.Messages;
44
import org.gvsig.raster.algorithm.process.DataProcess;
45
import org.gvsig.raster.fmap.layers.FLyrRaster;
46
import org.gvsig.tools.task.Cancellable;
47
import org.slf4j.Logger;
48
import org.slf4j.LoggerFactory;
49

  
50
/**
51
 * Sirve datos solicitados por los drivers que salvan a raster. Hereda de
52
 * Rasterizer y reescribe el m?todo readData que es el que ser? llamado desde el
53
 * driver cada vez que vacie el buffer y necesite m?s datos.
54
 *
55
 * @version 04/06/2007
56
 * @author Nacho Brodin (nachobrodin@gmail.com)
57
 */
58
@SuppressWarnings("deprecation")
59
public class RasterizeFLayers implements DataServerWriter, IIncrementable {
60
	private static final GeometryManager 	geomManager		= GeometryLocator.getGeometryManager();
61
	private Logger                          logger          = LoggerFactory.getLogger(DataProcess.class.toString());
62
	
63
	private ViewPort						viewPort 		= null;
64
	private ViewPort						viewPortBlock	= null;
65
	private FLayers							flayers 		= null;
66
	private Color							backgroundColor = null;
67
	private boolean							firstRead 		= true;
68
	private int 							nBlocks 		= 0;
69
//	private double 							percentMax 		= 100.0D;
70
	protected double 						wcIntervalo 	= 0;
71
	protected Dimension 					dimension 		= null;
72
	protected int 							blockSize 		= 0;
73
	protected double 						wcAlto 			= 0;
74
	protected int 							lastBlock 		= 0;
75
	protected BufferedImage 				image 			= null;
76
	protected int[] 						rasterData 		= null;
77
	protected int 							contBlocks 		= 1;
78
	protected int							percent 		= 0;
79
	protected int							imgHeight 		= 0;
80

  
81
	/**
82
	 * Calculo del viewPort
83
	 * @param vp
84
	 */
85
	private void calcViewPort(ViewPort vp) {
86
		Rectangle2D ext = null;
87

  
88
		if (viewPortBlock == null)
89
			ext = new Rectangle2D.Double(	vp.getExtent().getMinX(),
90
											vp.getExtent().getMaxY() - wcIntervalo,
91
											vp.getExtent().getWidth(),
92
											wcIntervalo
93
										);
94
		else
95
			ext = new Rectangle2D.Double(	viewPortBlock.getExtent().getMinX(),
96
											viewPortBlock.getExtent().getMinY() - wcIntervalo,
97
											viewPortBlock.getExtent().getWidth(),
98
											wcIntervalo
99
										);
100

  
101
		viewPortBlock = new ViewPort(vp.getProjection());
102
		Envelope env;
103
		try {
104
			env = geomManager.createEnvelope(ext.getMinX(), ext.getMinY(), ext.getMaxX(), ext.getMaxY(), SUBTYPES.GEOM2D);
105
			viewPortBlock.setEnvelope(env);
106
		} catch (CreateEnvelopeException e) {
107
			logger.debug("Error creating the envelope", null, e);
108
		}		
109
		viewPortBlock.setImageSize(dimension);
110
		viewPortBlock.refreshExtent();
111
	}
112

  
113
	/**
114
	 * Constructor
115
	 * @param flyrs capas
116
	 * @param vp viewport
117
	 * @param blockSize altura del bloque que se lee de una vez en la imagen de entrada
118
	 * @param mapCtrl Mapcontrol
119
	 */
120
	public RasterizeFLayers(FLayers flyrs, ViewPort vp, int blockSize) {
121
		this.blockSize = blockSize;
122
		backgroundColor = vp.getBackColor();
123
		viewPort = new ViewPort(vp.getProjection());
124
		viewPort.setImageSize(vp.getImageSize());
125
		/*Rectangle2D ex = vp.getExtent();
126
		Envelope env = null;
127
		try {
128
			env = geomManager.createEnvelope(ex.getMinX(), ex.getMinY(), ex.getMaxX(), ex.getMaxY(), SUBTYPES.GEOM2D);
129
			//viewPortBlock = new ViewPort(vp.getProjection());
130
			//viewPortBlock.setEnvelope(env);
131
		} catch (CreateEnvelopeException e) {
132
			logger.debug("Error creating the envelope", null, e);
133
		}*/
134
		
135

  
136
		// Calculo del viewPort del primer bloque
137
		viewPort.setEnvelope(vp.getAdjustedExtent());
138
		wcAlto = viewPort.getExtent().getMaxY() - viewPort.getExtent().getMinY();
139
		wcIntervalo = (blockSize * wcAlto) / viewPort.getImageHeight();
140
		dimension = new Dimension(viewPort.getImageWidth(), blockSize);
141

  
142
		imgHeight = vp.getImageHeight();
143
		nBlocks = (vp.getImageHeight() / blockSize);
144

  
145
		// Tama?o de ?ltimo bloque en pixeles
146
		lastBlock = vp.getImageHeight() - (nBlocks * blockSize);
147

  
148
		calcViewPort(viewPort);
149

  
150
		this.flayers = flyrs;
151
	}
152

  
153
	/**
154
	 * Compatibilidad con el piloto de raster
155
	 * @see readData
156
	 */
157
	public int[] readARGBData(int sX, int sY, int nBand) throws ProcessInterruptedException, OutOfMemoryError {
158
		return readData( sX, sY, nBand);
159
	}
160

  
161
	public int[] readData(int sX, int sY, int nBand) throws ProcessInterruptedException, OutOfMemoryError {
162
		if (nBand == 0) { // Con nBand==0 se devuelven las 3 bandas
163
			nBlocks = (int) Math.ceil(imgHeight / (double) blockSize);
164
			image = new BufferedImage(sX, sY, BufferedImage.TYPE_INT_ARGB);
165
			Graphics2D g = (Graphics2D) image.getGraphics();
166
			g.setColor(backgroundColor);
167
			g.fillRect(0, 0, viewPortBlock.getImageWidth(), viewPortBlock.getImageHeight());
168
			try {
169
				// TODO: FUNCIONALIDAD: Salvar los m?ximos y m?nimos para salvar 16 bits
170

  
171
				// Si es la primera lectura salvamos los valores de m?ximo y m?nimo para la aplicaci?n
172
				// de realce si la imagen es de 16 bits.
173
				if (firstRead) {
174
					for (int i = 0; i < flayers.getLayersCount(); i++)
175
						if (flayers.getLayer(i) instanceof FLyrRaster) {
176
							FLyrRaster raster = (FLyrRaster) flayers.getLayer(i);
177
							if (raster.getDataStore().getDataType()[0] == Buffer.TYPE_SHORT || raster.getDataStore().getDataType()[0] == Buffer.TYPE_USHORT) {
178
								//Statistic stats = raster.getSource().getFilterStack().getStats();
179
								//stats.history.add(stats.new History(raster.getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue));
180
							}
181
						}
182
					firstRead = false;
183
				}
184

  
185
				DefaultMapContextDrawer mapContextDrawer = new DefaultMapContextDrawer();
186
				mapContextDrawer.setMapContext(flayers.getMapContext());
187
				mapContextDrawer.setViewPort(viewPortBlock);
188
				mapContextDrawer.draw(flayers, image, g, new Cancellable(){
189
					public boolean isCanceled() {
190
						return false;
191
					}
192

  
193
					public void setCanceled(boolean canceled) {
194
					}
195
				}, flayers.getMapContext().getScaleView());
196

  
197
				// Si es el ?ltimo bloque vaciamos el historial de m?ximos y m?nimos
198
				if ((contBlocks + 1) == nBlocks)
199
					for (int i = 0; i < flayers.getLayersCount(); i++)
200
						if (flayers.getLayer(i) instanceof FLyrRaster) {
201
							FLyrRaster raster = (FLyrRaster) flayers.getLayer(i);
202
							if (raster.getDataStore().getDataType()[0] == Buffer.TYPE_SHORT || raster.getDataStore().getDataType()[0] == Buffer.TYPE_USHORT) {
203
								//raster.getDatasource().getFilterStack().getStats().history.clear();
204
								//Statistic stats = raster.getSource().getFilterStack().getStats();
205
							}
206
						}
207

  
208
			} catch (ReadException e) {
209
				logger.debug("Error en el draw de capa", e);
210
			}
211
			rasterData = image.getRGB(0, 0, sX, sY, rasterData, 0, sX);
212

  
213
			// Calculamos el viewPort del sgte bloque
214

  
215
			if (((contBlocks + 1) * blockSize) <= viewPort.getImageHeight())
216
				dimension = new Dimension(sX, sY);
217
			else { // Calculo de la altura del ?ltimo bloque
218
				dimension = new Dimension(sX, (viewPort.getImageHeight() - (contBlocks * blockSize)));
219
				wcIntervalo = (lastBlock * wcAlto) / viewPort.getImageHeight();
220
			}
221

  
222
			calcViewPort(viewPortBlock);
223

  
224
			percent = ((100 * (contBlocks)) / nBlocks);
225
			contBlocks++;
226

  
227
			return rasterData;
228
		}
229

  
230
		return null;
231
	}
232

  
233
	/**
234
	 * Asigna el ancho del bloque
235
	 * @param sizeBlock Ancho del bloque en pixeles
236
	 */
237
	public void setBlockSize(int blockSize) {
238
		this.blockSize = blockSize;
239
	}
240

  
241
	/**
242
	 * No tiene uso en RasterizerLayer
243
	 */
244
	public byte[][] readByteData(int sizeX, int sizeY) {
245
		return null;
246
	}
247

  
248
	/**
249
	 * No tiene uso en RasterizerLayer
250
	 */
251
	public double[][] readDoubleData(int sizeX, int sizeY) {
252
		return null;
253
	}
254

  
255
	/**
256
	 * No tiene uso en RasterizerLayer
257
	 */
258
	public float[][] readFloatData(int sizeX, int sizeY) {
259
		return null;
260
	}
261

  
262
	/**
263
	 * No tiene uso en RasterizerLayer
264
	 */
265
	public int[][] readIntData(int sizeX, int sizeY) {
266
		return null;
267
	}
268

  
269
	/**
270
	 * No tiene uso en RasterizerLayer
271
	 */
272
	public short[][] readShortData(int sizeX, int sizeY) {
273
		return null;
274
	}
275

  
276
	public String getTitle() {
277
		return Messages.getText("salvando_raster");
278
	}
279

  
280
	public String getLog() {
281
		return Messages.getText("salvando_bloque") + " " + Math.min(nBlocks, contBlocks) + " " + Messages.getText("de") + " " + nBlocks;
282
	}
283

  
284
	public String getLabel() {
285
		return Messages.getText("rasterizando") + "...";
286
	}
287

  
288
	public int getPercent() {
289
		return percent;
290
	}
291

  
292
	public boolean isCancelable() {
293
		return true;
294
	}
295

  
296
	public boolean isPausable() {
297
		return false;
298
	}
299

  
300
	public void setAlphaBuffer(Buffer alphaBuffer) {
301
	}
302

  
303
	public void setBuffer(Buffer buffer, int nband) {
304
	}
305
	
306
	public Buffer getBuffer() {
307
		return null;
308
	}
309

  
310
	public void setBand(int nband) {
311
	}
312

  
313
	public void dispose() {
314
	}
315

  
316
	public Buffer getSource() {
317
		return null;
318
	}
319

  
320
	public void setPercent(int value) {
321
	}
322
}
0 323

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.76/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/src/main/java/org/gvsig/raster/tools/algorithm/saveraster/SaveRasterProcess.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.algorithm.saveraster;
23

  
24
import java.awt.Dimension;
25
import java.awt.geom.AffineTransform;
26
import java.io.File;
27
import java.io.IOException;
28
import java.util.Date;
29

  
30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.dal.coverage.RasterLocator;
32
import org.gvsig.fmap.dal.coverage.RasterManager;
33
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
34
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
35
import org.gvsig.fmap.dal.coverage.datastruct.Params;
36
import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData;
37
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
38
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
39
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
40
import org.gvsig.fmap.dal.coverage.process.TaskEventManager;
41
import org.gvsig.fmap.dal.coverage.store.DataServerWriter;
42
import org.gvsig.fmap.dal.coverage.store.RasterWriter;
43
import org.gvsig.fmap.dal.coverage.util.CRSUtils;
44
import org.gvsig.fmap.geom.primitive.Envelope;
45
import org.gvsig.fmap.mapcontext.ViewPort;
46
import org.gvsig.fmap.mapcontext.layers.FLayers;
47
import org.gvsig.raster.algorithm.process.ProcessException;
48
import org.gvsig.raster.algorithm.process.DataProcess;
49

  
50
/**
51
 * Thread que se encarga de llamar a los writer para realizar la tarea de
52
 * salvado y/p compresi?n
53
 *
54
 * @author Nacho Brodin (nachobrodin@gmail.com)
55
 */
56
public class SaveRasterProcess extends DataProcess {
57
	public static String      VIEWPORT          = "ViewPort";
58
	public static String      PATH              = "Path";
59
	public static String      DIMENSION         = "Dimension";
60
	public static String      BLOCKSIZE         = "Blocksize";
61
	public static String      FILENAME          = "FileName";
62
	public static String      PARAMS            = "WriterParams";
63
	public static String      FLYRS             = "FLyrs";
64
	public static String      TIME              = "Time";
65
	public static String      PROJECTION        = "Projection";
66
	
67
	private IProjection       projection        = null;
68
	private ViewPort          viewPort          = null;
69
	private Dimension         dimension         = null;
70
	private RasterizeFLayers  rasterizerLayer   = null;
71
	private String            fileName          = "";
72
	private Params            writerParams      = null;
73
	//private CopyDataset       jp2Copy           = null;
74
	private boolean           supportImage      = false;
75
	private RasterManager     rManager          = RasterLocator.getManager();
76
	//private Logger            logger            = LoggerFactory.getLogger(RasterProcess.class.toString());
77
	
78
	public static void registerParameters() {
79
		registerInputParameter(VIEWPORT, ViewPort.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL);
80
		registerInputParameter(PATH, String.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL);
81
		registerInputParameter(DIMENSION, Dimension.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL);
82
		registerInputParameter(FLYRS, FLayers.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL);
83
		registerInputParameter(PARAMS, Params.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL);
84
		registerOutputParameter(PROJECTION, IProjection.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL);
85
		
86
		registerOutputParameter(FILENAME, String.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL);
87
		registerOutputParameter(TIME, Long.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL);
88
	}
89
	
90
	public void init() {
91
		viewPort = getParam(VIEWPORT) != null ? (ViewPort)getParam(VIEWPORT) : null;
92
		dimension = getParam(DIMENSION) != null ? (Dimension) getParam(DIMENSION) : null;
93
		FLayers flyrs = getParam(FLYRS) != null ? (FLayers) getParam(FLYRS) : null;
94
		int blockSize = getIntParam(BLOCKSIZE);
95
		rasterizerLayer = new RasterizeFLayers(flyrs, viewPort, blockSize);
96
		fileName = getStringParam(FILENAME);
97
		writerParams = getParam(PARAMS) != null ? (Params) getParam(PARAMS) : null;
98
		projection = getParam(PROJECTION) != null ? (IProjection) getParam(PROJECTION) : null;
99
		//supportImage = getBooleanParam("remotelayers") && fileName.endsWith(".jp2");
100
	}
101

  
102
	/**
103
	 * Procesos de escritura de una porci?n de la vista.
104
	 */
105
	public void process() throws ProcessInterruptedException, ProcessException {
106
		TaskEventManager task = rManager.getRasterTask();
107
		
108
		//jp2Copy = null;
109
		long t2;
110
		long t1 = new java.util.Date().getTime();
111
		
112
		//Creamos el driver
113
		Envelope env = viewPort.getAdjustedEnvelope();
114
		Extent ex = rManager.getDataStructFactory().createExtent(env.getMinimum(0), env.getMaximum(1), env.getMaximum(0), env.getMinimum(1));
115
		Dimension imgSz = viewPort.getImageSize();
116
		ViewPortData vpData = rManager.getDataStructFactory().createViewPortData(viewPort.getProjection(), ex, imgSz );
117
		vpData.setDPI((int)viewPort.getDPI());
118
		AffineTransform at = new AffineTransform(vpData.getExtent().width() / imgSz.width,
119
												 0, 0,
120
												 -(vpData.getExtent().height() / imgSz.height),
121
												 vpData.getExtent().getULX(),
122
												 vpData.getExtent().getULY());
123
		String oldFileName = fileName;
124
		if(supportImage) {
125
			fileName = fileName.substring(0, Math.min(fileName.lastIndexOf(File.separator) + 1, fileName.length() - 1));
126
			fileName += rManager.getFileUtils().usesOnlyLayerName() + ".tif";
127
			writerParams = getWriterParams(fileName);
128
		}
129

  
130
		//Ejecutamos el driver con los datos pasados
131
		try {
132
			write(fileName, at, writerParams, rasterizerLayer);
133

  
134
			if(task.getEvent() != null)
135
				task.manageEvent(task.getEvent());
136
			
137
			/*if(supportImage) {
138
				try {
139
					insertLineLog(Messages.getText("saving_jp2"));
140
					jp2Copy = new CopyDataset(fileName, oldFileName, incrementableTask);
141
					jp2Copy.copy();
142
					new File(fileName).delete();
143
					new File(rManager.getFileUtils().getRMFNameFromFileName(fileName)).delete();
144
				} catch (LoadLayerException e) {
145
					throw new ProcessException("error_processing", e);
146
				} 
147
				jp2Copy = null;
148
			} */
149
			t2 = new Date().getTime();
150
			try {
151
				saveRasterFinalize(oldFileName, (t2 - t1));
152
			} catch(ArrayIndexOutOfBoundsException exc) {
153
				//Si la ventana se ha cerrado ya es porque ha sido cancelada por lo que
154
				//producir? esta excepci?n. En este caso no se lanza la ventana de informaci?n
155
				//de finalizaci?n.
156
			}
157

  
158
		} catch(IOException ev) {
159
			throw new ProcessException("error_processing", ev);
160
		} catch(OutOfMemoryError ev) {
161
			throw new ProcessException("memoria_excedida", ev);
162
		} finally {
163
			if (incrementableTask != null) {
164
				incrementableTask.processFinalize();
165
				incrementableTask = null;
166
			}
167
		}
168
	}
169
	
170
	/**
171
	 * 
172
	 * @param name
173
	 * @param at
174
	 * @throws IOException
175
	 * @throws ProcessException 
176
	 * @throws InterruptedException
177
	 */
178
	private void write(String name, AffineTransform at, Params writerParams, DataServerWriter rasterizerLayer) throws IOException, ProcessInterruptedException, ProcessException {
179
		//TODO: Usar el nuevo API basado en NewRasterStoreParameters y DataServerExplorer. Ejemplo en ClippingProcess
180
		
181
		TaskEventManager task = rManager.getRasterTask();
182
		RasterWriter geoRasterWriter = null;
183
		try {
184
			//TODO: FUNCIONALIDAD: Poner los gerWriter con la proyecci?n de la vista
185
			geoRasterWriter = rManager.createWriter(rasterizerLayer, name,
186
												3, at, dimension.width,
187
												dimension.height, Buffer.TYPE_IMAGE, writerParams, null);
188
			CRSUtils crsUtil = RasterLocator.getManager().getCRSUtils();
189
			geoRasterWriter.setWkt(crsUtil.convertIProjectionToWkt(projection));
190
		} catch (NotSupportedExtensionException e) {
191
			throw new ProcessException("extension_no_soportada", e);
192
		} catch (RasterDriverException e) {
193
			throw new ProcessException("no_driver_escritura", e);
194
		}
195
		
196
		if(task.getEvent() != null)
197
			task.manageEvent(task.getEvent());
198
		
199
		geoRasterWriter.setCancellableRasterDriver(new ExternalCancellable(incrementableTask));
200
		geoRasterWriter.dataWrite();
201
		geoRasterWriter.writeClose();
202
	}
203
	
204
	/**
205
	 * Obtiene los par?metros del driver de escritura. Si el driver no se ha creado a?n se obtienen
206
	 * unos par?metros con la inicializaci?n por defecto. Si se ha creado ya y se han modificado se
207
	 * devuelven los par?metros con las modificaciones. Si se cambia de driver se devolver? un WriterParams
208
	 * como si fuera la primera vez que se abre.
209
	 * @param name Nombre del fichero sobre el que se salva.
210
	 * @return WriterParams
211
	 */
212
	private Params getWriterParams(String name) throws ProcessException {
213
		RasterWriter writer = null;
214
		String ext = rManager.getFileUtils().getExtensionFromFileName(name);
215
		try {
216
			if(writer == null) //La primera vez que se obtiene el driver
217
				writer = rManager.createWriter(name);
218
			else {
219
				String newType = rManager.getProviderServices().getWriteDriverType(ext);
220
				String oldType = writer.getDriverName();
221
				if(!newType.equals(oldType))  //Cambio de driver despu?s de haber seleccionado y modificado las propiedades de uno
222
					writer = rManager.createWriter(name);
223
			}
224

  
225
			if(writer == null)
226
				throw new ProcessException("no_driver_escritura");
227

  
228
			return writer.getParams();
229

  
230
		} catch (NotSupportedExtensionException e1) {
231
			throw new ProcessException("no_driver_escritura", e1);
232
		} catch (RasterDriverException e1) {
233
			throw new ProcessException("no_driver_escritura", e1);
234
		}
235
	}
236

  
237
	/**
238
	 * Acciones que se realizan al finalizar de salvar a raster.
239
	 * @param fileName Nombre del fichero
240
	 * @param milis Tiempo que ha tardado en ejecutarse
241
	 */
242
	private void saveRasterFinalize(String fileName, long milis) {
243
		if (incrementableTask != null)
244
			incrementableTask.hideWindow();
245
		externalActions.end(new Object[]{fileName, new Long(milis)});
246
	}
247

  
248
	/*
249
	 * (non-Javadoc)
250
	 * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
251
	 */
252
	public int getPercent() {
253
		if(rasterizerLayer != null)
254
			return rasterizerLayer.getPercent();
255
		return 0;
256
	}
257

  
258
	/*
259
	 * (non-Javadoc)
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff