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