Revision 3637

View differences:

org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
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/xsd/maven-4.0.0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.raster.tools</artifactId>
5
	<packaging>pom</packaging>
6
	<version>2.2.10</version>
7
	<name>org.gvsig.raster.tools</name>
8
	<description>Raster tools for gvSIG</description>
9
	<inceptionYear>2011</inceptionYear>
10
	<parent>
11
      <groupId>org.gvsig</groupId>
12
      <artifactId>org.gvsig.desktop</artifactId>
13
      <version>2.0.101</version>
14
  </parent>
15

  
16
        <properties>
17
            <!-- El plugin versions:use-latest-versions falla con scope import -->
18
            <!-- asi que toca usar el versions:update-properties que si que funciona -->
19
            <org.gvsig.raster.version>2.2.13</org.gvsig.raster.version>
20
            <org.gvsig.geoprocess.version>2.2.27</org.gvsig.geoprocess.version>
21
        </properties>
22

  
23
  <repositories>
24
    <repository>
25
      <id>gvsig-public-http-repository</id>
26
      <name>gvSIG maven public HTTP repository</name>
27
      <url>http://devel.gvsig.org/m2repo/j2se</url>
28
      <releases>
29
        <enabled>true</enabled>
30
        <updatePolicy>daily</updatePolicy>
31
        <checksumPolicy>warn</checksumPolicy>
32
      </releases>
33
      <snapshots>
34
        <enabled>true</enabled>
35
        <updatePolicy>daily</updatePolicy>
36
        <checksumPolicy>warn</checksumPolicy>
37
      </snapshots>
38
    </repository>
39
  </repositories>
40

  
41
  <scm>
42
      <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10</connection>
43
      <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10</developerConnection>
44
      <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10</url>
45
  </scm>
46

  
47
  <dependencyManagement>
48
  	<dependencies>
49
                        <dependency>
50
                                <groupId>org.gvsig</groupId>
51
                                <artifactId>org.gvsig.raster</artifactId>
52
                                <version>${org.gvsig.raster.version}</version>
53
                                <type>pom</type>
54
                                <scope>import</scope>
55
                        </dependency>
56

  
57
                        <dependency>
58
                                <groupId>org.gvsig</groupId>
59
                                <artifactId>org.gvsig.geoprocess</artifactId>
60
                                <version>${org.gvsig.geoprocess.version}</version>
61
                                <type>pom</type>
62
                                <scope>import</scope>
63
                        </dependency>
64

  
65

  
66
    	<!--
67
    	Versions of child projects
68
    	-->
69
			<dependency>
70
				<groupId>org.gvsig</groupId>
71
				<artifactId>org.gvsig.raster.tools.app.basic</artifactId>
72
				<version>2.2.10</version>
73
			</dependency>
74
			<dependency>
75
				<groupId>org.gvsig</groupId>
76
				<artifactId>org.gvsig.raster.tools.algorithm.layerdatatype</artifactId>
77
       	<version>2.2.10</version>
78
			</dependency>
79
			<dependency>
80
				<groupId>org.gvsig</groupId>
81
				<artifactId>org.gvsig.raster.tools.algorithm.saveraster</artifactId>
82
       	<version>2.2.10</version>
83
			</dependency>
84
			<!--
85
			<dependency>
86
				<groupId>org.gvsig</groupId>
87
				<artifactId>org.gvsig.raster.tools.algorithm.clip</artifactId>
88
       	<version>2.0.1-SNAPSHOT</version>
89
			</dependency>
90
			-->
91
			<dependency>
92
          <groupId>org.gvsig</groupId>
93
	        <artifactId>org.gvsig.raster.tools.algorithm.swing.api</artifactId>
94
	        <version>2.2.10</version>
95
    	</dependency>
96
    	<dependency>
97
          <groupId>org.gvsig</groupId>
98
	        <artifactId>org.gvsig.raster.tools.algorithm.swing.impl</artifactId>
99
	        <version>2.2.10</version>
100
    	</dependency>
101
    	<dependency>
102
          <groupId>org.gvsig</groupId>
103
	        <artifactId>org.gvsig.raster.tools.algorithm.maskthreshold</artifactId>
104
	        <version>2.2.10</version>
105
    	</dependency>
106
    	<dependency>
107
				<groupId>org.gvsig</groupId>
108
				<artifactId>org.gvsig.raster.tools.toolbox.algorithm</artifactId>
109
				<version>2.2.10</version>
110
			</dependency>
111

  
112
  	</dependencies>
113
  </dependencyManagement>
114

  
115

  
116
  <build>
117
      <plugins>
118
          <plugin>
119
              <groupId>org.apache.maven.plugins</groupId>
120
              <artifactId>maven-release-plugin</artifactId>
121
              <configuration>
122
                  <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.tools/tags/</tagBase>
123
                  <goals>deploy</goals>
124
              </configuration>
125
          </plugin>
126
      </plugins>
127
  </build>
