gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.main / src / main / java / org / gvsig / raster / tools / algorithm / TestMaskthreholdOutPutLayerThreshold.java @ 2480
History | View | Annotate | Download (5.6 KB)
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 |
} |