Revision 3934

View differences:

org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.app/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

  
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.raster.gdal.app</artifactId>
6
	<packaging>pom</packaging>
7
	<name>${project.artifactId}</name>
8
	<parent>
9
		<groupId>org.gvsig</groupId>
10
		<artifactId>org.gvsig.raster.gdal</artifactId>
11
		<version>2.2.16</version>
12
	</parent>
13

  
14
	<modules>
15
		<module>org.gvsig.raster.gdal.app.mainplugin</module>
16
	</modules>
17

  
18
</project>
19

  
0 20

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.app/org.gvsig.raster.gdal.app.mainplugin/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.gdal.app.mainplugin</artifactId>
6
    <packaging>jar</packaging>
7
    <name>${project.artifactId}</name>
8
    <description>GDAL raster data provider for gvSIG: jpeg, tiff, png, gif.</description>
9
    <parent>
10
        <groupId>org.gvsig</groupId>
11
        <artifactId>org.gvsig.raster.gdal.app</artifactId>
12
        <version>2.2.16</version>
13
    </parent>
14

  
15
    <dependencies>
16
        <dependency>
17
            <groupId>org.gvsig</groupId>
18
            <artifactId>org.gvsig.andami</artifactId>
19
            <scope>compile</scope>
20
        </dependency>
21
        <dependency>
22
            <groupId>org.gvsig</groupId>
23
            <artifactId>org.gvsig.raster.gdal.io</artifactId>
24
            <scope>runtime</scope>
25
        </dependency>
26
    </dependencies>
27

  
28
    <properties>
29
        <svn.tags.folder>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.gdal/tags/</svn.tags.folder>
30

  
31
        <gvsig.package.info.name>Formats: GDAL raster file formats support</gvsig.package.info.name>     
32
        <gvsig.package.info.state>testing</gvsig.package.info.state>
33
        <gvsig.package.info.official>true</gvsig.package.info.official>
34
        <gvsig.package.info.operatingSystem>all</gvsig.package.info.operatingSystem>
35
        <gvsig.package.info.architecture>all</gvsig.package.info.architecture>
36
        <gvsig.package.info.categories>Raster, Formats</gvsig.package.info.categories>
37
        <gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/Raster/pool/</gvsig.package.info.poolURL>
38
        <gvsig.package.info.codealias>org.gvsig.raster.gdal.app</gvsig.package.info.codealias>
39
        <gvsig.package.info.description>${project.parent.description}</gvsig.package.info.description>
40
        <gvsig.package.info.dependencies>required: org.gvsig.gdal.app.mainplugin -ge 1, required: org.gvsig.raster.tilecache.app -ge 2</gvsig.package.info.dependencies>
41

  
42
        <gvsig.install.plugin>true</gvsig.install.plugin>
43
        <gvsig.install.plugin.package>true</gvsig.install.plugin.package>
44

  
45
    </properties>
46

  
47
    <build>
48
        <plugins>
49

  
50
            <plugin>
51
                <!-- Skip compilation tests -->
52
                <groupId>org.apache.maven.plugins</groupId>
53
                <artifactId>maven-compiler-plugin</artifactId>
54
                <executions>
55
                    <execution>
56
                        <id>default-testCompile</id>
57
                        <phase>process-test-sources</phase>
58
                        <goals>
59
                            <goal>testCompile</goal>
60
                        </goals>
61
                        <configuration>
62
                            <skip>true</skip>
63
                        </configuration>
64
                    </execution>
65
                </executions>
66
            </plugin>
67

  
68
            <plugin>
69
                <!-- Skip test execution -->
70
                <groupId>org.apache.maven.plugins</groupId>
71
                <artifactId>maven-surefire-plugin</artifactId>
72
                <configuration>
73
                    <skipTests>true</skipTests>
74
                </configuration>
75
            </plugin>
76
 
77
        </plugins>
78
    </build>
79

  
80
</project>
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.app/org.gvsig.raster.gdal.app.mainplugin/buildNumber.properties
1
#Fri Oct 16 19:09:02 CEST 2015
2
buildNumber=68
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.app/org.gvsig.raster.gdal.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<!--
2

  
3
    gvSIG. Desktop Geographic Information System.
4

  
5
    Copyright (C) 2007-2013 gvSIG Association.
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 3
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
    For any additional information, do not hesitate to contact us
23
    at info AT gvsig.com, or visit our website www.gvsig.com.
24

  
25
-->
26
<assembly>
27
    <id>gvsig-plugin-package</id>
28
    <formats>
29
        <format>zip</format>
30
    </formats>
31
    <baseDirectory>${project.artifactId}</baseDirectory>
32
    <includeBaseDirectory>true</includeBaseDirectory>
33
    <files>
34
        <file>
35
            <source>target/${project.artifactId}-${project.version}.jar</source>
36
            <outputDirectory>lib</outputDirectory>
37
        </file>
38
        <file>
39
            <source>target/package.info</source>
40
        </file>
41
    </files>
42

  
43
    <fileSets>
44
        <fileSet>
45
            <directory>src/main/resources-plugin</directory>
46
            <outputDirectory>.</outputDirectory>
47
        </fileSet>
48
    </fileSets>
49

  
50

  
51
    <dependencySets>
52
        <dependencySet>
53
            <useProjectArtifact>false</useProjectArtifact>
54
            <useTransitiveDependencies>false</useTransitiveDependencies>
55
            <outputDirectory>lib</outputDirectory>
56
            <includes>
57
                <include>org.gvsig:org.gvsig.raster.gdal.io:jar</include>
58
            </includes>
59
        </dependencySet>
60
    </dependencySets>
61

  
62
</assembly>
63

  
64

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.app/org.gvsig.raster.gdal.app.mainplugin/src/main/java/org/gvsig/raster/gdal/app/GdalExtension.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.gdal.app;
23

  
24
import org.gvsig.andami.plugins.Extension;
25

  
26
/**
27
 * Extension to add Gdal library support
28
 *
29
 * @author Nacho Brodin (nachobrodin@gmail.com)
30
 */