128

  
129
	<modules>
130
		<module>org.gvsig.raster.tools.algorithm</module>
131
		<module>org.gvsig.raster.tools.app.basic</module>
132
		<module>org.gvsig.raster.tools.toolbox.algorithm</module>
133
		<!-- <module>org.gvsig.raster.tools.main</module>-->
134
	</modules>
135

  
136
</project>
0 137

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.toolbox.algorithm/src/main/resources/org/gvsig/raster/tools/sextante/i18n/text.properties
1
layer_datatype=Cambiar tipo de dato
2
raster_layer=Capas r?ster
3
Input_layer=Capa de entrada
4
dst_datatype=Tipo de dato de destino
5
dec_2_int=De decimal a entero
6
big_2_small=De mayor a menor
7
file_exists=El fichero existe
8
convert_datatype=Convirtiendo el tipo de dato
0 9

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.toolbox.algorithm/src/main/resources/org/gvsig/raster/tools/sextante/i18n/text_en.properties
1
layer_datatype=Change the data type
2
raster_layer=Raster layers
3
Input_layer=Input layer
4
dst_datatype=Data type of the result
5
dec_2_int=From decimal to integer
6
big_2_small=From greater type to lesser type
7
file_exists=The file exists
8
convert_datatype=Transforming the data type
0 9

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.toolbox.algorithm/src/main/resources/help/LayerDatatypeSextanteAlgorithm.xml
1
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
2
<help>
3
	<element name="DESCRIPTION"
4
		text=""
5
		description="Descripci&#243;n" type="0">
6
		<!-- <image description="" file="">
7
		</image>-->
8
	</element>
9
	<element name="ADDITIONAL_INFO" text=""
10
		description="Informaci&#243;n adicional" type="0">
11
	</element>
12
	<element name="EXTENSION_AUTHOR" text=""
13
		description="Algoritmo creado por" type="0">
14
	</element>
15
	<element name="HELP_AUTHOR" text="" description="Ayuda creada por"
16
		type="0">
17
	</element>
18
	<element name="USER_NOTES" text="" description="Notas de usuario"
19
		type="0">
20
	</element>
21
</help>
0 22

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.toolbox.algorithm/src/main/resources/help/LayerDatatypeSextanteAlgorithm_en.xml
1
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
2
<help>
3
	<element name="DESCRIPTION"
4
		text=""
5
		description="Descripci&#243;n" type="0">
6
		<!-- <image description="" file="">
7
		</image> -->
8
	</element>
9
	<element name="ADDITIONAL_INFO" text=""
10
		description="Informaci&#243;n adicional" type="0">
11
	</element>
12
	<element name="EXTENSION_AUTHOR" text=""
13
		description="Algoritmo creado por" type="0">
14
	</element>
15
	<element name="HELP_AUTHOR" text="" description="Ayuda creada por"
16
		type="0">
17
	</element>
18
	<element name="USER_NOTES" text="" description="Notas de usuario"
19
		type="0">
20
	</element>
21
</help>
0 22

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.toolbox.algorithm/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.tools.RasterToolsSextanteLibrary
0 2

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.toolbox.algorithm/src/main/java/org/gvsig/raster/tools/LayerDatatypeSextanteAlgorithm.java
1
package org.gvsig.raster.tools;
2

  
3
import java.util.HashMap;
4
import java.util.List;
5

  
6
import org.gvsig.fmap.dal.coverage.RasterLocator;
7
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
8
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
9
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
10
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
11
import org.gvsig.geoprocess.lib.sextante.dataObjects.FLyrRasterIRasterLayer;
12
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary;
13
import org.gvsig.raster.algorithm.process.DataProcess;
14
import org.gvsig.raster.algorithm.process.IProcessActions;
15
import org.gvsig.raster.algorithm.process.ProcessException;
16
import org.gvsig.raster.fmap.layers.FLyrRaster;
17

  
18
import es.unex.sextante.core.AnalysisExtent;
19
import es.unex.sextante.core.Sextante;
20
import es.unex.sextante.dataObjects.IRasterLayer;
21
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
22
import es.unex.sextante.exceptions.NullParameterAdditionalInfoException;
23
import es.unex.sextante.exceptions.NullParameterValueException;
24
import es.unex.sextante.exceptions.RepeatedParameterNameException;
25
import es.unex.sextante.exceptions.WrongParameterIDException;
26
import es.unex.sextante.exceptions.WrongParameterTypeException;
27

  
28
/**
29
 * Process to change a layer of data type
30
 * @author Nacho Brodin (nachobrodin@gmail.com)
31
 */
