Statistics
| Revision:

root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / utils / GeoPointPersistence.java @ 12546

History | View | Annotate | Download (21.1 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.utils;
20
import java.awt.Dimension;
21
import java.awt.geom.Point2D;
22
import java.awt.geom.Rectangle2D;
23
import java.io.BufferedOutputStream;
24
import java.io.BufferedReader;
25
import java.io.BufferedWriter;
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.io.StringWriter;
35
import java.util.ArrayList;
36

    
37
import javax.xml.parsers.DocumentBuilder;
38
import javax.xml.parsers.DocumentBuilderFactory;
39
import javax.xml.parsers.ParserConfigurationException;
40

    
41
import org.apache.xml.serialize.OutputFormat;
42
import org.apache.xml.serialize.XMLSerializer;
43
import org.gvsig.georeferencing.GeoreferencingToolsModule;
44
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog;
45
import org.gvsig.georeferencing.gui.panels.ZoomControlPanel;
46
import org.gvsig.raster.dataset.RasterMetaFileTags;
47
import org.gvsig.raster.dataset.io.rmf.RmfBlocksManager;
48
import org.gvsig.raster.dataset.serializer.GeoPointRmfSerializer;
49
import org.gvsig.raster.datastruct.GeoPoint;
50
import org.w3c.dom.Document;
51
import org.w3c.dom.Element;
52
import org.w3c.dom.Node;
53
import org.w3c.dom.NodeList;
54
import org.xml.sax.SAXException;
55

    
56
import com.iver.andami.PluginServices;
57
import com.iver.cit.gvsig.fmap.ViewPort;
58
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
59
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster;
60
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
61
import com.iver.cit.gvsig.fmap.layers.IPersistence;
62
import com.iver.cit.gvsig.project.documents.view.gui.View;
63

    
64
/**
65
 * Clase que controla la persistencia de la capa de puntos.
66
 * @author Nacho Brodin (brodin_ign@gva.es)
67
 */
68
public class GeoPointPersistence implements IPersistence{
69
        //**********************Vars**********************************
70
        private ArrayList                 geoPointList = null;
71
        private Document                 xmlDoc = null;
72
        private Element                 generalTag = null;
73
        private FLyrPoints                 lyrPoints = null;
74
        private double[]                lastViewPort = null;
75
        //**********************End Vars******************************
76

    
77
        //**********************Methods*******************************
78
        /**
79
         * Constructor
80
         */
81
        public GeoPointPersistence(){}
82

    
83
        /**
84
         * Constructor
85
         * @param geoPointList        Lista de geopuntos
86
         */
87
        public GeoPointPersistence(FLyrPoints lyrPoints){
88
                this.geoPointList = lyrPoints.getListPoint();
89
                this.lyrPoints = lyrPoints;
90
        }
91

    
92
        /**
93
         * Carga la lista de puntos desde un fichero
94
         * @param file        Nombre del fichero
95
         * @return        Array con la lista de puntos
96
         */
97
        public void loadPointList(String file){
98
                try {
99
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
100
                DocumentBuilder db = dbf.newDocumentBuilder();
101
                File f = new File(file);
102
                Document doc = db.parse(f);
103

    
104
                if(doc.getDocumentElement().getTagName().equals(RasterMetaFileTags.MAIN_TAG)){
105
                        NodeList nodeListMain = doc.getDocumentElement().getChildNodes();
106
                        for(int j=0;j<nodeListMain.getLength();j++){
107
                                Node nodeMain = nodeListMain.item(j);
108
                                if(nodeMain.getNodeName().equals(RasterMetaFileTags.GEOPOINTS)){
109

    
110
                                        NodeList nodeListGeoPoints = nodeMain.getChildNodes();
111
                                    lyrPoints.clear();
112
                                    for(int i=0;i<nodeListGeoPoints.getLength();i++){
113
                                            Node node = nodeListGeoPoints.item(i);
114
                                            if(node.getNodeName().equals(RasterMetaFileTags.POINTS_LYR)){
115
                                                    NodeList nl = node.getChildNodes();
116
                                                    lastViewPort = processFlyrGeoRasterNodeValue(nl);
117
                                            }
118
                                            if(node.getNodeName().equals(RasterMetaFileTags.GEOPOINT)){
119
                                                    NodeList nl = node.getChildNodes();
120
                                                    processGeoPointNodeValue(nl);
121
                                            }
122
                                    }
123
                                    this.geoPointList = lyrPoints.getListPoint();
124

    
125
                                }
126
                        }
127
                }
128

    
129
            } catch (ParserConfigurationException e) {
130
                    return;
131
            } catch (SAXException e1) {
132
                    return;
133
            } catch (IOException e1) {
134
                    return;
135
            }
136
        }
137

    
138
        /**
139
         * Crea el XML con la lista de puntos y la salva a disco
140
         * @param file
141
         */
142
        public void savePointList(String file){
143
                this.geoPointList = lyrPoints.getListPoint();
144
                
145
                GeoPoint[] list = new GeoPoint[geoPointList.size()];
146
                for (int i = 0; i < list.length; i++)
147
                        list[i] = (GeoPoint)geoPointList.get(i);
148
                
149
                GeoPointRmfSerializer ser = new GeoPointRmfSerializer(list);
150
                RmfBlocksManager manager = new RmfBlocksManager(file);
151
                manager.addClient(ser);
152
                
153
                try {
154
                        manager.write();
155
                } catch (FileNotFoundException e) {
156
                        e.printStackTrace();
157
                } catch (IOException e) {
158
                        e.printStackTrace();
159
                }
160
        }
161

    
162
        /**
163
         * Crea la lista de puntos a partir de un fichero CSV
164
         * @param file
165
         */
166
        public void loadCSVPointList(String file){
167
                try{
168
                        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
169
                        String line = in.readLine();
170
                        int nPoint = 0;
171
                        while(line != null){
172
                                if(nPoint == 0){
173
                                        if(!line.equals("\"Pt\",\"X\",\"Y\",\"X'\",\"Y'\",\"ErrX\",\"ErrY\",\"RMS\""))
174
                                                return;
175
                                }else{
176
                                        double x = 0D, y = 0D, xx = 0D, yy = 0D;
177
                                        String[] tokens = line.split(",");
178
                                    for(int tok=0; tok<tokens.length;tok++){
179
                                            try{
180
                                                    if(tok == 1)
181
                                                            x = Double.parseDouble(tokens[tok]);
182
                                                    if(tok == 2)
183
                                                            y = Double.parseDouble(tokens[tok]);
184
                                                    if(tok == 3)
185
                                                            xx = Double.parseDouble(tokens[tok]);
186
                                                    if(tok == 4)
187
                                                            yy = Double.parseDouble(tokens[tok]);
188
                                            }catch(NumberFormatException ex){
189
                                                    return;
190
                                            }
191
                                    }
192
                                        int pos = nPoint - 1;
193

    
194
                                        if(x == 0 && y == 0 && xx == 0 && yy == 0){
195
                                                line = in.readLine();
196
                                                continue;
197
                                        }
198

    
199
                                        lyrPoints.getPointManager().newEmptyPoint();
200
                                    Point2D p = new Point2D.Double();
201
                                        p.setLocation(x, y);
202
                                        Point2D m = new Point2D.Double();
203
                                        m.setLocation(xx, yy);
204

    
205
                                        Point2D leftCenter = new Point2D.Double();
206
                                        leftCenter.setLocation(lyrPoints.getLyrGeoRaster().img2World(p));
207
                                        Point2D rightCenter = new Point2D.Double();
208
                                        rightCenter.setLocation(m);
209

    
210
                                        View theView = null;
211
                                        ViewPort viewPort = null;
212
                                try{
213
                                        theView = (View) PluginServices.getMDIManager().getActiveWindow();
214
                                        viewPort = theView.getMapControl().getMapContext().getViewPort();
215
                                }catch(ClassCastException exc){
216
                                        return ;
217
                                }
218
                                        ViewPort leftViewPort = viewPort.cloneViewPort();
219
                                        leftViewPort.setImageSize(new java.awt.Dimension(ZoomControlPanel.WIDTH_MINIMG, ZoomControlPanel.HEIGHT_MINIMG));
220
                                        ViewPort rightViewPort = viewPort.cloneViewPort();
221
                                        rightViewPort.setImageSize(new java.awt.Dimension(ZoomControlPanel.WIDTH_MINIMG, ZoomControlPanel.HEIGHT_MINIMG));
222
                                        leftViewPort = lyrPoints.getPointManager().getDialog().getZoomControlLeft().getCanvas().initViewPort(viewPort, leftCenter, leftViewPort, 1);
223
                                        rightViewPort = lyrPoints.getPointManager().getDialog().getZoomControlLeft().getCanvas().initViewPort(viewPort, rightCenter, rightViewPort, 1);
224

    
225
                                        GeoreferencingToolsModule.setEnabled(true);
226

    
227
                                        lyrPoints.setPointActive(pos, true);
228
                                        lyrPoints.setLeftCenterPoint(pos,leftCenter);
229
                                        lyrPoints.setRightCenterPoint(pos, rightCenter);
230
                                        lyrPoints.setMiniExtent(pos, lyrPoints.getLyrGeoRaster().img2World(p), leftViewPort, false);
231
                                        lyrPoints.setMiniExtent(pos, m, rightViewPort, true);
232
                                        lyrPoints.getPointManager().updateData(pos + 1, p, m, lyrPoints.getPointManager().getDialog(), null);
233
                                        lyrPoints.setZoomLeft(pos, 1);
234
                                        lyrPoints.setZoomRight(pos, 1);
235
                                        if(lyrPoints.getCountPoints() > 0){
236
                                                GeoreferencingDialog grd = lyrPoints.getPointManager().getDialog();
237
                                                grd.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints());
238
                                                grd.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints());
239
                                                lyrPoints.getPointManager().selectPoint(0, grd);
240
                                        }
241
                                }
242
                                nPoint++;
243
                                line = in.readLine();
244
                        }
245
                        in.close();
246
                }catch(FileNotFoundException ex){
247
                        //No salvamos el csv
248
                }catch(IOException ex){
249
                        //No salvamos el csv
250
                }
251
        }
