gvsig-raster / org.gvsig.raster.ermapper / trunk / org.gvsig.raster.ermapper / org.gvsig.raster.ermapper.io / src / main / java / org / gvsig / raster / ermapper / io / ErmapperFilesystemServerExplorer.java @ 2449
History | View | Annotate | Download (6.9 KB)
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.ermapper.io; |
29 |
|
30 |
import java.awt.geom.AffineTransform; |
31 |
import java.io.File; |
32 |
import java.io.IOException; |
33 |
|
34 |
import org.gvsig.fmap.dal.DALLocator; |
35 |
import org.gvsig.fmap.dal.DataManager; |
36 |
import org.gvsig.fmap.dal.DataServerExplorer; |
37 |
import org.gvsig.fmap.dal.DataStoreParameters; |
38 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
39 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
40 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
41 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
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.DataServerWriter; |
45 |
import org.gvsig.fmap.dal.coverage.store.RasterWriter; |
46 |
import org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters; |
47 |
import org.gvsig.fmap.dal.exception.CreateException; |
48 |
import org.gvsig.fmap.dal.exception.DataException; |
49 |
import org.gvsig.fmap.dal.exception.RemoveException; |
50 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider; |
51 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
52 |
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters; |
53 |
import org.gvsig.tools.locator.LocatorException; |
54 |
|
55 |
public class ErmapperFilesystemServerExplorer extends AbstractFilesystemServerExplorerProvider { |
56 |
|
57 |
/*
|
58 |
* (non-Javadoc)
|
59 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#canCreate()
|
60 |
*/
|
61 |
public boolean canCreate() { |
62 |
return false; |
63 |
} |
64 |
|
65 |
/*
|
66 |
* (non-Javadoc)
|
67 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#canCreate(org.gvsig.fmap.dal.NewDataStoreParameters)
|
68 |
*/
|
69 |
public boolean canCreate(NewDataStoreParameters parameters) { |
70 |
return false; |
71 |
} |
72 |
|
73 |
/*
|
74 |
* (non-Javadoc)
|
75 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#create(org.gvsig.fmap.dal.NewDataStoreParameters, boolean)
|
76 |
*/
|
77 |
public void create(NewDataStoreParameters parameters, boolean overwrite) |
78 |
throws CreateException {
|
79 |
NewRasterStoreParameters p = null;
|
80 |
if(parameters instanceof NewRasterStoreParameters) |
81 |
p = (NewRasterStoreParameters)parameters; |
82 |
|
83 |
DataServerWriter dataWriter = p.getDataServer(); |
84 |
if(dataWriter == null) |
85 |
dataWriter = RasterLocator.getManager().createDataServerWriter(); |
86 |
dataWriter.setBuffer(p.getBuffer(), p.getBand()); |
87 |
Params params; |
88 |
try {
|
89 |
if(p.getDriverParams() != null) |
90 |
params = p.getDriverParams(); |
91 |
else
|
92 |
params = RasterLocator.getManager().createWriter(p.getFileName()).getParams(); |
93 |
|
94 |
AffineTransform affineTransform = p.getAffineTransform();
|
95 |
if(affineTransform == null) { |
96 |
if(p.getBuffer().getDataExtent() != null) { |
97 |
double x = p.getBuffer().getDataExtent().getMinX();
|
98 |
double y = p.getBuffer().getDataExtent().getMaxY();
|
99 |
double pixelSizeX = p.getBuffer().getDataExtent().getWidth() / p.getBuffer().getWidth();
|
100 |
double pixelSizeY = p.getBuffer().getDataExtent().getHeight() / p.getBuffer().getHeight();
|
101 |
affineTransform = new AffineTransform(pixelSizeX, 0, 0, pixelSizeY, x, y); |
102 |
} else {
|
103 |
affineTransform = new AffineTransform(); |
104 |
} |
105 |
} |
106 |
|
107 |
RasterWriter writer = RasterLocator.getManager().createWriter( |
108 |
dataWriter, |
109 |
p.getPath() + File.separator + p.getFileName(),
|
110 |
p.getBand() < 0 ? p.getBuffer().getBandCount() : 1, |
111 |
affineTransform, |
112 |
p.getBuffer().getWidth(), |
113 |
p.getBuffer().getHeight(), |
114 |
p.getBuffer().getDataType(), |
115 |
params, |
116 |
null);
|
117 |
if(p.getColorInterpretation() != null) |
118 |
writer.setColorBandsInterpretation(p.getColorInterpretation()); |
119 |
writer.setWkt(p.getWktProjection()); |
120 |
|
121 |
writer.dataWrite(); |
122 |
writer.writeClose(); |
123 |
} catch (LocatorException e) {
|
124 |
throw new CreateException("", e); |
125 |
} catch (NotSupportedExtensionException e) {
|
126 |
throw new CreateException("", e); |
127 |
} catch (RasterDriverException e) {
|
128 |
throw new CreateException("", e); |
129 |
} catch (ProcessInterruptedException e) {
|
130 |
//Fin del proceso
|
131 |
} catch (IOException e) { |
132 |
throw new CreateException("", e); |
133 |
} |
134 |
} |
135 |
|
136 |
/*
|
137 |
* (non-Javadoc)
|
138 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#getCreateParameters()
|
139 |
*/
|
140 |
public NewDataStoreParameters getCreateParameters() throws DataException { |
141 |
return new ErmapperNewRasterStoreParameters(); |
142 |
} |
143 |
|
144 |
/*
|
145 |
* (non-Javadoc)
|
146 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#initialize(org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices)
|
147 |
*/
|
148 |
public void initialize( |
149 |
FilesystemServerExplorerProviderServices serverExplorer) { |
150 |
} |
151 |
|
152 |
/*
|
153 |
* (non-Javadoc)
|
154 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#remove(org.gvsig.fmap.dal.DataStoreParameters)
|
155 |
*/
|
156 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
157 |
throw new UnsupportedOperationException(); |
158 |
} |
159 |
|
160 |
/*
|
161 |
* (non-Javadoc)
|
162 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter#getDataStoreProviderName()
|
163 |
*/
|
164 |
public String getDataStoreProviderName() { |
165 |
return ErmapperProvider.NAME;
|
166 |
} |
167 |
|
168 |
/*
|
169 |
* (non-Javadoc)
|
170 |
* @see java.io.FileFilter#accept(java.io.File)
|
171 |
*/
|
172 |
public boolean accept(File pathname) { |
173 |
return RasterLocator.getManager().getProviderServices().isExtensionSupported(
|
174 |
pathname.getAbsolutePath(), |
175 |
ErmapperProvider.class); |
176 |
} |
177 |
|
178 |
/*
|
179 |
* (non-Javadoc)
|
180 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter#getDescription()
|
181 |
*/
|
182 |
public String getDescription() { |
183 |
return ErmapperProvider.DESCRIPTION;
|
184 |
} |
185 |
|
186 |
public DataStoreParameters getParameters(File file) throws DataException { |
187 |
DataManager manager = DALLocator.getDataManager(); |
188 |
AbstractRasterFileDataParameters params = (AbstractRasterFileDataParameters) manager |
189 |
.createStoreParameters(this.getDataStoreProviderName());
|
190 |
params.setFile(file); |
191 |
return params;
|
192 |
} |
193 |
|
194 |
public int getMode() { |
195 |
return DataServerExplorer.MODE_RASTER;
|
196 |
} |
197 |
} |