32
public class LayerDatatypeSextanteAlgorithm extends AbstractSextanteGeoProcess implements IProcessActions {
33
    public static final String RESULT            = "RESULT";
34
    public static final String LAYER             = "RasterStore1";
35
	public static final String DATATYPE          = "Datatype";
36
	public static final String ADJUST_DEC2INT    = "AdjustDec2Int";
37
	public static final String ADJUST_BIG2SMALL  = "AdjustBig2Small";
38

  
39
	public static String[]    DEC2INT_OPTIONS    = new String[]{"Trunk", "Round", "Ceil", "Floor"};
40
	public static String[]    BIG2SMALL_OPTIONS  = new String[]{"Trunk", "Maxvalue", "NoData"};
41
	public static String[]    DATATYPES          = new String[]{"Byte", "UShort", "Short", "Integer", "Float", "Double"};
42

  
43
    private DataProcess        task            = null;
44

  
45

  
46
    public void defineCharacteristics() {
47
        setName(getTranslation("layer_datatype"));
48
        setGroup(getTranslation("raster_layer"));
49

  
50
        try {
51
            m_Parameters.addInputRasterLayer(LAYER, getTranslation("Input_layer"), true);
52
            m_Parameters.addSelection(DATATYPE, getTranslation("dst_datatype"), DATATYPES);
53
            m_Parameters.addSelection(ADJUST_DEC2INT, getTranslation("dec_2_int"), DEC2INT_OPTIONS);
54
            m_Parameters.addSelection(ADJUST_BIG2SMALL, getTranslation("big_2_small"), BIG2SMALL_OPTIONS);
55
        } catch (RepeatedParameterNameException e) {
56
            Sextante.addErrorToLog(e);
57
        }
58
        addOutputRasterLayer(RESULT, getTranslation("principalcomponents"));
59
    }
60

  
61
    public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
62

  
63
    	if(existsOutPutFile(LayerDatatypeSextanteAlgorithm.RESULT, 0)) {
64
    		throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
65
    	}
66

  
67
    	IRasterLayer input = m_Parameters.getParameterValueAsRasterLayer(LAYER);
68

  
69
    	FLyrRaster lyrRaster = ((FLyrRaster)input.getBaseDataObject());
70
    	IRasterLayer output = null;
71

  
72
    	output = getNewRORasterLayer(
73
    			RESULT,
74
    			Sextante.getText("layerdatatype_description"),
75
    			input.getDataType(),
76
    			input.getBandsCount());
77

  
78
    	String fileName = ((FLyrRasterIRasterLayer)output).getName();
79

  
80
    	try {
81
    		setProgressText(getTranslation("convert_datatype"));
82
			task = createLayerDatatypeProcess(lyrRaster.getDataStore(), fileName);
83
			task.execute();
84
			HashMap<String, Object> params = task.getResult();
85
			fileName = (String)params.get("FileName");
86

  
87
			((FLyrRasterIRasterLayer)output).setBaseDataObject(fileName);
88
		} catch (ProcessInterruptedException e) {
89
			Sextante.addErrorToLog(e);
90
		} catch (ProcessException e) {
91
			Sextante.addErrorToLog(e);
92
		}
93

  
94
		if(getTaskMonitor().isCanceled())
95
			return false;
96

  
97
        return true;
98
    }
99

  
100
    /**
101
     * Creates a process to calculate statistics
102
     * @param inputStore
103
     * @return
104
     * @throws ProcessException
105
     * @throws NullParameterAdditionalInfoException
106
     * @throws NullParameterValueException
107
     * @throws WrongParameterIDException
108
     * @throws WrongParameterTypeException
109
     */
110
    private DataProcess createLayerDatatypeProcess(RasterDataStore inputStore, String fileName) throws ProcessException, WrongParameterTypeException, WrongParameterIDException, NullParameterValueException, NullParameterAdditionalInfoException {
111
    	DataProcess taskStats = RasterBaseAlgorithmLibrary.getManager().createRasterTask("LayerDatatypeProcess");
112
    	taskStats.setActions(this);
113
    	List<String> params = taskStats.getRasterTaskInputParameters("LayerDatatypeProcess");
114
    	for (int i = 0; i < params.size(); i++) {
115
    		String paramName = params.get(i);
116
    		Class<?> paramType = taskStats.getParameterTypeByProcess("LayerDatatypeProcess", paramName);
117
    		if(paramType == RasterDataStore.class) {
118
    			taskStats.addParam(paramName, (RasterDataStore)inputStore);
119
    		}
120

  
121
    		if(paramName.equals("Path")) {
122
    			taskStats.addParam(paramName, fileName);
123
    		}
124

  
125
    		if(paramName.equals(DATATYPE)) {
126
    			String value = m_Parameters.getParameterValueAsString(DATATYPE);
127
    			int position = 0;
128
    			for (int j = 0; j < DATATYPES.length; j++) {
129
					if(DATATYPES[j].equals(value))
130
						position = j;
131
				}
132
    			taskStats.addParam(paramName, position);
133
    		}
134

  
135
    		if(paramName.equals(ADJUST_DEC2INT)) {
136
    			String value = m_Parameters.getParameterValueAsString(ADJUST_DEC2INT);
137
    			int position = 0;
138
    			for (int j = 0; j < DEC2INT_OPTIONS.length; j++) {
139
					if(DEC2INT_OPTIONS[j].equals(value))
140
						position = j;
141
				}
142
    			taskStats.addParam(paramName, position);
143
    		}
144

  
145
    		if(paramName.equals(ADJUST_BIG2SMALL)) {
146
    			String value = m_Parameters.getParameterValueAsString(ADJUST_BIG2SMALL);
147
    			int position = 0;
148
    			for (int j = 0; j < BIG2SMALL_OPTIONS.length; j++) {
149
					if(BIG2SMALL_OPTIONS[j].equals(value))
150
						position = j;
151
				}
152
    			taskStats.addParam(paramName, position);
153
    		}
154

  
155
    		if(paramName.equals("WINDOW")) {
156
    			AnalysisExtent ext = getAnalysisExtent();
157
    			Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(
158
    					ext.getXMin(), ext.getYMax(), ext.getXMax(), ext.getYMin());
159
    			Extent inputBbox = inputStore.getExtent();
160
    			if(bbox.getULX() != inputBbox.getULX() ||
161
    				bbox.getULY() != inputBbox.getULY() ||
162
    				bbox.getLRX() != inputBbox.getLRX() ||
163
    				bbox.getLRY() != inputBbox.getLRY()) {
164
    				taskStats.addParam(paramName, bbox);
165
    			}
166
    		}
167
    	}
168
    	return taskStats;
169
    }
170

  
171
	public void interrupted() {
172

  
173
	}
174

  
175
	public void end(Object param) {
176

  
177
	}
178

  
179
	public void updateProgress(int current, int total) {
180
		boolean cancelled = setProgress(current, total);
181

  
182
		if(!cancelled) {
183
			if(task != null)
184
				task.actionCanceled(null);
185
		}
186
	}
187

  
188
    /*
189
     * TODO: Customized panels
190
    @Override
191
    public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() {
192
        return PrincipalComponentsParametersPanel.class;
193
    }*/
194
}
0 195

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.toolbox.algorithm/src/main/java/org/gvsig/raster/tools/RasterToolsSextanteLibrary.java
1
package org.gvsig.raster.tools;
2

  
3
import org.gvsig.geoprocess.algorithm.base.core.AlgorithmAbstractLibrary;
4
import org.gvsig.i18n.Messages;
5
import org.gvsig.tools.library.LibraryException;
6

  
7
/**
8
 * Initialization of <code>RasterToolsSextanteLibrary</code> library.
9
 */
10
public class RasterToolsSextanteLibrary extends AlgorithmAbstractLibrary {
11

  
12
    @Override
13
    protected void doInitialize() throws LibraryException {
14
        // Nothing to do
15
    }
16

  
17
    @Override
18
    protected void doPostInitialize() throws LibraryException {
19
        Messages.addResourceFamily(
20
            "org.gvsig.raster.tools.sextante.i18n.text", RasterToolsSextanteLibrary.class
21
                .getClassLoader(), RasterToolsSextanteLibrary.class.getClass().getName());
22
        
23
        registerGeoProcess(new LayerDatatypeSextanteAlgorithm());
24
    }
25

  
26
}
0 27

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.toolbox.algorithm/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/xsd/maven-4.0.0.xsd">
3

  
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.raster.tools.toolbox.algorithm</artifactId>
6
	<packaging>jar</packaging>
7
	<name>org.gvsig.raster.tools.toolbox.algorithm</name>
8
	<parent>
9
		<groupId>org.gvsig</groupId>
10
		<artifactId>org.gvsig.raster.tools</artifactId>
11
		<version>2.2.10</version>
12
	</parent>
13
	<dependencies>
14
		<dependency>
15
		    <groupId>org.gvsig</groupId>
16
   			<artifactId>org.gvsig.raster.tools.algorithm.layerdatatype</artifactId>
17
            <scope>runtime</scope>
18
   		</dependency>
19
		<dependency>
20
		    <groupId>org.gvsig</groupId>
21
   			<artifactId>org.gvsig.raster.algorithm</artifactId>
22
            <scope>compile</scope>
23
   		</dependency>
24
		<dependency>
25
		    <groupId>org.gvsig</groupId>
26
   			<artifactId>org.gvsig.geoprocess.algorithm.base</artifactId>
27
            <scope>compile</scope>
28
   		</dependency>
29
		<dependency>
30
			<groupId>org.gvsig</groupId>
31
			<artifactId>org.gvsig.geoprocess.lib.sextante</artifactId>
32
			<scope>compile</scope>
33
		</dependency>
34
		<dependency>
35
			<groupId>org.gvsig</groupId>
36
			<artifactId>org.gvsig.tools.lib</artifactId>
37
			<scope>compile</scope>
38
		</dependency>
39
		<dependency>
40
			<groupId>org.gvsig</groupId>
41
			<artifactId>org.gvsig.ui</artifactId>
42
			<scope>compile</scope>
43
		</dependency>
