Revision 9705
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.83/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/memory/io/MemoryRasterProvider.java | ||
---|---|---|
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 |
package org.gvsig.raster.memory.io; |
|
23 |
|
|
24 |
import java.awt.geom.AffineTransform; |
|
25 |
import java.awt.geom.Point2D; |
|
26 |
import java.awt.geom.Rectangle2D; |
|
27 |
import java.io.File; |
|
28 |
|
|
29 |
import org.cresques.cts.ICoordTrans; |
|
30 |
|
|
31 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
32 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
|
33 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
34 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
|
35 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
|
36 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
37 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
|
38 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
39 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
40 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
41 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
|
42 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
43 |
import org.gvsig.metadata.MetadataLocator; |
|
44 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
45 |
import org.gvsig.raster.impl.buffer.SpiRasterQuery; |
|
46 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
|
47 |
import org.gvsig.raster.impl.provider.AbstractRasterProvider; |
|
48 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
49 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
|
50 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
|
51 |
import org.gvsig.tools.ToolsLocator; |
|
52 |
import org.gvsig.tools.task.TaskStatus; |
|
53 |
|
|
54 |
/** |
|
55 |
* Driver para datos cargados en un objeto IBuffer |
|
56 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
57 |
* |
|
58 |
*/ |
|
59 |
public class MemoryRasterProvider extends AbstractRasterProvider { |
|
60 |
public static String NAME = "Gdal Store"; |
|
61 |
public static String DESCRIPTION = "Gdal Raster file"; |
|
62 |
public static final String METADATA_DEFINITION_NAME = "GdalStore"; |
|
63 |
|
|
64 |
private Extent v = null; |
|
65 |
protected Buffer buffer = null; |
|
66 |
private Extent extent = null; |
|
67 |
private boolean open = false; |
|
68 |
|
|
69 |
public static void register() { |
|
70 |
} |
|
71 |
|
|
72 |
public void registerTileProviderFormats(Class<RasterProvider> c) { |
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Mandatory constructor to instantiate an empty provider |
|
78 |
*/ |
|
79 |
public MemoryRasterProvider() {} |
|
80 |
|
|
81 |
/** |
|
82 |
* Constructor. Asigna el buffer de datos y la extensi?n |
|
83 |
* @param proj Proyecci?n |
|
84 |
* @param buf Buffer |
|
85 |
* @throws NotSupportedExtensionException |
|
86 |
*/ |
|
87 |
public MemoryRasterProvider(AbstractRasterDataParameters params, |
|
88 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException { |
|
89 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
|
90 |
.createDynObject( |
|
91 |
MetadataLocator.getMetadataManager().getDefinition( |
|
92 |
METADATA_DEFINITION_NAME))); |
|
93 |
setParam(storeServices, params); |
|
94 |
if(!(params instanceof MemoryDataParameters)) |
|
95 |
throw new NotSupportedExtensionException("Buffer not supported"); |
|
96 |
|
|
97 |
extent = ((MemoryDataParameters)params).getExtent(); |
|
98 |
this.buffer = ((MemoryDataParameters)params).getBuffer(); |
|
99 |
|
|
100 |
if(extent != null) { |
|
101 |
double psX = (extent.maxX() - extent.minX()) / buffer.getWidth(); |
|
102 |
double psY = (extent.minY() - extent.maxY()) / buffer.getHeight(); |
|
103 |
ownTransformation = new AffineTransform(psX, 0, 0, psY, extent.minX(), extent.maxY()); |
|
104 |
} else |
|
105 |
ownTransformation = new AffineTransform(1, 0, 0, -1, 0, buffer.getHeight()); |
|
106 |
|
|
107 |
if(buffer == null) |
|
108 |
throw new NotSupportedExtensionException("Buffer invalid"); |
|
109 |
|
|
110 |
load(); |
|
111 |
bandCount = buffer.getBandCount(); |
|
112 |
|
|
113 |
//Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf |
|
114 |
int[] dt = new int[buffer.getBandCount()]; |
|
115 |
for (int i = 0; i < dt.length; i++) |
|
116 |
dt[i] = buffer.getDataType(); |
|
117 |
setDataType(dt); |
|
118 |
open = true; |
|
119 |
} |
|
120 |
|
|
121 |
public RasterProvider load() { |
|
122 |
return this; |
|
123 |
} |
|
124 |
|
|
125 |
public boolean isOpen() { |
|
126 |
return open; |
|
127 |
} |
|
128 |
|
|
129 |
public void close() { |
|
130 |
buffer = null; |
|
131 |
open = false; |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Asigna el extent de la vista actual. |
|
136 |
*/ |
|
137 |
public void setView(Extent e) { |
|
138 |
v = e; |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* Obtiene extent de la vista actual |
|
143 |
*/ |
|
144 |
public Extent getView() { |
|
145 |
return v; |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Obtiene la anchura del fichero |
|
150 |
*/ |
|
151 |
public double getWidth() { |
|
152 |
return buffer.getWidth(); |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* Obtiene la altura del fichero |
|
157 |
*/ |
|
158 |
public double getHeight() { |
|
159 |
return buffer.getHeight(); |
|
160 |
} |
|
161 |
|
|
162 |
public void reProject(ICoordTrans rp) { |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Obtiene la orientaci?n de la imagen a partir del signo del tama?o de pixel para poder |
|
167 |
* asignarlo en el setView. Esto es util para poder conocer como debe leerse la image, |
|
168 |
* de abajo a arriba, de arriba a abajo, de izquierda a derecha o de derecha a izquierda. |
|
169 |
* La posici?n habitual es la que el pixel size en X es positivo y en Y negativo leyendose |
|
170 |
* en este caso las X de menor a mayor y las Y de mayor a menor. Los casos posibles son: |
|
171 |
* <UL> |
|
172 |
* <LI><B>X > 0; Y < 0;</B> {true, false}</LI> |
|
173 |
* <LI><B>X > 0; Y > 0;</B> {true, true}</LI> |
|
174 |
* <LI><B>X < 0; Y > 0;</B> {false, true}</LI> |
|
175 |
* <LI><B>X < 0; Y < 0;</B> {false, false}</LI> |
|
176 |
* </UL> |
|
177 |
* |
|
178 |
* @return |
|
179 |
*/ |
|
180 |
/*private boolean[] getOrientation(){ |
|
181 |
boolean[] orientation = {true, false}; |
|
182 |
return orientation; |
|
183 |
}*/ |
|
184 |
|
|
185 |
public Object getData(int x, int y, int band) { |
|
186 |
if(buffer.getDataType() == Buffer.TYPE_BYTE){ |
|
187 |
return new Integer(buffer.getElemByte(y, x, band)); |
|
188 |
}else if(buffer.getDataType() == Buffer.TYPE_SHORT){ |
|
189 |
return new Integer(buffer.getElemShort(y, x, band)); |
|
190 |
}else if(buffer.getDataType() == Buffer.TYPE_INT){ |
|
191 |
return new Integer(buffer.getElemInt(y, x, band)); |
|
192 |
}else if(buffer.getDataType() == Buffer.TYPE_FLOAT){ |
|
193 |
return new Float(buffer.getElemFloat(y, x, band)); |
|
194 |
}else if(buffer.getDataType() == Buffer.TYPE_DOUBLE){ |
|
195 |
return new Double(buffer.getElemDouble(y, x, band)); |
|
196 |
} |
|
197 |
return null; |
|
198 |
} |
|
199 |
|
|
200 |
|
|
201 |
/** |
|
202 |
* Devuelve el tama?o de bloque |
|
203 |
* @return Tama?o de bloque |
|
204 |
*/ |
|
205 |
public int getBlockSize(){ |
|
206 |
return 0; |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* Obtiene el flag que dice si la imagen est? o no georreferenciada |
|
211 |
* @return true si est? georreferenciada y false si no lo est?. |
|
212 |
*/ |
|
213 |
public boolean isGeoreferenced() { |
|
214 |
return (this.extent != null); |
|
215 |
} |
|
216 |
|
|
217 |
/** |
|
218 |
* Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar? |
|
219 |
* el valor de esta variable cada vez que dibuja. |
|
220 |
* @return true si se ha supersampleado y false si no se ha hecho. |
|
221 |
*/ |
|
222 |
public boolean isSupersampling() { |
|
223 |
return false; |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* @return Returns the dataType. |
|
228 |
*/ |
|
229 |
public int[] getDataType() { |
|
230 |
int[] dt = new int[buffer.getBandCount()]; |
|
231 |
for (int i = 0; i < dt.length; i++) |
|
232 |
dt[i] = buffer.getDataType(); |
|
233 |
return dt; |
|
234 |
} |
|
235 |
|
|
236 |
/** |
|
237 |
* Ajusta los puntos pasados por par?metro a los l?mites del buffer. Es decir si alguno excede |
|
238 |
* los l?mites por arriba o por abajo los ajusta. |
|
239 |
* @param begin Punto inicial |
|
240 |
* @param end Punto final |
|
241 |
*/ |
|
242 |
private void adjustPointsToBufferLimits(Point2D begin, Point2D end) { |
|
243 |
if(begin.getX() < 0) |
|
244 |
begin.setLocation(0, begin.getY()); |
|
245 |
if(begin.getY() > buffer.getHeight()) |
|
246 |
begin.setLocation(begin.getX(), buffer.getHeight()); |
|
247 |
if(end.getY() < 0) |
|
248 |
end.setLocation(begin.getX(), 0); |
|
249 |
if(end.getX() > buffer.getWidth()) |
|
250 |
begin.setLocation(buffer.getWidth(), begin.getY()); |
|
251 |
} |
|
252 |
|
|
253 |
public void loadBuffer(SpiRasterQuery q) |
|
254 |
throws ProcessInterruptedException, RasterDriverException { |
|
255 |
getWindow(q.getAdjustedRequestBoundingBox(), q.getBandList(), q.getBufferForProviders(), q.getTaskStatus()); |
|
256 |
} |
|
257 |
|
|
258 |
public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status) { |
|
259 |
Point2D begin = worldToRaster(new Point2D.Double(ex.getULX(), ex.getULY())); |
|
260 |
Point2D end = worldToRaster(new Point2D.Double(ex.getLRX(), ex.getLRY())); |
|
261 |
setView(ex); |
|
262 |
|
|
263 |
adjustPointsToBufferLimits(begin, end); |
|
264 |
|
|
265 |
switch(buffer.getDataType()){ |
|
266 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
267 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
268 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
269 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
270 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
271 |
} |
|
272 |
return rasterBuf; |
|
273 |
} |
|
274 |
|
|
275 |
public Buffer getWindow(double x, double y, double w, double h, |
|
276 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) { |
|
277 |
Point2D begin = worldToRaster(new Point2D.Double(x, y)); |
|
278 |
Point2D end = worldToRaster(new Point2D.Double(x + w, y - h)); |
|
279 |
setView(new ExtentImpl(x, y, x + w, y - h)); |
|
280 |
|
|
281 |
adjustPointsToBufferLimits(begin, end); |
|
282 |
|
|
283 |
switch(buffer.getDataType()){ |
|
284 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
285 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
286 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
287 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
288 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
289 |
} |
|
290 |
return rasterBuf; |
|
291 |
} |
|
292 |
|
|
293 |
public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, |
|
294 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) { |
|
295 |
Point2D begin = worldToRaster(new Point2D.Double(extent.getMin().getX(), extent.getMax().getY())); |
|
296 |
Point2D end = worldToRaster(new Point2D.Double(extent.getMax().getX(), extent.getMin().getY())); |
|
297 |
setView(extent); |
|
298 |
|
|
299 |
adjustPointsToBufferLimits(begin, end); |
|
300 |
|
|
301 |
//Ancho y alto en pixels (double) del area seleccionada. |
|
302 |
double w = Math.abs(end.getX() - begin.getX()); |
|
303 |
double h = Math.abs(end.getY() - begin.getY()); |
|
304 |
|
|
305 |
//Relaci?n entre el n?mero de pixels del buffer origen (area seleccionada) y el destino |
|
306 |
double stepX = w / ((double)bufWidth); |
|
307 |
double stepY = h / ((double)bufHeight); |
|
308 |
|
|
309 |
//Escritura separada en 5 llamadas para mejorar el rendimiento |
|
310 |
switch(buffer.getDataType()){ |
|
311 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
|
312 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
|
313 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
|
314 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
|
315 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
|
316 |
} |
|
317 |
|
|
318 |
/*int xPx = 0, yPx = 0; |
|
319 |
for (int iBand = 0; iBand < rasterBuf.getBandCount(); iBand++) { |
|
320 |
yPx = 0; |
|
321 |
for(double row = begin.getY(); yPx < bufHeight; row += stepY) { |
|
322 |
xPx = 0; |
|
323 |
for(double col = begin.getX(); xPx < bufWidth; col += stepX) { |
|
324 |
switch(buffer.getDataType()){ |
|
325 |
case Buffer.TYPE_BYTE: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemByte((int)row, (int)col, iBand)); break; |
|
326 |
case Buffer.TYPE_SHORT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemShort((int)row, (int)col, iBand)); break; |
|
327 |
case Buffer.TYPE_INT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemInt((int)row, (int)col, iBand)); break; |
|
328 |
case Buffer.TYPE_FLOAT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemFloat((int)row, (int)col, iBand)); break; |
|
329 |
case Buffer.TYPE_DOUBLE: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemDouble((int)row, (int)col, iBand)); break; |
|
330 |
} |
|
331 |
xPx ++; |
|
332 |
} |
|
333 |
yPx ++; |
|
334 |
} |
|
335 |
}*/ |
|
336 |
return rasterBuf; |
|
337 |
} |
|
338 |
|
|
339 |
/** |
|
340 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores |
|
341 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a |
|
342 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento. |
|
343 |
* @param rasterBuf Buffer donde se escriben los datos |
|
344 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario |
|
345 |
* ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino. |
|
346 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario |
|
347 |
* ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino. |
|
348 |
* @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio |
|
349 |
* del pixel. Esto es util cuando se supersamplea. |
|
350 |
*/ |
|
351 |
private void writeByteBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
|
352 |
int xPx = 0, yPx = 0; |
|
353 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
354 |
int[] drawableBands = bandList.getBufferBandToDraw(new File(this.getURIOfFirstProvider()).getAbsolutePath(), iBand); |
|
355 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
356 |
continue; |
|
357 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
358 |
yPx = 0; |
|
359 |
for(double row = begin.getY(); (yPx < rasterBuf.getHeight() && row < buffer.getHeight()); row += stepY) { |
|
360 |
xPx = 0; |
|
361 |
for(double col = begin.getX(); (xPx < rasterBuf.getWidth() && col < buffer.getWidth()); col += stepX) { |
|
362 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemByte((int)row, (int)col, iBand)); |
|
363 |
xPx ++; |
|
364 |
} |
|
365 |
yPx ++; |
|
366 |
} |
|
367 |
} |
|
368 |
} |
|
369 |
} |
|
370 |
|
|
371 |
/** |
|
372 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores |
|
373 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a |
|
374 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento. |
|
375 |
* @param rasterBuf Buffer donde se escriben los datos |
|
376 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario |
|
377 |
* ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino. |
|
378 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario |
|
379 |
* ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino. |
|
380 |
* @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio |
|
381 |
* del pixel. Esto es util cuando se supersamplea. |
|
382 |
*/ |
|
383 |
private void writeShortBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
|
384 |
int xPx = 0, yPx = 0; |
|
385 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
386 |
int[] drawableBands = bandList.getBufferBandToDraw(new File(this.getURIOfFirstProvider()).getAbsolutePath(), iBand); |
|
387 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
388 |
continue; |
|
389 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
390 |
yPx = 0; |
|
391 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
|
392 |
xPx = 0; |
|
393 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
|
394 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemShort((int)row, (int)col, iBand)); |
|
395 |
xPx ++; |
|
396 |
} |
|
397 |
yPx ++; |
|
398 |
} |
|
399 |
} |
|
400 |
} |
|
401 |
} |
|
402 |
|
|
403 |
/** |
|
404 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores |
|
405 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a |
|
406 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento. |
|
407 |
* @param rasterBuf Buffer donde se escriben los datos |
|
408 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario |
|
409 |
* ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino. |
|
410 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario |
|
411 |
* ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino. |
|
412 |
* @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio |
|
413 |
* del pixel. Esto es util cuando se supersamplea. |
|
414 |
*/ |
|
415 |
private void writeIntBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
|
416 |
int xPx = 0, yPx = 0; |
|
417 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
418 |
int[] drawableBands = bandList.getBufferBandToDraw(new File(this.getURIOfFirstProvider()).getAbsolutePath(), iBand); |
|
419 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
420 |
continue; |
|
421 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
422 |
yPx = 0; |
|
423 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
|
424 |
xPx = 0; |
|
425 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
|
426 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemInt((int)row, (int)col, iBand)); |
|
427 |
xPx ++; |
|
428 |
} |
|
429 |
yPx ++; |
|
430 |
} |
|
431 |
} |
|
432 |
} |
|
433 |
} |
|
434 |
|
|
435 |
/** |
|
436 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores |
|
437 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a |
|
438 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento. |
|
439 |
* @param rasterBuf Buffer donde se escriben los datos |
|
440 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario |
|
441 |
* ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino. |
|
442 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario |
|
443 |
* ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino. |
|
444 |
* @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio |
|
445 |
* del pixel. Esto es util cuando se supersamplea. |
|
446 |
*/ |
|
447 |
private void writeFloatBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
|
448 |
int xPx = 0, yPx = 0; |
|
449 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
450 |
int[] drawableBands = bandList.getBufferBandToDraw(new File(this.getURIOfFirstProvider()).getAbsolutePath(), iBand); |
|
451 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
452 |
continue; |
|
453 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
454 |
yPx = 0; |
|
455 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
|
456 |
xPx = 0; |
|
457 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
|
458 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemFloat((int)row, (int)col, iBand)); |
|
459 |
xPx ++; |
|
460 |
} |
|
461 |
yPx ++; |
|
462 |
} |
|
463 |
} |
|
464 |
} |
|
465 |
} |
|
466 |
|
|
467 |
/** |
|
468 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores |
|
469 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a |
|
470 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento. |
|
471 |
* @param rasterBuf Buffer donde se escriben los datos |
|
472 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario |
|
473 |
* ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino. |
|
474 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario |
|
475 |
* ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino. |
|
476 |
* @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio |
|
477 |
* del pixel. Esto es util cuando se supersamplea. |
|
478 |
*/ |
|
479 |
private void writeDoubleBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
|
480 |
int xPx = 0, yPx = 0; |
|
481 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
482 |
int[] drawableBands = bandList.getBufferBandToDraw(new File(this.getURIOfFirstProvider()).getAbsolutePath(), iBand); |
|
483 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
484 |
continue; |
|
485 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
486 |
yPx = 0; |
|
487 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
|
488 |
xPx = 0; |
|
489 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
|
490 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemDouble((int)row, (int)col, iBand)); |
|
491 |
xPx ++; |
|
492 |
} |
|
493 |
yPx ++; |
|
494 |
} |
|
495 |
} |
|
496 |
} |
|
497 |
} |
|
498 |
|
|
499 |
/* |
|
500 |
* (non-Javadoc) |
|
501 |
* @see org.gvsig.raster.dataset.RasterDataset#getWindowRaster(int, int, org.gvsig.raster.dataset.BandList, org.gvsig.raster.dataset.Buffer) |
|
502 |
*/ |
|
503 |
// public Buffer getWindow(int x, int y, BandList bandList, Buffer rasterBuf) { |
|
504 |
// int w = rasterBuf.getWidth(); |
|
505 |
// int h = rasterBuf.getHeight(); |
|
506 |
// setView( |
|
507 |
// new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(), |
|
508 |
// getWidth(), |
|
509 |
// getHeight(), |
|
510 |
// new Rectangle2D.Double(x, y, w, h))) |
|
511 |
// ); |
|
512 |
// |
|
513 |
// for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++){ |
|
514 |
// int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
|
515 |
// if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
516 |
// continue; |
|
517 |
// if(buffer.getDataType() == Buffer.TYPE_BYTE) { |
|
518 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
519 |
// for(int line = y; line < (y + h); line ++) |
|
520 |
// for(int col = x; col < (x + w); col ++) |
|
521 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemByte(line, col, drawableBands[drawBands])); |
|
522 |
// } |
|
523 |
// }else if(buffer.getDataType() == Buffer.TYPE_SHORT){ |
|
524 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){ |
|
525 |
// for(int line = y; line < (y + h); line ++) |
|
526 |
// for(int col = x; col < (x + w); col ++) |
|
527 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemShort(line, col, drawableBands[drawBands])); |
|
528 |
// } |
|
529 |
// }else if(buffer.getDataType() == Buffer.TYPE_INT){ |
|
530 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){ |
|
531 |
// for(int line = y; line < (y + h); line ++) |
|
532 |
// for(int col = x; col < (x + w); col ++) |
|
533 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemInt(line, col, drawableBands[drawBands])); |
|
534 |
// } |
|
535 |
// }else if(buffer.getDataType() == Buffer.TYPE_FLOAT){ |
|
536 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){ |
|
537 |
// for(int line = y; line < (y + h); line ++) |
|
538 |
// for(int col = x; col < (x + w); col ++) |
|
539 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemFloat(line, col, drawableBands[drawBands])); |
|
540 |
// } |
|
541 |
// }else if(buffer.getDataType() == Buffer.TYPE_DOUBLE){ |
|
542 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){ |
|
543 |
// for(int line = y; line < (y + h); line ++) |
|
544 |
// for(int col = x; col < (x + w); col ++) |
|
545 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemDouble(line, col, drawableBands[drawBands])); |
|
546 |
// } |
|
547 |
// } |
|
548 |
// } |
|
549 |
// return rasterBuf; |
|
550 |
// } |
|
551 |
|
|
552 |
public Buffer getWindow(int x, int y, int w, int h, |
|
553 |
BandList bandList, Buffer rasterBuf, TaskStatus status) { |
|
554 |
setView( |
|
555 |
new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(), |
|
556 |
getWidth(), |
|
557 |
getHeight(), |
|
558 |
new Rectangle2D.Double(x, y, w, h))) |
|
559 |
); |
|
560 |
|
|
561 |
//Relaci?n entre el n?mero de pixels del buffer origen (area seleccionada) y el destino |
|
562 |
double stepX = w / ((double)rasterBuf.getWidth()); |
|
563 |
double stepY = h / ((double)rasterBuf.getHeight()); |
|
564 |
switch(buffer.getDataType()){ |
|
565 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
|
566 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
|
567 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
|
568 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
|
569 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
|
570 |
} |
|
571 |
return rasterBuf; |
|
572 |
} |
|
573 |
|
|
574 |
public Object readCompleteLine(int line, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
575 |
switch(buffer.getDataType()){ |
|
576 |
case Buffer.TYPE_BYTE: return buffer.getLineFromBandByte(line, band); |
|
577 |
case Buffer.TYPE_SHORT: return buffer.getLineFromBandShort(line, band); |
|
578 |
case Buffer.TYPE_INT: return buffer.getLineFromBandInt(line, band); |
|
579 |
case Buffer.TYPE_FLOAT: return buffer.getLineFromBandFloat(line, band); |
|
580 |
case Buffer.TYPE_DOUBLE: return buffer.getLineFromBandDouble(line, band); |
|
581 |
} |
|
582 |
return null; |
|
583 |
} |
|
584 |
|
|
585 |
public Object readBlock(int pos, int blockHeight, double scale) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
586 |
if(pos < 0) |
|
587 |
throw new InvalidSetViewException("Request out of grid"); |
|
588 |
|
|
589 |
if((pos + blockHeight) > buffer.getHeight()) |
|
590 |
blockHeight = Math.abs(buffer.getHeight() - pos); |
|
591 |
|
|
592 |
switch(buffer.getDataType()){ |
|
593 |
case Buffer.TYPE_BYTE: |
|
594 |
byte[][][] bufb = new byte[getBandCount()][][]; |
|
595 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
596 |
for (int row = 0; row < blockHeight; row++) { |
|
597 |
bufb[iBand][row] = buffer.getLineFromBandByte(row, iBand); |
|
598 |
} |
|
599 |
} |
|
600 |
return bufb; |
|
601 |
case Buffer.TYPE_SHORT: |
|
602 |
short[][][] bufs = new short[getBandCount()][][]; |
|
603 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
604 |
for (int row = 0; row < blockHeight; row++) { |
|
605 |
bufs[iBand][row] = buffer.getLineFromBandShort(row, iBand); |
|
606 |
} |
|
607 |
} |
|
608 |
return bufs; |
|
609 |
case Buffer.TYPE_INT: |
|
610 |
int[][][] bufi = new int[getBandCount()][][]; |
|
611 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
612 |
for (int row = 0; row < blockHeight; row++) { |
|
613 |
bufi[iBand][row] = buffer.getLineFromBandInt(row, iBand); |
|
614 |
} |
|
615 |
} |
|
616 |
return bufi; |
|
617 |
case Buffer.TYPE_FLOAT: |
|
618 |
float[][][] buff = new float[getBandCount()][][]; |
|
619 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
620 |
for (int row = 0; row < blockHeight; row++) { |
|
621 |
buff[iBand][row] = buffer.getLineFromBandFloat(row, iBand); |
|
622 |
} |
|
623 |
} |
|
624 |
return buff; |
|
625 |
case Buffer.TYPE_DOUBLE: |
|
626 |
double[][][] bufd = new double[getBandCount()][][]; |
|
627 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
628 |
for (int row = 0; row < blockHeight; row++) { |
|
629 |
bufd[iBand][row] = buffer.getLineFromBandDouble(row, iBand); |
|
630 |
} |
|
631 |
} |
|
632 |
return bufd; |
|
633 |
} |
|
634 |
return null; |
|
635 |
} |
|
636 |
|
|
637 |
/** |
|
638 |
* Obtiene el objeto que contiene el estado de la transparencia |
|
639 |
*/ |
|
640 |
public Transparency getTransparency() { |
|
641 |
if(transparency == null) |
|
642 |
transparency = new DataStoreTransparency(getColorInterpretation()); |
|
643 |
return transparency; |
|
644 |
} |
|
645 |
|
|
646 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
|
647 |
if(band >= getBandCount()) |
|
648 |
throw new BandAccessException("Wrong band"); |
|
649 |
return 0; |
|
650 |
} |
|
651 |
|
|
652 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
|
653 |
if (band >= getBandCount()) |
|
654 |
throw new BandAccessException("Wrong band"); |
|
655 |
return 0; |
|
656 |
} |
|
657 |
|
|
658 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
|
659 |
if (band >= getBandCount()) |
|
660 |
throw new BandAccessException("Wrong band"); |
|
661 |
return 0; |
|
662 |
} |
|
663 |
|
|
664 |
public boolean isOverviewsSupported() { |
|
665 |
return false; |
|
666 |
} |
|
667 |
|
|
668 |
public String getProviderName() { |
|
669 |
return NAME; |
|
670 |
} |
|
671 |
|
|
672 |
public String getName() { |
|
673 |
return "buffer"+this.hashCode(); |
|
674 |
} |
|
675 |
|
|
676 |
public String getFullName() { |
|
677 |
return this.getName(); |
|
678 |
} |
|
679 |
|
|
680 |
public void setStatus(RasterProvider provider) { |
|
681 |
if(provider instanceof MemoryRasterProvider) { |
|
682 |
//Not implemented yet |
|
683 |
} |
|
684 |
} |
|
685 |
|
|
686 |
public TileServer getTileServer() { |
|
687 |
return null; |
|
688 |
} |
|
689 |
|
|
690 |
public void addFile(File file) throws InvalidSourceException { |
|
691 |
// Do nothing |
|
692 |
} |
|
693 |
|
|
694 |
public void removeFile(File file) { |
|
695 |
// Do nothing |
|
696 |
} |
|
697 |
|
|
698 |
} |
|
0 | 699 |
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.83/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/memory/io/MemoryDataParameters.java | ||
---|---|---|
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.memory.io; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
31 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
32 |
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters; |
|
33 |
|
|
34 |
/** |
|
35 |
* Parameters for the memory provider |
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
37 |
*/ |
|
38 |
public class MemoryDataParameters extends AbstractRasterFileDataParameters { |
|
39 |
private final String id = "memory"; |
|
40 |
private Buffer buffer = null; |
|
41 |
private Extent extent = null; |
|
42 |
|
|
43 |
/** |
|
44 |
* Constructor vacio |
|
45 |
*/ |
|
46 |
public MemoryDataParameters() { |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* Contructor |
|
51 |
* @param buf buffer del driver |
|
52 |
* @param ext extensi?n del buffer |
|
53 |
*/ |
|
54 |
public MemoryDataParameters(Buffer buf, Extent ext) { |
|
55 |
this.buffer = buf; |
|
56 |
this.extent = ext; |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Obtiene el buffer de datos |
|
61 |
* @return Buffer |
|
62 |
*/ |
|
63 |
public Buffer getBuffer() { |
|
64 |
return buffer; |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* Asigna el buffer de datos |
|
69 |
* @param buffer Buffer |
|
70 |
*/ |
|
71 |
public void setBuffer(Buffer buffer) { |
|
72 |
this.buffer = buffer; |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* Obtiene la extensi?n del buffer de datos |
|
77 |
* @return Extent |
|
78 |
*/ |
|
79 |
public Extent getExtent() { |
|
80 |
return extent; |
|
81 |
} |
|
82 |
|
|
83 |
/**O |
|
84 |
* Asigna la extensi?n del buffer de datos |
|
85 |
* @param extent |
|
86 |
*/ |
|
87 |
public void setExtent(Extent extent) { |
|
88 |
this.extent = extent; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Obtiene el identificador del driver |
|
93 |
* @return String |
|
94 |
*/ |
|
95 |
public String getFormatID() { |
|
96 |
return id; |
|
97 |
} |
|
98 |
|
|
99 |
/* |
|
100 |
* (non-Javadoc) |
|
101 |
* @see org.gvsig.fmap.dal.DataStoreParameters#getDataStoreName() |
|
102 |
*/ |
|
103 |
public String getDataStoreName() { |
|
104 |
return MemoryRasterProvider.NAME; |
|
105 |
} |
|
106 |
|
|
107 |
/* |
|
108 |
* (non-Javadoc) |
|
109 |
* @see org.gvsig.fmap.dal.DataStoreParameters#getDescription() |
|
110 |
*/ |
|
111 |
public String getDescription() { |
|
112 |
return MemoryRasterProvider.DESCRIPTION; |
|
113 |
} |
|
114 |
} |
|
0 | 115 |
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.83/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/overview/GdalOverviewBuilder.java | ||
---|---|---|
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 |
package org.gvsig.raster.gdal.overview; |
|
23 |
|
|
24 |
import org.gvsig.addo.BuildingOverviewsException; |
|
25 |
import org.gvsig.addo.IOverviewIncrement; |
|
26 |
import org.gvsig.addo.Jaddo; |
|
27 |
import org.gvsig.addo.WritingException; |
|
28 |
import org.gvsig.fmap.dal.coverage.exception.OverviewException; |
|
29 |
import org.gvsig.fmap.dal.coverage.process.BaseIncrementableTask; |
|
30 |
import org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder; |
|
31 |
|
|
32 |
/** |
|
33 |
* Servicios ofrecidos por el proceso de construcci?n de overviews. Esta |
|
34 |
* implementaci?n usa gdal para construir las overviews. |
|
35 |
* |
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
37 |
*/ |
|
38 |
public class GdalOverviewBuilder implements OverviewBuilder { |
|
39 |
private Jaddo build = new Jaddo(); |
|
40 |
private int value = 0; |
|
41 |
|
|
42 |
/** |
|
43 |
* Bindings between an IOverviewIncrement and a BaseIncrementableTask |
|
44 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
45 |
*/ |
|
46 |
class ProcessBinding implements IOverviewIncrement { |
|
47 |
private BaseIncrementableTask task = null; |
|
48 |
|
|
49 |
public ProcessBinding(BaseIncrementableTask task) { |
|
50 |
this.task = task; |
|
51 |
} |
|
52 |
|
|
53 |
public int getPercent() { |
|
54 |
return task.getPercent(); |
|
55 |
} |
|
56 |
|
|
57 |
public void setPercent(int value) { |
|
58 |
task.setPercent(value); |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
/* |
|
63 |
* (non-Javadoc) |
|
64 |
* @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#buildOverviews(int, java.lang.String, int[]) |
|
65 |
*/ |
|
66 |
public void buildOverviews(int resamplingAlg, String file, int[] overviews) |
|
67 |
throws OverviewException { |
|
68 |
try { |
|
69 |
build.buildOverviews(resamplingAlg, file, overviews); |
|
70 |
} catch (BuildingOverviewsException e) { |
|
71 |
throw new OverviewException("Error building overviews", e); |
|
72 |
} catch (WritingException e) { |
|
73 |
throw new OverviewException("Error writing overviews", e); |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
/* |
|
78 |
* (non-Javadoc) |
|
79 |
* @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#getPercent() |
|
80 |
*/ |
|
81 |
public int getPercent() { |
|
82 |
return value; |
|
83 |
} |
|
84 |
|
|
85 |
/* |
|
86 |
* (non-Javadoc) |
|
87 |
* @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#setIncrementListener(org.gvsig.addo.IOverviewIncrement) |
|
88 |
*/ |
|
89 |
public void setIncrementListener(BaseIncrementableTask incr) { |
|
90 |
build.setIncrementListener(new ProcessBinding(incr)); |
|
91 |
} |
|
92 |
|
|
93 |
/* |
|
94 |
* (non-Javadoc) |
|
95 |
* @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#setPercent(int) |
|
96 |
*/ |
|
97 |
public void setPercent(int value) { |
|
98 |
this.value = value; |
|
99 |
} |
|
100 |
} |
|
0 | 101 |
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.83/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalFilesystemServerExplorer.java | ||
---|---|---|
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 |
} |
|
0 | 193 |
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.83/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalWriter.java | ||
---|---|---|
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 |
package org.gvsig.raster.gdal.io; |
|
23 |
|
|
24 |
import java.awt.geom.AffineTransform; |
|
25 |
import java.awt.geom.Point2D; |
|
26 |
import java.io.File; |
|
27 |
import java.io.IOException; |
|
28 |
import java.sql.Savepoint; |
|
29 |
import java.util.ArrayList; |
|
30 |
|
|
31 |
import org.apache.commons.io.FileUtils; |
|
32 |
import org.apache.commons.io.FilenameUtils; |
|
33 |
import org.cresques.cts.ICRSFactory; |
|
34 |
import org.cresques.cts.IProjection; |
|
35 |
import org.slf4j.Logger; |
|
36 |
import org.slf4j.LoggerFactory; |
|
37 |
|
|
38 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
|
39 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
40 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
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.RmfSerializerException; |
|
45 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
|
46 |
import org.gvsig.jgdal.GdalBuffer; |
|
47 |
import org.gvsig.jgdal.GdalDataset; |
|
48 |
import org.gvsig.jgdal.GdalDriver; |
|
49 |
import org.gvsig.jgdal.GdalException; |
|
50 |
import org.gvsig.jgdal.GdalRasterBand; |
|
51 |
import org.gvsig.jgdal.GeoTransform; |
|
52 |
import org.gvsig.raster.gdal.io.features.BMPFeatures; |
|
53 |
import org.gvsig.raster.gdal.io.features.GTiffFeatures; |
|
54 |
import org.gvsig.raster.gdal.io.features.HFAFeatures; |
|
55 |
import org.gvsig.raster.gdal.io.features.IDRISIFeatures; |
|
56 |
import org.gvsig.raster.gdal.io.features.ILWIS_MprFeatures; |
|
57 |
import org.gvsig.raster.gdal.io.features.Jpeg2000Features; |
|
58 |
import org.gvsig.raster.gdal.io.features.PNM_PgmFeatures; |
|
59 |
import org.gvsig.raster.gdal.io.features.PNM_PpmFeatures; |
|
60 |
import org.gvsig.raster.impl.buffer.DefaultDataServerWriter; |
|
61 |
import org.gvsig.raster.impl.buffer.RasterBuffer; |
|
62 |
import org.gvsig.raster.impl.process.RasterTask; |
|
63 |
import org.gvsig.raster.impl.process.RasterTaskQueue; |
|
64 |
import org.gvsig.raster.impl.store.ParamImpl; |
|
65 |
import org.gvsig.raster.impl.store.ParamsImpl; |
|
66 |
import org.gvsig.raster.impl.store.WriteFileFormatFeatures; |
|
67 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
|
68 |
import org.gvsig.raster.impl.store.writer.DefaultRasterWriter; |
|
69 |
import org.gvsig.raster.util.DefaultProviderServices; |
|
70 |
import org.gvsig.tools.ToolsLocator; |
|
71 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
72 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
73 |
|
|
74 |
|
|
75 |
/** |
|
76 |
* Driver para la escritura a trav?s de Gdal. |
|
77 |
* Puede exportar un fichero de un formato a otro desde un GeoRasterFile |
|
78 |
* en cualquier formato soportado por la lectura a un formato que este incluido |
|
79 |
* en la lista supportedDrv. |
|
80 |
* |
|
81 |
* Puede salvar a disco en un formato que este incluido en la lista supportedDrv |
|
82 |
* obteniendo los datos que van siendo servidos desde el cliente. Este cliente |
|
83 |
* debe implementar un DataServerWriter o tener un objeto que lo implemente. Inicialmente |
|
84 |
* le pasar? los par?metros de la imagen de salida y cuando el driver comience a |
|
85 |
* escribir le ir? solicitando m?s a trav?s del m?todo readData de DataServerWriter. |
|
86 |
* El cliente ser? el que lleve el control de lo que va sirviendo y lo que le queda |
|
87 |
* por servir. |
|
88 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
89 |
*/ |
|
90 |
public class GdalWriter extends DefaultRasterWriter { |
|
91 |
|
|
92 |
private static final Logger logger = LoggerFactory.getLogger(GdalWriter.class); |
|
93 |
|
|
94 |
/** |
|
95 |
* |
|
96 |
*/ |
|
97 |
public static void register() { |
|
98 |
DefaultProviderServices pInfo = (DefaultProviderServices)RasterLocator.getManager().getProviderServices(); |
|
99 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
100 |
ExtensionPoint point = extensionPoints.get("RasterWriter"); |
|
101 |
|
|
102 |
point.append("tif", "", GdalWriter.class); |
|
103 |
pInfo.getFileFeature().put("tif", new GTiffFeatures()); |
|
104 |
|
|
105 |
point.append("img", "", GdalWriter.class); |
|
106 |
pInfo.getFileFeature().put("img", new HFAFeatures()); |
|
107 |
|
|
108 |
point.append("bmp", "", GdalWriter.class); |
|
109 |
pInfo.getFileFeature().put("bmp", new BMPFeatures()); |
|
110 |
|
|
111 |
point.append("pgm", "", GdalWriter.class); |
|
112 |
pInfo.getFileFeature().put("pgm", new PNM_PgmFeatures()); |
|
113 |
|
|
114 |
point.append("ppm", "", GdalWriter.class); |
|
115 |
pInfo.getFileFeature().put("ppm", new PNM_PpmFeatures()); |
|
116 |
|
|
117 |
point.append("mpl", "", GdalWriter.class); |
|
118 |
pInfo.getFileFeature().put("mpl", new ILWIS_MprFeatures()); |
|
119 |
|
|
120 |
point.append("rst", "", GdalWriter.class); |
|
121 |
pInfo.getFileFeature().put("rst", new IDRISIFeatures()); |
|
122 |
|
|
123 |
point.append("jp2", "", GdalWriter.class); |
|
124 |
pInfo.getFileFeature().put("jp2", new Jpeg2000Features()); |
|
125 |
|
|
126 |
//La exportaci?n no es correcta del todo |
|
127 |
// point.append("rmf", "", GdalWriter.class); |
|
128 |
// pInfo.getFileFeature().put("rmf", new RMFFeatures()); |
|
129 |
|
|
130 |
//No salva datos. Siempre sale negra la imagen |
|
131 |
//point.register("aux", GdalWriter.class); |
|
132 |
//fileFeature.put("aux", new PAuxFeatures()); |
|
133 |
} |
|
134 |
|
|
135 |
private GdalDriver drv; |
|
136 |
private GdalDataset dstDataset = null; |
|
137 |
private GdalRasterBand rband = null; |
|
138 |
private GeoTransform geot = null; //Datos de georeferenciaci?n |
|
139 |
//private OGRSpatialReference oSRS; //Datos de proyecci?n |
|
140 |
private GdalBuffer[] bufBands = null; |
|
141 |
private int nBlocks = 0; //N?mero de bloques en Y en el que se divide la imagen para escribir |
|
142 |
private int anchoResto = 0; //Tama?o del ?ltimo bloque de la imagen. |
|
143 |
private boolean write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido |
|
144 |
private int dataType = RasterBuffer.TYPE_UNDEFINED; |
|
145 |
|
|
146 |
/** |
|
147 |
* Carga los par?metros de este driver. |
|
148 |
* @param ident |
|
149 |
*/ |
|
150 |
public void loadParams(String ident) { |
|
151 |
WriteFileFormatFeatures wfff = (WriteFileFormatFeatures)pInfo.getFileFeature().get(ident); |
|
152 |
wfff.loadParams(); |
|
153 |
driverParams = (ParamsImpl)wfff.getParams(); |
|
154 |
} |
|
155 |
|
|
156 |
public String getProviderName() { |
|
157 |
return GdalProvider.NAME; |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Constructor para la obtenci?n de par?metros del driver |
|
162 |
* @param fileName |
|
163 |
*/ |
|
164 |
public GdalWriter(String fileName) { |
|
165 |
ident = fileUtil.getExtensionFromFileName(fileName); |
|
166 |
driver = ((WriteFileFormatFeatures)pInfo.getFileFeature().get(ident)).getDriverName(); |
|
167 |
|
|
168 |
loadParams(ident); |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* Constructor para salvar datos servidos por el cliente |
|
173 |
* @param dataWriter Objeto servidor de datos para el driver de escritura |
|
174 |
* @param outFileName Fichero de salida |
|
175 |
* @param nBands N?mero de bandas |
|
176 |
* @param at Transformaci?n afin |
|
177 |
* @param outSizeX Tama?o de salida en X |
|
178 |
* @param outSizeY Tama?o de salida en Y |
|
179 |
* @param dataType Tipo de dato |
|
180 |
* @param params |
|
181 |
* @param proj |
|
182 |
* @throws GdalException |
|
183 |
* @throws IOException |
|
184 |
*/ |
|
185 |
public GdalWriter( DataServerWriter dataWriter, |
|
186 |
String outFileName, |
|
187 |
Integer nBands, |
|
188 |
AffineTransform at, |
|
189 |
Integer outSizeX, |
|
190 |
Integer outSizeY, |
|
191 |
Integer dataType, |
|
192 |
Params params, |
|
193 |
IProjection proj) throws GdalException, IOException { |
|
194 |
this(dataWriter, outFileName, nBands, at, outSizeX, outSizeY, dataType, params, proj, new Boolean(true)); |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* Constructor para salvar datos servidos por el cliente |
|
199 |
* @param dataWriter Objeto servidor de datos para el driver de escritura |
|
200 |
* @param outFileName |
|
201 |
* @param nBands |
|
202 |
* @param at |
|
203 |
* @param outFilename Fichero de salida |
|
204 |
* @param outSizeX Tama?o de salida en X |
|
205 |
* @param outSizeY Tama?o de salida en Y |
|
206 |
* @param dataType Tipo de dato |
|
207 |
* @param params |
|
208 |
* @param proj |
|
209 |
* @param geo Flag que dice si se salva con georreferenciaci?n o sin ella |
|
210 |
* @throws GdalException |
|
211 |
* @throws IOException |
|
212 |
*/ |
|
213 |
public GdalWriter( DataServerWriter dataWriter, |
|
214 |
String outFileName, |
|
215 |
Integer nBands, |
|
216 |
AffineTransform at, |
|
217 |
Integer outSizeX, |
|
218 |
Integer outSizeY, |
|
219 |
Integer dataType, |
|
220 |
Params params, |
|
221 |
IProjection proj, |
|
222 |
Boolean geo)throws GdalException, IOException { |
|
223 |
|
|
224 |
this.proj = proj; |
|
225 |
ident = outFileName.toLowerCase().substring(outFileName.lastIndexOf(".") + 1); |
|
226 |
driver = ((WriteFileFormatFeatures)pInfo.getFileFeature().get(ident)).getDriverName(); |
|
227 |
this.dataType = dataType.intValue(); |
|
228 |
this.at = at; |
|
229 |
percent = 0; |
|
230 |
|
|
231 |
this.dataWriter = dataWriter; |
|
232 |
this.outFileName = outFileName; |
|
233 |
|
|
234 |
this.sizeWindowX = outSizeX.intValue(); |
|
235 |
this.sizeWindowY = outSizeY.intValue(); |
|
236 |
|
|
237 |
if ((sizeWindowX < 0) || (sizeWindowY < 0)) |
|
238 |
throw new IOException("Tama?o del fichero de salida erroneo."); |
|
239 |
|
|
240 |
this.nBands = nBands.intValue(); |
|
241 |
|
|
242 |
//Calculamos la georeferenciaci?n a partir del extend pasado por el cliente. |
|
243 |
|
|
244 |
geot = new GeoTransform(); |
|
245 |
geot.adfgeotransform[0] = at.getTranslateX(); |
|
246 |
geot.adfgeotransform[3] = at.getTranslateY(); |
|
247 |
geot.adfgeotransform[1] = at.getScaleX(); |
|
248 |
geot.adfgeotransform[5] = at.getScaleY(); |
|
249 |
geot.adfgeotransform[2] = at.getShearX(); |
|
250 |
geot.adfgeotransform[4] = at.getShearY(); |
|
251 |
|
|
252 |
String outRmf = outFileName.substring(0, outFileName.lastIndexOf(".")); |
|
253 |
if(geo.booleanValue()) |
|
254 |
rasterUtil.saveGeoInfo(outRmf, at, new Point2D.Double(sizeWindowX, sizeWindowY)); |
|
255 |
|
|
256 |
if(params == null) |
|
257 |
loadParams(ident); |
|
258 |
else |
|
259 |
if(params instanceof ParamsImpl) |
|
260 |
this.driverParams = (ParamsImpl)params; |
|
261 |
|
|
262 |
init(); |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* A?ade la proyecci?n Wkt con la que salvar. |
|
267 |
* @param wkt |
|
268 |
* @throws GdalException |
|
269 |
*/ |
|
270 |
public void setWkt(String wkt) { |
|
271 |
if(dstDataset != null && wkt != null && wkt.compareTo("unknown") != 0) |
|
272 |
try { |
|
273 |
dstDataset.setProjection(wkt); |
|
274 |
} catch (GdalException e) { |
|
275 |
System.err.println("Proyecci?n Wkt no asignada en GdalWriter"); |
|
276 |
return; |
|
277 |
} |
|
278 |
} |
|
279 |
|
|
280 |
/** |
|
281 |
* Asigna el tipo de driver con el que se salvar? la imagen |
|
282 |
* @param drvType Tipo de driver |
|
283 |
*/ |
|
284 |
public void setDriverType(String drvType) { |
|
285 |
this.driver = drvType; |
|
286 |
} |
|
287 |
|
|
288 |
/** |
|
289 |
* Creaci?n del dataset de destino. |
|
290 |
* @throws EcwException |
|
291 |
*/ |
|
292 |
private void init() throws GdalException { |
|
293 |
//Controlamos que el tipo de driver sea correcto |
|
294 |
if (driver == null) |
|
295 |
throw new GdalException("Tipo de driver sin especificar."); |
|
296 |
|
|
297 |
boolean okdrvtype = false; |
|
298 |
|
|
299 |
String[] types = pInfo.getWriteDriversType(); |
|
300 |
for (int i = 0; i < pInfo.getWriteNTypes(); i++) |
|
301 |
if (driver.equals(types[i])) |
|
302 |
okdrvtype = true; |
|
303 |
|
|
304 |
if (okdrvtype == false) |
|
305 |
throw new GdalException("El tipo de driver " + driver + " no est? soportado por GdalWriter."); |
|
306 |
|
|
307 |
//Obtenemos el driver y creamos el dataset del destino |
|
308 |
drv = GdalDataset.getDriverByName(driver); |
|
309 |
|
|
310 |
if (dstDataset != null) { |
|
311 |
dstDataset.close(); |
|
312 |
dstDataset = null; |
|
313 |
} |
|
314 |
|
|
315 |
dstDataset = drv.create(outFileName, sizeWindowX, sizeWindowY, |
|
316 |
nBands, GdalDataSource.getGdalTypeFromRasterBufType(dataType), gdalParamsFromRasterParams(driverParams)); |
|
317 |
|
|
318 |
dstDataset.setGeoTransform(geot); |
|
319 |
|
|
320 |
int blockSize = RasterLibrary.blockHeight; |
|
321 |
if(dataWriter.getBuffer() != null && dataWriter.getBuffer().isCached()) |
|
322 |
blockSize = dataWriter.getBuffer().getBlockHeight(); |
|
323 |
|
|
324 |
nBlocks = (sizeWindowY / blockSize); |
|
325 |
anchoResto = sizeWindowY - (nBlocks * blockSize); |
|
326 |
} |
|
327 |
|
|
328 |
/** |
|
329 |
* @param fileName |
|
330 |
* @throws GdalException |
|
331 |
*/ |
|
332 |
public void anotherFile(String fileName) throws GdalException { |
|
333 |
dstDataset = drv.create(fileName, sizeWindowX, sizeWindowY, |
|
334 |
nBands, GdalDataSource.getGdalTypeFromRasterBufType(dataType), gdalParamsFromRasterParams(driverParams)); |
|
335 |
} |
|
336 |
|
|
337 |
/** |
|
338 |
* Convierte los par?metros obtenidos desde el objeto params a parametros |
|
339 |
* comprensibles por la librer?a gdal |
|
340 |
* @param p Params |
|
341 |
* @return Array de par?metros |
|
342 |
*/ |
|
343 |
public String[] gdalParamsFromRasterParams(Params p) { |
|
344 |
if (p == null) |
|
345 |
return null; |
|
346 |
ArrayList<String> paramList = new ArrayList<String>(); |
|
347 |
ParamImpl phot = (ParamImpl)p.getParamById("photometric"); |
Also available in: Unified diff