Revision 3746
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.raster.gdal.io</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>${project.artifactId}</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.raster.gdal</artifactId> |
|
10 |
<version>2.2.11-SNAPSHOT</version> |
|
11 |
</parent> |
|
12 |
|
|
13 |
<dependencies> |
|
14 |
<dependency> |
|
15 |
<groupId>org.gdal</groupId> |
|
16 |
<artifactId>gdal</artifactId> |
|
17 |
<scope>compile</scope> |
|
18 |
</dependency> |
|
19 |
<dependency> |
|
20 |
<groupId>org.gvsig</groupId> |
|
21 |
<artifactId>org.gvsig.raster.cache.lib.api</artifactId> |
|
22 |
<scope>compile</scope> |
|
23 |
</dependency> |
|
24 |
<dependency> |
|
25 |
<groupId>org.gvsig</groupId> |
|
26 |
<artifactId>org.gvsig.raster.lib.api</artifactId> |
|
27 |
<scope>compile</scope> |
|
28 |
</dependency> |
|
29 |
<dependency> |
|
30 |
<groupId>org.gvsig</groupId> |
|
31 |
<artifactId>org.gvsig.raster.lib.impl</artifactId> |
|
32 |
<scope>compile</scope> |
|
33 |
</dependency> |
|
34 |
<dependency> |
|
35 |
<groupId>org.gvsig</groupId> |
|
36 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
|
37 |
<scope>compile</scope> |
|
38 |
</dependency> |
|
39 |
<dependency> |
|
40 |
<groupId>org.gvsig</groupId> |
|
41 |
<artifactId>org.gvsig.remoteclient</artifactId> |
|
42 |
<scope>compile</scope> |
|
43 |
</dependency> |
|
44 |
<dependency> |
|
45 |
<groupId>org.gvsig</groupId> |
|
46 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
47 |
<scope>compile</scope> |
|
48 |
</dependency> |
|
49 |
<dependency> |
|
50 |
<groupId>org.gvsig</groupId> |
|
51 |
<artifactId>org.gvsig.projection.api</artifactId> |
|
52 |
<scope>compile</scope> |
|
53 |
</dependency> |
|
54 |
<dependency> |
|
55 |
<groupId>org.gvsig</groupId> |
|
56 |
<artifactId>org.gvsig.projection.cresques.impl</artifactId> |
|
57 |
<scope>runtime</scope> |
|
58 |
</dependency> |
|
59 |
<dependency> |
|
60 |
<groupId>org.gvsig</groupId> |
|
61 |
<artifactId>org.gvsig.compat.api</artifactId> |
|
62 |
<scope>compile</scope> |
|
63 |
</dependency> |
|
64 |
<dependency> |
|
65 |
<groupId>org.gvsig</groupId> |
|
66 |
<artifactId>org.gvsig.compat.se</artifactId> |
|
67 |
<scope>compile</scope> |
|
68 |
</dependency> |
|
69 |
<dependency> |
|
70 |
<groupId>org.gvsig</groupId> |
|
71 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
72 |
<scope>compile</scope> |
|
73 |
</dependency> |
|
74 |
<dependency> |
|
75 |
<groupId>org.gvsig</groupId> |
|
76 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
77 |
<scope>compile</scope> |
|
78 |
</dependency> |
|
79 |
<dependency> |
|
80 |
<groupId>org.gvsig</groupId> |
|
81 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
|
82 |
<scope>compile</scope> |
|
83 |
</dependency> |
|
84 |
<dependency> |
|
85 |
<groupId>org.gvsig</groupId> |
|
86 |
<artifactId>org.gvsig.fmap.dal.spi</artifactId> |
|
87 |
<scope>compile</scope> |
|
88 |
</dependency> |
|
89 |
<dependency> |
|
90 |
<groupId>org.gvsig</groupId> |
|
91 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
92 |
<scope>compile</scope> |
|
93 |
</dependency> |
|
94 |
<dependency> |
|
95 |
<groupId>org.gvsig</groupId> |
|
96 |
<artifactId>org.gvsig.fmap.geometry.generalpath</artifactId> |
|
97 |
<scope>runtime</scope> |
|
98 |
</dependency> |
|
99 |
<dependency> |
|
100 |
<groupId>org.gvsig</groupId> |
|
101 |
<artifactId>org.gvsig.fmap.geometry.operation</artifactId> |
|
102 |
<scope>runtime</scope> |
|
103 |
</dependency> |
|
104 |
</dependencies> |
|
105 |
|
|
106 |
|
|
107 |
</project> |
|
0 | 108 |
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/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/trunk/org.gvsig.raster.gdal/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/trunk/org.gvsig.raster.gdal/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/trunk/org.gvsig.raster.gdal/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/trunk/org.gvsig.raster.gdal/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/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/util/DefaultCRSUtils.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.util; |
|
23 |
|
|
24 |
import org.cresques.cts.ICRSFactory; |
|
25 |
import org.cresques.cts.IProjection; |
|
26 |
import org.gvsig.fmap.crs.CRSFactory; |
|
27 |
import org.gvsig.fmap.dal.coverage.util.CRSUtils; |
|
28 |
import org.gvsig.jogr.CrsGdalException; |
|
29 |
import org.gvsig.jogr.OGRException; |
|
30 |
import org.gvsig.jogr.OGRSpatialReference; |
|
31 |
import org.slf4j.LoggerFactory; |
|
32 |
/** |
|
33 |
* Esta clase se encarga de hacer la conversion entre Wkt e IProjection. |
|
34 |
* |
|
35 |
* El uso se hace mediante dos llamadas estaticas que son: convertIProjectionToWkt y |
|
36 |
* convertWktToIProjection. |
|
37 |
* |
|
38 |
* Antes de usarlos, hay que saber si tenemos acceso a gvSIG e intentar coger el factory desde all?. |
|
39 |
* Ya que su uso consume tiempo y espacio de memoria y es preferible reaprovechar ese objeto ya |
|
40 |
* creado. Esto se hace con setCRSFactory. |
|
41 |
* |
|
42 |
* En caso de no asignarse el ya existente, el crear? uno interno y lo dejara en una variable estatica. |
|
43 |
* |
|
44 |
* @version 11/07/2008 |
|
45 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
46 |
*/ |
|
47 |
public class DefaultCRSUtils implements CRSUtils { |
|
48 |
private ICRSFactory factory = null; |
|
49 |
|
|
50 |
public void setCRSFactory(ICRSFactory factory) { |
|
51 |
this.factory = factory; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Devuelve el CRSFactory asignado desde fuera o creado desde dentro, todo depende de como se haya |
|
56 |
* usado. |
|
57 |
* |
|
58 |
* @param code |
|
59 |
* @return |
|
60 |
*/ |
|
61 |
private IProjection getCRS(String code) { |
|
62 |
if (factory == null) |
|
63 |
factory = CRSFactory.getCRSFactory(); //new ProjectionPool(); |
|
64 |
return factory.get(code); |
|
65 |
} |
|
66 |
|
|
67 |
public IProjection convertWktToIProjection(String wkt) { |
|
68 |
if (wkt == null || wkt.equals("")) |
|
69 |
return null; |
|
70 |
|
|
71 |
String code = null; |
|
72 |
String name = null; |
|
73 |
|
|
74 |
OGRSpatialReference oSRSSource = new OGRSpatialReference(); |
|
75 |
try { |
|
76 |
OGRSpatialReference.importFromWkt(oSRSSource, wkt); |
|
77 |
|
|
78 |
code = oSRSSource.getAuthorityCode("PROJCS"); |
|
79 |
if (code == null) |
|
80 |
code = oSRSSource.getAuthorityCode("GEOGCS"); |
|
81 |
name = oSRSSource.getAuthorityName("PROJCS"); |
|
82 |
if (name == null) |
|
83 |
name = oSRSSource.getAuthorityName("GEOGCS"); |
|
84 |
try { |
|
85 |
if(name != null && code != null) |
|
86 |
return getCRS(name + ":" + code); |
|
87 |
} catch (NumberFormatException ex) { |
|
88 |
return null; |
|
89 |
} |
|
90 |
} catch (OGRException e) { |
|
91 |
LoggerFactory.getLogger(getClass().getName()).debug("Problemas obteniendo el c?digo EPSG", e); |
|
92 |
} catch (CrsGdalException e) { |
|
93 |
LoggerFactory.getLogger(getClass().getName()).debug("Problemas obteniendo el c?digo EPSG", e); |
|
94 |
} |
|
95 |
|
|
96 |
return null; |
|
97 |
} |
|
98 |
|
|
99 |
public String convertIProjectionToWkt(IProjection projection) { |
|
100 |
if(projection == null) |
|
101 |
return null; |
|
102 |
OGRSpatialReference oSRSSource = new OGRSpatialReference(); |
|
103 |
|
|
104 |
String code = projection.getAbrev(); |
|
105 |
String name = code.substring(0, code.indexOf(":")); |
|
106 |
code = code.substring(code.indexOf(":") + 1); |
|
107 |
|
|
108 |
try { |
|
109 |
do |
|
110 |
if (name.equals("EPSG")) { |
|
111 |
OGRSpatialReference.importFromEPSG(oSRSSource, Integer.parseInt(code)); |
|
112 |
break; |
|
113 |
} |
|
114 |
while (false); |
|
115 |
return OGRSpatialReference.exportToWkt(oSRSSource); |
|
116 |
} catch (CrsGdalException e) { |
|
117 |
LoggerFactory.getLogger(getClass().getName()).debug("Problemas obteniendo el c?digo WKT", e); |
|
118 |
} catch (NumberFormatException e) { |
|
119 |
LoggerFactory.getLogger(getClass().getName()).debug("Problemas obteniendo el c?digo WKT", e); |
|
120 |
} catch (OGRException e) { |
|
121 |
LoggerFactory.getLogger(getClass().getName()).debug("Problemas obteniendo el c?digo WKT", e); |
|
122 |
} |
|
123 |
return null; |
|
124 |
} |
|
125 |
} |
|
0 | 126 |
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/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/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalProvider.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.geom.AffineTransform; |
|
25 |
import java.io.BufferedReader; |
|
26 |
import java.io.File; |
|
27 |
import java.io.FileNotFoundException; |
|
28 |
import java.io.FileReader; |
|
29 |
import java.io.IOException; |
|
30 |
|
|
31 |
import org.gvsig.fmap.dal.DALFileLocator; |
|
32 |
import org.gvsig.fmap.dal.DALLocator; |
|
33 |
import org.gvsig.fmap.dal.DataStore; |
|
34 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
35 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
36 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
37 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
|
38 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
|
39 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
40 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
41 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
|
42 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
43 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
44 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
|
45 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
46 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
47 |
import org.gvsig.jgdal.GdalException; |
|
48 |
import org.gvsig.metadata.MetadataLocator; |
|
49 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
50 |
import org.gvsig.raster.impl.buffer.SpiRasterQuery; |
|
51 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
|
52 |
import org.gvsig.raster.impl.provider.AbstractRasterProvider; |
|
53 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
54 |
import org.gvsig.raster.impl.provider.tile.FileTileServer; |
|
55 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
|
56 |
import org.gvsig.raster.impl.store.DefaultRasterStore; |
|
57 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
|
58 |
import org.gvsig.raster.impl.store.properties.DataStoreMetadata; |
|
59 |
import org.gvsig.tools.ToolsLocator; |
|
60 |
import org.gvsig.tools.dynobject.DynObject; |
|
61 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
62 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
63 |
import org.slf4j.Logger; |
|
64 |
import org.slf4j.LoggerFactory; |
|
65 |
/** |
|
66 |
* This class represents the data access for gdal formats. |
|
67 |
* |
|
68 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
69 |
*/ |
|
70 |
public class GdalProvider extends AbstractRasterProvider { |
|
71 |
public static String NAME = "Gdal Store"; |
|
72 |
public static String DESCRIPTION = "Gdal Raster file"; |
|
73 |
public static final String METADATA_DEFINITION_NAME = "GdalStore"; |
|
74 |
private static final Logger logger = LoggerFactory.getLogger(GdalProvider.class); |
|
75 |
|
|
76 |
public static final String FORMAT_GTiff = "GTiff"; |
|
77 |
public static final String FORMAT_VRT = "VRT"; |
|
78 |
public static final String FORMAT_NITF = "NITF"; |
|
79 |
public static final String FORMAT_HFA = "HFA"; |
|
80 |
public static final String FORMAT_ELAS = "ELAS"; |
|
81 |
public static final String FORMAT_MEM = "MEM"; |
|
82 |
public static final String FORMAT_BMP = "BMP"; |
|
83 |
public static final String FORMAT_PCIDSK = "PCIDSK"; |
|
84 |
public static final String FORMAT_ILWIS = "ILWIS"; |
|
85 |
public static final String FORMAT_HDF4 = "HDF4Image"; |
|
86 |
public static final String FORMAT_PNM = "PNM"; |
|
87 |
public static final String FORMAT_ENVI = "ENVI"; |
|
88 |
public static final String FORMAT_EHDR = "EHdr"; |
|
89 |
public static final String FORMAT_PAUX = "PAux"; |
|
90 |
public static final String FORMAT_MFF = "MFF"; |
|
91 |
public static final String FORMAT_MFF2 = "MFF2"; |
|
92 |
public static final String FORMAT_BT = "BT"; |
|
93 |
public static final String FORMAT_IDA = "IDA"; |
|
94 |
public static final String FORMAT_RMF = "RMF"; |
|
95 |
public static final String FORMAT_RST = "RST"; |
|
96 |
public static final String FORMAT_LEVELLER = "Leveller"; |
|
97 |
public static final String FORMAT_TERRAGEN = "Terragen"; |
|
98 |
public static final String FORMAT_ERS = "ERS"; |
|
99 |
public static final String FORMAT_INGR = "INGR"; |
|
100 |
public static final String FORMAT_GSAG = "GSAG"; |
|
101 |
public static final String FORMAT_GSBG = "GSBG"; |
|
102 |
public static final String FORMAT_ADRG = "ADRG"; |
|
103 |
public static final String FORMAT_JP2 = "JPEG2000"; |
|
104 |
public static final String FORMAT_GRD = "GRD"; |
|
105 |
public static final int BAND_HEIGHT = 64; |
|
106 |
protected GdalNative file = null; |
|
107 |
private Extent viewRequest = null; |
|
108 |
protected static String[] formatList = null; |
|
109 |
|
|
110 |
public static void register() { |
|
111 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
112 |
registerFormats(); |
|
113 |
|
|
114 |
ExtensionPoint point = extensionPoints.get("DefaultRasterProvider"); |
|
115 |
point.append("reader", GdalProvider.NAME, GdalProvider.class); |
|
116 |
|
|
117 |
RasterLocator.getManager().getProviderServices().registerFileProvidersTiled(GdalProvider.class); |
|
118 |
|
|
119 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
120 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
|
121 |
dataman.registerStoreProvider(NAME, |
|
122 |
GdalProvider.class, GdalDataParameters.class); |
|
123 |
} |
|
124 |
|
|
125 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
|
126 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
|
127 |
NAME, DESCRIPTION, |
|
128 |
GdalFilesystemServerExplorer.class); |
|
129 |
|
|
130 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
|
131 |
} |
|
132 |
|
|
133 |
private static void registerFormats() { |
|
134 |
formatList = new String[] { |
|
135 |
"bmp", |
|
136 |
"gif", |
|
137 |
"tif", |
|
138 |
"tiff", |
|
139 |
"jpg", |
|
140 |
"jpeg", |
|
141 |
"png", |
|
142 |
"vrt", |
|
143 |
"dat", // Envi |
|
144 |
"lan", // Erdas |
|
145 |
"gis", // Erdas |
|
146 |
"img", // Erdas |
|
147 |
"pix", // PCI Geomatics |
|
148 |
"aux", // PCI Geomatics |
|
149 |
"adf", // ESRI Grids |
|
150 |
"mpr", // Ilwis |
|
151 |
"mpl", // Ilwis |
|
152 |
"map", // PC Raster |
|
153 |
"asc", |
|
154 |
"pgm", //Ficheros PNM en escala de grises |
|
155 |
"ppm", //Ficheros PNM en RGB |
|
156 |
"rst", //IDRISIS |
|
157 |
"rmf", //Raster Matrix Format |
|
158 |
"nos", |
|
159 |
"kap", |
|
160 |
"hdr", |
|
161 |
"raw", |
|
162 |
"ers", |
|
163 |
"xml", |
|
164 |
"grd", |
|
165 |
"txt"/*, |
|
166 |
"jp2"*/}; |
|
167 |
for (int i = 0; i < formatList.length; i++) |
|
168 |
RasterLocator.getManager().getProviderServices().addFormat(formatList[i], GdalProvider.class); |
|
169 |
} |
|
170 |
|
|
171 |
public String[] getFormatList() { |
|
172 |
return formatList; |
|
173 |
} |
|
174 |
|
|
175 |
/** |
|
176 |
* Returns true if the extension is supported and false if doesn't |
|
177 |
* @param ext |
|
178 |
* @return |
|
179 |
*/ |
|
180 |
public boolean isExtensionSupported(String ext) { |
|
181 |
if(ext.indexOf(".") != -1) |
|
182 |
ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length()); |
|
183 |
for (int i = 0; i < formatList.length; i++) { |
|
184 |
if(formatList[i].compareTo(ext) == 0) |
|
185 |
return true; |
|
186 |
} |
|
187 |
return false; |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* Mandatory constructor to instantiate an empty provider |
|
192 |
*/ |
|
193 |
public GdalProvider() { |
|
194 |
} |
|
195 |
|
|
196 |
/** |
|
197 |
* Constructor. Abre el dataset. |
|
198 |
* @param proj Proyecci?n |
|
199 |
* @param fName Nombre del fichero |
|
200 |
* @throws NotSupportedExtensionException |
|
201 |
*/ |
|
202 |
public GdalProvider(String params) throws NotSupportedExtensionException { |
|
203 |
super(params); |
|
204 |
if(params instanceof String) { |
|
205 |
GdalDataParameters p = new GdalDataParameters(); |
|
206 |
p.setURI((String)params); |
|
207 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
|
208 |
.createDynObject( |
|
209 |
MetadataLocator.getMetadataManager().getDefinition( |
|
210 |
DataStore.METADATA_DEFINITION_NAME))); |
|
211 |
init(p, null); |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
215 |
public GdalProvider (GdalDataParameters params, |
|
216 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException { |
|
217 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
|
218 |
.createDynObject( |
|
219 |
MetadataLocator.getMetadataManager().getDefinition( |
|
220 |
DataStore.METADATA_DEFINITION_NAME))); |
|
221 |
init(params, storeServices); |
|
222 |
} |
|
223 |
|
|
224 |
public GdalProvider(AbstractRasterDataParameters params, |
|
225 |
DataStoreProviderServices storeServices, DynObject metadata) { |
|
226 |
super(params, storeServices, metadata); |
|
227 |
} |
|
228 |
|
|
229 |
/** |
|
230 |
* Creates file references and loads structures with the information and metadata |
|
231 |
* @param params load parameters |
|
232 |
* @throws NotSupportedExtensionException |
|
233 |
*/ |
|
234 |
public void init (AbstractRasterDataParameters params, |
|
235 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException { |
|
236 |
try { |
|
237 |
setParam(storeServices, params); |
|
238 |
validRmf(params.getURI()); |
|
239 |
setFName(translateFileName(params.getURI())); |
|
240 |
// GdalNative aux = new GdalNative(translateFileName(params.getURI())); |
|
241 |
// long ptro = aux.getPtro(); |
|
242 |
// aux.delete(); |
|
243 |
file = new GdalNative(translateFileName(params.getURI())); |
|
244 |
setColorInterpretation(file.colorInterpr); |
|
245 |
setColorTable(file.palette); |
|
246 |
noData = file.getNoDataValue(); |
|
247 |
String wktProjection = file.getProjectionRef(); |
|
248 |
if(wktProjection != null && wktProjection != "") { |
|
249 |
try { |
|
250 |
if(RasterLocator.getManager().isCRSUtilSupported()) |
|
251 |
proj = RasterLocator.getManager().getCRSUtils().convertWktToIProjection(wktProjection); |
|
252 |
} catch (Exception e) { |
|
253 |
logger.info("Error reading WKT from the raster provider", e); |
|
254 |
} |
|
255 |
} |
|
256 |
//CrsWkt crs = new CrsWkt(wktProjection); |
|
257 |
//IProjection proj = CRSFactory.getCRS("EPSG:23030"); |
|
258 |
ownTransformation = file.getOwnTransformation(); |
|
259 |
externalTransformation = (AffineTransform)ownTransformation.clone(); |
|
260 |
load(); |
|
261 |
|
|
262 |
if(file != null) |
|
263 |
bandCount = file.getRasterCount(); |
|
264 |
} catch (GdalException e) { |
|
265 |
throw new NotSupportedExtensionException("Extension not supported", e); |
|
266 |
} catch(Exception e) { |
|
267 |
System.out.println("Error en GdalOpen"); |
|
268 |
e.printStackTrace(); |
|
269 |
file = null; |
|
270 |
} |
|
271 |
|
|
272 |
//Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf |
|
273 |
int[] dt = new int[file.getDataType().length]; |
|
274 |
for (int i = 0; i < dt.length; i++) |
|
275 |
dt[i] = GdalNative.getRasterBufTypeFromGdalType(file.getDataType()[i]); |
|
276 |
setDataType(dt); |
|
277 |
|
|
278 |
super.init(); |
|
279 |
|
|
280 |
try { |
|
281 |
loadFromRmf(getRmfBlocksManager()); |
|
282 |
} catch (ParsingException e) { |
|
283 |
//No lee desde rmf |
|
284 |
logger.debug("Problems reading from the RMF file", e); |
|
285 |
} |
|
286 |
} |
|
287 |
|
|
288 |
/** |
|
289 |
* Comprueba si el fichero abierto es un RasterMetaFile o una imagen |
|
290 |
* raster. |
|
291 |
* @throws GdalException |
|
292 |
*/ |
|
293 |
private void validRmf(String file) throws GdalException { |
|
294 |
if(file.endsWith(".rmf")) { |
|
295 |
File f = new File(file); |
|
296 |
try { |
|
297 |
FileReader fr = new FileReader(f); |
|
298 |
BufferedReader br = new BufferedReader(fr); |
|
299 |
char[] buffer = new char[5]; |
|
300 |
br.read(buffer); |
|
301 |
StringBuffer st = new StringBuffer(new String(buffer)); |
|
302 |
br.close(); |
|
303 |
fr.close(); |
|
304 |
if(st.toString().equals("<?xml")) |
|
305 |
throw new GdalException("RasterMetaFile"); |
|
306 |
} catch (FileNotFoundException e) { |
|
307 |
throw new GdalException("File Not Found"); |
|
308 |
} catch (IOException e) { |
|
309 |
throw new GdalException(""); |
|
310 |
} |
|
311 |
} |
|
312 |
} |
|
313 |
|
|
314 |
public RasterProvider load() { |
|
315 |
return this; |
|
316 |
} |
|
317 |
|
|
318 |
public boolean isOpen() { |
|
319 |
if(file != null && file.isOpen()) |
|
320 |
return true; |
|
321 |
return false; |
|
322 |
} |
|
323 |
|
|
324 |
public String translateFileName(String fileName) { |
|
325 |
if(fileName.endsWith("hdr")) |
|
326 |
return fileName.substring(0, fileName.lastIndexOf(".")); |
|
327 |
return fileName; |
|
328 |
} |
|
329 |
|
|
330 |
/** |
|
331 |
* Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci?n |
|
332 |
* de la vista asignada ya que la petici?n viene en coordenadas del fichero .rmf y la vista (v) |
|
333 |
* ha de estar en coordenadas del fichero. |
|
334 |
*/ |
|
335 |
public void setView(Extent e) { |
|
336 |
viewRequest = new ExtentImpl(e); |
|
337 |
} |
|
338 |
|
|
339 |
public Extent getView() { |
|
340 |
return viewRequest; |
|
341 |
} |
|
342 |
|
|
343 |
public double getWidth() { |
|
344 |
return file.width; |
|
345 |
} |
|
346 |
|
|
347 |
public double getHeight() { |
|
348 |
return file.height; |
|
349 |
} |
|
350 |
|
|
351 |
/** |
|
352 |
* Read a line from the file |
|
353 |
* @param line |
|
354 |
* @param band |
|
355 |
* @return |
|
356 |
* @throws InvalidSetViewException |
|
357 |
* @throws FileNotOpenException |
|
358 |
* @throws RasterDriverException |
|
359 |
* @Deprecated This operation is deprecated because is not useful and in the future |
|
360 |
* it will not be maintained. The abstract operation has dissapear |
|
361 |
*/ |
|
362 |
public Object readCompleteLine(int line, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
363 |
if(line > this.getHeight() || band > this.getBandCount()) |
|
364 |
throw new InvalidSetViewException("Request out of grid"); |
|
365 |
|
|
366 |
try{ |
|
367 |
return file.readCompleteLine(line, band); |
|
368 |
}catch(GdalException e){ |
|
369 |
throw new RasterDriverException("Error reading data from Gdal library"); |
|
370 |
} |
|
371 |
} |
|
372 |
|
|
373 |
public Object readBlock(int pos, int blockHeight, double scale) |
|
374 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException { |
|
375 |
if(pos < 0) |
|
376 |
throw new InvalidSetViewException("Request out of grid"); |
|
377 |
|
|
378 |
if((pos + blockHeight) > getHeight()) |
|
379 |
blockHeight = Math.abs(((int)getHeight()) - pos); |
|
380 |
try{ |
|
381 |
return file.readBlock(pos, blockHeight, scale); |
|
382 |
}catch(GdalException e){ |
|
383 |
throw new RasterDriverException("Error reading data from Gdal library"); |
|
384 |
} |
|
385 |
} |
|
386 |
|
|
387 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
388 |
if(file != null){ |
|
389 |
if(x < 0 || y < 0 || x >= file.width || y >= file.height) |
|
390 |
throw new InvalidSetViewException("Request out of grid"); |
|
391 |
Object[] data = file.getData(x, y); |
|
392 |
return data[band]; |
|
393 |
} |
|
394 |
throw new FileNotOpenException("GdalNative not exist"); |
|
395 |
} |
|
396 |
|
|
397 |
@Override |
|
398 |
public void loadBuffer(SpiRasterQuery q) |
|
399 |
throws ProcessInterruptedException, RasterDriverException { |
|
400 |
setView(q.getAdjustedRequestBoundingBox()); |
|
401 |
|
|
402 |
try { |
|
403 |
file.readWindow(q.getBufferForProviders(), |
|
404 |
q.getBandList(), |
|
405 |
q.getAdjustedRequestBoundingBox(), |
|
406 |
q.getAdjustedRequestPxWindow(), |
|
407 |
q.getTaskStatus()); |
|
408 |
} catch (GdalException e) { |
|
409 |
throw new RasterDriverException("Error reading data", e); |
|
410 |
} |
|
411 |
|
|
412 |
} |
|
413 |
|
|
414 |
public int getBlockSize(){ |
|
415 |
if(file != null) |
|
416 |
return file.getBlockSize(); |
|
417 |
else |
|
418 |
return 0; |
|
419 |
} |
|
420 |
|
|
421 |
public DataStoreMetadata getMetadata() { |
|
422 |
if(file != null) |
|
423 |
return file.metadata; |
|
424 |
else |
|
425 |
return null; |
|
426 |
} |
|
427 |
|
|
428 |
public Transparency getTransparency() { |
|
429 |
return file.fileTransparency; |
|
430 |
} |
|
431 |
|
|
432 |
public boolean isGeoreferenced() { |
|
433 |
if(file != null) |
|
434 |
return file.georeferenced; |
|
435 |
else |
|
436 |
return false; |
|
437 |
} |
|
438 |
|
|
439 |
/** |
|
440 |
* Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar? |
|
441 |
* el valor de esta variable cada vez que dibuja. |
|
442 |
* @return true si se ha supersampleado y false si no se ha hecho. |
|
443 |
*/ |
|
444 |
public boolean isSupersampling() { |
|
445 |
if(file != null) |
|
446 |
return file.isSupersampling; |
|
447 |
else |
|
448 |
return false; |
|
449 |
} |
|
450 |
|
|
451 |
public GdalNative getNative(){ |
|
452 |
return file; |
|
453 |
} |
|
454 |
|
|
455 |
public void setAffineTransform(AffineTransform t){ |
|
456 |
super.setAffineTransform(t); |
|
457 |
file.setExternalTransform(t); |
|
458 |
} |
|
459 |
|
|
460 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
|
461 |
if(band >= getBandCount()) |
|
462 |
throw new BandAccessException("Wrong band"); |
|
463 |
try { |
|
464 |
return file.getRasterBand(band + 1).getOverviewCount(); |
|
465 |
} catch (GdalException e) { |
|
466 |
throw new RasterDriverException(""); |
|
467 |
} |
|
468 |
} |
|
469 |
|
|
470 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
|
471 |
if (band >= getBandCount()) |
|
472 |
throw new BandAccessException("Wrong band"); |
|
473 |
try { |
|
474 |
if (overview >= file.getRasterBand(band + 1).getOverviewCount()) |
|
475 |
throw new BandAccessException("Wrong overview count"); |
|
476 |
return file.getRasterBand(band + 1).getOverview(overview).getRasterBandXSize(); |
|
477 |
} catch (GdalException e) { |
|
478 |
throw new RasterDriverException(""); |
|
479 |
} |
|
480 |
} |
|
481 |
|
|
482 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
|
483 |
if (band >= getBandCount()) |
|
484 |
throw new BandAccessException("Wrong band"); |
|
485 |
try { |
|
486 |
if (overview >= file.getRasterBand(band + 1).getOverviewCount()) |
|
487 |
throw new BandAccessException("Wrong overview count"); |
|
488 |
return file.getRasterBand(band + 1).getOverview(overview).getRasterBandYSize(); |
|
489 |
} catch (GdalException e) { |
|
490 |
throw new RasterDriverException(""); |
|
491 |
} |
|
492 |
} |
|
493 |
|
|
494 |
public boolean isOverviewsSupported() { |
|
495 |
return true; |
|
496 |
} |
|
497 |
|
|
498 |
public boolean isReproyectable() { |
|
499 |
return true; |
|
500 |
} |
|
501 |
|
|
502 |
public boolean needEnhanced() { |
|
503 |
return (getDataType()[0] != Buffer.TYPE_BYTE); |
|
504 |
//Desconozco pq raz?n estaba esta condici?n. Quiz?s haya que volver a a?adirla |
|
505 |
//Eliminada 30/5/2013 |
|
506 |
//|| (getBandCount() == 1 && getDataType()[0] == Buffer.TYPE_BYTE)); |
|
507 |
} |
|
508 |
|
|
509 |
public String getProviderName() { |
|
510 |
return NAME; |
|
511 |
} |
|
512 |
|
|
513 |
public void setStatus(RasterProvider provider) { |
|
514 |
if(provider instanceof GdalProvider) { |
|
515 |
//Not implemented yet |
|
516 |
} |
|
517 |
} |
|
518 |
|
|
519 |
public TileServer getTileServer() { |
|
520 |
if(tileServer == null) { |
|
521 |
DefaultRasterStore store = new DefaultRasterStore(); |
|
522 |
store.setProvider(this); |
|
523 |
tileServer = new FileTileServer(store); |
|
524 |
// tileServer.setFileSuffix("rmf"); |
|
525 |
} |
|
526 |
return tileServer; |
|
527 |
} |
|
528 |
|
|
529 |
public void close() { |
|
530 |
if(file != null){ |
|
531 |
file.dispose(); |
|
532 |
} |
|
533 |
try { |
|
534 |
finalize(); |
|
535 |
} catch (Throwable e) { |
|
536 |
} |
|
537 |
} |
|
538 |
|
|
539 |
protected void finalize() throws Throwable { |
|
540 |
file = null; |
|
541 |
viewRequest = null; |
|
542 |
if(formatList != null) { |
|
543 |
for (int i = 0; i < formatList.length; i++) { |
|
544 |
formatList[i] = null; |
|
545 |
} |
|
546 |
formatList = null; |
|
547 |
} |
|
548 |
super.finalize(); |
|
549 |
} |
|
550 |
} |
|
0 | 551 |
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/JpegWriter.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.geom.AffineTransform; |
|
25 |
import java.io.File; |
|
26 |
import java.io.IOException; |
|
27 |
|
|
28 |
import org.cresques.cts.IProjection; |
|
29 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
30 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
31 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
32 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
|
33 |
import org.gvsig.jgdal.Gdal; |
|
34 |
import org.gvsig.jgdal.GdalDriver; |
|
35 |
import org.gvsig.jgdal.GdalException; |
|
36 |
import org.gvsig.raster.gdal.io.features.JpegFeatures; |
|
37 |
import org.gvsig.raster.impl.store.WriteFileFormatFeatures; |
|
38 |
import org.gvsig.raster.impl.store.writer.DefaultRasterWriter; |
|
39 |
import org.gvsig.raster.util.DefaultProviderServices; |
|
40 |
import org.gvsig.tools.ToolsLocator; |
|
41 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
42 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
43 |
/** |
|
44 |
* Driver para la escritura de Jpeg. |
|
45 |
* Este driver utiliza GdalWriter para salvar Jpeg. |
|
46 |
* La escritura de un jpeg no es posible utilizando un servidor de datos |
|
47 |
* como el que usan los drivers comunes por lo que ser? necesario salvar antes |
|
48 |
* a Tif con el driver de Gdal para posteriormente convertir la imagen completa |
|
49 |
* a jpg. |
|
50 |
* |
|
51 |
* @version 22/07/2008 |
|
52 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
53 |
*/ |
|
54 |
public class JpegWriter extends DefaultRasterWriter { |
|
55 |
|
|
56 |
// Datos de registro de drivers |
|
57 |
public static void register() { |
|
58 |
DefaultProviderServices pInfo = (DefaultProviderServices)RasterLocator.getManager().getProviderServices(); |
|
59 |
ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager(); |
|
60 |
ExtensionPoint point=extensionPoints.get("RasterWriter"); |
|
61 |
point.append("jpg", "", JpegWriter.class); |
|
62 |
pInfo.getFileFeature().put("jpg", new JpegFeatures()); |
|
63 |
} |
|
64 |
|
|
65 |
private GdalWriter gdalWriter = null; |
|
66 |
private String outTif = null; |
|
67 |
private String outJpg = null; |
|
68 |
|
|
69 |
/** |
|
70 |
* Carga los par?metros de este driver. |
|
71 |
*/ |
|
72 |
public void loadParams(String ident) { |
|
73 |
WriteFileFormatFeatures wfff = (WriteFileFormatFeatures) pInfo.getFileFeature().get(ident); |
|
74 |
wfff.loadParams(); |
|
75 |
driverParams = wfff.getParams(); |
|
76 |
} |
|
77 |
|
|
78 |
/* |
|
79 |
* (non-Javadoc) |
|
80 |
* @see org.gvsig.fmap.dal.coverage.store.RasterWriter#getProviderName() |
|
81 |
*/ |
|
82 |
public String getProviderName() { |
|
83 |
return GdalProvider.NAME; |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* Constructor para la obtenci?n de par?metros del driver |
|
88 |
* @param drvType Tipo de driver |
|
89 |
*/ |
|
90 |
public JpegWriter(String fileName) { |
|
91 |
ident = fileUtil.getExtensionFromFileName(fileName); |
|
92 |
driver = ((WriteFileFormatFeatures) pInfo.getFileFeature().get(ident)).getDriverName(); |
|
93 |
gdalWriter = new GdalWriter(fileName); |
|
94 |
|
|
95 |
loadParams(ident); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* Constructor para salvar datos servidos por el cliente |
|
100 |
* @param dataWriter Objeto servidor de datos para el driver de escritura |
|
101 |
* @param outSizeX N?mero de pixels en X de la imagen de salida |
|
102 |
* @param outSizeY N?mero de pixels en Y de la imagen de salida |
|
103 |
* @param outFilename Fichero de salida |
|
104 |
* @param extentMaxX Posici?n en X m?xima del extent |
|
105 |
* @param extentMinX Posici?n en X m?nima del extent |
|
106 |
* @param extentMaxY Posici?n en Y m?xima del extent |
|
107 |
* @param extentMinY Posici?n en Y m?nima del extent |
|
108 |
* @param nBands N?mero de bandas |
|
109 |
* @param drvType Tipo de driver |
|
110 |
* @throws GdalException |
|
111 |
* @throws IOException |
|
112 |
*/ |
|
113 |
public JpegWriter(DataServerWriter dataWriter, |
|
114 |
String outFileName, |
|
115 |
Integer nBands, |
|
116 |
AffineTransform at, |
|
117 |
Integer outSizeX, |
|
118 |
Integer outSizeY, |
|
119 |
Integer dataType, |
|
120 |
Params params, |
|
121 |
IProjection proj, |
|
122 |
Boolean geo)throws GdalException, IOException { |
|
123 |
ident = fileUtil.getExtensionFromFileName(outFileName); |
|
124 |
driver = ((WriteFileFormatFeatures) pInfo.getFileFeature().get(ident)).getDriverName(); |
|
125 |
outJpg = outFileName; |
|
126 |
outTif = outFileName.substring(0, outFileName.lastIndexOf(".")); |
|
127 |
outTif += ".tif"; |
|
128 |
|
|
129 |
gdalWriter = new GdalWriter(dataWriter, outTif, nBands, at, outSizeX, outSizeY, dataType, params, proj, geo); |
|
130 |
if (params == null) |
|
131 |
loadParams(ident); |
|
132 |
else |
|
133 |
this.driverParams = params; |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Asigna el tipo de driver con el que se salvar? la imagen |
|
138 |
* @param drvType Tipo de driver |
|
139 |
*/ |
|
140 |
public void setDriverType(String drvType) { |
|
141 |
gdalWriter.setDriverType(drvType); |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile. |
|
146 |
* @throws IOException |
|
147 |
*/ |
|
148 |
public void fileWrite() throws IOException, ProcessInterruptedException { |
|
149 |
gdalWriter.fileWrite(); |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Realiza una copia en el formato especificado. |
|
154 |
* @throws IOException |
|
155 |
*/ |
|
156 |
public static void createCopy(GdalDriver driverDst, String dst, String src, boolean bstrict, String[] params) throws IOException, GdalException { |
|
157 |
GdalWriter.createCopy(driverDst, dst, src, bstrict, params); |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Realiza la escritura de datos con los datos que le pasa el cliente. |
|
162 |
* @throws IOException |
|
163 |
*/ |
|
164 |
public void dataWrite() throws IOException, ProcessInterruptedException { |
|
165 |
if (colorInterp != null) |
|
166 |
gdalWriter.setColorBandsInterpretation(colorInterp.getValues()); |
|
167 |
gdalWriter.dataWrite(); |
|
168 |
if (gdalWriter.isWrite()) { |
|
169 |
gdalWriter.writeClose(); |
|
170 |
if (outTif != null) { |
|
171 |
GdalDriver driver = null; |
|
172 |
try { |
|
173 |
driver = Gdal.getDriverByName("JPEG"); |
|
174 |
GdalWriter.createCopy(driver, outJpg, outTif, false, gdalWriter.gdalParamsFromRasterParams(driverParams)); |
|
175 |
} catch (GdalException exc) { |
|
176 |
throw new IOException("No se ha podido obtener el driver."); |
|
177 |
} |
|
178 |
File file = new File(outTif); |
|
179 |
file.delete(); |
|
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* Cancela el salvado de datos. |
|
186 |
*/ |
|
187 |
public void writeCancel() { |
|
188 |
gdalWriter.setWrite(false); |
|
189 |
} |
|
190 |
|
|
191 |
/* |
|
192 |
* (non-Javadoc) |
|
193 |
* @see org.gvsig.raster.dataset.GeoRasterWriter#setParams(org.gvsig.raster.dataset.Params) |
|
194 |
*/ |
|
195 |
public void setParams(Params params) { |
|
196 |
driverParams = params; |
|
197 |
if (gdalWriter != null) |
|
198 |
gdalWriter.setParams(params); |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* Cierra el compresor ecw. |
|
203 |
* @throws GdalException |
|
204 |
*/ |
|
205 |
public void writeClose() { |
|
206 |
// El close del tif se hizo en dataWrite |
|
207 |
} |
|
208 |
|
|
209 |
public void setWkt(String wkt) {} |
|
210 |
} |
|
0 | 211 |
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalNewRasterStoreParameters.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.raster.impl.store.AbstractNewRasterStoreParameters; |
|
25 |
|
|
26 |
/** |
|
27 |
* Parameters for creating a Gdal store |
|
28 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
29 |
*/ |
|
30 |
public class GdalNewRasterStoreParameters extends AbstractNewRasterStoreParameters { |
|
31 |
|
|
32 |
public String getDataStoreName() { |
|
33 |
return GdalProvider.NAME; |
|
34 |
} |
|
35 |
|
|
36 |
public String getDescription() { |
|
37 |
return GdalProvider.DESCRIPTION; |
|
38 |
} |
|
39 |
|
|
40 |
} |
|
0 | 41 |
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalFilesystemServerExplorer.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 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.raster.gdal.io; |
|
29 |
|
|
30 |
import java.awt.geom.AffineTransform; |
|
31 |
import java.io.File; |
|
32 |
import java.io.FileInputStream; |
|
33 |
import java.io.IOException; |
|
34 |
|
|
35 |
import org.gvsig.fmap.dal.DALLocator; |
|
36 |
import org.gvsig.fmap.dal.DataManager; |
Also available in: Unified diff