252

    
253
        /**
254
         * Crea el fichero Ascii con la lista de puntos y la salva a disco
255
         * @param file
256
         */
257
        public void saveCSVPointList(String file){
258
                this.geoPointList = lyrPoints.getListPoint();
259
                try{
260
                        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
261
                        if(lyrPoints.getLyrGeoRaster().getGeoDialog().isErrorCSV())
262
                                out.write("\"Pt\",\"X\",\"Y\",\"X'\",\"Y'\",\"ErrX\",\"ErrY\",\"RMS\"\n");
263
                        else
264
                                out.write("\"Pt\",\"X\",\"Y\",\"X'\",\"Y'\"\n");
265

    
266
                        for(int i=0;i<geoPointList.size();i++){
267
                                GeoPoint geoPoint =  (GeoPoint)geoPointList.get(i);
268
                                String point = (i+1)+","+
269
                                                                geoPoint.pixelPoint.getX()+","+
270
                                                                geoPoint.pixelPoint.getY()+","+
271
                                                                geoPoint.mapPoint.getX()+","+
272
                                                                geoPoint.mapPoint.getY();
273
                                double[][] err = lyrPoints.getLyrGeoRaster().getGeoDialog().getErrors();
274
                                String error = "";
275
                                try{
276
                                        error = err[i][0]+","+err[i][1]+","+err[i][2];
277
                                        if(lyrPoints.getLyrGeoRaster().getGeoDialog().isErrorCSV())
278
                                                out.write(point+","+error+"\n");
279
                                        else
280
                                                out.write(point+"\n");
281
                                }catch(ArrayIndexOutOfBoundsException ex){
282
                                        out.write(point+"\n");
283
                                }
284
                        }
285
                        out.close();
286
                }catch(FileNotFoundException ex){
287
                        //No salvamos el csv
288
                }catch(IOException ex){
289
                        //No salvamos el csv
290
                }
291
        }
