gvsig-gdal / trunk / org.gvsig.gdal2 / org.gvsig.gdal2.prov / org.gvsig.gdal2.prov.raster / src / main / java / org / gvsig / raster / gdal / provider / RasterGdalStoreProviderCreate.java @ 370
History | View | Annotate | Download (3.34 KB)
1 |
package org.gvsig.raster.gdal.provider; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.IOException; |
5 |
|
6 |
import org.cresques.cts.ICRSFactory; |
7 |
import org.cresques.cts.IProjection; |
8 |
import org.gdal.gdal.Dataset; |
9 |
import org.gdal.gdal.Driver; |
10 |
import org.gvsig.fmap.dal.exception.CreateException; |
11 |
import org.gvsig.fmap.dal.exception.InitializeException; |
12 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
13 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
14 |
import org.gvsig.tools.dynobject.DynObject; |
15 |
|
16 |
/**
|
17 |
* Raster GDAL store provider that stores new raster through create method
|
18 |
* @author dmartinezizquierdo
|
19 |
*
|
20 |
*/
|
21 |
public class RasterGdalStoreProviderCreate extends DefaultRasterGdalStoreProvider { |
22 |
|
23 |
protected RasterGdalStoreProviderCreate(RasterGdalFileStoreParameters params,
|
24 |
DataStoreProviderServices storeServices, DynObject metadata) throws InitializeException {
|
25 |
super(params, storeServices, metadata);
|
26 |
} |
27 |
|
28 |
/**
|
29 |
* Constructor
|
30 |
*
|
31 |
* @param params
|
32 |
* @param storeServices
|
33 |
* @throws InitializeException
|
34 |
*/
|
35 |
public RasterGdalStoreProviderCreate(RasterGdalFileStoreParameters params, DataStoreProviderServices storeServices)
|
36 |
throws InitializeException {
|
37 |
super(params, storeServices);
|
38 |
} |
39 |
|
40 |
protected RasterGdalStoreProviderCreate(NewRasterGdalStoreParameters params, Driver gdalDriver) { |
41 |
super(params, gdalDriver);
|
42 |
} |
43 |
|
44 |
@Override
|
45 |
public void store(boolean overwrite) throws CreateException { |
46 |
NewRasterGdalStoreParameters newRasterParams = (NewRasterGdalStoreParameters) this.getParameters();
|
47 |
File file = newRasterParams.getFile();
|
48 |
Buffer buffer = newRasterParams.getBuffer();
|
49 |
|
50 |
String[] options = getStoringOptions(newRasterParams); |
51 |
|
52 |
if (file.exists() && !overwrite) {
|
53 |
throw new CreateException("File already exists: " + file.toString(), null); |
54 |
} |
55 |
Dataset gdalDataset = null;
|
56 |
IProjection projection = buffer.getProjection(); |
57 |
try {
|
58 |
if (options.length == 0) { |
59 |
gdalDataset = |
60 |
gdalDriver.Create(file.getAbsolutePath(), buffer.getColumns(), buffer.getRows(), |
61 |
buffer.getBandCount(), getGdalTypeFromRasterBufType(buffer.getBandTypes()[0]));
|
62 |
} else {
|
63 |
gdalDataset = |
64 |
gdalDriver.Create(file.getAbsolutePath(), buffer.getColumns(), buffer.getRows(), |
65 |
buffer.getBandCount(), getGdalTypeFromRasterBufType(buffer.getBandTypes()[0]), options);
|
66 |
} |
67 |
|
68 |
if (projection != null) { |
69 |
String wkt = projection.export(ICRSFactory.FORMAT_WKT_ESRI);
|
70 |
if (wkt != null) { |
71 |
gdalDataset.SetProjection(wkt); |
72 |
} |
73 |
} |
74 |
gdalDataset.SetGeoTransform(createGeoTransform(buffer)); |
75 |
|
76 |
fillDataset(buffer, gdalDataset); |
77 |
gdalDataset.FlushCache(); |
78 |
} finally {
|
79 |
if (gdalDataset != null) { |
80 |
gdalDataset.delete(); |
81 |
} |
82 |
} |
83 |
// Create WLD
|
84 |
try {
|
85 |
createWorldFile(file, buffer); |
86 |
} catch (IOException e) { |
87 |
throw new CreateException("WLD File", e); |
88 |
} |
89 |
|
90 |
// Create PRJ file
|
91 |
try {
|
92 |
savePrjFile(file, projection); |
93 |
} catch (IOException e) { |
94 |
throw new CreateException("PRJ File", e); |
95 |
} |
96 |
} |
97 |
} |