31
public class GdalExtension extends Extension {
32

  
33
	public void execute(String actionCommand) {
34
	}
35

  
36
	public void initialize() {
37
	}
38
	
39
	public boolean isEnabled() {
40
		return false;
41
	}
42

  
43
	public boolean isVisible() {
44
		return false;
45
	}
46

  
47
}
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.app/org.gvsig.raster.gdal.app.mainplugin/src/main/resources-plugin/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
    <depends plugin-name="org.gvsig.gdal.app.mainplugin" />
4
    <depends plugin-name="org.gvsig.raster.mainplugin" />
5
    <depends plugin-name="org.gvsig.raster.tilecache.app" optional="true" />
6
    <libraries library-dir="lib"/>
7
    <resourceBundle name="text"/>
8
    <extensions>
9
        <extension class-name="org.gvsig.raster.gdal.app.GdalExtension"
10
                           description=""
11
                           active="true"
12
                           priority="1">
13
        </extension>
14
    </extensions>
15
</plugin-config>
0 16

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/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.gdal</artifactId>
5
	<packaging>pom</packaging>
6
	<version>2.2.16</version>
7
	<name>${project.artifactId}</name>
8
	<description>GDAL raster data provider for gvSIG</description>
9
	<inceptionYear>2011</inceptionYear>
10

  
11
	<parent>
12
		<groupId>org.gvsig</groupId>
13
		<artifactId>org.gvsig.desktop</artifactId>
14
		<version>2.0.105</version>
15
	</parent>
16

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

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

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

  
48
	<build>
49
		<plugins>
50
			<plugin>
51
				<groupId>org.apache.maven.plugins</groupId>
52
				<artifactId>maven-release-plugin</artifactId>
53
				<configuration>
54
					<tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.gdal/tags/</tagBase>
55
					<goals>deploy</goals>
56
				</configuration>
57
			</plugin>
58
		</plugins>
59
	</build>
60

  
61
	<developers>
62
		<developer>
63
			<id>nbrodin</id>
64
			<name>Nacho Brodin</name>
65
			<email>nachobrodin@gmail.com</email>
66
			<roles>
67
				<role>Architect</role>
68
				<role>Developer</role>
69
			</roles>
70
		</developer>
71
	</developers>
72

  
73
	<dependencyManagement>
74
		<dependencies>
75
			<dependency>
76
				<groupId>org.gvsig</groupId>
77
				<artifactId>org.gvsig.raster</artifactId>
78
				<version>${org.gvsig.raster.version}</version>
79
				<type>pom</type>
80
				<scope>import</scope>
81
			</dependency>
82

  
83
			<dependency>
84
				<groupId>org.gvsig</groupId>
85
				<artifactId>org.gvsig.gdal</artifactId>
86
				<version>${org.gvsig.gdal.version}</version>
87
				<type>pom</type>
88
				<scope>import</scope>
89
			</dependency>
90

  
91
                        <dependency>
92
				<groupId>org.gvsig</groupId>
93
				<artifactId>org.gvsig.raster.gdal.app.common</artifactId>
94
				<version>2.2.14-SNAPSHOT</version>
95
				<type>zip</type>
96
			</dependency>
97

  
98
			<dependency>
99
				<groupId>org.gvsig</groupId>
100
				<artifactId>org.gvsig.raster.gdal.io</artifactId>
101
				<version>2.2.16</version>
102
			</dependency>
103

  
104
		</dependencies>
105
	</dependencyManagement>
106

  
107
	<modules>
108
		<module>org.gvsig.raster.gdal.io</module>
109
		<module>org.gvsig.raster.gdal.app</module>
110
	</modules>
111

  
112
</project>
113

  
0 114

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.io/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.gdal.io.DefaultGdalIOLibrary
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/addo/Jaddo.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.addo;
23
import java.io.File;
24

  
25
import org.gdal.gdal.Dataset;
26
import org.gdal.gdal.gdal;
27
import org.gvsig.jgdal.JNIBase;
28

  
29
/**
30
 * Clase para la construccion de overviews de un raster.
31
 *
32
 * 15-nov-2007
33
 * @author Nacho Brodin (nachobrodin@gmail.com)
34
 */
35
public class Jaddo extends JNIBase implements IOverviewIncrement{
36
	public final static int NEAREST = 0;
37
	public final static int AVERAGE = 1;
38
	public final static int AVERAGE_MP = 2;
39
	public final static int AVERAGE_MAGPHASE = 3;
40
	public final static int MODE = 4;
41

  
42
	private IOverviewIncrement  incrementListener = null;
43
	private int value = 0;
44

  
45
//	private native int buildOverviewsNative(int resamplingAlg, String file, int[] overviews);
46

  
47
	/**
48
	 * Construccion de overviews
49
	 */
50
	public void buildOverviews(int resamplingAlg, String file, int[] overviews)
51
		throws BuildingOverviewsException, WritingException {
52
		File f = new File(file);
53
		if(!f.exists() || !f.isFile())
54
			throw new BuildingOverviewsException("File does not exist.");
55
		if(!f.canWrite())
56
			throw new WritingException("File is not writeable");
57
		Dataset data = gdal.Open(file);
58
		if(data.BuildOverviews(overviews) >= 0)
59
			throw new BuildingOverviewsException("Problems building overviews");
60
	}
61

  
62
	/**
63
	 * Devuelve el porcentaje del incremento.
64
	 * @return int
65
	 */
66
	public int getPercent() {
67
		return value;
68
	}
69

  
70
	/**
71
	 * Asigna el porcentaje de incremento de la construccion de overview.
72
	 * Esto se hace automaticamente desde el callback que asigna el porcentaje.
73
	 */
74
	public void setPercent(int value) {
75
		this.value = value;
76
		if(incrementListener != null)
77
			incrementListener.setPercent(value);
78
	}
79

  
80
	/**
81
	 * Asigna el listener para la asignacion del incremento
82
	 * @param incr IOverviewIncrement
83
	 */
84
	public void setIncrementListener(IOverviewIncrement incr) {
85
		this.incrementListener = incr;
86
	}
87
}
0 88

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/addo/WritingException.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.addo;
23

  
24
/**
25
 * Es generada no se puede escribir las overviews
26
 * 
27
 * @author Nacho Brodin (nachobrodin@gmail.com).<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
28
 * @version 0.0
29
 * @link http://www.gvsig.org
30
 */
31

  
32

  
33
public class WritingException extends Exception {
34

  
35
	public WritingException(String msg){
36
		super(msg);
37
	}
38
	
39
	
40
}
0 41

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/addo/IOverviewIncrement.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.addo;
23

  
24
/**
25
 * Interfaz para la asignacion y recuperacion del incremento
26
 * de la tarea.
27
 *
28
 * 17-nov-2007
29
 * @author Nacho Brodin (nachobrodin@gmail.com)
30
 */
31
public interface IOverviewIncrement {
32
	/**
33
	 * Devuelve el porcentaje del incremento
34
	 * @return int
35
	 */
36
	public int getPercent();
37
	
38
	/**
39
	 * Asigna el porcentaje de incremento de la construccion de overview.
40
	 * Esto se hace automaticamente desde el callback que asigna el porcentaje. 
41
	 */
42
	public void setPercent(int value);
43
}
0 44

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/addo/BuildingOverviewsException.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.addo;
23

  
24
/**
25
 * Es generada cuando hay algun problema en la construccion de 
26
 * las overviews y la funcion nativa devuelve 0
27
 * 
28
 * @author Nacho Brodin (nachobrodin@gmail.com).<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
29
 * @version 0.0
30
 * @link http://www.gvsig.org
31
 */
32
public class BuildingOverviewsException extends Exception {
33

  
34
	public BuildingOverviewsException(String msg) {
35
		super(msg);
36
	}
37
	
38
}
0 39

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/overview/GdalOverviewBuilder.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.gdal.overview;
23

  
24
import org.gvsig.addo.BuildingOverviewsException;
25
import org.gvsig.addo.IOverviewIncrement;
26
import org.gvsig.addo.Jaddo;
27
import org.gvsig.addo.WritingException;
28
import org.gvsig.fmap.dal.coverage.exception.OverviewException;
29
import org.gvsig.fmap.dal.coverage.process.BaseIncrementableTask;
30
import org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder;
31

  
32
/**
33
 * Servicios ofrecidos por el proceso de construcci?n de overviews. Esta
34
 * implementaci?n usa gdal para construir las overviews.
35
 * 
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class GdalOverviewBuilder implements OverviewBuilder {
39
	private Jaddo        build         = new Jaddo();
40
	private int          value         = 0;
41

  
42
	/**
43
	 * Bindings between an IOverviewIncrement and a BaseIncrementableTask
44
	 * @author Nacho Brodin (nachobrodin@gmail.com)
45
	 */
46
	class ProcessBinding implements IOverviewIncrement {
47
		private BaseIncrementableTask  task = null;
48
		
49
		public ProcessBinding(BaseIncrementableTask task) {
50
			this.task = task;	
51
		}
52
		
53
		public int getPercent() {
54
			return task.getPercent();
55
		}
56

  
57
		public void setPercent(int value) {
58
			task.setPercent(value);
59
		}
60
	}
61
	
62
	/*
63
	 * (non-Javadoc)
64
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#buildOverviews(int, java.lang.String, int[])
65
	 */
66
	public void buildOverviews(int resamplingAlg, String file, int[] overviews)
67
			throws OverviewException {
68
		try {
69
			build.buildOverviews(resamplingAlg, file, overviews);
70
		} catch (BuildingOverviewsException e) {
71
			throw new OverviewException("Error building overviews", e);
72
		} catch (WritingException e) {
73
			throw new OverviewException("Error writing overviews", e);
74
		}
75
	}
76

  
77
	/*
78
	 * (non-Javadoc)
79
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#getPercent()
80
	 */
81
	public int getPercent() {
82
		return value;
83
	}
84

  
85
	/*
86
	 * (non-Javadoc)
87
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#setIncrementListener(org.gvsig.addo.IOverviewIncrement)
88
	 */
89
	public void setIncrementListener(BaseIncrementableTask incr) {
90
		build.setIncrementListener(new ProcessBinding(incr));
91
	}
92

  
93
	/*
94
	 * (non-Javadoc)
95
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#setPercent(int)
96
	 */
97
	public void setPercent(int value) {
98
		this.value = value;
99
	}
100
}
0 101

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/DefaultGdalIOLibrary.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.gdal.io;
23

  
24
import org.gvsig.fmap.dal.DALFileLibrary;
25
import org.gvsig.fmap.dal.DALLibrary;
26
import org.gvsig.fmap.dal.coverage.RasterLocator;
27
import org.gvsig.raster.gdal.overview.GdalOverviewBuilder;
28
import org.gvsig.raster.gdal.util.DefaultCRSUtils;
29
import org.gvsig.raster.impl.store.AbstractNewRasterStoreParameters;
30
import org.gvsig.tools.ToolsLibrary;
31
import org.gvsig.tools.library.AbstractLibrary;
32
import org.gvsig.tools.library.Library;
33
import org.gvsig.tools.library.LibraryException;
34
/**
35
 *
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class DefaultGdalIOLibrary extends AbstractLibrary {	
39

  
40
	public DefaultGdalIOLibrary() {
41
		super(DefaultGdalIOLibrary.class,Library.TYPE.IMPL);
42
		require(ToolsLibrary.class);
43
		require(DALLibrary.class);
44
		require(DALFileLibrary.class);
45
	}
46
	
47
	@Override
48
	protected void doInitialize() throws LibraryException {
49
		//RasterLibrary.wakeUp();
50
	}
51

  
52
	@Override
53
	protected void doPostInitialize() throws LibraryException {
54
		//AbstractRasterFileDataParameters.registerDynClass();
55
		AbstractNewRasterStoreParameters.registerDynClass();
56
		
57
		// Registro de los drivers de lectura
58
		GdalProvider.register();
59
		
60
		// Registro de los drivers de escritura
61
		GdalWriter.register();
62
		JpegWriter.register();
63
		PngWriter.register();
64
		GdalDataParameters.registerDynClass();
65
		
66
		//Register GdalOverviewBuilder
67
		RasterLocator.getManager().getProviderServices().registerOverviewBuilderImplementation(
68
				"GDAL",
69
				new GdalOverviewBuilder());
70
		
71
		//Register CRSUtils
72
		RasterLocator.getManager().getProviderServices().registerCRSUtilImplementation(
73
						new DefaultCRSUtils());
74
	}
75
}
0 76

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.16/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalNative.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.gdal.io;
23

  
24
import java.awt.Color;
25
import java.awt.Rectangle;
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.NoninvertibleTransformException;
28
import java.awt.geom.Point2D;
29
import java.io.IOException;
30
import java.util.ArrayList;
31
import java.util.List;
32

  
33
import org.gdal.gdal.Dataset;
34
import org.gdal.gdal.gdal;
35
import org.gdal.gdal.gdalJNI;
36
import org.gdal.ogr.ogrJNI;
37
import org.gvsig.fmap.dal.coverage.RasterLibrary;
38
import org.gvsig.fmap.dal.coverage.RasterLocator;
39
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
40
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
41
import org.gvsig.fmap.dal.coverage.datastruct.ColorItem;
42
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
43
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
44
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
45
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
46
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
47
import org.gvsig.fmap.dal.coverage.util.FileUtils;
48
import org.gvsig.jgdal.Gdal;
49
import org.gvsig.jgdal.GdalBuffer;
50
import org.gvsig.jgdal.GdalColorEntry;
51
import org.gvsig.jgdal.GdalColorTable;
52
import org.gvsig.jgdal.GdalDataset;
53
import org.gvsig.jgdal.GdalException;
54
import org.gvsig.jgdal.GdalRasterBand;
55
import org.gvsig.jgdal.GeoTransform;
56
import org.gvsig.raster.impl.datastruct.ColorItemImpl;
57
import org.gvsig.raster.impl.datastruct.DefaultNoData;
58
import org.gvsig.raster.impl.datastruct.ExtentImpl;
59
import org.gvsig.raster.impl.process.RasterTask;
60
import org.gvsig.raster.impl.process.RasterTaskQueue;
61
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
62
import org.gvsig.raster.impl.store.properties.DataStoreColorTable;
63
import org.gvsig.raster.impl.store.properties.DataStoreMetadata;
64
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
65
import org.gvsig.tools.dispose.Disposable;
66
import org.gvsig.tools.task.TaskStatus;
67
/**
68
 * Soporte 'nativo' para ficheros desde GDAL.
69
 * 
70
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
71
 * @author Nacho Brodin (nachobrodin@gmail.com)
72
 */
73
public class GdalNative extends Gdal implements Disposable {
74
//	private boolean isInitialized = false;
75
	private String                       fileName                = null;
76
	private String                       shortName               = "";
77
	public 	GeoTransform                 trans                   = null;
78
	public int                           width                   = 0, height = 0;
79
	public double                        originX                 = 0D, originY = 0D;
80
	public String                        version                 = "";
81
	protected int                        rBandNr                 = 1, gBandNr = 2, bBandNr = 3, aBandNr = 4;
82
	private int[]                        dataType                = null;
83
	DataStoreMetadata                    metadata                = null;
84
	protected boolean                    georeferenced           = true;
85
	
86
	/**
87
	 * Vectores que contiene los desplazamientos de un pixel cuando hay supersampling.
88
	 * , es decir el n?mero de pixels de pantalla que tiene un pixel de imagen. Como todos
89
	 * los pixeles no tienen el mismo ancho y alto ha de meterse en un array y no puede ser
90
	 * una variable. Adem?s hay que tener en cuenta que el primer y ?ltimo pixel son de 
91
	 * distinto tama?o que el resto.   
92
	 */
93
	public int[]                              stepArrayX             = null;
94
	public int[]                              stepArrayY             = null;
95
	protected GdalRasterBand[]                gdalBands              = null;
96
	private double                            lastReadLine           = -1;
97
	private int                               overviewWidth          = -1;
98
	private int                               overviewHeight         = -1;
99
	private int                               currentViewWidth       = -1;
100
	private int                               currentViewHeight      = -1;
101
	private double                            currentViewX           = 0D;
102
	private double                            viewportScaleX         = 0D;
103
	private double                            viewportScaleY         = 0D;
104
	private double                            stepX                  = 0D;
105
	private double                            stepY                  = 0D;
106
	public boolean                            isSupersampling        = false;
107
	private boolean                           open                   = false;
108
	/**
109
	 * Estado de transparencia del raster.
110
	 */
111
	protected DataStoreTransparency           fileTransparency       = null;
112
	protected DataStoreColorTable             palette                = null;
113
	protected DataStoreColorInterpretation    colorInterpr           = null;
114
	protected AffineTransform                 ownTransformation      = null;
115
	protected AffineTransform                 externalTransformation = new AffineTransform();
116
	
117
	public static int getGdalTypeFromRasterBufType(int rasterBufType) {
118
		switch (rasterBufType) {
119
			case Buffer.TYPE_BYTE: return Gdal.GDT_Byte;
120
			case Buffer.TYPE_USHORT: return Gdal.GDT_UInt16;
121
			case Buffer.TYPE_SHORT: return Gdal.GDT_Int16;
122
			case Buffer.TYPE_INT: return Gdal.GDT_Int32;
123
			case Buffer.TYPE_FLOAT: return Gdal.GDT_Float32;
124
			case Buffer.TYPE_DOUBLE: return Gdal.GDT_Float64;
125
			case Buffer.TYPE_UNDEFINED: return Gdal.GDT_Unknown;
126
			case Buffer.TYPE_IMAGE: return Gdal.GDT_Byte;
127
		}
128
		return Gdal.GDT_Unknown;
129
	}
130
	
131
	/**
132
	 * Conversi?n de los tipos de datos de gdal a los tipos de datos de RasterBuf
133
	 * @param gdalType Tipo de dato de gdal
134
	 * @return Tipo de dato de RasterBuf
135
	 */
136
	public static int getRasterBufTypeFromGdalType(int gdalType) {
137
		switch (gdalType) {
138
			case 1:// Eight bit unsigned integer GDT_Byte = 1
139
				return Buffer.TYPE_BYTE;
140

  
141
			case 3:// Sixteen bit signed integer GDT_Int16 = 3,
142
				return Buffer.TYPE_SHORT;
143

  
144
			case 2:// Sixteen bit unsigned integer GDT_UInt16 = 2
145
				//return RasterBuffer.TYPE_USHORT;
146
				return Buffer.TYPE_SHORT; //Apa?o para usar los tipos de datos que soportamos
147

  
148
			case 5:// Thirty two bit signed integer GDT_Int32 = 5
149
				return Buffer.TYPE_INT;
150

  
151
			case 6:// Thirty two bit floating point GDT_Float32 = 6
152
				return Buffer.TYPE_FLOAT;
153

  
154
			case 7:// Sixty four bit floating point GDT_Float64 = 7
155
				return Buffer.TYPE_DOUBLE;
156

  
157
				// TODO:Estos tipos de datos no podemos gestionarlos. Habria que definir
158
				// el tipo complejo y usar el tipo long que de momento no se gasta.
159
			case 4:// Thirty two bit unsigned integer GDT_UInt32 = 4,
160
				return Buffer.TYPE_INT;
161
				//return RasterBuffer.TYPE_UNDEFINED; // Deberia devolver un Long
162

  
163
			case 8:// Complex Int16 GDT_CInt16 = 8
164
			case 9:// Complex Int32 GDT_CInt32 = 9
165
			case 10:// Complex Float32 GDT_CFloat32 = 10
166
			case 11:// Complex Float64 GDT_CFloat64 = 11
167
				return Buffer.TYPE_UNDEFINED;
168
		}
169
		return Buffer.TYPE_UNDEFINED;
170
	}
171
	
172
	/**
173
	 * Overview usada en el ?ltimo setView
174
	 */
175
	int currentOverview = -1;
176
	
177
	public GdalNative(String fName) throws GdalException, IOException {
178
		super();
179
		init(fName);
180
	}
181
	
182
	private static long initializeGdal(String fName) throws GdalException {
183
		gdalJNI.AllRegister();
184
		ogrJNI.RegisterAll();
185
		Dataset data = gdal.Open(fName, 1);
186
		if (data == null)
187
			throw new GdalException("Error en la apertura del fichero. El fichero no tiene un formato v?lido.");
188
		
189
		return GdalDataset.getCPtr(data);
190
	}
191

  
192
//	public GdalNative(long cPtr, String fName) throws GdalException, IOException {
193
//		super(cPtr);
194
//		isInitialized = true;
195
//		init(fName);
196
//	}
197
	
198
	private void init(String fName) throws GdalException, IOException {
199
		gdalJNI.AllRegister();
200
		ogrJNI.RegisterAll();
201
		fileName = fName;
202
		open(fName, GA_ReadOnly);
203
		open = true;
204
		if (getDataset() == null)
205
			throw new GdalException("Error en la apertura del fichero. El fichero no tiene un formato v?lido.");
206
//		if(isInitialized){
207
//		ext = RasterUtilities.getExtensionFromFileName(fName);
208
		width = getRasterXSize();
209
		height = getRasterYSize();
210

  
211
		int[] dt = new int[getRasterCount()];
212
		for (int i = 0; i < getRasterCount(); i++)
213
			dt[i] = this.getRasterBand(i + 1).getRasterDataType();
214
		setDataType(dt);
215
		shortName = getDriverShortName();
216
		colorInterpr = new DataStoreColorInterpretation(getRasterCount());
217
		fileTransparency = new DataStoreTransparency(colorInterpr);
218
		metadata = new DataStoreMetadata(getMetadata(), colorInterpr);
219

  
220
		// Asignamos la interpretaci?n de color leida por gdal a cada banda. Esto
221
		// nos sirve para saber que banda de la imagen va asignada a cada banda de
222
		// visualizaci?n (ARGB)
223
		metadata.initNoDataByBand(getRasterCount());
224
		for (int i = 0; i < getRasterCount(); i++) {
225
			GdalRasterBand rb = getRasterBand(i + 1);
226
			String colorInt = getColorInterpretationName(rb.getRasterColorInterpretation());
227
			metadata.setNoDataEnabled(rb.existsNoDataValue());
228
			if(rb.existsNoDataValue()) {
229
				metadata.setNoDataValue(i, rb.getRasterNoDataValue());
230
				metadata.setNoDataEnabled(rb.existsNoDataValue());
231
			}
232
			colorInterpr.setColorInterpValue(i, colorInt);
233
			if (colorInt.equals("Alpha"))
234
				fileTransparency.setTransparencyBand(i);
235

  
236
			if (rb.getRasterColorTable() != null && palette == null) {
237
				palette = new DataStoreColorTable(gdalColorTable2ColorItems(rb.getRasterColorTable()), false);
238
//				fileTransparency.setTransparencyRangeList(palette.getTransparencyRange());
239
			}
240
		}
241
		fileTransparency.setTransparencyByPixelFromMetadata(metadata);
242

  
243
		try {
244
			trans = getGeoTransform();
245

  
246
			boolean isCorrect = false;
247
			for (int i = 0; i < trans.adfgeotransform.length; i++)
248
				if (trans.adfgeotransform[i] != 0)
249
					isCorrect = true;
250
			if (!isCorrect)
251
				throw new GdalException("");
252
			
253
			double psX = trans.adfgeotransform[1];
254
			double psY = trans.adfgeotransform[5];
255
			double rotX = trans.adfgeotransform[4];
256
			double rotY = trans.adfgeotransform[2];
257
			double offX = trans.adfgeotransform[0];
258
			double offY = trans.adfgeotransform[3];
259
			
260
			ownTransformation = new AffineTransform(psX, rotX, rotY, psY, offX, offY);
261
					//trans.adfgeotransform[1], trans.adfgeotransform[4], trans.adfgeotransform[2], trans.adfgeotransform[5], trans.adfgeotransform[0], trans.adfgeotransform[3]);
262
			externalTransformation = (AffineTransform) ownTransformation.clone();
263
			overviewWidth = width;
264
			overviewHeight = height;
265

  
266
			this.georeferenced = true;
267
		} catch (GdalException exc) {
268
			// Transformaci�n para ficheros sin georreferenciaci�n. Se invierte la Y
269
			// ya que las WC decrecen de
270
			// arriba a abajo y los pixeles crecen de arriba a abajo
271
			ownTransformation = new AffineTransform(1, 0, 0, -1, 0, height);
272
			externalTransformation = (AffineTransform) ownTransformation.clone();
273
			overviewWidth = width;
274
			overviewHeight = height;
275
			this.georeferenced = false;
276
		}
277
//		}
278
	}
279
	
280
	/**
281
	 * Returns true if this provider is open and false if don't
282
	 * @return
283
	 */
284
	public boolean isOpen() {
285
		return open;
286
	}
287
	
288
	/**
289
	 * Obtiene el flag que informa de si el raster tiene valor no data o no.
290
	 * Consultar� todas las bandas del mismo y si alguna tiene valor no data
291
	 * devuelve true sino devolver� false.
292
	 * @return true si tiene valor no data y false si no lo tiene
293
	 * @throws GdalException
294
	 */
295
	public boolean existsNoDataValue() throws GdalException {
296
		for (int i = 0; i < getRasterCount(); i++) {
297
			GdalRasterBand rb = getRasterBand(i + 1);
298
			if (rb.existsNoDataValue())
299
				return true;
300
		}
301
		return false;
302
	}
303
	
304
	/**
305
	 * Obtiene el flag que informa de si el raster tiene valor no data o no
306
	 * en una banda concreta.
307
	 * @return true si tiene valor no data en esa banda y false si no lo tiene
308
	 * @param band Posici�n de la banda a consultar (0..n)
309
	 * @throws GdalException
310
	 */
311
	public boolean existsNoDataValue(int band) throws GdalException {
312
		GdalRasterBand rb = getRasterBand(band + 1);
313
		return rb.existsNoDataValue();
314
	}
315

  
316
	/**
317
	 * Gets nodata value
318
	 * @return
319
	 */
320
	public NoData getNoDataValue() {
321
		Number value = null;
322
		int type = getRasterBufTypeFromGdalType(getDataType()[0]);
323
		if (metadata != null && metadata.isNoDataEnabled() && metadata.getNoDataValue().length > 0) {
324
			switch (type) {
325
			case Buffer.TYPE_BYTE:
326
				if (metadata == null || metadata.getNoDataValue().length == 0)
327
					value = new Byte(RasterLibrary.defaultByteNoDataValue);
328
				else
329
					value = new Byte((byte)metadata.getNoDataValue()[0]);
330
				break;
331
			case Buffer.TYPE_SHORT:
332
				if (metadata == null || metadata.getNoDataValue().length == 0)
333
					value = new Short(RasterLibrary.defaultShortNoDataValue);
334
				else
335
					value = new Short((short)metadata.getNoDataValue()[0]);
336
				break;
337
			case Buffer.TYPE_INT:
338
				if (metadata == null || metadata.getNoDataValue().length == 0)
339
					value = new Integer((int)RasterLibrary.defaultIntegerNoDataValue);
340
				else
341
					value = new Integer((int)metadata.getNoDataValue()[0]);
342
				break;
343
			case Buffer.TYPE_FLOAT:
344
				if (metadata == null || metadata.getNoDataValue().length == 0)
345
					value = new Float(RasterLibrary.defaultFloatNoDataValue);
346
				else
347
					value = new Float(metadata.getNoDataValue()[0]);
348
				break;
349
			case Buffer.TYPE_DOUBLE:
350
				if (metadata == null || metadata.getNoDataValue().length == 0)
351
					value = new Double(RasterLibrary.defaultFloatNoDataValue);
352
				else
353
					value = new Double(metadata.getNoDataValue()[0]);
354
				break;
355
			}
356
		}
357

  
358
		NoData nodata = new DefaultNoData(value, value, fileName);
359
		nodata.setNoDataTransparent(false);
360
		return nodata;
361
	}
362

  
363
	/**
364
	 * Asigna el tipo de dato
365
	 * @param dt entero que representa el tipo de dato
366
	 */
367
	public void setDataType(int[] dt) { 
368
		dataType = dt; 
369
	}
370
	
371
	/**
372
	 * Obtiene el tipo de dato
373
	 * @return entero que representa el tipo de dato
374
	 */
375
	public int[] getDataType() { 
376
		return dataType; 
377
	}
378
	
379
	/**
380
	 * Gets the color interpretation
381
	 * @return
382
	 */
383
	public ColorInterpretation getColorInterpretation() { 
384
		return colorInterpr; 
385
	}
386
	
387
	/**
388
	 * Gets the color table
389
	 * @return
390
	 */
391
	public ColorTable getColorTable() {
392
		return palette;
393
	}
394
	
395
	/**
396
	 * Obtiene un punto 2D con las coordenadas del raster a partir de uno en coordenadas
397
	 * del punto real.
398
	 * Supone rasters no girados
399
	 * @param pt	punto en coordenadas del punto real
400
	 * @return	punto en coordenadas del raster
401
	 */
402
	public Point2D worldToRasterWithoutRot(Point2D pt) {
403
		Point2D p = new Point2D.Double();
404
		AffineTransform at = new AffineTransform(	externalTransformation.getScaleX(), 0, 
405
													0, externalTransformation.getScaleY(), 
406
													externalTransformation.getTranslateX(), externalTransformation.getTranslateY());
407
		try {
408
			at.inverseTransform(pt, p);
409
		} catch (NoninvertibleTransformException e) {
410
			return pt;
411
		}
412
		return p;
413
	}
414
		
415
	/**
416
	 * Obtiene un punto 2D con las coordenadas del raster a partir de uno en coordenadas
417
	 * del punto real.
418
	 * Supone rasters no girados
419
	 * @param pt	punto en coordenadas del punto real
420
	 * @return	punto en coordenadas del raster
421
	 */
422
	public Point2D worldToRaster(Point2D pt) {
423
		Point2D p = new Point2D.Double();
424
		try {
425
			externalTransformation.inverseTransform(pt, p);
426
		} catch (NoninvertibleTransformException e) {
427
			return pt;
428
		}
429
		return p;
430
	}
431
	
432
	/**
433
	 * Obtiene un punto del raster en coordenadas pixel a partir de un punto en coordenadas
434
	 * reales. 
435
	 * @param pt Punto en coordenadas reales
436
	 * @return Punto en coordenadas pixel.
437
	 */
438
	public Point2D rasterToWorld(Point2D pt) {
439
		Point2D p = new Point2D.Double();
440
		externalTransformation.transform(pt, p);
441
		return p;
442
	}
443
	
444
	/**
445
	 * Calcula el overview a usar. Hay que tener en cuenta que tenemos que tener calculadas las variables
446
	 * viewPortScale, currentFullWidth y currentFulHeight
447
	 * @param coordenada pixel expresada en double que indica la posici�n superior izquierda
448
	 * @throws GdalException
449
	 */
450
	private void calcOverview(Point2D tl, Point2D br) throws GdalException {
451
		gdalBands[0] = getRasterBand(1);
452
		currentOverview = -1;
453
		if (gdalBands[0].getOverviewCount() > 0) {
454
			GdalRasterBand ovb = null;
455
			for (int i = gdalBands[0].getOverviewCount() - 1; i > 0; i--) {
456
				ovb = gdalBands[0].getOverview(i);
457
				if (ovb.getRasterBandXSize() > getRasterXSize() * viewportScaleX) {
458
					currentOverview = i;
459
					viewportScaleX *= ((double) width / (double) ovb.getRasterBandXSize());
460
					viewportScaleY *= ((double) height / (double) ovb.getRasterBandYSize());
461
					stepX = 1D / viewportScaleX;
462
					stepY = 1D / viewportScaleY;
463
					overviewWidth = ovb.getRasterBandXSize();
464
					overviewHeight = ovb.getRasterBandYSize();
465
					currentViewX = Math.min(tl.getX(), br.getX());
466
					lastReadLine = Math.min(tl.getY(), br.getY());
467
					break;
468
				}
469
			}
470
		}
471
	}
472
	
473
	public void setView(double dWorldTLX, double dWorldTLY,
474
						double dWorldBRX, double dWorldBRY,
475
						int nWidth, int nHeight) throws GdalException {
476
		overviewWidth = width;
477
		overviewHeight = height;
478
		Point2D tl = worldToRaster(new Point2D.Double(dWorldTLX, dWorldTLY));
479
		Point2D br = worldToRaster(new Point2D.Double(dWorldBRX, dWorldBRY));
480
		// Calcula cual es la primera l�nea a leer;
481
		currentViewWidth = nWidth;
482
		currentViewHeight = nHeight;
483
//		wcWidth = Math.abs(br.getX() - tl.getX());
484

  
485
		currentViewX = Math.min(tl.getX(), br.getX());
486

  
487
		viewportScaleX = (double) currentViewWidth / (br.getX() - tl.getX());
488
		viewportScaleY = (double) currentViewHeight / (br.getY() - tl.getY());
489
		stepX = 1D / viewportScaleX;
490
		stepY = 1D / viewportScaleY;
491

  
492
		lastReadLine = Math.min(tl.getY(), br.getY());
493
		
494
		//Para lectura del renderizado (ARGB). readWindow selecciona las bandas que necesita.
495

  
496
		// calcula el overview a usar
497
		gdalBands = new GdalRasterBand[4];
498
		calcOverview(tl, br);
499
	}
500
	
501
	/**
502
	 * Selecciona bandas y overview en el objeto GdalRasterBand[] para el n�mero de bandas solicitado.
503
	 * @param nbands N�mero de bandas solicitado.
504
	 * @throws GdalException
505
	 */
506
	public void selectGdalBands(int nbands) throws GdalException {
507
		gdalBands = new GdalRasterBand[nbands];
508
		// Selecciona las bandas y los overviews necesarios
509
		gdalBands[0] = getRasterBand(1);
510
		for (int i = 0; i < nbands; i++)
511
			gdalBands[i] = gdalBands[0];
512

  
513
		assignDataTypeFromGdalRasterBands(gdalBands);
514
//		setDataType(gdalBands[0].getRasterDataType());
515

  
516
		for (int i = 2; i <= nbands; i++) {
517
			if (getRasterCount() >= i) {
518
				gdalBands[i - 1] = getRasterBand(i);
519
				for (int j = i; j < nbands; j++)
520
					gdalBands[j] = gdalBands[i - 1];
521
			}
522
		}
523

  
524
		if (currentOverview > 0) {
525
			gdalBands[0] = gdalBands[0].getOverview(currentOverview);
526
			for (int i = 2; i <= nbands; i++) {
527
				if (getRasterCount() >= i)
528
					gdalBands[i - 1] = gdalBands[i - 1].getOverview(currentOverview);
529
			}
530
		}
531
	}
532
		
533
	int lastY = -1;
534
	
535
	/**
536
	 * Lee una l�nea de bytes
537
	 * @param line Buffer donde se cargan los datos
538
	 * @param initOffset Desplazamiento inicial desde el margen inzquierdo. Esto es necesario para cuando
539
	 * se supersamplea ya que cada pixel de imagen ocupa muchos pixeles de pantalla y puede empezar a dibujarse
540
	 * por la izquierda a mitad de pixel
541
	 * @param gdalBuffer Buffer con la l�nea de datos original
542
	 */
543
	private void readLine(byte[][] line, double initOffset, GdalBuffer[] gdalBuffer) {
544
		double j = 0D;
545
		int i = 0;
546
		for (int iBand = 0; iBand < gdalBuffer.length; iBand++) {
547
			for (i = 0, j = initOffset; i < currentViewWidth && j < gdalBuffer[0].getSize(); i++, j += stepX) {
548
				line[iBand][i] = gdalBuffer[iBand].buffByte[(int) j];
549
			}
550
		}
551
	}
552
	
553
	/**
554
	 * Lee una l�nea de shorts
555
	 * @param line Buffer donde se cargan los datos
556
	 * @param initOffset Desplazamiento inicial desde el margen inzquierdo. Esto es necesario para cuando
557
	 * se supersamplea ya que cada pixel de imagen ocupa muchos pixeles de pantalla y puede empezar a dibujarse
558
	 * por la izquierda a mitad de pixel
559
	 * @param gdalBuffer Buffer con la l�nea de datos original
560
	 */
561
	private void readLine(short[][] line, double initOffset, GdalBuffer[] gdalBuffer) {
562
		double j = 0D;
563
		int i = 0;
564
		for (int iBand = 0; iBand < gdalBuffer.length; iBand++) {
565
			for (i = 0, j = initOffset; i < currentViewWidth && j < gdalBuffer[0].getSize(); i++, j += stepX) {
566
				line[iBand][i] = (short) (gdalBuffer[iBand].buffShort[(int) j] & 0xffff);
567
			}
568
		}
569
	}
570

  
571
	/**
572
	 * Lee una l�nea de ints
573
	 * @param line Buffer donde se cargan los datos
574
	 * @param initOffset Desplazamiento inicial desde el margen inzquierdo. Esto es necesario para cuando
575
	 * se supersamplea ya que cada pixel de imagen ocupa muchos pixeles de pantalla y puede empezar a dibujarse
576
	 * por la izquierda a mitad de pixel
577
	 * @param gdalBuffer Buffer con la l�nea de datos original
578
	 */
579
	private void readLine(int[][] line, double initOffset, GdalBuffer[] gdalBuffer) {
580
		double j = 0D;
581
		int i = 0;
582
		for (int iBand = 0; iBand < gdalBuffer.length; iBand++) {
583
			for (i = 0, j = initOffset; i < currentViewWidth && j < gdalBuffer[0].getSize(); i++, j += stepX) {
584
				line[iBand][i] = (gdalBuffer[iBand].buffInt[(int) j] & 0xffffffff);
585
			}
586
		}
587
	}
588

  
589
	/**
590
	 * Lee una l�nea de float
591
	 * @param line Buffer donde se cargan los datos
592
	 * @param initOffset Desplazamiento inicial desde el margen izquierdo. Esto es necesario para cuando
593
	 * se supersamplea ya que cada pixel de imagen ocupa muchos pixeles de pantalla y puede empezar a dibujarse
594
	 * por la izquierda a mitad de pixel
595
	 * @param gdalBuffer Buffer con la l�nea de datos original
596
	 */
597
	private void readLine(float[][] line, double initOffset, GdalBuffer[] gdalBuffer) {
598
		double j = 0D;
599
		int i = 0;
600
		for (int iBand = 0; iBand < gdalBuffer.length; iBand++) {
601
			for (i = 0, j = initOffset; i < currentViewWidth && j < gdalBuffer[0].getSize(); i++, j += stepX) {
602
				line[iBand][i] = gdalBuffer[iBand].buffFloat[(int) j];
603
			}
604
		}
605
	}
606
	
607
	/**
608
	 * Lee una l�nea de doubles
609
	 * @param line Buffer donde se cargan los datos
610
	 * @param initOffset Desplazamiento inicial desde el margen inzquierdo. Esto es necesario para cuando
611
	 * se supersamplea ya que cada pixel de imagen ocupa muchos pixeles de pantalla y puede empezar a dibujarse
612
	 * por la izquierda a mitad de pixel
613
	 * @param gdalBuffer Buffer con la l�nea de datos original
614
	 */
615
	private void readLine(double[][] line, double initOffset, GdalBuffer[] gdalBuffer) {
616
		double j = 0D;
617
		int i = 0;
618
		for (int iBand = 0; iBand < gdalBuffer.length; iBand++) {
619
			for (i = 0, j = initOffset; i < currentViewWidth && j < gdalBuffer[0].getSize(); i++, j += stepX) {
620
				line[iBand][i] = gdalBuffer[iBand].buffDouble[(int) j];
621
			}
622
		}
623
	}
624

  
625
	/**
626
	 * Lee una l�nea completa del raster y devuelve un array del tipo correcto. Esta funci�n es util
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff