Statistics
| Revision:

root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / GeoOperations.java @ 5952

History | View | Annotate | Download (19.6 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 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.georeferencing;
20

    
21
import java.awt.geom.Point2D;
22
import java.io.BufferedOutputStream;
23
import java.io.BufferedReader;
24
import java.io.BufferedWriter;
25
import java.io.DataOutputStream;
26
import java.io.File;
27
import java.io.FileInputStream;
28
import java.io.FileNotFoundException;
29
import java.io.FileOutputStream;
30
import java.io.IOException;
31
import java.io.InputStreamReader;
32
import java.io.OutputStream;
33
import java.io.OutputStreamWriter;
34
import java.util.zip.DataFormatException;
35

    
36
import org.cresques.io.RasterMetaFileTags;
37
import org.gvsig.georeferencing.utils.AffineT;
38
import org.gvsig.georeferencing.utils.GeoUtils;
39
import org.gvsig.georeferencing.utils.PointT;
40
import org.xmlpull.v1.XmlPullParserException;
41
import org.xmlpull.v1.XmlPullParserFactory;
42
import org.xmlpull.v1.XmlSerializer;
43

    
44
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
45

    
46

    
47
/** 
48
 * Operaciones necesarias para la georreferenciaci?n a partir de la capa de puntos. 
49
 * En base a unos puntos de control de origen y otros de destino se crea una matriz
50
 * de transformaci?n para asignar la nueva posici?n a la imagen y crear ficheros 
51
 * de georreferenciaci?n en dos formatos: worldfile y rasterMetaFile
52
 * 
53
 * @author Nacho Brodin (brodin_ign@gva.es)
54
 */
55
public class GeoOperations{
56
        
57
        //**********************Vars**********************************
58
        private int                         order = 1;
59
        private PointT[]                 src = null;
60
        private PointT[]                 dst = null;
61
        private AffineT                affine = null;
62
        private boolean         createWorldFile = false;
63
        //**********************End Vars******************************
64
        
65
        //**********************Methods*******************************
66
        /**
67
         * Constructor
68
         */
69
        public GeoOperations(){}
70
        
71
        /**
72
         * Constructor. Crea las estructuras de puntos y calcula la transformaci?n af?n.
73
         * @param lyr
74
         */
75
        public GeoOperations(FLyrPoints lyr){
76
                FLyrPoints         lyrPoints = lyr;
77
                src = new PointT[lyr.getCountActivePoints()]; 
78
                dst = new PointT[lyr.getCountActivePoints()];
79
                int nPoint = 0;
80
                for(int i = 0; i<lyr.getCountActivePoints(); i++){
81
                        if(lyr.getPoint(i).active == true){
82
                                src[nPoint] = new PointT();
83
                                dst[nPoint] = new PointT();
84
                                src[nPoint].setX(lyr.getPoint(i).pixelPoint.getX());
85
                                src[nPoint].setY(lyr.getPoint(i).pixelPoint.getY());
86
                                src[nPoint].setI(lyr.getCountPoints());
87
                                dst[nPoint].setX(lyr.getPoint(i).mapPoint.getX());
88
                                dst[nPoint].setY(lyr.getPoint(i).mapPoint.getY());
89
                                dst[nPoint].setI(lyr.getCountPoints());
90
                                nPoint++;
91
                        }
92
                }
93
                
94
                if(lyr.getCountActivePoints() >= 3 * 10)
95
                        order = 3;
96
                else if(lyr.getCountActivePoints() >= 3 * 6)
97
                        order = 2;
98
                else
99
                        order = 1;
100

    
101
                affine = new AffineT();
102
                
103
                //Calcular la transformaci?n afin por m?nimos cuadrados
104
                affine = computeLeastSquaresAffine(affine, src, dst, order);
105
        }
106
        
107
        /**
108
         * A partir de la transformaci?n af?n creada en el construtor
109
         * genera un fichero de georreferenciaci?n para la imagen.
110
         * @param lyr                Capa de puntos
111
         * @param order        Orden del sistema de ecuaciones
112
         * @param widthPx        Ancho en pixeles de la imagen a georreferenciar
113
         * @param heightPx        Alto en pixeles de la imagen a georreferenciar
114
         * @param file                Nombre del fichero raster a georreferenciar
115
         */
116
        public void createGeorefFile(int widthPx, int heightPx, String file){
117
                try{
118
                        File f = new File(file);
119
                        String nameWorldFile = f.getPath().substring(0, f.getPath().lastIndexOf(".")) + getExtensionWorldFile(file);
120
                        if(createWorldFile)
121
                                createWorldFile(affine, widthPx, heightPx, nameWorldFile);
122
                        createRasterMetaFile(affine, widthPx, heightPx, nameWorldFile.substring(0, nameWorldFile.lastIndexOf("."))+".rmf");
123
                }catch(IOException ex){
124
                        System.err.println("Can't create WorldFile");
125
                }
126
        }
127
        
128
        /**
129
         * A partir de la transformaci?n af?n calculada en el contructor
130
         * transforma los puntos pasados como par?metros.
131
         * @param lyr                Capa de puntos
132
         * @param list                Lista de puntos a transformar
133
         * @return                  Lista de puntos transformados
134
         */
135
        public Point2D[] transformPoints(Point2D[] list){
136
                Point2D[] result = new Point2D[list.length];
137
                for(int i = 0; i < list.length;i++){
138
                        double[] pto = transformPoint((int)list[i].getX(), (int)list[i].getY(), affine);
139
                        result[i] = new Point2D.Double(pto[0], pto[1]);
140
                }
141
                return result;
142
        }
143
        
144
        /**
145
         * Crea un fichero de georreferenciaci?n (worldfile) a partir de la transformaci?n af?n. Para
146
         * esto necesita obtener las coordenadas reales de la coordenada en pixels (0,0) y calcular
147
         * el tama?o de pixel. 
148
         * @param affine                Transformaci?n
149
         * @param widthPx                Ancho en pixeles de la imagen a georreferenciar
150
         * @param heightPx                Alto en pixeles de la imagen a georreferenciar
151
         * @param nameWordlFile        Nombre del fichero de georreferenciaci?n
152
         * @throws IOException
153
         */
154
        private void createWorldFile(AffineT affine, int widthPx, int heightPx, String nameWordlFile) throws IOException {
155
                StringBuffer data = new StringBuffer();
156
                //double[] begin = transformPoint(0, 0, affine);
157
                //double[] end = transformPoint(widthPx, heightPx, affine);
158
                //double pixelSizeX = (end[0] - begin[0])/(widthPx - 1);
159
                //double pixelSizeY = (end[1] - begin[1])/(heightPx - 1);
160

    
161
                File f = new File(nameWordlFile);
162
                DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(f)) );
163
                
164
            data.append(affine.getCofX(1)+"\n");//pixelSizeX+"\n");
165
            data.append(affine.getCofX(2)+"\n");
166
            data.append(affine.getCofY(1)+"\n");
167
            data.append(affine.getCofY(2)+"\n");//(-1  * pixelSizeY)+"\n");
168
            data.append(affine.getCofX(0)+"\n");//""+begin[0]+"\n");
169
            data.append(affine.getCofY(0)+"\n");//""+end[1]+"\n");
170
            
171
            dos.writeBytes(data.toString());
172
                dos.close();
173
        }