292
        //****************************************************
293

    
294
        /**
295
         * Aplica una transformaci?n al extent dependiendo de si el extent de la imagen
296
         * original ha cambiado o no. Si la capa FLyrGeoRaster cargada tiene un extent
297
         * distinto al que se ha salvado en el fichero de puntos esto significa que el
298
         * extent de la miniimagen que tiene los puntos relativos a las coordenadas de la
299
         * imagen en pixels ha de sufrir un desplazamiento. Este cambio puede producirse
300
         * cuando el usuario carga un proyecto con una capa a georreferenciar y la desplaza de
301
         * sitio con las herramientas. Posteriormente puede cargar los puntos del fichero .rmf
302
         * @param imgExtent Extent de la imagen
303
         * @param miniExtent ViewPor del miniextent a transformar
304
         * @return ViewPort        ViewPort del miniextent transformado
305
         */
306
        private ViewPort transformMiniExtent(Rectangle2D imgExtent, ViewPort miniExtent){
307
                if(        lastViewPort[0] != imgExtent.getMinX() ||
308
                        lastViewPort[1] != imgExtent.getMinY() ||
309
                        lastViewPort[2] != imgExtent.getWidth() ||
310
                        lastViewPort[3] != imgExtent.getHeight()){
311
                        Rectangle2D r = new Rectangle2D.Double();
312
                        r.setRect(         miniExtent.getExtent().getMinX() - (lastViewPort[0] - imgExtent.getMinX()),
313
                                                miniExtent.getExtent().getMinY() - (lastViewPort[1] - imgExtent.getMinY()),
314
                                                miniExtent.getExtent().getWidth(),
315
                                                miniExtent.getExtent().getHeight());
316
                        miniExtent.setExtent(r);
317
                }
318
                return miniExtent;
319
        }
