gvsig-gdal / trunk / org.gvsig.gdal2 / org.gvsig.gdal2.prov / org.gvsig.gdal2.prov.raster / src / main / java / org / gvsig / raster / gdal / provider / AbstractRasterGdalStoreProvider.java @ 370
History | View | Annotate | Download (21.5 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2016 gvSIG Association
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.raster.gdal.provider; |
24 |
|
25 |
import java.util.ArrayList; |
26 |
import java.util.HashMap; |
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
29 |
import java.util.Map; |
30 |
|
31 |
import org.cresques.cts.IProjection; |
32 |
import org.gdal.gdal.Dataset; |
33 |
import org.gdal.gdal.Driver; |
34 |
import org.slf4j.Logger; |
35 |
import org.slf4j.LoggerFactory; |
36 |
|
37 |
import org.gvsig.fmap.dal.DataStoreNotification; |
38 |
import org.gvsig.fmap.dal.DataStoreParameters; |
39 |
import org.gvsig.fmap.dal.FileHelper; |
40 |
import org.gvsig.fmap.dal.exception.CloseException; |
41 |
import org.gvsig.fmap.dal.exception.CreateException; |
42 |
import org.gvsig.fmap.dal.exception.InitializeException; |
43 |
import org.gvsig.fmap.dal.exception.OpenException; |
44 |
import org.gvsig.fmap.dal.raster.BandQuery; |
45 |
import org.gvsig.fmap.dal.raster.RasterQuery; |
46 |
import org.gvsig.fmap.dal.raster.spi.AbstractRasterStoreProvider; |
47 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
48 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
49 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
50 |
import org.gvsig.fmap.geom.DataTypes; |
51 |
import org.gvsig.fmap.geom.Geometry; |
52 |
import org.gvsig.fmap.geom.GeometryLocator; |
53 |
import org.gvsig.fmap.geom.Geometry.DIMENSIONS; |
54 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
55 |
import org.gvsig.fmap.geom.primitive.Envelope; |
56 |
import org.gvsig.metadata.MetadataLocator; |
57 |
import org.gvsig.metadata.MetadataManager; |
58 |
import org.gvsig.metadata.exceptions.MetadataException; |
59 |
import org.gvsig.raster.lib.buffer.api.Band; |
60 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
61 |
import org.gvsig.raster.lib.buffer.api.BufferDimensions; |
62 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
63 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
64 |
import org.gvsig.raster.lib.buffer.api.NoData; |
65 |
import org.gvsig.raster.lib.buffer.api.PageManager; |
66 |
import org.gvsig.raster.lib.buffer.api.TileStruct; |
67 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException; |
68 |
import org.gvsig.raster.lib.buffer.spi.DefaultTileStruct; |
69 |
import org.gvsig.tools.ToolsLocator; |
70 |
import org.gvsig.tools.dispose.DisposeUtils; |
71 |
import org.gvsig.tools.dynobject.DynClass; |
72 |
import org.gvsig.tools.dynobject.DynField; |
73 |
import org.gvsig.tools.dynobject.DynObject; |
74 |
import org.gvsig.tools.exception.BaseException; |
75 |
import org.gvsig.tools.locator.LocatorException; |
76 |
import org.gvsig.tools.task.SimpleTaskStatus; |
77 |
import org.gvsig.tools.task.TaskStatusManager; |
78 |
|
79 |
/**
|
80 |
* Provider for Raster GDAL files
|
81 |
* @author dmartinezizquierdo
|
82 |
*
|
83 |
*/
|
84 |
public abstract class AbstractRasterGdalStoreProvider extends AbstractRasterStoreProvider implements |
85 |
ResourceConsumer{ |
86 |
|
87 |
private static final Logger logger = |
88 |
LoggerFactory.getLogger(AbstractRasterGdalStoreProvider.class); |
89 |
|
90 |
/**
|
91 |
* Provider name
|
92 |
*/
|
93 |
public static String NAME = "RasterGdal"; |
94 |
/**
|
95 |
* Provider description
|
96 |
*/
|
97 |
public static String DESCRIPTION = "Raster GDAL provider"; |
98 |
/**
|
99 |
* Parameters definition name for metadata
|
100 |
*/
|
101 |
public static final String METADATA_DEFINITION_NAME = NAME; |
102 |
|
103 |
protected ResourceProvider resource;
|
104 |
protected final SimpleTaskStatus taskStatus; |
105 |
|
106 |
protected Envelope envelope = null; |
107 |
protected IProjection projection= null; |
108 |
protected Dataset gdalDataSet;
|
109 |
protected Driver gdalDriver; |
110 |
|
111 |
private List<PageManager> pageManagers; |
112 |
|
113 |
/**
|
114 |
* Dataset from gdal containing the raster data
|
115 |
* @return Dataset
|
116 |
*/
|
117 |
public Dataset getGdalDataSet() {
|
118 |
return gdalDataSet;
|
119 |
} |
120 |
|
121 |
protected static void registerMetadataDefinition() |
122 |
throws MetadataException {
|
123 |
MetadataManager manager = MetadataLocator.getMetadataManager(); |
124 |
if (manager.getDefinition(METADATA_DEFINITION_NAME) == null) { |
125 |
manager.addDefinition(METADATA_DEFINITION_NAME, |
126 |
DataStoreParameters.class |
127 |
.getResourceAsStream("RasterGdalMetadata.xml"),
|
128 |
DataStoreParameters.class.getClassLoader()); |
129 |
} |
130 |
} |
131 |
|
132 |
/**
|
133 |
* Constructor
|
134 |
* @param params
|
135 |
* @param storeServices
|
136 |
* @throws InitializeException
|
137 |
*/
|
138 |
public AbstractRasterGdalStoreProvider(DataStoreParameters params,
|
139 |
DataStoreProviderServices storeServices) |
140 |
throws InitializeException {
|
141 |
super(
|
142 |
params, |
143 |
storeServices, |
144 |
FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME) |
145 |
); |
146 |
TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
147 |
this.taskStatus = manager.createDefaultSimpleTaskStatus("RasterGdal"); |
148 |
this.init(params, storeServices);
|
149 |
} |
150 |
|
151 |
protected AbstractRasterGdalStoreProvider(DataStoreParameters params,
|
152 |
DataStoreProviderServices storeServices, DynObject metadata) |
153 |
throws InitializeException {
|
154 |
super(params, storeServices, metadata);
|
155 |
TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
156 |
this.taskStatus = manager.createDefaultSimpleTaskStatus("RasterGdal"); |
157 |
this.init((DataStoreParameters)params, storeServices);
|
158 |
} |
159 |
|
160 |
protected AbstractRasterGdalStoreProvider(NewRasterGdalStoreParameters params, Driver gdalDriver) { |
161 |
//PARA Exportar
|
162 |
super(params,null,null); |
163 |
this.gdalDriver=gdalDriver;
|
164 |
TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
165 |
this.taskStatus = manager.createDefaultSimpleTaskStatus("RasterGdal"); |
166 |
} |
167 |
|
168 |
protected void init(DataStoreParameters params, |
169 |
DataStoreProviderServices storeServices) throws InitializeException {
|
170 |
if (params == null) { |
171 |
throw new InitializeException( |
172 |
new NullPointerException("params is null")); |
173 |
} |
174 |
|
175 |
} |
176 |
|
177 |
protected DataStoreParameters getRasterGdalParameters() {
|
178 |
return (DataStoreParameters) this.getParameters(); |
179 |
} |
180 |
|
181 |
/**
|
182 |
* Used to obtain the specific options for a specific driver
|
183 |
* Not in use yet. Used as example.
|
184 |
* @return options used to open a specific driver in format ("optionName=optionValue")
|
185 |
*/
|
186 |
private String [] getParametersDriverOptions(){ |
187 |
ArrayList<String> optionsList=new ArrayList<String>(); |
188 |
DynClass dynClass = getRasterGdalParameters().getDynClass(); |
189 |
DynField[] fields = dynClass.getDynFields();
|
190 |
for (DynField field:fields){
|
191 |
String fieldName = field.getName();
|
192 |
String gdalOption = fieldName.toUpperCase();
|
193 |
Object dynValue = getRasterGdalParameters().getDynValue(fieldName);
|
194 |
|
195 |
if (dynValue!=null && field.getGroup().equalsIgnoreCase(RasterGdalFileStoreParameters.OPEN_OPTIONS_GROUP)){ |
196 |
if(field.getType() == DataTypes.BOOLEAN) {
|
197 |
if((Boolean)dynValue){ |
198 |
optionsList.add(gdalOption+"=YES");
|
199 |
}else{
|
200 |
optionsList.add(gdalOption+"=NO");
|
201 |
} |
202 |
|
203 |
} else {
|
204 |
optionsList.add(gdalOption+"="+dynValue);
|
205 |
} |
206 |
} |
207 |
} |
208 |
String[]options=new String[optionsList.size()]; |
209 |
optionsList.toArray(options); |
210 |
return options;
|
211 |
} |
212 |
|
213 |
@Override
|
214 |
public Buffer createBuffer(RasterQuery rasterQuery) throws BufferException { |
215 |
|
216 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
217 |
|
218 |
Buffer buffer = null; |
219 |
|
220 |
if (rasterQuery != null && !rasterQuery.getBands().isEmpty()) { |
221 |
List<BandQuery> bands;
|
222 |
bands = rasterQuery.getBands(); |
223 |
int bandDataTypes[]; |
224 |
bandDataTypes = new int[bands.size()]; |
225 |
NoData[] bandNoDatas = new NoData[bands.size()]; |
226 |
List<PageManager> pageManagers = new ArrayList<PageManager>(); |
227 |
|
228 |
int i=0; |
229 |
for (BandQuery bandQuery : bands) {
|
230 |
int band = bandQuery.getBand();
|
231 |
bandDataTypes[i] = this.getBandDescriptor(band).getDataType();
|
232 |
bandNoDatas[i] = this.getNoData(rasterQuery, band);
|
233 |
pageManagers.add(this.pageManagers.get(band));
|
234 |
i++; |
235 |
} |
236 |
buffer = |
237 |
bufferManager.createBuffer(gdalDataSet.getRasterYSize(), gdalDataSet.getRasterXSize(), bandDataTypes, |
238 |
bandNoDatas, this.projection, envelope, pageManagers);
|
239 |
} else {
|
240 |
buffer = |
241 |
bufferManager.createBuffer(gdalDataSet.getRasterYSize(), gdalDataSet.getRasterXSize(), this.getDataTypes(),
|
242 |
this.getNoDatas(), this.projection, this.envelope, this.pageManagers); |
243 |
} |
244 |
|
245 |
return buffer;
|
246 |
} |
247 |
|
248 |
@Override
|
249 |
public int getBands() { |
250 |
return gdalDataSet.getRasterCount();
|
251 |
} |
252 |
|
253 |
private Double getNoData(org.gdal.gdal.Band gdalBand){ |
254 |
Double[] noDataValueResult=new Double[1]; |
255 |
gdalBand.GetNoDataValue(noDataValueResult); |
256 |
Double noData=noDataValueResult[0]; |
257 |
return noData;
|
258 |
} |
259 |
|
260 |
|
261 |
|
262 |
public void open() throws OpenException { |
263 |
if (this.gdalDataSet != null) { |
264 |
return;
|
265 |
} |
266 |
openEver(); |
267 |
//Create the page managers
|
268 |
BufferManager bufferManager=BufferLocator.getBufferManager(); |
269 |
|
270 |
int bandCount=gdalDataSet.getRasterCount();
|
271 |
|
272 |
pageManagers = new ArrayList<PageManager>(); |
273 |
|
274 |
for (int i=0;i<bandCount;i++){ |
275 |
//Gdal bands begin count in 1
|
276 |
int gdalBandNumber=i+1; |
277 |
org.gdal.gdal.Band gdalBand=gdalDataSet.GetRasterBand(gdalBandNumber); |
278 |
|
279 |
this.getBandDescriptor(i).setDataType(getRasterBufTypeFromGdalType(gdalBand.getDataType()));
|
280 |
Double noData=getNoData(gdalBand);
|
281 |
this.getBandDescriptor(i).setDescription(gdalBand.GetDescription());
|
282 |
if (noData!=null){ |
283 |
this.getBandDescriptor(i).setNoData(bufferManager.createNoData(noData, noData));
|
284 |
} |
285 |
//Paginated
|
286 |
pageManagers.add(new RasterGdalBandPageManager(gdalDataSet, gdalBandNumber));
|
287 |
//Tiled
|
288 |
// pageManagers.add(new RasterGdalBandTileManager(gdalDataSet, gdalBandNumber, 256, 256));
|
289 |
} |
290 |
|
291 |
|
292 |
} |
293 |
|
294 |
protected abstract void openEver() throws OpenException; |
295 |
|
296 |
protected Envelope createEnvelope(double[] geotransform){ |
297 |
|
298 |
double leftMostX = geotransform[0];/* top left x */ |
299 |
double pixelSizeX = geotransform[1];/* w-e pixel resolution */ |
300 |
double rotationAxisX = geotransform[2];/* 0 */ |
301 |
double upperMostY = geotransform[3];/* top left y */ |
302 |
double rotationAxisY = geotransform[4];/* 0 */ |
303 |
double pixelSizeY = geotransform[5];/* n-s pixel resolution (negative value) */ |
304 |
|
305 |
if (0.0 != rotationAxisX || 0.0 != rotationAxisY) { |
306 |
logger.warn( |
307 |
"Rotation in wld file not implemented yet. It will be ignored");
|
308 |
} |
309 |
|
310 |
double width =Math.abs(gdalDataSet.getRasterXSize()*pixelSizeX); |
311 |
double height=Math.abs(gdalDataSet.getRasterYSize()*pixelSizeY); |
312 |
|
313 |
// double minX, double minY, double maxX, double maxY, int subType
|
314 |
try {
|
315 |
envelope = GeometryLocator.getGeometryManager().createEnvelope( |
316 |
Math.min(leftMostX,leftMostX + width),
|
317 |
Math.min(upperMostY,upperMostY - height),
|
318 |
Math.max(leftMostX,leftMostX + width),
|
319 |
Math.max(upperMostY,upperMostY - height),
|
320 |
Geometry.SUBTYPES.GEOM2D); |
321 |
} catch (LocatorException | CreateEnvelopeException e) {
|
322 |
logger.warn( |
323 |
"Failed to create envelope from wld file with coords: minx:"+leftMostX+
|
324 |
", miny:"+upperMostY+", maxX: "+leftMostX + width+", maxY: "+upperMostY + height); |
325 |
e.printStackTrace(); |
326 |
} |
327 |
|
328 |
return envelope;
|
329 |
} |
330 |
|
331 |
@Override
|
332 |
public void close() throws CloseException { |
333 |
this.gdalDataSet.delete();
|
334 |
this.gdalDataSet = null; |
335 |
} |
336 |
|
337 |
@Override
|
338 |
public ResourceProvider getResource() {
|
339 |
return this.resource; |
340 |
} |
341 |
|
342 |
@Override
|
343 |
public String getProviderName() { |
344 |
return getRasterGdalParameters().getDataStoreName();
|
345 |
} |
346 |
|
347 |
@Override
|
348 |
public boolean closeResourceRequested(ResourceProvider resource) { |
349 |
return true; |
350 |
} |
351 |
|
352 |
@Override
|
353 |
/*
|
354 |
* (non-Javadoc)
|
355 |
*
|
356 |
* @see
|
357 |
* org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
|
358 |
* gvsig.fmap.dal.resource.spi.ResourceProvider)
|
359 |
*/
|
360 |
public void resourceChanged(ResourceProvider resource) { |
361 |
this.getStoreServices().notifyChange(
|
362 |
DataStoreNotification.RESOURCE_CHANGED, |
363 |
resource); |
364 |
} |
365 |
|
366 |
@Override
|
367 |
/* (non-Javadoc)
|
368 |
* @see org.gvsig.fmap.dal.feature.spi.memory.AbstractMemoryStoreProvider#doDispose()
|
369 |
*/
|
370 |
protected void doDispose() throws BaseException { |
371 |
super.doDispose();
|
372 |
if(gdalDataSet!=null){ |
373 |
gdalDataSet.delete(); |
374 |
gdalDataSet=null;
|
375 |
} |
376 |
if (pageManagers != null) { |
377 |
for (Iterator iterator = pageManagers.iterator(); iterator.hasNext();) { |
378 |
PageManager pageManager = (PageManager) iterator.next(); |
379 |
DisposeUtils.dispose(pageManager); |
380 |
iterator.remove(); |
381 |
} |
382 |
pageManagers = null;
|
383 |
} |
384 |
if(resource!=null){ |
385 |
resource.removeConsumer(this);
|
386 |
} |
387 |
} |
388 |
|
389 |
/**
|
390 |
* Conversi?n de los tipos de datos de gdal a los tipos de datos de RasterBuf
|
391 |
* @param gdalType Tipo de dato de gdal
|
392 |
* @return Tipo de dato de RasterBuf
|
393 |
*/
|
394 |
protected static int getRasterBufTypeFromGdalType(int gdalType) { |
395 |
switch (gdalType) {
|
396 |
case 1:// Eight bit unsigned integer GDT_Byte = 1 |
397 |
return BufferManager.TYPE_BYTE;
|
398 |
|
399 |
case 3:// Sixteen bit signed integer GDT_Int16 = 3, |
400 |
return BufferManager.TYPE_SHORT;
|
401 |
|
402 |
case 2:// Sixteen bit unsigned integer GDT_UInt16 = 2 |
403 |
//return RasterBuffer.TYPE_USHORT;
|
404 |
return BufferManager.TYPE_SHORT; //Apa?o para usar los tipos de datos que soportamos |
405 |
|
406 |
case 5:// Thirty two bit signed integer GDT_Int32 = 5 |
407 |
return BufferManager.TYPE_INT;
|
408 |
|
409 |
case 6:// Thirty two bit floating point GDT_Float32 = 6 |
410 |
return BufferManager.TYPE_FLOAT;
|
411 |
|
412 |
case 7:// Sixty four bit floating point GDT_Float64 = 7 |
413 |
return BufferManager.TYPE_DOUBLE;
|
414 |
|
415 |
// TODO:Estos tipos de datos no podemos gestionarlos. Habria que definir
|
416 |
// el tipo complejo y usar el tipo long que de momento no se gasta.
|
417 |
case 4:// Thirty two bit unsigned integer GDT_UInt32 = 4, |
418 |
return BufferManager.TYPE_INT;
|
419 |
//return RasterBuffer.TYPE_UNDEFINED; // Deberia devolver un Long
|
420 |
|
421 |
case 8:// Complex Int16 GDT_CInt16 = 8 |
422 |
case 9:// Complex Int32 GDT_CInt32 = 9 |
423 |
case 10:// Complex Float32 GDT_CFloat32 = 10 |
424 |
case 11:// Complex Float64 GDT_CFloat64 = 11 |
425 |
return BufferManager.TYPE_UNDEFINED;
|
426 |
} |
427 |
return BufferManager.TYPE_UNDEFINED;
|
428 |
} |
429 |
|
430 |
/**
|
431 |
* Conversi?n de los tipos de datos de RasterBuffer a los tipos de datos de gdal
|
432 |
* @param ype Tipo de dato de RasterBuffer
|
433 |
* @return Tipo de dato de gdal
|
434 |
*/
|
435 |
protected static int getGdalTypeFromRasterBufType(int type) { |
436 |
switch (type) {
|
437 |
case BufferManager.TYPE_BYTE:
|
438 |
return 1; // Eight bit unsigned integer GDT_Byte = 1 |
439 |
case BufferManager.TYPE_SHORT:
|
440 |
return 3;// Sixteen bit signed integer GDT_Int16 = 3, |
441 |
case BufferManager.TYPE_USHORT:
|
442 |
return 2;// Sixteen bit unsigned integer GDT_UInt16 = 2 |
443 |
case BufferManager.TYPE_INT:
|
444 |
return 5;// Thirty two bit signed integer GDT_Int32 = 5 |
445 |
case BufferManager.TYPE_FLOAT:
|
446 |
return 6;// Thirty two bit floating point GDT_Float32 = 6 |
447 |
case BufferManager.TYPE_DOUBLE:
|
448 |
return 7;// Sixty four bit floating point GDT_Float64 = 7 |
449 |
default:
|
450 |
return 1; // By default eight bit unsigned integer GDT_Byte = 1 and the force be with you. |
451 |
} |
452 |
} |
453 |
|
454 |
|
455 |
|
456 |
/**
|
457 |
* Stores a buffer into a new entity
|
458 |
* @param newRasterParams
|
459 |
* @param overwrite
|
460 |
* @throws CreateException
|
461 |
*/
|
462 |
public void store(boolean overwrite) |
463 |
throws CreateException {
|
464 |
//This method must be overwritten by subclasses than can be stored
|
465 |
throw new UnsupportedOperationException("This provider can't store the raster"); |
466 |
} |
467 |
|
468 |
|
469 |
/**
|
470 |
* Fills a given dataset with data from a buffer
|
471 |
* @param buffer
|
472 |
* @param gdalDataset
|
473 |
*/
|
474 |
protected void fillDataset(Buffer buffer, Dataset gdalDataset) { |
475 |
for (int i=0;i<buffer.getBandCount();i++){ |
476 |
Band band = buffer.getBand(i); |
477 |
|
478 |
switch (band.getDataType()) {
|
479 |
case BufferManager.TYPE_BYTE:
|
480 |
byte[] byteRowBuffer = (byte[])band.createRowBuffer(); //new byte[band.getColumns()]; |
481 |
for (int row=0;row<band.getRows();row++){ |
482 |
band.fetchRow(row, byteRowBuffer); |
483 |
gdalDataset.GetRasterBand(i+1).WriteRaster(0, row, band.getColumns(), 1, |
484 |
byteRowBuffer); |
485 |
} |
486 |
break;
|
487 |
|
488 |
case BufferManager.TYPE_DOUBLE:
|
489 |
double[] doubleRowBuffer=(double[])band.createRowBuffer(); |
490 |
for (int row=0;row<band.getRows();row++){ |
491 |
band.fetchRow(row, doubleRowBuffer); |
492 |
gdalDataset.GetRasterBand(i+1).WriteRaster(0, row, band.getColumns(), 1, |
493 |
doubleRowBuffer); |
494 |
} |
495 |
break;
|
496 |
|
497 |
case BufferManager.TYPE_FLOAT:
|
498 |
float[] floatRowBuffer=(float[])band.createRowBuffer(); |
499 |
for (int row=0;row<band.getRows();row++){ |
500 |
band.fetchRow(row, floatRowBuffer); |
501 |
gdalDataset.GetRasterBand(i+1).WriteRaster(0, row, band.getColumns(), 1, |
502 |
floatRowBuffer); |
503 |
} |
504 |
break;
|
505 |
|
506 |
case BufferManager.TYPE_INT:
|
507 |
int[] intRowBuffer=(int[])band.createRowBuffer(); |
508 |
for (int row=0;row<band.getRows();row++){ |
509 |
band.fetchRow(row, intRowBuffer); |
510 |
gdalDataset.GetRasterBand(i+1).WriteRaster(0, row, band.getColumns(), 1, |
511 |
intRowBuffer); |
512 |
} |
513 |
break;
|
514 |
|
515 |
case BufferManager.TYPE_SHORT:
|
516 |
case BufferManager.TYPE_USHORT:
|
517 |
short[] shortRowBuffer=(short[])band.createRowBuffer(); |
518 |
for (int row=0;row<band.getRows();row++){ |
519 |
band.fetchRow(row, shortRowBuffer); |
520 |
gdalDataset.GetRasterBand(i+1).WriteRaster(0, row, band.getColumns(), 1, |
521 |
shortRowBuffer); |
522 |
} |
523 |
break;
|
524 |
|
525 |
default:
|
526 |
break;
|
527 |
} |
528 |
|
529 |
} |
530 |
} |
531 |
|
532 |
public TileStruct getTileStruct() {
|
533 |
|
534 |
List<Double> pixelSizes = new ArrayList<Double>(); |
535 |
Map<Integer, Double> zoomLevels = new HashMap<Integer, Double>(); |
536 |
|
537 |
TileStruct tileStruct = new DefaultTileStruct();
|
538 |
//FIXME: DefaultTileStruct ya pone un rows y columns per tile por defecto a 256,
|
539 |
// si se prefiere otro asignar los nuevos valores aqu?.
|
540 |
|
541 |
int completeRows = getGdalDataSet().getRasterYSize();
|
542 |
int completeColumns = getGdalDataSet().getRasterXSize(); //image.columns; |
543 |
double completePixelSizeX = envelope.getLength(DIMENSIONS.X)/completeColumns;
|
544 |
double completePixelSizeY = envelope.getLength(DIMENSIONS.Y)/completeRows;
|
545 |
|
546 |
int maximumLength = completeColumns;
|
547 |
int tileMaximumLength = tileStruct.getColumnsPerTile(); //tileSizeX; |
548 |
double maximumPixelSize = completePixelSizeX;
|
549 |
|
550 |
if (completeRows * tileStruct.getRowsPerTile() > completeColumns * tileStruct.getColumnsPerTile()) {
|
551 |
maximumLength = completeRows; |
552 |
tileMaximumLength = tileStruct.getRowsPerTile(); |
553 |
maximumPixelSize = completePixelSizeY; |
554 |
} |
555 |
|
556 |
double pixelSize = maximumPixelSize;
|
557 |
while (maximumLength * maximumPixelSize / pixelSize > tileMaximumLength) {
|
558 |
pixelSizes.add(pixelSize); |
559 |
pixelSize = pixelSize * 2;
|
560 |
} |
561 |
pixelSizes.add(pixelSize); |
562 |
int i = 0; |
563 |
for (int zoomLevel = pixelSizes.size() - 1; zoomLevel >= 0; zoomLevel--) { |
564 |
zoomLevels.put(i, pixelSizes.get(zoomLevel)); |
565 |
i++; |
566 |
} |
567 |
tileStruct.setEnvelope(this.envelope);
|
568 |
tileStruct.setPixelSizePerZoomLevel(zoomLevels); |
569 |
|
570 |
return tileStruct;
|
571 |
|
572 |
} |
573 |
|
574 |
|
575 |
|
576 |
@Override
|
577 |
public BufferDimensions getDimensions() throws InitializeException { |
578 |
if(this.dimensions==null){; |
579 |
this.dimensions = BufferLocator.getBufferManager().createBufferDimensions(this.gdalDataSet.getRasterYSize(), this.gdalDataSet.getRasterXSize(), this.envelope); |
580 |
} |
581 |
return this.dimensions; |
582 |
} |
583 |
|
584 |
|
585 |
} |