174
        
175
        /**
176
         * A partir de XmlSerializer se salva la georreferenciaci?n 
177
         * @param serializer
178
         * @param min                
179
         * @param max                
180
         * @param widthPx                Ancho en pixeles de la imagen a georreferenciar
181
         * @param heightPx                Alto en pixeles de la imagen a georreferenciar
182
         * @throws IOException
183
         */
184
        private void serializeGeoreferencing(XmlSerializer serializer, double[] min, double[] max, int widthPx, int heightPx) throws IOException {
185
                double pixelSizeX = (max[0] - min[0])/(widthPx - 1);
186
                double pixelSizeY = (max[1] - min[1])/(heightPx - 1);
187
                
188
                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PROJ).text("Projection").endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PROJ).text("\n");
189
                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.BBOX).text("\n");
190
                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.POSX).text(""+min[0]).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.POSX).text("\n");
191
                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.POSY).text(""+min[1]).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.POSY).text("\n");
192
                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_SIZE_X).text(""+pixelSizeX).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_SIZE_X).text("\n");
193
                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_SIZE_Y).text(""+ pixelSizeY).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_SIZE_Y).text("\n");                
194
                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.WIDTH).text(""+(max[0] - min[0])).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.WIDTH).text("\n");
195
                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.HEIGHT).text(""+(max[1] - min[1])).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.HEIGHT).text("\n");
196
                serializer.endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.BBOX).text("\n");
197
                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.DIM).text("\n");
198
                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_WIDTH).text(""+widthPx).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_WIDTH).text("\n");
199
                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_HEIGHT).text(""+heightPx).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_HEIGHT).text("\n");
200
                serializer.endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.DIM).text("\n");
201
        }
202
        
203
        /**
204
         * Si ya existe un fichero de georreferenciaci?n se ha creado un fichero .tmp con
205
         * la nueva georreferenciaci?n. Esta funci?n mezcla este temporal con el .rmf existente
206
         * en un nuevo fichero _tmpOutput que ser? renombrado como el nuevo .rmf. Finalmente 
207
         * elimina el temporal y el _tmpOutput. 
208
         * @param fileName
209
         */
210
        private void mergeFiles(String fileName){
211
                try{
212
                        File rmfFile = new File(fileName);
213
                        File tmpFile = new File(fileName.substring(0, fileName.lastIndexOf("."))+".tmp");
214
                        File out = new File(rmfFile+"_tmpOutput");
215
                        
216
                        BufferedReader inRmf = new BufferedReader(new InputStreamReader(new FileInputStream(rmfFile)));
217
                        BufferedReader inTmp = new BufferedReader(new InputStreamReader(new FileInputStream(tmpFile)));
218
                        BufferedWriter outTmp = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out)));
219
                        
220
                        //Leemos el principio del .rmf
221
                String str = inRmf.readLine();
222
                while(!str.startsWith("<"+RasterMetaFileTags.MAIN_TAG)){
223
                        outTmp.write(str+"\n");
224
                        str = inRmf.readLine();
225
                }
226
                    outTmp.write(str+"\n");
227
                
228
                //Leemos la georreferenciaci?n del .tmp
229
                while(str != null && !str.startsWith("<"+RasterMetaFileTags.LAYER))
230
                        str = inTmp.readLine();
231
                while(str != null){
232
                        outTmp.write(str+"\n");
233
                        str = inTmp.readLine();
234
                }
235
                        
236
                //Saltamos la georreferenciaci?n que ya existia en el .rmf
237
                try{
238
                        str = inRmf.readLine();
239
                        while(str != null && 
240
                                  !str.startsWith("</"+RasterMetaFileTags.LAYER) &&
241
                                  !str.startsWith("<"+RasterMetaFileTags.GEOPOINTS) &&
242
                                  !str.startsWith("</"+RasterMetaFileTags.MAIN_TAG))
243
                                str = inRmf.readLine();
244
                }catch(Exception exc){
245
                        
246
                }
247
                
248
                //Leemos el resto del fichero .rmf
249
                if(!str.startsWith("<"+RasterMetaFileTags.GEOPOINTS))
250
                        str = inRmf.readLine();
251
                while(str != null){
252
                        outTmp.write(str+"\n");
253
                        str = inRmf.readLine();
254
                }
255
                
256
                outTmp.close();
257
                inRmf.close();
258
                inTmp.close();
259
                
260
                //Eliminamos el antiguo .rmf y lo sustituimos
261
                rmfFile.delete();
262
                out.renameTo(rmfFile);
263
                tmpFile.delete();
264
                
265
                }catch(FileNotFoundException exc){
266
                        
267
                }catch(IOException exc){
268
                        
269
                }
270
        }
271
        
272
        /**
273
         * Si no existe crea un fichero .rmf con la georreferenciaci?n de la imagen. Si existe este 
274
         * deber? a?adir o modificar la informaci?n de georreferenciaci?n en el fichero.
275
         * Para esto necesita obtener las coordenadas reales de la coordenada en pixels (0,0) y 
276
         * calcular el tama?o de pixel. 
277
         * @param affine                Transformaci?n
278
         * @param widthPx                Ancho en pixeles de la imagen a georreferenciar
279
         * @param heightPx                Alto en pixeles de la imagen a georreferenciar
280
         * @param nameWordlFile        Nombre del fichero de georreferenciaci?n
281
         * @throws IOException
282
         */
283
        private void createRasterMetaFile(AffineT affine, int widthPx, int heightPx, String nameWorldFile) throws IOException {
284
                File file = new File(nameWorldFile);
285
                double[] min = transformPoint(0, 0, affine);
286
                double[] max = transformPoint(widthPx, heightPx, affine);
287
                try{                
288
                        XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
289
                        XmlSerializer serializer = factory.newSerializer();
290
                        
291
                        if(file.exists()){
292
                                file = new File(nameWorldFile.substring(0, nameWorldFile.lastIndexOf("."))+".tmp");
293
                                serializer.setOutput(new FileOutputStream(file), null);
294
                                serializer.startDocument(null, null);
295
                                serializer.ignorableWhitespace("\n\n");
296
                                serializer.setPrefix("", RasterMetaFileTags.NAMESPACE);
297
                                serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.LAYER).text("\n");
298
                                serializeGeoreferencing(serializer, min, max, widthPx, heightPx);
299
                                serializer.endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.LAYER).text("\n");
300
                                serializer.endDocument();
301
                                mergeFiles(nameWorldFile);
302
                        }else{
303
                                        serializer.setOutput(new FileOutputStream(file), null);
304
                                        serializer.startDocument(null, null);
305
                                        serializer.ignorableWhitespace("\n\n");
306
                                        serializer.setPrefix("", RasterMetaFileTags.NAMESPACE);
307
                                        serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.MAIN_TAG).text("\n");
308
                                        serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.LAYER).text("\n");
309
                                        serializeGeoreferencing(serializer, min, max, widthPx, heightPx);
310
                                        serializer.endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.LAYER).text("\n");
311
                                        serializer.endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.MAIN_TAG).text("\n");
312
                                        serializer.endDocument();
313
                        }
314
                }catch(XmlPullParserException exc){}
315
        }
316
                
317
        /**
318
         * Calcula la transformaci?n af?n a partir de los puntos introducidos por el m?todo de 
319
         * m?nimos cuadrados.
320
         * @param af        Transformaci?n af?n
321
         * @param src        Puntos de entrada en coordenadas pixel
322
         * @param dst        Puntos de destino en coordenadas del mundo         
323
         * @param order        Orden del sistema de ecuaciones
324
         */
325
        public AffineT computeLeastSquaresAffine(AffineT af, PointT[] src, PointT[] dst, int order){
326
                double[] b = new double[dst.length];
327
                int i,cofs;
328

    
329
                af.setOrder(order);
330
                cofs = order <= 2 ? order*3 : 10;
331
                af.mallocCofs(cofs);
332
                
333
                //First compute the X cofs  
334
                for(i = 0; i < dst.length; i++) {    
335
                        b[i] = dst[i].getX();  
336
                }
337
                
338
                af.setCofX(singleLeastSquaresAffine(af.getXcofs(), src, b, order));
339
                
340
                //Now compute the Y cofs  
341
                for(i = 0; i < dst.length; i++) {    
342
                        b[i] = dst[i].getY();  
343
                }
344
                
345
                af.setCofY(singleLeastSquaresAffine(af.getYcofs(), src, b, order));
346
                
347
                return af;
348
        }
349
        
350
        private double[] singleLeastSquaresAffine(double[] a, PointT[] src, double[] dst, int order){
351
                int i,j;
352
                int n = dst.length;
353

    
354
                int points = order <= 2 ? order * 3 : 10;        
355
                double[][] combined = new double[points][points + 1];
356
                double[][] A = new double[n + 1][points];
357
                double[][] b = new double[n + 1][1];
358
                
359
                for(i = 0; i < n; i++) {
360
                        A[i][0] = 1.0;
361
                        A[i][1] = src[i].getX();
362
                        A[i][2] = src[i].getY();
363
                        if(order > 1) {
364
                                A[i][3] = src[i].getX() * src[i].getX();
365
                                A[i][4] = src[i].getX() * src[i].getY();
366
                                A[i][5] = src[i].getY() * src[i].getY();
367
                        }
368
                        if(order > 2) {
369
                                A[i][6] = src[i].getX() * src[i].getX() * src[i].getX();
370
                                A[i][7] = src[i].getX() * src[i].getX() * src[i].getY();
371
                                A[i][8] = src[i].getX() * src[i].getY() * src[i].getY();
372
                                A[i][9] = src[i].getY() * src[i].getY() * src[i].getY();
373
                        }
374
                        b[i][0] = dst[i];
375
                }
376
                
377
                double[][] Atrans = GeoUtils.transpose(A, n, points);
378
                double[][] left = GeoUtils.multmatrix(Atrans,A,points,n,points);
379
                double[][] right = GeoUtils.multmatrix(Atrans,b,points,n,1);
380
                
381
                for(i = 0; i < points; i++) {
382
                        combined[i][0] = right[i][0];
383
                        for(j = 0; j < points; j++) {
384
                                combined[i][j+1] = left[i][j];
385
                        }
386
                }
387
                
388
                try{
389
                        combined = solve(combined, points, points+1);
390
                }catch(DataFormatException ex){
391
                        System.err.println("Can't solve matrix");
392
                }
393

    
394
                for(i = 0; i < points; i++) {
395
                        a[i] = combined[i][0];
396
                }
397
                return a;
398
        }
399
        
400
        
401
        private double[][] solve(double[][] mat,int rows,int cols)throws DataFormatException{
402
                int i,j,k;
403
                double d,tmp;
404
                int big;
405

    
406
                for(i = 0; i < rows; i++) {
407
                        // Find largest row
408
                                big = i;
409
                                for(j = i; j < rows; j++) {
410
                                        if(Math.abs(mat[j][i+1]) > Math.abs(mat[big][i+1])) {
411
                                                big = j;
412
                                        }
413
                                }
414
                                // swap row i and row big
415
                                for(k = 0; k < cols ; k++) {
416
                                        tmp = mat[i][k];
417
                                        mat[i][k] = mat[big][k];
418
                                        mat[big][k] = tmp;
419
                                }
420
                        if(mat[i][i+1] == 0) 
421
                                throw new DataFormatException();
422
                        
423
                        d = 1.0 / mat[i][i+1]; 
424
                        for(j = 0; j < cols ; j++) {
425
                                mat[i][j] *= d;
426
                                //assert(!isnan(mat[i][j]));
427
                        }
428
                        for(k = 0; k < rows; k++) {
429
                                if(k == i)
430
                                        continue;
431
                                if(mat[k][i+1] != 0.0) {
432
                                d = mat[k][i+1] / mat[i][i+1]; 
433
                                        for(j = 0; j < cols ; j++) {
434
                                                mat[k][j] -= d*mat[i][j];
435
                                                //assert(!isnan(mat[k][j]));
436
                                        }
437
                                }
438
                        }
439
                }
440
                return mat;
441
        }
442
        
443
        /**
444
         * Obtiene las coordenadas de un punto en coordenadas del mundo a partir de una transformaci?n 
445
         * y el punto de entrada en coordenadas de la imagen.
446
         * @param sx        Coordenada X del punto de entrada 
447
         * @param syz        Coordenada Y del punto de entrada
448
         * @param af        Transformaci?n
449
         * @return                Punto transformado
450
         */
451
        public double[] transformPoint(int sx, int sy, AffineT af){
452
                double[] p = new double[2];
453
                if(af.getOrder() == 1) {
454
                        p[0] = af.getCofX(0) + af.getCofX(1) * sx + af.getCofX(2) * sy;
455
                        p[1] = af.getCofY(0) + af.getCofY(1) * sx + af.getCofY(2) * sy;
456
                }
457
                else if(af.getOrder() == 2) {
458
                        p = quadTransformPoint(sx, sy, af);
459
                }
460
                else {
461
                        p = cubicTransformPoint(sx, sy, af);
462
                 }
463
                return p;
464
        }
465
        
466
        private static double[] quadTransformPoint(int sx, int sy, AffineT af){
467
                double[] p = new double[2];
468
                p[0] = af.getCofX(0) + af.getCofX(1) * sx + af.getCofX(2) * sy + 
469
                        af.getCofX(3) * sx * sx + af.getCofX(4) * sx * sy + af.getCofX(5) * sy * sy;
470
                p[1] = af.getCofY(0) + af.getCofY(1) * sx + af.getCofY(2) * sy + 
471
                        af.getCofY(3) * sx * sx + af.getCofY(4) * sx * sy + af.getCofY(5) * sy * sy;
472
                return p;
473
        }
474
        
475
        private static double[] cubicTransformPoint(int sx, int sy, AffineT af){
476
                double[] p = new double[2];
477
                p[0] = af.getCofX(0) + af.getCofX(1) * sx + af.getCofX(2) * sy + 
478
                        af.getCofX(3) * sx * sx + af.getCofX(4) * sx * sy + af.getCofX(5) * sy * sy +
479
                        af.getCofX(6) * sx * sx * sx + af.getCofX(7) * sx * sx * sy +
480
                        af.getCofX(8)*sx*sy*sy + af.getCofX(9)*sy*sy*sy;
481
                p[1] = af.getCofY(0) + af.getCofY(1) * sx + af.getCofY(2) * sy + 
482
                        af.getCofY(3) * sx * sx + af.getCofY(4) * sx * sy + af.getCofY(5) * sy * sy +
483
                        af.getCofY(6) * sx * sx * sx + af.getCofY(7) * sx * sx * sy +
484
                        af.getCofY(8) * sx * sy * sy + af.getCofY(9) * sy * sy * sy;
485
                return p;
486
        }        
487
        //**********************End Methods***************************
488
        
489
        //**********************Setters & Getters*********************
490
        /**
491
         * M?todo para notificar si se desea crear o no el fichero de coordenadas .tfw, .wld .jpgw ,... 
492
         * @param createWorldFile
493
         */
494
        public void setCreateWorldFile(boolean createWorldFile) {
495
                this.createWorldFile = createWorldFile;
496
        }
497
        
498
        /**
499
         * Obtiene la extensi?n del fichero de georreferenciaci?n
500
         * @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
501
         * del valor del formato obtenido del servidor. Por defecto asignaremos un .wld 
502
         */
503
        private String getExtensionWorldFile(String file){
504
                String ext = file.substring(file.lastIndexOf(".") + 1).toLowerCase();
505
                String extWorldFile = ".wld";
506
            if(ext.equals("tif") || ext.equals("tiff"))
507
                    extWorldFile = ".tfw";
508
            if(ext.equals("jpeg") || ext.equals("jpg"))
509
                    extWorldFile = ".jgw";
510
            if(ext.equals("gif"))
511
                    extWorldFile = ".gfw";
512
            if(ext.equals("png"))
513
                    extWorldFile = ".pgw";
514
            return extWorldFile;
515
        }
516
        
517
        /**
518
         * Obtiene la matriz de transformaci?n
519
         * @return AffineT
520
         */
521
        public AffineT getAffine() {
522
                return affine;
523
        }
524
        //**********************End Setters & Getters*****************
525
        
526
}