320

    
321
        /**
322
         * Aplica una transformaci?n al centro del extent dependiendo de si el extent de la imagen
323
         * original ha cambiado o no.
324
         */
325
        private Point2D transformCenter(Rectangle2D imgExtent, Point2D center){
326
                if(        lastViewPort[0] != imgExtent.getMinX() ||
327
                        lastViewPort[1] != imgExtent.getMinY() ||
328
                        lastViewPort[2] != imgExtent.getWidth() ||
329
                        lastViewPort[3] != imgExtent.getHeight()){
330
                        Point2D c = new Point2D.Double();
331
                        c.setLocation(center.getX() - (lastViewPort[0] - imgExtent.getMinX()),
332
                                                  center.getY() - (lastViewPort[1] - imgExtent.getMinY()));
333
                        return c;
334
                }
335
                return center;
336
        }
337

    
338
        /**
339
         * Obtiene el valor del extent de la imagen obtenido desde un nodo
340
         * XML. A partir de este valor obtenido crea un punto en la capa.
341
         */
342
        private double[] processFlyrGeoRasterNodeValue(NodeList nl){
343
                double[] res = null;
344
                for(int j=0;j<nl.getLength();j++){
345
                        Node geoNode = nl.item(j);
346
                        if(geoNode.getNodeName().equals(RasterMetaFileTags.POINTS_VP)){
347
                                res = new double[7];
348
                                NodeList vpChildNodes = geoNode.getChildNodes();
349
                                for(int i=0;i<vpChildNodes.getLength();i++){
350
                                        Node vpNode = vpChildNodes.item(i);
351
                                        if(vpNode.getNodeName().equals(RasterMetaFileTags.POINTS_BBOX)){
352
                                                NodeList extentChildNodes = vpNode.getChildNodes();
353
                                                for(int k=0;k<extentChildNodes.getLength();k++){
354
                                                        Node extentNode = extentChildNodes.item(k);
355
                                                        if(extentNode.getNodeName().equals(RasterMetaFileTags.POINTS_PX))
356
                                                                res[0] = Double.valueOf(extentNode.getFirstChild().getNodeValue()).doubleValue();
357
                                                        if(extentNode.getNodeName().equals(RasterMetaFileTags.POINTS_PY))
358
                                                                res[1] = Double.valueOf(extentNode.getFirstChild().getNodeValue()).doubleValue();
359
                                                        if(extentNode.getNodeName().equals(RasterMetaFileTags.POINTS_W))
360
                                                                res[2] = Double.valueOf(extentNode.getFirstChild().getNodeValue()).doubleValue();
361
                                                        if(extentNode.getNodeName().equals(RasterMetaFileTags.POINTS_H))
362
                                                                res[3] = Double.valueOf(extentNode.getFirstChild().getNodeValue()).doubleValue();
363
                                                }
364
                                        }
365
                                        if(vpNode.getNodeName().equals(RasterMetaFileTags.POINTS_DIM)){
366
                                                NodeList dimChildNodes = vpNode.getChildNodes();
367
                                                for(int k=0; k<dimChildNodes.getLength();k++){
368
                                                        Node dimNode = dimChildNodes.item(k);
369
                                                        if(dimNode.getNodeName().equals(RasterMetaFileTags.WIDTH))
370
                                                                res[4] = Double.valueOf(dimNode.getFirstChild().getNodeValue()).doubleValue();
371
                                                        if(dimNode.getNodeName().equals(RasterMetaFileTags.HEIGHT))
372
                                                                res[5] = Double.valueOf(dimNode.getFirstChild().getNodeValue()).doubleValue();
373
                                                }
374
                                                lyrPoints.getLyrGeoRaster().setImageDimension(res[4], res[5]);
375
                                        }
376
                                }
377
                        }
378
                }
379
                return res;
380
        }
