Revision 4181 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/AbstractRasterDataStore.java
AbstractRasterDataStore.java | ||
---|---|---|
93 | 93 |
|
94 | 94 |
/** |
95 | 95 |
* Default implementation for RasterDataSource |
96 |
*
|
|
96 |
* |
|
97 | 97 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
98 | 98 |
*/ |
99 |
public abstract class AbstractRasterDataStore extends AbstractDisposable
|
|
99 |
public abstract class AbstractRasterDataStore extends AbstractDisposable |
|
100 | 100 |
implements RasterDataStore, CoverageStoreProviderServices, QueryableRaster, DataStoreInitializer { |
101 | 101 |
public static final String PERSISTENT_NAME = "AbstractRasterDataStore_Persistent"; |
102 | 102 |
public static final String PERSISTENT_DESCRIPTION = "AbstractRasterDataStore Persistent"; |
... | ... | |
105 | 105 |
protected BandListImpl storeBandList = null; |
106 | 106 |
protected RasterProvider provider = null; |
107 | 107 |
protected Metadata metadata = null; |
108 |
|
|
108 |
|
|
109 | 109 |
/** |
110 | 110 |
* Lista de paletas asociadas a las bandas cargadas en el DataSource. Estas son calculadas |
111 | 111 |
* en las funciones que asignan las bandas a dibujar (addDrawableBands) |
... | ... | |
118 | 118 |
protected double nWidth = 0; |
119 | 119 |
protected double nHeight = 0; |
120 | 120 |
private Buffer lastBuffer = null; |
121 |
|
|
121 |
|
|
122 | 122 |
private DataManager dataManager = null; |
123 | 123 |
protected DataStoreParameters parameters = null; |
124 | 124 |
private DelegatedDynObject dynobj = null; |
125 |
private DelegateWeakReferencingObservable
|
|
125 |
private DelegateWeakReferencingObservable |
|
126 | 126 |
delegateObservable = new DelegateWeakReferencingObservable(this); |
127 | 127 |
private Render render = null; |
128 | 128 |
protected ICoordTrans coordTrans = null; |
129 | 129 |
protected RasterDataServerExplorer explorer = null; |
130 |
|
|
130 |
|
|
131 | 131 |
public BandList getDefaultBandList() { |
132 | 132 |
if(storeBandList == null) { |
133 | 133 |
initializeBandList(); |
134 | 134 |
} |
135 | 135 |
return storeBandList; |
136 | 136 |
} |
137 |
|
|
137 |
|
|
138 | 138 |
public void initializeBandList() { |
139 | 139 |
if(provider != null) { |
140 | 140 |
storeBandList = new BandListImpl(); |
... | ... | |
142 | 142 |
for(int i = 0; i < provider.getBandCount(); i++) { |
143 | 143 |
try { |
144 | 144 |
int dataType = provider.getDataType()[i]; |
145 |
DatasetBand band = new DatasetBandImpl(provider.getURIByBand(i),
|
|
146 |
provider.getBandPositionByProvider(i),
|
|
147 |
dataType,
|
|
145 |
DatasetBand band = new DatasetBandImpl(provider.getURIByBand(i).getPath(),
|
|
146 |
provider.getBandPositionByProvider(i), |
|
147 |
dataType, |
|
148 | 148 |
provider.getBandCount()); |
149 | 149 |
storeBandList.addBand(band, i); |
150 | 150 |
} catch(BandNotFoundInListException ex) { |
... | ... | |
160 | 160 |
storeBandList.setDrawableBands(drawableBands); |
161 | 161 |
} |
162 | 162 |
} |
163 |
|
|
163 |
|
|
164 | 164 |
public Buffer query(RasterQuery query) throws ProcessInterruptedException, QueryException { |
165 | 165 |
Object[] obj = queryArray(query); |
166 | 166 |
if(obj != null && obj.length > 0 && obj[0] instanceof Buffer) |
167 | 167 |
return ((Buffer)obj[0]); |
168 | 168 |
return null; |
169 | 169 |
} |
170 |
|
|
170 |
|
|
171 | 171 |
/** |
172 | 172 |
* <UL>Tasks to do in the <code>Datastore</code> |
173 | 173 |
* <LI>Check parameters and adjust them to not exceed the window size</LI> |
... | ... | |
181 | 181 |
Object[] result = null; |
182 | 182 |
currentQuery = (DefaultRasterQuery)query; |
183 | 183 |
DefaultRasterQuery q = currentQuery; |
184 |
|
|
184 |
|
|
185 | 185 |
if(isTiled() || provider instanceof RemoteRasterProvider) |
186 | 186 |
q.dontBuildBuffer(); |
187 |
|
|
187 |
|
|
188 | 188 |
Buffer buf = null; |
189 |
|
|
189 |
|
|
190 | 190 |
if(q.requestHasShift()) { |
191 | 191 |
//TODO: Sin probar |
192 | 192 |
FramedBufferResampling framedBufferResampling = new FramedBufferResampling(q, this); |
193 |
buf = framedBufferResampling.query(provider);
|
|
193 |
buf = framedBufferResampling.query(provider); |
|
194 | 194 |
} else { |
195 | 195 |
q.calculateParameters(this); |
196 | 196 |
try { |
... | ... | |
201 | 201 |
} catch (RasterDriverException e) { |
202 | 202 |
throw new QueryException("Error getting data", e); |
203 | 203 |
} |
204 |
|
|
204 |
|
|
205 | 205 |
if(q.isSupersamplingOptionActive() && q.isSupersamplingTheRequest()) { |
206 | 206 |
buf = buf.getAdjustedWindow(q.getBufWidth(), q.getBufHeight(), Buffer.INTERPOLATION_NearestNeighbour); |
207 | 207 |
} |
... | ... | |
209 | 209 |
if(buf != null) |
210 | 210 |
buf.setDataExtent(q.getAdjustedRequestBoundingBox().toRectangle2D()); |
211 | 211 |
result = new Object[]{buf}; |
212 |
|
|
212 |
|
|
213 | 213 |
if(q.isStoredLastBuffer()) |
214 | 214 |
lastBuffer = buf; |
215 | 215 |
else |
216 | 216 |
lastBuffer = null; |
217 | 217 |
q.storeLastBuffer(false); |
218 |
|
|
218 |
|
|
219 | 219 |
if(result != null && result.length > 0 && result[0] instanceof Buffer) { |
220 | 220 |
((Buffer)result[0]).setStore(this); |
221 | 221 |
if(getNoDataValue() != null && getNoDataValue().isDefined()) |
... | ... | |
224 | 224 |
} |
225 | 225 |
return null; |
226 | 226 |
} |
227 |
|
|
227 |
|
|
228 | 228 |
public Extent adjustToExtent(Extent e) { |
229 | 229 |
Extent currentExtent = this.getExtent(); |
230 |
|
|
230 |
|
|
231 | 231 |
double minx = e.getMin().getX() < currentExtent.getMin().getX() ? currentExtent.getMin().getX() : e.getMin().getX(); |
232 | 232 |
double maxx = e.getMax().getX() > currentExtent.getMax().getX() ? currentExtent.getMax().getX() : e.getMax().getX(); |
233 | 233 |
double miny = e.getMin().getY() < currentExtent.getMin().getY() ? currentExtent.getMin().getY() : e.getMin().getY(); |
234 | 234 |
double maxy = e.getMax().getY() > currentExtent.getMax().getY() ? currentExtent.getMax().getY() : e.getMax().getY(); |
235 |
|
|
235 |
|
|
236 | 236 |
return new ExtentImpl(minx, maxy, maxx, miny); |
237 | 237 |
} |
238 |
|
|
238 |
|
|
239 | 239 |
public String getFullName() { |
240 | 240 |
return getName(); |
241 | 241 |
} |
... | ... | |
243 | 243 |
public Buffer getLastBuffer() { |
244 | 244 |
return lastBuffer; |
245 | 245 |
} |
246 |
|
|
246 |
|
|
247 | 247 |
public TimeSeries getTimeSerials() throws RmfSerializerException { |
248 | 248 |
if(getProvider() instanceof RasterProvider) |
249 | 249 |
return ((RasterProvider)getProvider()).getTimeSerials(); |
... | ... | |
252 | 252 |
|
253 | 253 |
public void setTimeSerials(TimeSeries serialInfo) throws RmfSerializerException { |
254 | 254 |
if(getProvider() instanceof RasterProvider) |
255 |
((RasterProvider)getProvider()).setTimeSerials(serialInfo);
|
|
255 |
((RasterProvider)getProvider()).setTimeSerials(serialInfo); |
|
256 | 256 |
} |
257 |
|
|
257 |
|
|
258 | 258 |
public abstract void saveColorTableToRmf(ColorTable table) throws RmfSerializerException; |
259 |
|
|
259 |
|
|
260 | 260 |
public abstract void saveGeoPointListToRmf(GeoPointList pointList) throws RmfSerializerException; |
261 |
|
|
261 |
|
|
262 | 262 |
public abstract void saveROIFileListToRmf(List<File> fileList) throws RmfSerializerException; |
263 |
|
|
263 |
|
|
264 | 264 |
/** |
265 | 265 |
* Saves information about serials |
266 | 266 |
* @param object to save |
267 | 267 |
* @throws RmfSerializerException |
268 | 268 |
*/ |
269 | 269 |
public abstract void saveSerialInfoToRmf(TimeSeries serialInfo) throws RmfSerializerException; |
270 |
|
|
270 |
|
|
271 | 271 |
/** |
272 | 272 |
* Loads information about serials |
273 | 273 |
* @param object to load |
274 | 274 |
* @throws RmfSerializerException |
275 | 275 |
*/ |
276 | 276 |
public abstract boolean loadSerialInfoFromRmf(TimeSeries serialInfo); |
277 |
|
|
277 |
|
|
278 | 278 |
public Vectorization createVectorizeObject() throws QueryException, ProcessInterruptedException { |
279 | 279 |
return new PotraceVectorization((RasterDataStore)this); |
280 | 280 |
} |
281 |
|
|
281 |
|
|
282 | 282 |
public Render getRender() { |
283 | 283 |
if(render == null) |
284 | 284 |
render = new DefaultRender(this); |
285 | 285 |
return render; |
286 | 286 |
} |
287 |
|
|
287 |
|
|
288 | 288 |
public void setRender(Render render) { |
289 | 289 |
this.render = render; |
290 | 290 |
} |
... | ... | |
292 | 292 |
public boolean isFileSupported(String fName) { |
293 | 293 |
return RasterLocator.getManager().getProviderServices().isExtensionSupported(fName); |
294 | 294 |
} |
295 |
|
|
295 |
|
|
296 | 296 |
/** |
297 | 297 |
* Registers metadata definition |
298 | 298 |
* @throws MetadataException |
299 | 299 |
*/ |
300 | 300 |
public static void registerMetadataDefinition() throws MetadataException { |
301 | 301 |
MetadataManager manager = MetadataLocator.getMetadataManager(); |
302 |
|
|
302 |
|
|
303 | 303 |
if(manager == null) |
304 | 304 |
return; |
305 |
|
|
305 |
|
|
306 | 306 |
if( manager.getDefinition(METADATA_DEFINITION_NAME) == null ) { |
307 | 307 |
DynStruct defnition = manager.addDefinition( |
308 | 308 |
METADATA_DEFINITION_NAME, |
309 |
METADATA_DEFINITION_NAME
|
|
309 |
METADATA_DEFINITION_NAME |
|
310 | 310 |
); |
311 | 311 |
defnition.extend( |
312 |
MetadataManager.METADATA_NAMESPACE,
|
|
312 |
MetadataManager.METADATA_NAMESPACE, |
|
313 | 313 |
DataStore.METADATA_DEFINITION_NAME |
314 | 314 |
); |
315 | 315 |
} |
... | ... | |
318 | 318 |
public int getSourceType() { |
319 | 319 |
return ((RasterProvider)getProvider()).getSourceType(); |
320 | 320 |
} |
321 |
|
|
321 |
|
|
322 | 322 |
//**************************************************** |
323 | 323 |
//****Implementing DataStoreImplementation methods**** |
324 | 324 |
//**************************************************** |
... | ... | |
328 | 328 |
DynObjectManager dynManager = ToolsLocator.getDynObjectManager(); |
329 | 329 |
|
330 | 330 |
this.dynobj = (DelegatedDynObject) dynManager |
331 |
.createDynObject(
|
|
331 |
.createDynObject( |
|
332 | 332 |
MetadataLocator.getMetadataManager().getDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME) |
333 | 333 |
); |
334 | 334 |
this.dataManager = dataManager; |
... | ... | |
340 | 340 |
throws InitializeException { |
341 | 341 |
setProvider((RasterProvider)provider); |
342 | 342 |
} |
343 |
|
|
343 |
|
|
344 | 344 |
public DataManager getManager() { |
345 | 345 |
return this.dataManager; |
346 |
}
|
|
346 |
} |
|
347 | 347 |
|
348 | 348 |
//**************************************************** |
349 | 349 |
//*********Implementing DataStore methods************* |
... | ... | |
352 | 352 |
public String getProviderName() { |
353 | 353 |
return getProvider().getFullName(); |
354 | 354 |
} |
355 |
|
|
355 |
|
|
356 | 356 |
public void refresh() throws DataException { |
357 | 357 |
return; |
358 | 358 |
} |
... | ... | |
433 | 433 |
public DataServerExplorer getExplorer() throws DataException, ValidateDataParametersException { |
434 | 434 |
return explorer; |
435 | 435 |
} |
436 |
|
|
436 |
|
|
437 | 437 |
/** |
438 | 438 |
* Sets the explorer |
439 | 439 |
* @param explorer |
... | ... | |
441 | 441 |
public void setExplorer(RasterDataServerExplorer explorer) { |
442 | 442 |
this.explorer = explorer; |
443 | 443 |
} |
444 |
|
|
444 |
|
|
445 | 445 |
public DataQuery createQuery() { |
446 | 446 |
return new DefaultRasterQuery(); |
447 | 447 |
} |
448 |
|
|
448 |
|
|
449 | 449 |
//**************************************************** |
450 | 450 |
//*********Implementing Metadata methods************* |
451 | 451 |
//**************************************************** |
452 |
|
|
452 |
|
|
453 | 453 |
public Object getMetadataID() { |
454 | 454 |
if(parameters != null && parameters instanceof RasterFileStoreParameters) |
455 | 455 |
return ((RasterFileStoreParameters)parameters).getFile(); |
... | ... | |
461 | 461 |
public Set<?> getMetadataChildren() { |
462 | 462 |
return null; |
463 | 463 |
} |
464 |
|
|
464 |
|
|
465 | 465 |
//**************************************************** |
466 | 466 |
//*********Implementing Disposable methods************ |
467 | 467 |
//**************************************************** |
468 |
|
|
468 |
|
|
469 | 469 |
public void doDispose() { |
470 |
|
|
470 |
|
|
471 | 471 |
} |
472 |
|
|
472 |
|
|
473 | 473 |
//**************************************************** |
474 | 474 |
//*********Implementing Visitable methods************* |
475 | 475 |
//**************************************************** |
476 |
|
|
476 |
|
|
477 | 477 |
public void accept(Visitor visitor) throws BaseException { |
478 |
|
|
478 |
|
|
479 | 479 |
} |
480 |
|
|
480 |
|
|
481 | 481 |
//**************************************************** |
482 | 482 |
//****Implementing ComplexObservable methods********** |
483 | 483 |
//**************************************************** |
484 |
|
|
484 |
|
|
485 | 485 |
public void disableNotifications() { |
486 |
|
|
486 |
|
|
487 | 487 |
} |
488 | 488 |
|
489 | 489 |
public void enableNotifications() { |
490 |
|
|
490 |
|
|
491 | 491 |
} |
492 | 492 |
|
493 | 493 |
public void beginComplexNotification() { |
494 |
|
|
494 |
|
|
495 | 495 |
} |
496 | 496 |
|
497 | 497 |
public void endComplexNotification() { |
498 |
|
|
498 |
|
|
499 | 499 |
} |
500 |
|
|
500 |
|
|
501 | 501 |
//**************************************************** |
502 | 502 |
//********Implementing Observable methods************* |
503 | 503 |
//**************************************************** |
504 |
|
|
504 |
|
|
505 | 505 |
public void addObserver(org.gvsig.tools.observer.Observer o) { |
506 |
|
|
506 |
|
|
507 | 507 |
} |
508 | 508 |
|
509 | 509 |
public void deleteObserver(org.gvsig.tools.observer.Observer o) { |
510 |
|
|
510 |
|
|
511 | 511 |
} |
512 | 512 |
|
513 | 513 |
public void deleteObservers() { |
514 |
|
|
514 |
|
|
515 | 515 |
} |
516 |
|
|
516 |
|
|
517 | 517 |
//**************************************************** |
518 | 518 |
//********Implementing DynObject methods************* |
519 | 519 |
//**************************************************** |
520 |
|
|
520 |
|
|
521 | 521 |
public DynClass getDynClass() { |
522 | 522 |
return this.dynobj.getDynClass(); |
523 | 523 |
} |
... | ... | |
555 | 555 |
dynobj.clear(); |
556 | 556 |
} |
557 | 557 |
} |
558 |
|
|
558 |
|
|
559 | 559 |
public DataStoreParameters getParameters() { |
560 | 560 |
return parameters; |
561 | 561 |
} |
562 |
|
|
562 |
|
|
563 | 563 |
//*********************************************************************** |
564 | 564 |
//********Implementing CoverageStoreProviderServices methods************* |
565 | 565 |
//*********************************************************************** |
... | ... | |
595 | 595 |
public DataStore getStore() { |
596 | 596 |
return this; |
597 | 597 |
} |
598 |
|
|
598 |
|
|
599 | 599 |
public void setCoordTrans(ICoordTrans t) { |
600 | 600 |
this.coordTrans = t; |
601 | 601 |
} |
602 |
|
|
602 |
|
|
603 | 603 |
public void close() { |
604 | 604 |
if(lastBuffer != null) { |
605 | 605 |
lastBuffer.dispose(); |
606 | 606 |
} |
607 | 607 |
} |
608 |
|
|
608 |
|
|
609 | 609 |
protected void finalize() throws Throwable { |
610 | 610 |
currentQuery = null; |
611 | 611 |
if(palette != null) { |
Also available in: Unified diff