Statistics
| Revision:

gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / data / DefaultDataRasterReader.java @ 446

History | View | Annotate | Download (4.07 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 gvSIG Association
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
package org.gvsig.view3d.swing.impl.data;
26

    
27
import java.io.IOException;
28

    
29
import org.gvsig.fmap.mapcontext.MapContext;
30
import org.gvsig.fmap.mapcontext.layers.FLayer;
31

    
32
import gov.nasa.worldwind.avlist.AVKey;
33
import gov.nasa.worldwind.avlist.AVList;
34
import gov.nasa.worldwind.avlist.AVListImpl;
35
import gov.nasa.worldwind.data.AbstractDataRasterReader;
36
import gov.nasa.worldwind.data.DataRaster;
37
import gov.nasa.worldwind.geom.Sector;
38

    
39
/**
40
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
41
 *
42
 */
43
public class DefaultDataRasterReader extends AbstractDataRasterReader {
44

    
45
    /**
46
     * @param description
47
     */
48
    protected DefaultDataRasterReader(String description) {
49
        super(description);
50
    }
51

    
52
    @Override
53
    public boolean canRead(Object source, AVList params) {
54

    
55
        if (source == null) {
56
            throw new IllegalArgumentException();
57
        }
58

    
59
        return this.doCanRead(source, params);
60
    }
61

    
62
    @Override
63
    protected boolean doCanRead(Object source, AVList params) {
64

    
65
        if (params == null) {
66
            return false;
67
        }
68

    
69
        Sector sector = (Sector) params.getValue(AVKey.SECTOR);
70
        if (sector == null) {
71
            return false;
72
        }
73

    
74
        if (source instanceof FLayer) {
75

    
76
            boolean canRead = false;
77
            GvSIGLayerDataRaster dataRaster = null;
78

    
79
            try {
80
                FLayer layer = (FLayer) source;
81
                MapContext mapContext =
82
                    (MapContext) params.getValue("GVSIG_MAPCONTEXT");
83
                dataRaster =
84
                    new GvSIGLayerDataRaster(mapContext, layer, params);
85
                canRead = true;
86
            } catch (Throwable e) {
87
                canRead = false;
88
            } finally {
89
                if (dataRaster != null) {
90
                    dataRaster.dispose();
91
                }
92
            }
93

    
94
            return canRead;
95
        }
96

    
97
        return false;
98
    }
99

    
100
    @Override
101
    protected DataRaster[] doRead(Object source, AVList params)
102
        throws IOException {
103

    
104
        if (source == null) {
105
            throw new IllegalArgumentException();
106
        }
107

    
108
        if (source instanceof FLayer) {
109

    
110
            FLayer layer = (FLayer) source;
111
            MapContext mapContext =
112
                (MapContext) params.getValue("GVSIG_MAPCONTEXT");
113
            GvSIGLayerDataRaster dataRaster =
114
                new GvSIGLayerDataRaster(mapContext, layer, params);
115
            return new DataRaster[] { dataRaster };
116

    
117
        }
118

    
119
        return null;
120
    }
121

    
122
    @Override
123
    protected void doReadMetadata(Object source, AVList params)
124
        throws IOException {
125
        
126
        //TODO: fill weigth height and sector
127

    
128
    }
129
    
130
    @Override
131
    public AVList readMetadata(Object source, AVList params) throws java.io.IOException
132
    {
133
        if (!this.canRead(source, params))
134
        {
135
            throw new IllegalArgumentException();
136
        }
137

    
138
        if (params == null)
139
            params = new AVListImpl();
140

    
141
        this.doReadMetadata(source, params);
142

    
143
        String message = this.validateMetadata(source, params);
144
        if (message != null)
145
            throw new java.io.IOException(message);
146

    
147
        return params;
148
    }
149

    
150
}