381

    
382
        /**
383
         * Obtiene el valor de un punto georeferenciado obtenido desde un nodo
384
         * XML. A partir de este valor obtenido crea un punto en la capa.
385
         */
386
        private void processGeoPointNodeValue(NodeList nl){
387
                Point2D leftCenter = null, rightCenter = null;
388
                ViewPort leftViewPort = null, rightViewPort = null;
389
                double zoomLeft = 1, zoomRight = 1;
390
                double pX = 0D, pY = 0D, mX = 0D, mY = 0D;
391
                boolean active = false;
392
                for(int j=0;j<nl.getLength();j++){
393
                        Node geoNode = nl.item(j);
394
                        if(geoNode.getNodeName().equals(RasterMetaFileTags.GEOPOINT_PX))
395
                                pX = Double.valueOf(geoNode.getFirstChild().getNodeValue()).doubleValue();
396
                        if(geoNode.getNodeName().equals(RasterMetaFileTags.GEOPOINT_PY))
397
                                pY = Double.valueOf(geoNode.getFirstChild().getNodeValue()).doubleValue();
398
                        if(geoNode.getNodeName().equals(RasterMetaFileTags.GEOPOINT_MAPX))
399
                                mX = Double.valueOf(geoNode.getFirstChild().getNodeValue()).doubleValue();
400
                        if(geoNode.getNodeName().equals(RasterMetaFileTags.GEOPOINT_MAPY))
401
                                mY = Double.valueOf(geoNode.getFirstChild().getNodeValue()).doubleValue();
402
                        if(geoNode.getNodeName().equals(RasterMetaFileTags.GEOPOINT_ACTIVE))
403
                                active =  Boolean.valueOf(geoNode.getFirstChild().getNodeValue()).booleanValue();
404
                        if(geoNode.getNodeName().equals(RasterMetaFileTags.GEOPOINT_LCENTER))
405
                                leftCenter = processCenterPoint(geoNode.getChildNodes());
406
                        if(geoNode.getNodeName().equals(RasterMetaFileTags.GEOPOINT_RCENTER))
407
                                rightCenter = processCenterPoint(geoNode.getChildNodes());
408
                        if(geoNode.getNodeName().equals(RasterMetaFileTags.GEOPOINT_LVP)){
409
                                Object[] obj = processViewPort(geoNode.getChildNodes());
410
                                leftViewPort = (ViewPort)obj[0];
411
                                zoomLeft = ((Double)obj[1]).doubleValue();
412
                        }
413
                        if(geoNode.getNodeName().equals(RasterMetaFileTags.GEOPOINT_RVP)){
414
                                Object[] obj = processViewPort(geoNode.getChildNodes());
415
                                rightViewPort = (ViewPort)obj[0];
416
                                zoomRight = ((Double)obj[1]).doubleValue();
417
                        }
418
                }
419

    
420
                Point2D p = new Point2D.Double();
421
                p.setLocation(pX, pY);
422
                Point2D m = new Point2D.Double();
423
                m.setLocation(mX, mY);
424

    
425
                lyrPoints.getPointManager().newEmptyPoint();
426
                GeoreferencingToolsModule.setEnabled(true);
427

    
428
                int pos = lyrPoints.getCountPoints() -1;
429
                leftViewPort = transformMiniExtent(lyrPoints.getLyrGeoRaster().getFullExtent(), leftViewPort);
430
                leftCenter = transformCenter(lyrPoints.getLyrGeoRaster().getFullExtent(), leftCenter);
431
                lyrPoints.setPointActive(pos, active);
432
                lyrPoints.setLeftCenterPoint(pos,leftCenter);
433
                lyrPoints.setRightCenterPoint(pos, rightCenter);
434
                lyrPoints.setMiniExtent(pos, lyrPoints.getLyrGeoRaster().img2World(p), leftViewPort, false);
435
                lyrPoints.setMiniExtent(pos, m, rightViewPort, true);
436
                lyrPoints.getPointManager().updateData(pos + 1, p, m, lyrPoints.getPointManager().getDialog(), null);
437
                lyrPoints.setZoomLeft(pos, zoomLeft);
438
                lyrPoints.setZoomRight(pos, zoomRight);
439
                if(lyrPoints.getCountPoints() > 0){
440
                        GeoreferencingDialog grd = lyrPoints.getPointManager().getDialog();
441
                        grd.getConectorPanel().getDataPointsTabPanel().
442
                                getSelectPointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints());
443
                        grd.getConectorPanel().getDataPointsTabPanel().
444
                                getTablePointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints());
445
                        lyrPoints.getPointManager().selectPoint(0, grd);
446
                }
447
                //lyrPoints.addPoint(p, m);
448
        }
449

    
450
        /**
451
         * Procesa un nodo correspondiente a un extent
452
         * @param nodeList Lista de nodos
453
         * @return Rectangle2D
454
         */
455
        private Rectangle2D processExtent(NodeList nodeList){
456
                Rectangle2D r = new Rectangle2D.Double();
457
                double x = 0D, y = 0D, width = 0D, height = 0D;
458
                for(int j=0;j<nodeList.getLength();j++){
459
                        Node node = nodeList.item(j);
460
                        if(node.getNodeName().equals(RasterMetaFileTags.POINTS_PX))
461
                                x = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
462
                        if(node.getNodeName().equals(RasterMetaFileTags.POINTS_PY))
463
                                y = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
464
                        if(node.getNodeName().equals(RasterMetaFileTags.POINTS_W))
465
                                width = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
466
                        if(node.getNodeName().equals(RasterMetaFileTags.POINTS_H))
467
                                height = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
468
                }
469
                r.setRect(x, y, width, height);
470
                return r;
471
        }
472

    
473
        /**
474
         * Procesa un nodo correspondiente a la dimension de un viewPort
475
         * @param nodeList Lista de nodos
476
         * @return Rectangle2D
477
         */
478
        private Dimension processImageSize(NodeList nodeList){
479
                Dimension d = new Dimension();
480
                double x = 0D, y = 0D;
481
                for(int j=0;j<nodeList.getLength();j++){
482
                        Node node = nodeList.item(j);
483
                        if(node.getNodeName().equals(RasterMetaFileTags.WIDTH))
484
                                x = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
485
                        if(node.getNodeName().equals(RasterMetaFileTags.HEIGHT))
486
                                y = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
487
                }
488
                d.setSize(x, y);
489
                return d;
490
        }
491

    
492
        /**
493
         * Procesa el nodo correspondiente a un viewport de una mini imagen
494
         * @param nodeList Lista de nodos
495
         * @return ViewPort obtenido
496
         */
497
        private Object[] processViewPort(NodeList nodeList){
498
                Object[] obj = new Object[2];
499
                ViewPort vp = new ViewPort(null);
500
                Double zoom =  new Double(1);
501
                for(int j=0;j<nodeList.getLength();j++){
502
                        Node node = nodeList.item(j);
503
                        if(node.getNodeName().equals(RasterMetaFileTags.POINTS_PROJ))
504
                                vp.setProjection(CRSFactory.getCRS(node.getFirstChild().getNodeValue()));
505
                        if(node.getNodeName().equals(RasterMetaFileTags.POINTS_BBOX))
506
                                vp.setExtent(processExtent(node.getChildNodes()));
507
                        if(node.getNodeName().equals(RasterMetaFileTags.POINTS_DIM))
508
                                vp.setImageSize(processImageSize(node.getChildNodes()));
509
                        if(node.getNodeName().equals(RasterMetaFileTags.POINTS_ZOOM))
510
                                zoom = new Double(node.getFirstChild().getNodeValue());
511
                }
512
                obj[0] = vp;
513
                obj[1] = zoom;
514
                vp.refreshExtent();
515
                return obj;
516
        }
517

    
518
        /**
519
         * Procesa un node correspondiente a un punto central de una
520
         * mini imagen
521
         * @param nodeList Lista de elementos del nodo centro
522
         * @return Punto obtenido
523
         */
524
        private Point2D processCenterPoint(NodeList nodeList){
525
                Point2D p = new Point2D.Double();
526
                double x = 0D, y = 0D;
527
                for(int j=0;j<nodeList.getLength();j++){
528
                        Node node = nodeList.item(j);
529
                        if(node.getNodeName().equals(RasterMetaFileTags.POSX))
530
                                x = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
531
                        if(node.getNodeName().equals(RasterMetaFileTags.POSY))
532
                                y = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
533
                }
534
                p.setLocation(x, y);
535
                return p;
536
        }
537
        //**********************End Methods***************************
538

    
539
        //**********************Getters & Setters*********************
540
        /**
541
         * Asigna la capa de puntos
542
         * @param lyrPoints
543
         */
544
        public void setLyrPoints(FLyrPoints lyrPoints) {
545
                this.geoPointList = lyrPoints.getListPoint();
546
                this.lyrPoints = lyrPoints;
547
        }
548
        //**********************End Getters & Setters*****************
549
}