44
	    <dependency>
45
			<groupId>org.gvsig</groupId>
46
			<artifactId>org.gvsig.i18n</artifactId>
47
			<scope>compile</scope>
48
		</dependency>
49
		<dependency>
50
            <groupId>org.gvsig</groupId>
51
            <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
52
            <scope>compile</scope>
53
        </dependency>
54
        <dependency>
55
            <groupId>org.gvsig</groupId>
56
            <artifactId>org.gvsig.fmap.mapcontext.impl</artifactId>
57
            <scope>runtime</scope>
58
        </dependency>
59
		<dependency>
60
            <groupId>org.gvsig</groupId>
61
            <artifactId>org.gvsig.projection.api</artifactId>
62
            <scope>compile</scope>
63
        </dependency>
64
        <dependency>
65
            <groupId>org.gvsig</groupId>
66
            <artifactId>org.gvsig.projection.cresques.impl</artifactId>
67
            <scope>runtime</scope>
68
        </dependency>
69
   		<dependency>
70
            <groupId>org.gvsig</groupId>
71
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
72
            <scope>compile</scope>
73
        </dependency>
74
	</dependencies>
75
</project>
0 76

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.app.basic/buildNumber.properties
1
#Fri Jul 03 22:26:30 CEST 2015
2
buildNumber=61
0 3

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.app.basic/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25

  
26
  <dependencySets>
27
    <dependencySet>
28
      <useProjectArtifact>false</useProjectArtifact>
29
	  <useTransitiveDependencies>false</useTransitiveDependencies>
30
      <outputDirectory>lib</outputDirectory>
31
      <includes> 
32
				<include>org.gvsig:org.gvsig.raster.tools.app.basic:jar</include>
33
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.layerdatatype:jar</include>
34
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.saveraster:jar</include>
35
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.api:jar</include>
36
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.impl:jar</include>
37
				<include>org.gvsig:org.gvsig.raster.tools.toolbox.algorithm:jar</include>
38
	  </includes>
39
	</dependencySet>
40
  </dependencySets>
41
</assembly>
0 42

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/HistogramProcess.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.app.basic.raster.process;
23

  
24
import javax.swing.SwingUtilities;
25

  
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram;
28
import org.gvsig.fmap.dal.coverage.exception.HistogramException;
29
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
30
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
31

  
32
/**
33
* Process to calculate a Histogram using a Histogramable object. A Histogramable object
34
* has its own method to build an histogram an this process will call to this function. 
35
* 
36
* @author Nacho Brodin (nachobrodin@gmail.com)
37
*/
38
public class HistogramProcess extends RasterProcess {
39
	private BufferHistogram        lastHistogram  = null;
40
	private HistogramComputer      histogramable  = null;
41
	
42
	/*
43
	 * (non-Javadoc)
44
	 * @see org.gvsig.rastertools.RasterProcess#init()
45
	 */
46
	public void init() {
47
		histogramable = (HistogramComputer) getParam("histogramable");
48
	}
49

  
50
	/*
51
	 * (non-Javadoc)
52
	 * @see org.gvsig.rastertools.RasterProcess#process()
53
	 */
54
	public void process() throws ProcessInterruptedException, ProcessException {
55
		try {
56
			// Proceso duro de obtener un histograma. Puede durar bastante tiempo.
57
			lastHistogram = histogramable.getBufferHistogram();
58
			// Ya tenemos el histograma y lo representamos en la ventana
59
			SwingUtilities.invokeLater(new Runnable() {
60
				public void run() {
61
					if ((externalActions != null) && (lastHistogram != null))
62
						externalActions.end(lastHistogram);
63
				}
64
			});
65
			
66
		} catch (HistogramException e) {
67
			throw new ProcessException("Error calculando el histograma", e);
68
		} 
69
	}
70
	
71
	/*
72
	 * (non-Javadoc)
73
	 * @see org.gvsig.raster.RasterProcess#getResult()
74
	 */
75
	public Object getResult() {
76
		return lastHistogram;
77
	}
78

  
79
	/*
80
	 * (non-Javadoc)
81
	 * @see org.gvsig.rastertools.RasterProcess#getLog()
82
	 */
83
	public String getLog() {
84
		return PluginServices.getText(this, "calculando_histograma") + "...\n";
85
	}
86

  
87
	/*
88
	 * (non-Javadoc)
89
	 * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
90
	 */
91
	public int getPercent() {
92
		if (histogramable != null)
93
			return histogramable.getPercent();
94
		return 0;
95
	}
96

  
97
	/*
98
	 * (non-Javadoc)
99
	 * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
100
	 */
101
	public String getTitle() {
102
		return PluginServices.getText(this, "calculando_histograma");
103
	}
104
	
105
	/*
106
	 * (non-Javadoc)
107
	 * @see java.lang.Object#finalize()
108
	 */
109
	protected void finalize() throws Throwable {
110
		lastHistogram           = null;
111
		histogramable           = null;
112
		super.finalize();
113
	}
114
}
0 115

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/ProcessException.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.app.basic.raster.process;
23
/**
24
 * This exception is thrown when a problem inside a raster process
25
 * is detected. 
26
 * 
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public class ProcessException extends Exception {
30
	private static final long serialVersionUID = 666908550965442025L;
31

  
32
	public ProcessException(String msg, Throwable e) {
33
		super(msg, e);
34
	}
35
	
36
	public ProcessException(String msg){
37
		super(msg);
38
	}
39
}
0 40

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.10/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/RasterProcess.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.app.basic.raster.process;
23

  
24
import java.util.Hashtable;
25

  
26
import org.gvsig.fmap.dal.coverage.RasterLocator;
27
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
28
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29
import org.gvsig.fmap.dal.coverage.process.CancelEvent;
30
import org.gvsig.fmap.dal.coverage.process.TaskEventManager;
31
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
32
import org.gvsig.gui.beans.incrementabletask.IIncrementable;
33
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent;
34
import org.gvsig.gui.beans.incrementabletask.IncrementableListener;
35
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
36
import org.gvsig.raster.fmap.layers.FLyrRaster;
37
import org.gvsig.raster.swing.RasterSwingLibrary;
38
import org.gvsig.tools.dispose.Disposable;
39
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41
/**
42
 * Clase base de todos los procesos raster. En ella se genstionan todas las
43
 * funciones comunes como incremento de la tarea, gesti?n de eventos a la tarea, 
44
 * par?metros de la tarea, etc ...
45
 * 
46
 * 18/12/2007
47
 * @author Nacho Brodin nachobrodin@gmail.com
48
 * @deprecated Use DataProcess in org.gvsig.raster.algorithm
49
 */
50
public abstract class RasterProcess implements IIncrementable, IncrementableListener, Runnable, Disposable {
51
	protected IncrementableTask incrementableTask = null;
52
	protected volatile Thread   blinker           = null;
53
	protected TaskEventManager  taskEventManager  = null;
54
	protected IProcessActions   externalActions   = null;
55
	protected Hashtable<String, Object>
56
	                            taskParams        = new Hashtable<String, Object>();
57

  
58
	private String              log               = "";
59
	private String              lastLine          = "";
60
	private long                time              = 0;
61
	private boolean             progressActive    = true;
62
	private IProcessActions     queueActions      = null;
63
	private Logger              logger            = LoggerFactory.getLogger(RasterProcess.class.toString());
64

  
65
	
66
	/**
67
	 * Crea la ventana de IncrementableTask
68
	 */
69
	public IncrementableTask getIncrementableTask() {
70
		if (incrementableTask == null) {
71
			incrementableTask = new IncrementableTask(this);
72
			incrementableTask.addIncrementableListener(this);
73
		}
74
		return incrementableTask;
75
	}
76
	
77
	/**
78
	 * Define si se puede cancelar el proceso. Por defecto es true.
79
	 * @param enabled
80
	 */
81
	public void setCancelable(boolean enabled) {
82
		getIncrementableTask().getButtonsPanel().setEnabled(ButtonsPanel.BUTTON_CANCEL, enabled);
83
	}
84
	
85
	/**
86
	 * Muestra la ventana de IncrementableTask
87
	 */
88
	public void showIncrementableWindow() {
89
		if (progressActive) {
90
			getIncrementableTask().showWindow();
91
			getIncrementableTask().start();
92
		}
93
	}
94

  
95
	/**
96
	 * Arranca el proceso de recorte de un layer
97
	 */
98
	public void start() {
99
		showIncrementableWindow();
100
		if(blinker == null)
101
			blinker = new Thread(this);
102
		blinker.start();
103
	}
104
		
105
	/**
106
	 * Proceso de carga de par?metros. Puede no hacerse una carga de par?metros 
107
	 * explicita y obtenerlos directamente de la tabla Hash cuando vayan a usarse. 
108
	 * Esto queda a elecci?n del programador. En caso de hacerse una carga de par?metros
109
	 * explicita esta llamada deber?a hacerse justo despues del constructor de la clase
110
	 * que contendr? el proceso.
111
	 */
112
	public abstract void init();
113
	
114
	/**
115
	 * Proceso
116
	 * @throws InterruptedException
117
	 */
118
	public abstract void process() throws ProcessInterruptedException, ProcessException;
119
	
120
	/**
121
	 * Obtenci?n de un objeto de resultado. Este objeto deber? ser el mismo que el que se
122
	 * pasa por par?metro en el "end" de IProcessActions. Este m?todo es util cuando la tarea no se
123
	 * lanza en un Thread (ejecutamos process directamente) y queremos recoger el resultado
124
	 * sin registrarnos al evento de finalizaci?n de tarea.
125
	 * @return objeto resultado de la tarea
126
	 */
127
	public Object getResult() {
128
		return null;
129
	}
130
	
131
	/**
132
	 * Proceso
133
	 * @throws ProcessException 
134
	 */
135
	public void execute() throws ProcessInterruptedException, ProcessException {
136
		init();
137
		process();
138
	}
139
	
140
	/**
141
	 * M?todo donde se ejecutar? el Thread. Este har? las acciones globales para 
142
	 * cualquier tarea y llamar? al m?todo execute especifico de una tarea.
143
	 */
144
	public void run() {
145
		long t1 = new java.util.Date().getTime();
146

  
147
		try {
148
			taskEventManager = RasterLocator.getManager().createRasterTask(this);
149
			execute();
150
		} catch (ProcessInterruptedException e) {
151
			if (externalActions != null)
152
				externalActions.interrupted();
153
			Thread.currentThread().interrupt();
154
		} catch (ProcessException e) {
155
			if (progressActive) {
156
				if (incrementableTask != null) {
157
					getIncrementableTask().processFinalize();
158
					incrementableTask = null;
159
				}
160
			}
161
			logger.warn(RasterLocator.getManager().getRasterUtils().getTrace(e));
162
			if(e.getMessage() != null && e.getMessage().compareTo("") != 0)
163
				RasterSwingLibrary.messageBoxError(e.getMessage(), this);
164
			else
165
				RasterSwingLibrary.messageBoxError("error_processing", this);
166
			queueActions = null;
167

  
168
		} catch (Exception e) {
169
			if (progressActive) {
170
				if (incrementableTask != null) {
171
					getIncrementableTask().processFinalize();
172
					incrementableTask = null;
173
				}
174
			}
175
			logger.warn(RasterLocator.getManager().getRasterUtils().getTrace(e));
176
			if(e.getMessage() != null && e.getMessage().compareTo("") != 0)
177
				RasterSwingLibrary.messageBoxError(e.getMessage(), this);
178
			else
179
				RasterSwingLibrary.messageBoxError("error_processing", this);
180
			queueActions = null;
181
		} finally {
182
			taskEventManager.removeTask();
183
			if (progressActive) {
184
				if (incrementableTask != null)
185
					getIncrementableTask().processFinalize();
186
			}
187
			if (queueActions != null)
188
				queueActions.end(this);
189
			time = new java.util.Date().getTime() - t1;
190
			blinker = null;
191
		}
192
	}
193
	
194
	/**
195
	 * Activa o desactiva el interfaz de progreso en el lanzamiento de la tarea como un thread.
196
	 * @param active true para activarlo o false para desactivarlo
197
	 */
198
	public void setProgressActive(boolean active){
199
		this.progressActive = active;
200
	}
201
	
202
	/**
203
	 * Obtiene el tiempo que tard? en ejecutarse la tarea 
204
	 * la ?ltima vez que se proces?
205
	 */
206
	public long getTime() {
207
		return time;
208
	}
209
	
210
	/**
211
	 * Obtiene el objeto para ejecutar acciones externar.
212
	 * @param IProcessActions
213
	 */
214
	public IProcessActions getActions() {
215
		return externalActions;
216
	}
217

  
218
	/**
219
	 * Asigna el objeto para ejecutar acciones externar.
220
	 * @param IProcessActions
221
	 */
222
	public void setActions(IProcessActions actions) {
223
		this.externalActions = actions;
224
	}
225
	
226
	/**
227
	 * Obtiene el objeto para ejecutar acciones de la cola de procesos de ejecuci?n exclusiva.
228
	 * @param IProcessActions
229
	 */
230
	public IProcessActions getUniqueProcessActions() {
231
		return queueActions;
232
	}
233

  
234
	/**
235
	 * Asigna el objeto para ejecutar acciones externar.
236
	 * @param IProcessActions
237
	 */
238
	public void setUniqueProcessActions(IProcessActions actions) {
239
		this.queueActions = actions;
240
	}
241
	
242
	/**
243
	 * Inserta una nueva l?nea en el log del cuadro de incremento de tarea
244
	 * @param line
245
	 */
246
	protected void insertLineLog(String line) {
247
		lastLine = line;
248
		log = log + line + "\n";
249
	}
250
	
251
	/**
252
	 * Obtiene la ?ltima l?nea introducida en el log del cuadro de incremento.
253
	 */
254
	public String getLabel() {
255
		return lastLine;
256
	}
257
	
258
	/**
259
	 * Obtiene el texto de log del cuadro de incremento completo.
260
	 */
261
	public String getLog() {
262
		return log;
263
	}
264
	
265
	/**
266
	 * Un evento de cancelado es enviado a la tarea cuando actionCanceled es activado. Para
267
	 * ello se crear? un objeto CancelEvent y se asignar? a la tarea en ejecuci?n. Esta lo
268
	 * procesar? cuando pueda e interrumpir? el proceso.
269
	 */
270
	public void actionCanceled(IncrementableEvent e) {
271
		taskEventManager.setEvent(new CancelEvent(this));
272
	}
273
	
274
	/**
275
	 * A?ade un par?metro a la tarea
276
	 * @param name Clave del par?metro
277
	 * @param param Objeto pasado como par?metro
278
	 */
279
	public void addParam(String name, Object param) {
280
		if (param != null)
281
			taskParams.put(name, param);
282
		else
283
			taskParams.remove(name);
284
	}
285

  
286
	/**
287
	 * Elimina un par?metro de la tarea
288
	 * @param name Clave del par?metro a eliminar
289
	 */
290
	public void removeParam(String name) {
291
		taskParams.remove(name);
292
	}
293

  
294
	/**
295
	 * Obtiene un par?metro a partir de la clave
296
	 * @param name Par?metro
297
	 * @return Par?metro
298
	 */
299
	public Object getParam(String name) {
300
		return taskParams.get(name);
301
	}
302
	
303
	/**
304
	 * Obtiene un par?metro String a partir de la clave
305
	 * @param name Par?metro
306
	 * @return Par?metro
307
	 */
308
	public String getStringParam(String name) {
309
		Object value = taskParams.get(name);
310
		return (value != null && value instanceof String) ? (String)value : null;
311
	}
312
	
313
	/**
314
	 * Obtiene un par?metro byte a partir de la clave
315
	 * @param name Par?metro
316
	 * @return Par?metro
317
	 */
318
	public byte getByteParam(String name) {
319
		Object value = taskParams.get(name);
320
		return (value != null && value instanceof Byte) ? ((Byte)value).byteValue() : 0;
321
	}
322
	
323
	/**
324
	 * Obtiene un par?metro float a partir de la clave
325
	 * @param name Par?metro
326
	 * @return Par?metro
327
	 */
328
	public float getFloatParam(String name) {
329
		Object value = taskParams.get(name);
330
		return (value != null && value instanceof Float) ? ((Float)value).floatValue() : 0F;
331
	}
332
	
333
	/**
334
	 * Obtiene un par?metro double a partir de la clave
335
	 * @param name Par?metro
336
	 * @return Par?metro
337
	 */
338
	public double getDoubleParam(String name) {
339
		Object value = taskParams.get(name);
340
		return (value != null && value instanceof Double) ? ((Double)value).doubleValue() : 0D;
341
	}
342
	
343
	/**
344
	 * Obtiene un par?metro entero a partir de la clave
345
	 * @param name Par?metro
346
	 * @return Par?metro
347
	 */
348
	public int getIntParam(String name) {
349
		Object value = taskParams.get(name);
350
		return (value != null && value instanceof Integer) ? ((Integer)value).intValue() : 0;
351
	}
352
	
353
	/**
354
	 * Obtiene un par?metro boolean a partir de la clave
355
	 * @param name Par?metro
356
	 * @return Par?metro
357
	 */
358
	public boolean getBooleanParam(String name) {
359
		Object value = taskParams.get(name);
360
		return (value != null && value instanceof Boolean) ? ((Boolean)value).booleanValue() : false;
361
	}
362
	
363
	/**
364
	 * Obtiene un par?metro int[] a partir de la clave
365
	 * @param name Par?metro
366
	 * @return Par?metro
367
	 */
368
	public int[] getIntArrayParam(String name) {
369
		Object value = taskParams.get(name);
370
		return (value != null && value instanceof int[]) ? ((int[])value) : null;
371
	}
372
	
373
	/**
374
	 * Obtiene un par?metro double[] a partir de la clave
375
	 * @param name Par?metro
376
	 * @return Par?metro
377
	 */
378
	public double[] getDoubleArrayParam(String name) {
379
		Object value = taskParams.get(name);
380
		return (value != null && value instanceof double[]) ? ((double[])value) : null;
381
	}
382
	
383
	/**
384
	 * Obtiene un par?metro capa raster a partir de la clave
385
	 * @param name Par?metro
386
	 * @return Par?metro
387
	 */
388
	public FLyrRaster getLayerParam(String name) {
389
		Object value = taskParams.get(name);
390
		return (value != null && value instanceof FLyrRaster) ? ((FLyrRaster)value) : null;
391
	}
392
	
393
	/**
394
	 * Obtiene un par?metro extent a partir de la clave
395
	 * @param name Par?metro
396
	 * @return Par?metro
397
	 */
398
	public Extent getExtentParam(String name) {
399
		Object value = taskParams.get(name);
400
		return (value != null && value instanceof Extent) ? ((Extent)value) : null;
401
	}
402
	
403
	/*
404
	 * (non-Javadoc)
405
	 * @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionResumed(org.gvsig.gui.beans.incrementabletask.IncrementableEvent)
406
	 */
407
	public void actionResumed(IncrementableEvent e) {	
408
	}
409
	
410
	/*
411
	 * (non-Javadoc)
412
	 * @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionSuspended(org.gvsig.gui.beans.incrementabletask.IncrementableEvent)
413
	 */
414
	public void actionSuspended(IncrementableEvent e) {
415
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff