Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extRasterTools-SE / src / org / gvsig / rastertools / reproject / Reproject.java @ 28502

History | View | Annotate | Download (5.64 KB)

1 20651 nbrodin
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools.reproject;
20
21
import java.io.File;
22
23
import org.cresques.cts.IProjection;
24
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
25 22109 bsanchez
import org.gvsig.raster.dataset.GeoRasterWriter;
26
import org.gvsig.raster.dataset.NotSupportedExtensionException;
27 28498 nbrodin
import org.gvsig.raster.dataset.RasterDriverException;
28 20651 nbrodin
29
import es.gva.cit.jgdal.GdalException;
30
import es.gva.cit.jgdal.GdalWarp;
31
/**
32 21813 bsanchez
 * Clase encargada de la reproyecci?n. Se le asigna una capa raster y la ruta de
33
 * destino
34
 *
35
 * @version 30/04/2008
36 20651 nbrodin
 * @author Nacho Brodin nachobrodin@gmail.com
37
 */
38
public class Reproject {
39 21813 bsanchez
        private FLyrRasterSE lyr      = null;
40
        private String       pathDest = null;
41
        private GdalWarp     warper   = null;
42
43 20651 nbrodin
        /**
44
         * Constructor de la clase.
45 21813 bsanchez
         * @param lyr
46 20651 nbrodin
         * @param pathDest Ruta de destino
47
         */
48 21813 bsanchez
        public Reproject(FLyrRasterSE lyr, String pathDest) {
49 20651 nbrodin
                this.lyr = lyr;
50
                this.pathDest = pathDest;
51
        }
52
53
        /**
54
         * M?todo para la transformaci?n del raster.
55
         * @param proj Proyecci?n destino
56
         */
57 21813 bsanchez
        public void warp(IProjection proj, IProjection sourceSrs) throws ReprojectException {
58
                if (lyr == null)
59
                        throw new ReprojectException("Capa no valida.");
60
                if (!lyr.isReproyectable())
61
                        throw new ReprojectException("Esta capa no se puede reproyectar.");
62
                if (proj == null || proj.getAbrev() == null)
63
                        throw new ReprojectException("Proyecci?n de destino no valida.");
64
65
                String epsg = proj.getAbrev();
66
                String s_srs = null;
67
                if (sourceSrs != null) {
68
                        s_srs = sourceSrs.getAbrev();
69
                }
70
                if (sourceSrs == null) {
71
                        if (lyr.getProjection() != null) {
72
                                s_srs = lyr.getProjection().getAbrev();
73 20812 bsanchez
                        } else {
74 21813 bsanchez
                                throw new ReprojectException("No se encuentra la proyeccion de origen.");
75 20812 bsanchez
                        }
76 21813 bsanchez
                }
77
                String source = null;
78
                if (lyr.getFile() != null)
79
                        source = lyr.getFile().getPath();
80
81
                if (source == null)
82
                        throw new ReprojectException("Fichero fuente no valido.");
83
84
                if (source.endsWith(".hdr"))
85
                        source = source.substring(0, source.lastIndexOf(".hdr"));
86
87
                File file = new File(pathDest);
88
                if (!file.getParentFile().canWrite())
89
                        throw new ReprojectException("Ruta de destino no valida.");
90
91
                warper = new GdalWarp();
92
93
                try {
94
                        warper.setSsrs(s_srs);
95 22109 bsanchez
96
//                        GTiff: GeoTIFF
97
//                        GTiff_FORMAT = 1;     // Reproyecta .tif
98
//                        VRT: Virtual Raster
99
//                        VRT_FORMAT = 2;       // No reproyecta
100
//                        NITF: National Imagery Transmission Format
101
//                        NITF_FORMAT = 3;      // Reproyecta .nitf
102
//                        HFA: Erdas Imagine Images (.img)
103
//                        HFA_FORMAT = 4;       // Reproyecta .img
104
//                        ELAS: ELAS
105
//                        ELAS_FORMAT = 5;      // No reproyecta
106
//                        MEM: In Memory Raster
107
//                        MEM_FORMAT = 6;       // No usarlo, aunque reproyecta
108
//                        BMP: MS Windows Device Independent Bitmap
109
//                        BMP_FORMAT = 7;       // No reproyecta
110
//                        PCIDSK: PCIDSK Database File
111
//                        PCIDSK_FORMAT = 8;    // Reproyecta
112
//                        ILWIS: ILWIS Raster Map
113
//                        ILWIS_FORMAT = 9;     // No reproyecta
114
115
//                        HDF4_FORMAT = 10;     // No reproyecta y se cierra gvSIG
116
117
//                        PNM: Portable Pixmap Format (netpbm)
118
//                        PNM_FORMAT = 11;      // No reproyecta
119
//                        ENVI: ENVI .hdr Labelled
120
//                        ENVI_FORMAT = 12;     // Reproyecta
121
//                        EHdr: ESRI .hdr Labelled
122
//                        EHDR_FORMAT = 13;     // Reproyecta
123
//                        PAux: PCI .aux Labelled
124
//                        PAUX_FORMAT = 14;     // Reproyecta
125
//                        MFF: Vexcel MFF Raster
126
//                        MFF_FORMAT = 15;      // No reproyecta
127
//                        MFF2: Vexcel MFF2 (HKV) Raster
128
//                        MFF2_FORMAT = 16;     // No reproyecta
129
//                        BT: VTP .bt (Binary Terrain) 1.3 Format
130
//                        BT_FORMAT = 17;       // No reproyecta
131
//                        IDA: Image Data and Analysis
132
//                        IDA_FORMAT = 18;      // No reproyecta
133
//                        RMF: Raster Matrix Format
134
//                        RMF_FORMAT = 19;      // No reproyecta
135
//                        RST: Idrisi Raster A.1
136
//                        RST_FORMAT = 20;      // No reproyecta
137
138
//                        Leveller: Leveller heightfield
139
//                        LEVELLER_FORMAT = 21; // No reproyecta
140
//                        Terragen: Terragen heightfield
141
//                        TERRAGEN_FORMAT = 22; // No reproyecta
142
//                        ERS: ERMapper .ers Labelled
143
//                        ERS_FORMAT = 23;      // No reproyecta
144
//                        INGR: Intergraph Raster
145
//                        INGR_FORMAT = 24;     // No reproyecta
146
//                        GSAG: Golden Software ASCII Grid (.grd)
147
//                        GSAG_FORMAT = 25;     // No reproyecta
148
//                        GSBG: Golden Software Binary Grid (.grd)
149
//                        GSBG_FORMAT = 26;     // No reproyecta
150
//                        ADRG: ARC Digitized Raster Graphics
151
//                        ADRG_FORMAT = 27;     // No reproyecta
152
153
//                        warper.setFormat(27);
154
                        warper.warp(epsg, source, pathDest, GeoRasterWriter.getWriter(pathDest).getDriverName());
155 21813 bsanchez
                } catch (GdalException e) {
156
                        throw new ReprojectException("Error al reproyectar.");
157 22109 bsanchez
                } catch (NotSupportedExtensionException e) {
158
                        throw new ReprojectException("Error al reproyectar.");
159
                } catch (RasterDriverException e) {
160
                        throw new ReprojectException("Error al reproyectar.");
161 21813 bsanchez
                }
162 20651 nbrodin
        }
163 21813 bsanchez
164 20651 nbrodin
        /**
165 21813 bsanchez
         * Obtiene el porcentaje de progreso de la tarea de reproyecci?n para
166
         * mostrarlo por pantalla.
167 20651 nbrodin
         * @return
168
         */
169 21813 bsanchez
        public int getPercent() {
170
                if (warper != null)
171 20651 nbrodin
                        return warper.getPercent();
172
                return 0;
173
        }
174 21813 bsanchez
}