Revision 4181 org.gvsig.raster.netcdf/trunk/org.gvsig.raster.netcdf/org.gvsig.raster.netcdf.io/src/main/java/org/gvsig/raster/netcdf/io/NetCDFProvider.java
NetCDFProvider.java | ||
---|---|---|
24 | 24 |
import java.awt.geom.AffineTransform; |
25 | 25 |
import java.awt.geom.Point2D; |
26 | 26 |
import java.awt.geom.Rectangle2D; |
27 |
import java.io.File; |
|
27 | 28 |
import java.io.IOException; |
29 |
import java.net.URI; |
|
30 |
import java.net.URISyntaxException; |
|
28 | 31 |
import java.util.List; |
29 | 32 |
|
33 |
import org.slf4j.Logger; |
|
34 |
import org.slf4j.LoggerFactory; |
|
35 |
|
|
30 | 36 |
import org.gvsig.fmap.dal.DALFileLocator; |
31 | 37 |
import org.gvsig.fmap.dal.DALLocator; |
32 | 38 |
import org.gvsig.fmap.dal.DataStore; |
... | ... | |
37 | 43 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
38 | 44 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
39 | 45 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
46 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
|
40 | 47 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
41 | 48 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
42 | 49 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
... | ... | |
60 | 67 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
61 | 68 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
62 | 69 |
import org.gvsig.tools.ToolsLocator; |
63 |
import org.slf4j.Logger; |
|
64 |
import org.slf4j.LoggerFactory; |
|
65 | 70 |
|
66 | 71 |
import ucar.ma2.Array; |
67 | 72 |
import ucar.ma2.DataType; |
... | ... | |
82 | 87 |
private Extent viewRequest = null; |
83 | 88 |
private TileServer tileServer = null; |
84 | 89 |
private boolean open = false; |
85 |
|
|
90 |
|
|
86 | 91 |
private GridDataset gridNetCDF = null; |
87 | 92 |
private List<GridDatatype> gridList = null; |
88 | 93 |
private GridDatatype selectedGridDataType = null; |
89 | 94 |
private DataStoreTransparency fileTransparency = null; |
90 | 95 |
private static final Logger logger = LoggerFactory.getLogger(NetCDFProvider.class); |
91 | 96 |
protected static String[] formatList = null; |
92 |
|
|
97 |
|
|
93 | 98 |
public static void register() { |
94 | 99 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
95 | 100 |
RasterLocator.getManager().getProviderServices().registerFileProvidersTiled(NetCDFProvider.class); |
96 | 101 |
registerFormats(); |
97 |
|
|
102 |
|
|
98 | 103 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
99 | 104 |
dataman.registerStoreProvider(NAME, |
100 | 105 |
NetCDFProvider.class, NetCDFDataParametersImpl.class); |
101 | 106 |
} |
102 |
|
|
103 | 107 |
|
108 |
|
|
104 | 109 |
/*if (!dataman.getExplorerProviders().contains(NetCDFFilesystemServerExplorer.NAME)) { |
105 | 110 |
dataman.registerExplorerProvider(NetCDFFilesystemServerExplorer.NAME, NetCDFFilesystemServerExplorer.class, NetCDFServerExplorerParameters.class); |
106 | 111 |
}*/ |
107 |
|
|
112 |
|
|
108 | 113 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
109 | 114 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
110 | 115 |
NAME, DESCRIPTION, |
111 | 116 |
NetCDFFilesystemServerExplorer.class); |
112 |
|
|
113 |
|
|
117 |
|
|
118 |
|
|
114 | 119 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
115 | 120 |
} |
116 |
|
|
121 |
|
|
117 | 122 |
private static void registerFormats() { |
118 | 123 |
formatList = new String[] {"nc", "nc4"}; |
119 |
for (int i = 0; i < formatList.length; i++)
|
|
124 |
for (int i = 0; i < formatList.length; i++) |
|
120 | 125 |
RasterLocator.getManager().getProviderServices().addFormat(formatList[i], NetCDFProvider.class); |
121 | 126 |
} |
122 |
|
|
127 |
|
|
123 | 128 |
public String[] getFormatList() { |
124 | 129 |
return formatList; |
125 | 130 |
} |
126 |
|
|
131 |
|
|
127 | 132 |
/** |
128 | 133 |
* Returns true if the extension is supported and false if doesn't |
129 | 134 |
* @param ext |
... | ... | |
138 | 143 |
} |
139 | 144 |
return false; |
140 | 145 |
} |
141 |
|
|
146 |
|
|
142 | 147 |
public NetCDFProvider() { |
143 | 148 |
} |
144 |
|
|
149 |
|
|
145 | 150 |
/** |
146 | 151 |
* Opens the dataset. |
147 | 152 |
* @param proj Projection |
148 | 153 |
* @param fName File name |
149 | 154 |
* @throws NotSupportedExtensionException |
155 |
* @deprecated use {@link #NetCDFProvider(URI)}, this constructor will be removed in gvSIG 2.5 |
|
150 | 156 |
*/ |
151 | 157 |
public NetCDFProvider(String params) throws NotSupportedExtensionException, OpenException { |
152 | 158 |
super(params); |
159 |
logger.info("Deprecated use of NetCDFProvider constructor"); |
|
153 | 160 |
if(params instanceof String) { |
154 | 161 |
NetCDFDataParameters p = new NetCDFDataParametersImpl(); |
155 |
p.setURI((String)params); |
|
162 |
URI uriObj; |
|
163 |
try { |
|
164 |
uriObj = new URI((String)params); |
|
165 |
} catch (URISyntaxException e) { |
|
166 |
throw new OpenException("Can't create URI from "+(String)params, e); |
|
167 |
} |
|
168 |
p.setURI(uriObj); |
|
156 | 169 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
157 | 170 |
.createDynObject( |
158 | 171 |
MetadataLocator.getMetadataManager().getDefinition( |
... | ... | |
160 | 173 |
init(p, null); |
161 | 174 |
} |
162 | 175 |
} |
163 |
|
|
164 |
public NetCDFProvider (NetCDFDataParameters params, |
|
176 |
|
|
177 |
/** |
|
178 |
* Opens the dataset. |
|
179 |
* @param proj Projection |
|
180 |
* @param fName File name |
|
181 |
* @throws NotSupportedExtensionException |
|
182 |
*/ |
|
183 |
public NetCDFProvider(URI uri) throws NotSupportedExtensionException, OpenException { |
|
184 |
super(uri); |
|
185 |
NetCDFDataParameters p = new NetCDFDataParametersImpl(); |
|
186 |
p.setURI(uri); |
|
187 |
super.init( |
|
188 |
p, |
|
189 |
null, |
|
190 |
ToolsLocator.getDynObjectManager().createDynObject( |
|
191 |
MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME))); |
|
192 |
init(p, null); |
|
193 |
} |
|
194 |
|
|
195 |
public NetCDFProvider (NetCDFDataParameters params, |
|
165 | 196 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
166 | 197 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
167 | 198 |
.createDynObject( |
... | ... | |
178 | 209 |
*/ |
179 | 210 |
public void init (NetCDFDataParameters params, |
180 | 211 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
181 |
|
|
212 |
|
|
182 | 213 |
if(((RasterFileStoreParameters)params).getFile().exists()) { |
183 | 214 |
String fileName = ((RasterFileStoreParameters)params).getFile().getAbsolutePath(); |
184 |
try {
|
|
215 |
try { |
|
185 | 216 |
gridNetCDF = GridDataset.open(fileName); |
186 | 217 |
gridList = gridNetCDF.getGrids(); |
187 | 218 |
if(gridList.size() == 0) |
... | ... | |
190 | 221 |
//netCDFFile = NetcdfFile.open(((RasterFileStoreParameters)params).getFile().getAbsolutePath()); |
191 | 222 |
} catch (IOException e) { |
192 | 223 |
throw new OpenException("Imposible to read the file", e); |
193 |
}
|
|
194 |
|
|
224 |
} |
|
225 |
|
|
195 | 226 |
/*List<Variable> variableList = netCDFFile.getVariables(); |
196 | 227 |
Iterator<Variable> it = variableList.iterator(); |
197 | 228 |
while(it.hasNext()) { |
198 | 229 |
Variable var = it.next(); |
199 | 230 |
System.out.println("===>>" + var.getName()); |
200 | 231 |
}*/ |
201 |
|
|
232 |
|
|
202 | 233 |
setParam(storeServices, params); |
203 | 234 |
reloadMetadataFromGrid(); |
204 |
|
|
235 |
|
|
205 | 236 |
noData = new DefaultNoData(Double.NaN, Double.NaN, fileName); |
206 | 237 |
load(); |
207 | 238 |
} else |
208 | 239 |
setParam(storeServices, params); |
209 |
|
|
240 |
|
|
210 | 241 |
super.init(); |
211 | 242 |
selectSubdataset(getId(0, 0, 0)); |
212 | 243 |
try { |
... | ... | |
216 | 247 |
} |
217 | 248 |
open = true; |
218 | 249 |
} |
219 |
|
|
250 |
|
|
220 | 251 |
/** |
221 | 252 |
* Reloads metadata using the selected grid |
222 | 253 |
*/ |
... | ... | |
224 | 255 |
//wktProjection = null; |
225 | 256 |
//CrsWkt crs = new CrsWkt(wktProjection); |
226 | 257 |
//IProjection proj = CRSFactory.getCRS("EPSG:23030"); |
227 |
|
|
258 |
|
|
228 | 259 |
/*LatLonRect gcs = selectedGridDataType.getCoordinateSystem().getLatLonBoundingBox(); |
229 | 260 |
getColorInterpretation(); |
230 | 261 |
double scaleX = gcs.getWidth() / selectedGridDataType.getXDimension().getLength(); |
231 | 262 |
double scaleY = gcs.getHeight() / selectedGridDataType.getYDimension().getLength(); |
232 | 263 |
ownTransformation = new AffineTransform( |
233 |
scaleX, 0,
|
|
234 |
0, -scaleY,
|
|
235 |
gcs.getLonMin(),
|
|
264 |
scaleX, 0, |
|
265 |
0, -scaleY, |
|
266 |
gcs.getLonMin(), |
|
236 | 267 |
gcs.getLatMax());*/ |
237 |
|
|
268 |
|
|
238 | 269 |
ProjectionRect pRect = selectedGridDataType.getCoordinateSystem().getBoundingBox(); |
239 | 270 |
double scaleX = pRect.getWidth() / selectedGridDataType.getXDimension().getLength(); |
240 | 271 |
double scaleY = pRect.getHeight() / selectedGridDataType.getYDimension().getLength(); |
241 | 272 |
ownTransformation = new AffineTransform( |
242 |
scaleX, 0,
|
|
243 |
0, -scaleY,
|
|
244 |
pRect.getMinX(),
|
|
273 |
scaleX, 0, |
|
274 |
0, -scaleY, |
|
275 |
pRect.getMinX(), |
|
245 | 276 |
pRect.getMaxY()); |
246 | 277 |
externalTransformation = (AffineTransform)ownTransformation.clone(); |
247 | 278 |
bandCount = 1; //One variable is always shown |
248 | 279 |
setDataType(); |
249 | 280 |
} |
250 |
|
|
281 |
|
|
251 | 282 |
/** |
252 | 283 |
* @param dataType The dataType to set. |
253 | 284 |
*/ |
... | ... | |
272 | 303 |
if(dt.name() == DataType.LONG.name()) { |
273 | 304 |
type = Buffer.TYPE_DOUBLE; |
274 | 305 |
} |
275 |
|
|
306 |
|
|
276 | 307 |
int[] dtype = new int[getBandCount()]; |
277 | 308 |
for (int i = 0; i < dtype.length; i++) |
278 | 309 |
dtype[i] = type; |
... | ... | |
282 | 313 |
public RasterProvider load() { |
283 | 314 |
return this; |
284 | 315 |
} |
285 |
|
|
316 |
|
|
286 | 317 |
public boolean isOpen() { |
287 | 318 |
return open; |
288 | 319 |
} |
... | ... | |
295 | 326 |
} |
296 | 327 |
} |
297 | 328 |
|
298 |
public String translateFileName(String fileName) {
|
|
299 |
return fileName;
|
|
300 |
}
|
|
329 |
public URI translateURI(URI uri) {
|
|
330 |
return uri;
|
|
331 |
}
|
|
301 | 332 |
|
302 | 333 |
/** |
303 | 334 |
* Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci�n |
... | ... | |
328 | 359 |
|
329 | 360 |
if((pos + blockHeight) > getHeight()) |
330 | 361 |
blockHeight = Math.abs(((int)getHeight()) - pos); |
331 |
|
|
362 |
|
|
332 | 363 |
Buffer buf = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], (int)getWidth(), blockHeight, 1, true); |
333 | 364 |
try { |
334 | 365 |
int time = p.getFieldTime(); |
... | ... | |
354 | 385 |
int strideY = 1; |
355 | 386 |
Range rangeY = new Range((int)(getHeight() - y), (int)(getHeight() - y), strideY); |
356 | 387 |
Range rangeX = new Range(x, x, strideX); |
357 |
|
|
388 |
|
|
358 | 389 |
selectSubdataset(); |
359 | 390 |
int time = p.getFieldTime(); |
360 | 391 |
int level = getLevelValue(); |
361 | 392 |
GridDatatype dt = selectedGridDataType.makeSubset(null, null, null, null, rangeY, rangeX); |
362 | 393 |
Array values = dt.readDataSlice(time, level, -1, -1); |
363 | 394 |
Object data = null; |
364 |
|
|
395 |
|
|
365 | 396 |
if(getDataType()[0] == Buffer.TYPE_BYTE) { |
366 | 397 |
data = new java.lang.Integer(values.getByte(0)); |
367 | 398 |
} |
... | ... | |
387 | 418 |
throw new RasterDriverException("Error reading a slice", e); |
388 | 419 |
} |
389 | 420 |
} |
390 |
|
|
421 |
|
|
391 | 422 |
@Override |
392 | 423 |
public void loadBuffer(SpiRasterQuery query) |
393 | 424 |
throws ProcessInterruptedException, RasterDriverException { |
394 | 425 |
NetCDFDataParameters p = (NetCDFDataParameters)param; |
395 | 426 |
setView(query.getAdjustedRequestBoundingBox()); |
396 |
|
|
427 |
|
|
397 | 428 |
Point2D ul = new Point2D.Double(viewRequest.getULX(), viewRequest.getULY()); |
398 | 429 |
Point2D lr = new Point2D.Double(viewRequest.getLRX(), viewRequest.getLRY()); |
399 | 430 |
ul = worldToRaster(ul); |
... | ... | |
402 | 433 |
lr.setLocation(lr.getX() < 0 ? 0 : lr.getX(), lr.getY() < 0 ? 0 : lr.getY()); |
403 | 434 |
ul.setLocation(ul.getX() >= getWidth() ? getWidth() - 1 : ul.getX(), ul.getY() >= getHeight() ? getHeight() - 1 : ul.getY()); |
404 | 435 |
lr.setLocation(lr.getX() >= getWidth() ? getWidth() - 1 : lr.getX(), lr.getY() >= getHeight() ? getHeight() - 1 : lr.getY()); |
405 |
|
|
436 |
|
|
406 | 437 |
adjustPoints(ul, lr); |
407 |
|
|
438 |
|
|
408 | 439 |
//int width = Math.abs(((int)lr.getX()) - ((int)ul.getX())); |
409 | 440 |
//int height = Math.abs(((int)lr.getY()) - ((int)ul.getY())); |
410 | 441 |
try { |
... | ... | |
412 | 443 |
int strideY = 1; |
413 | 444 |
Range rangeY = new Range((int)(getHeight() - lr.getY()), (int)(getHeight() - ul.getY() - 1), strideY <= 0 ? 1 : strideY); |
414 | 445 |
Range rangeX = new Range((int)ul.getX(), (int)(lr.getX() - 1), strideX <= 0 ? 1 : strideX); |
415 |
|
|
446 |
|
|
416 | 447 |
selectSubdataset(); |
417 | 448 |
int time = p.getFieldTime(); |
418 | 449 |
int level = getLevelValue(); |
... | ... | |
420 | 451 |
Array values = dt.readDataSlice(time, level, -1, -1); |
421 | 452 |
Rectangle2D r = query.getBufferForProviders().getDataExtent(); |
422 | 453 |
Buffer rasterBuf = arrayValuesToBuffer( |
423 |
values,
|
|
424 |
query.getBufferForProviders(),
|
|
425 |
rangeX.length(),
|
|
426 |
rangeY.length(),
|
|
454 |
values, |
|
455 |
query.getBufferForProviders(), |
|
456 |
rangeX.length(), |
|
457 |
rangeY.length(), |
|
427 | 458 |
query.getBandList()); |
428 | 459 |
rasterBuf.setDataExtent(r); |
429 | 460 |
query.setBufferResult(rasterBuf); |
... | ... | |
432 | 463 |
} catch (InvalidRangeException e) { |
433 | 464 |
throw new RasterDriverException("Error reading a slice", e); |
434 | 465 |
} |
435 |
|
|
466 |
|
|
436 | 467 |
} |
437 | 468 |
|
438 | 469 |
|
439 |
/*public Buffer getWindow(Extent extent, BandList bandList, Buffer rasterBuf, TaskStatus status)
|
|
470 |
/*public Buffer getWindow(Extent extent, BandList bandList, Buffer rasterBuf, TaskStatus status) |
|
440 | 471 |
throws ProcessInterruptedException, RasterDriverException { |
441 | 472 |
NetCDFDataParameters p = (NetCDFDataParameters)param; |
442 | 473 |
setView(extent); |
... | ... | |
449 | 480 |
lr.setLocation(lr.getX() < 0 ? 0 : lr.getX(), lr.getY() < 0 ? 0 : lr.getY()); |
450 | 481 |
ul.setLocation(ul.getX() > getWidth() ? getWidth() : ul.getX(), ul.getY() > getHeight() ? getHeight() : ul.getY()); |
451 | 482 |
lr.setLocation(lr.getX() > getWidth() ? getWidth() : lr.getX(), lr.getY() > getHeight() ? getHeight() : lr.getY()); |
452 |
|
|
483 |
|
|
453 | 484 |
adjustPoints(ul, lr); |
454 |
|
|
485 |
|
|
455 | 486 |
try { |
456 | 487 |
int strideX = 1; |
457 | 488 |
int strideY = 1; |
458 | 489 |
Range rangeY = new Range((int)(getHeight() - lr.getY()), (int)(getHeight() - ul.getY() - 1), strideY); |
459 | 490 |
Range rangeX = new Range((int)ul.getX(), (int)(lr.getX() - 1), strideX); |
460 |
|
|
491 |
|
|
461 | 492 |
selectSubdataset(); |
462 | 493 |
int time = p.getFieldTime(); |
463 | 494 |
int level = getLevelValue(); |
... | ... | |
469 | 500 |
} catch (InvalidRangeException e) { |
470 | 501 |
throw new RasterDriverException("Error reading a slice", e); |
471 | 502 |
} |
472 |
|
|
503 |
|
|
473 | 504 |
return rasterBuf; |
474 | 505 |
}*/ |
475 |
|
|
476 |
/*public Buffer getWindow(Extent extent, int bufWidth, int bufHeight,
|
|
506 |
|
|
507 |
/*public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, |
|
477 | 508 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
478 | 509 |
NetCDFDataParameters p = (NetCDFDataParameters)param; |
479 | 510 |
setView(extent); |
... | ... | |
486 | 517 |
lr.setLocation(lr.getX() < 0 ? 0 : lr.getX(), lr.getY() < 0 ? 0 : lr.getY()); |
487 | 518 |
ul.setLocation(ul.getX() >= getWidth() ? getWidth() - 1 : ul.getX(), ul.getY() >= getHeight() ? getHeight() - 1 : ul.getY()); |
488 | 519 |
lr.setLocation(lr.getX() >= getWidth() ? getWidth() - 1 : lr.getX(), lr.getY() >= getHeight() ? getHeight() - 1 : lr.getY()); |
489 |
|
|
520 |
|
|
490 | 521 |
adjustPoints(ul, lr); |
491 |
|
|
522 |
|
|
492 | 523 |
int width = Math.abs(((int)lr.getX()) - ((int)ul.getX())); |
493 | 524 |
int height = Math.abs(((int)lr.getY()) - ((int)ul.getY())); |
494 |
|
|
525 |
|
|
495 | 526 |
try { |
496 | 527 |
int strideX = width / rasterBuf.getWidth(); |
497 | 528 |
int strideY = height / rasterBuf.getHeight(); |
498 | 529 |
Range rangeY = new Range((int)(getHeight() - lr.getY()), (int)(getHeight() - ul.getY() - 1), strideY <= 0 ? 1 : strideY); |
499 | 530 |
Range rangeX = new Range((int)ul.getX(), (int)(lr.getX() - 1), strideX <= 0 ? 1 : strideX); |
500 |
|
|
531 |
|
|
501 | 532 |
selectSubdataset(); |
502 | 533 |
int time = p.getFieldTime(); |
503 | 534 |
int level = getLevelValue(); |
... | ... | |
509 | 540 |
} catch (InvalidRangeException e) { |
510 | 541 |
throw new RasterDriverException("Error reading a slice", e); |
511 | 542 |
} |
512 |
|
|
543 |
|
|
513 | 544 |
return rasterBuf; |
514 | 545 |
}*/ |
515 |
|
|
516 |
/*public Buffer getWindow(int x, int y, int w, int h,
|
|
546 |
|
|
547 |
/*public Buffer getWindow(int x, int y, int w, int h, |
|
517 | 548 |
BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
518 | 549 |
try { |
519 | 550 |
NetCDFDataParameters p = (NetCDFDataParameters)param; |
... | ... | |
521 | 552 |
int strideY = 1; |
522 | 553 |
Range rangeY = new Range((int)(h - y), (int)(h - y - 1), strideY); |
523 | 554 |
Range rangeX = new Range((int)x, (int)(x + w - 1), strideX); |
524 |
|
|
555 |
|
|
525 | 556 |
selectSubdataset(); |
526 | 557 |
int time = p.getFieldTime(); |
527 | 558 |
int level = getLevelValue(); |
... | ... | |
533 | 564 |
} catch (InvalidRangeException e) { |
534 | 565 |
throw new RasterDriverException("Error reading a slice", e); |
535 | 566 |
} |
536 |
|
|
567 |
|
|
537 | 568 |
return rasterBuf; |
538 | 569 |
}*/ |
539 |
|
|
570 |
|
|
540 | 571 |
/** |
541 | 572 |
* Gets the Range of the selected time or null if there is not a selected time |
542 | 573 |
* @param strideX |
... | ... | |
549 | 580 |
int time = p.getFieldTime(); |
550 | 581 |
return new Range(time, time, strideX); |
551 | 582 |
} |
552 |
|
|
583 |
|
|
553 | 584 |
/*private int getTimeValue() { |
554 | 585 |
int time = 0; |
555 | 586 |
if(param.hasDynValue(NetCDFDataParameters.FIELD_TIME)) |
556 | 587 |
time = ((Integer)param.getDynValue(NetCDFDataParameters.FIELD_TIME)).intValue(); |
557 | 588 |
return time; |
558 | 589 |
}*/ |
559 |
|
|
590 |
|
|
560 | 591 |
/** |
561 | 592 |
* Gets the Range of the selected level or null if there is not a selected level |
562 | 593 |
* @param strideX |
... | ... | |
568 | 599 |
int level = getLevelValue(); |
569 | 600 |
return new Range(level, level, strideX); |
570 | 601 |
} |
571 |
|
|
602 |
|
|
572 | 603 |
private int getLevelValue() { |
573 | 604 |
int level = 0; |
574 | 605 |
if(param.hasDynValue(NetCDFDataParameters.FIELD_LEVEL) && param.getDynValue(NetCDFDataParameters.FIELD_LEVEL) != null) |
575 | 606 |
level = ((Integer)param.getDynValue(NetCDFDataParameters.FIELD_LEVEL)).intValue(); |
576 | 607 |
return level; |
577 | 608 |
} |
578 |
|
|
579 |
|
|
609 |
|
|
610 |
|
|
580 | 611 |
/** |
581 | 612 |
* Selects the GridDataType using the selected variable in the parameters |
582 | 613 |
*/ |
... | ... | |
606 | 637 |
private String getId(int grid, int level, int time) { |
607 | 638 |
return grid + "-" + level + "-" + time; |
608 | 639 |
} |
609 |
|
|
640 |
|
|
610 | 641 |
/** |
611 |
* Loads a Buffer object from an netCDF Array.
|
|
642 |
* Loads a Buffer object from an netCDF Array. |
|
612 | 643 |
* @param values |
613 | 644 |
* @param rasterBuf |
614 | 645 |
* @param w |
... | ... | |
618 | 649 |
private Buffer arrayValuesToBuffer(Array values, Buffer rasterBuf, int w, int h, BandList bandList) { |
619 | 650 |
Buffer buf = null; |
620 | 651 |
boolean resampling = false; |
621 |
|
|
652 |
|
|
622 | 653 |
if((rasterBuf.getWidth() * rasterBuf.getHeight()) != values.getSize()) { |
623 | 654 |
buf = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], w, h, rasterBuf.getBandCount(), true); |
624 | 655 |
resampling = true; |
625 | 656 |
} else |
626 | 657 |
buf = rasterBuf; |
627 |
|
|
628 |
int[] drawableBands = bandList != null ? bandList.getBufferBandToDraw(getURIOfFirstProvider(), 0) : new int[1]; |
|
658 |
|
|
659 |
int[] drawableBands = bandList != null ? bandList.getBufferBandToDraw(getURIOfFirstProvider().getPath(), 0) : new int[1];
|
|
629 | 660 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
630 | 661 |
return rasterBuf; |
631 |
|
|
662 |
|
|
632 | 663 |
if(getDataType()[0] == Buffer.TYPE_BYTE) { |
633 | 664 |
for (int i = 0; i < values.getSize(); i++) { |
634 | 665 |
int[] rc = getColAndRow(i, buf); |
635 |
for (int iBands = 0; iBands < drawableBands.length; iBands++)
|
|
666 |
for (int iBands = 0; iBands < drawableBands.length; iBands++) |
|
636 | 667 |
buf.setElem(rc[0], rc[1], drawableBands[iBands], values.getByte(i)); |
637 | 668 |
} |
638 | 669 |
} |
... | ... | |
640 | 671 |
if(getDataType()[0] == Buffer.TYPE_SHORT) { |
641 | 672 |
for (int i = 0; i < values.getSize(); i++) { |
642 | 673 |
int[] rc = getColAndRow(i, buf); |
643 |
for (int iBands = 0; iBands < drawableBands.length; iBands++)
|
|
674 |
for (int iBands = 0; iBands < drawableBands.length; iBands++) |
|
644 | 675 |
buf.setElem(rc[0], rc[1], drawableBands[iBands], values.getShort(i)); |
645 | 676 |
} |
646 | 677 |
} |
... | ... | |
648 | 679 |
if(getDataType()[0] == Buffer.TYPE_INT) { |
649 | 680 |
for (int i = 0; i < values.getSize(); i++) { |
650 | 681 |
int[] rc = getColAndRow(i, buf); |
651 |
for (int iBands = 0; iBands < drawableBands.length; iBands++)
|
|
682 |
for (int iBands = 0; iBands < drawableBands.length; iBands++) |
|
652 | 683 |
buf.setElem(rc[0], rc[1], drawableBands[iBands], values.getInt(i)); |
653 | 684 |
} |
654 | 685 |
} |
... | ... | |
656 | 687 |
if(getDataType()[0] == Buffer.TYPE_FLOAT) { |
657 | 688 |
for (int i = 0; i < values.getSize(); i++) { |
658 | 689 |
int[] rc = getColAndRow(i, buf); |
659 |
for (int iBands = 0; iBands < drawableBands.length; iBands++)
|
|
690 |
for (int iBands = 0; iBands < drawableBands.length; iBands++) |
|
660 | 691 |
buf.setElem(rc[0], rc[1], drawableBands[iBands], values.getFloat(i)); |
661 | 692 |
} |
662 | 693 |
} |
... | ... | |
664 | 695 |
if(getDataType()[0] == Buffer.TYPE_DOUBLE) { |
665 | 696 |
for (int i = 0; i < values.getSize(); i++) { |
666 | 697 |
int[] rc = getColAndRow(i, buf); |
667 |
for (int iBands = 0; iBands < drawableBands.length; iBands++)
|
|
698 |
for (int iBands = 0; iBands < drawableBands.length; iBands++) |
|
668 | 699 |
buf.setElem(rc[0], rc[1], drawableBands[iBands], values.getDouble(i)); |
669 | 700 |
} |
670 | 701 |
} |
... | ... | |
681 | 712 |
} |
682 | 713 |
return buf; |
683 | 714 |
} |
684 |
|
|
715 |
|
|
685 | 716 |
/** |
686 | 717 |
* Calculates the row and column number for the position i in the |
687 | 718 |
* array of data |
... | ... | |
691 | 722 |
*/ |
692 | 723 |
private int[] getColAndRow(int i, Buffer buf) { |
693 | 724 |
int auxRow = (int)(i / buf.getWidth()); |
694 |
return new int[]{
|
|
725 |
return new int[]{ |
|
695 | 726 |
(int)buf.getHeight() - auxRow - 1, |
696 | 727 |
i - (auxRow * buf.getWidth()) |
697 | 728 |
}; |
... | ... | |
700 | 731 |
private void adjustPoints(Point2D ul, Point2D lr) { |
701 | 732 |
double a = (ul.getX() - (int)ul.getX()); |
702 | 733 |
double b = (ul.getY() - (int)ul.getY()); |
703 |
ul.setLocation( (a > 0.95 || a < 0.05) ? Math.round(ul.getX()) : ul.getX(),
|
|
734 |
ul.setLocation( (a > 0.95 || a < 0.05) ? Math.round(ul.getX()) : ul.getX(), |
|
704 | 735 |
(b > 0.95 || b < 0.05) ? Math.round(ul.getY()) : ul.getY()); |
705 |
lr.setLocation( (a > 0.95 || a < 0.05) ? Math.round(lr.getX()) : lr.getX(),
|
|
736 |
lr.setLocation( (a > 0.95 || a < 0.05) ? Math.round(lr.getX()) : lr.getX(), |
|
706 | 737 |
(b > 0.95 || b < 0.05) ? Math.round(lr.getY()) : lr.getY()); |
707 | 738 |
} |
708 | 739 |
|
... | ... | |
765 | 796 |
public String getProviderName() { |
766 | 797 |
return NAME; |
767 | 798 |
} |
768 |
|
|
799 |
|
|
769 | 800 |
public void setStatus(RasterProvider provider) { |
770 | 801 |
if(provider instanceof NetCDFProvider) { |
771 | 802 |
//Not implemented yet |
772 | 803 |
} |
773 | 804 |
} |
774 |
|
|
805 |
|
|
775 | 806 |
public boolean isTimeSupported() { |
776 | 807 |
return true; |
777 | 808 |
} |
778 |
|
|
809 |
|
|
779 | 810 |
public TileServer getTileServer() { |
780 | 811 |
if(tileServer == null) { |
781 | 812 |
DefaultRasterStore store = new DefaultRasterStore(); |
... | ... | |
784 | 815 |
} |
785 | 816 |
return tileServer; |
786 | 817 |
} |
818 |
|
|
819 |
public void addFile(File file) throws InvalidSourceException { |
|
820 |
// Do nothing |
|
821 |
} |
|
822 |
|
|
823 |
public void removeFile(File file) { |
|
824 |
// Do nothing |
|
825 |
} |
|
787 | 826 |
} |
Also available in: Unified diff