Revision 6335 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.gdal/org.gvsig.raster.gdal.provider/src/main/java/org/gvsig/raster/gdal/provider/RasterGdalFileSystemServerProvider.java
RasterGdalFileSystemServerProvider.java | ||
---|---|---|
23 | 23 |
package org.gvsig.raster.gdal.provider; |
24 | 24 |
|
25 | 25 |
import java.io.File; |
26 |
import java.io.FileInputStream; |
|
27 | 26 |
import java.io.IOException; |
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Iterator; |
|
30 |
import java.util.Vector; |
|
31 | 27 |
|
32 |
import org.apache.commons.lang3.StringUtils; |
|
33 | 28 |
import org.gdal.gdal.Driver; |
34 |
import org.gdal.gdal.gdal; |
|
35 | 29 |
import org.gdal.gdalconst.gdalconstConstants; |
36 |
import org.slf4j.Logger; |
|
37 |
import org.slf4j.LoggerFactory; |
|
38 |
|
|
39 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
40 | 30 |
import org.gvsig.fmap.dal.DataStoreParameters; |
41 | 31 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
42 | 32 |
import org.gvsig.fmap.dal.exception.CreateException; |
43 | 33 |
import org.gvsig.fmap.dal.exception.DataException; |
44 | 34 |
import org.gvsig.fmap.dal.exception.FileNotFoundException; |
35 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
45 | 36 |
import org.gvsig.fmap.dal.exception.RemoveException; |
46 | 37 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
47 | 38 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
48 | 39 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider; |
40 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemProviderServices; |
|
49 | 41 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider; |
50 | 42 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
43 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
|
44 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
|
45 |
import org.slf4j.Logger; |
|
46 |
import org.slf4j.LoggerFactory; |
|
51 | 47 |
|
52 | 48 |
/** |
53 | 49 |
* Filesystem Provider for Raster GDAL. |
... | ... | |
59 | 55 |
|
60 | 56 |
private static final Logger logger = LoggerFactory.getLogger(RasterGdalFileSystemServerProvider.class); |
61 | 57 |
protected FilesystemServerExplorerProviderServices serverExplorer; |
62 |
private ArrayList<String> acceptedExtensions; |
|
58 |
private RasterGdalFileSystemServerProviderFactory factory; |
|
59 |
//private ArrayList<String> acceptedExtensions; |
|
63 | 60 |
|
61 |
RasterGdalFileSystemServerProvider (RasterGdalFileSystemServerProviderFactory factory){ |
|
62 |
this.factory=factory; |
|
63 |
} |
|
64 |
|
|
64 | 65 |
public int getMode() { |
65 |
return DataServerExplorer.MODE_RASTER;
|
|
66 |
return factory.getMode();
|
|
66 | 67 |
} |
67 | 68 |
|
68 | 69 |
@Override |
69 | 70 |
public boolean canCreate() { |
70 |
return false;
|
|
71 |
return factory.allowCreate()==FilesystemProviderServices.YES;
|
|
71 | 72 |
} |
72 | 73 |
|
73 | 74 |
@Override |
74 |
public boolean canCreate(NewDataStoreParameters arg0) { |
|
75 |
public boolean canCreate(NewDataStoreParameters newDataStoreParameters) { |
|
76 |
if (canCreate()){ |
|
77 |
if (newDataStoreParameters instanceof NewRasterGdalStoreParameters){ |
|
78 |
if ( newDataStoreParameters.isValid() ){ |
|
79 |
Driver gdalDriver=factory.getProviderFactory().getDriver(); |
|
80 |
|
|
81 |
Buffer buffer=((NewRasterGdalStoreParameters)newDataStoreParameters).getBuffer(); |
|
82 |
String creationTypes=(String)gdalDriver.GetMetadata_Dict().get(gdalconstConstants.GDAL_DMD_CREATIONDATATYPES); |
|
83 |
if (creationTypes == null || (creationTypes!=null && creationTypes.contains(getBufferGDALDataType(buffer)))){ |
|
84 |
return true; |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
} |
|
75 | 89 |
return false; |
76 | 90 |
} |
77 | 91 |
|
92 |
private String getBufferGDALDataType(Buffer buffer){ |
|
93 |
int[] bufferTypes=buffer.getBandTypes(); |
|
94 |
int type=BufferManager.TYPE_UNDEFINED; |
|
95 |
for (int i = 0; i < bufferTypes.length; i++) { |
|
96 |
if(type==BufferManager.TYPE_UNDEFINED){ |
|
97 |
type = bufferTypes[i]; |
|
98 |
} else if(type != bufferTypes[i]){ |
|
99 |
type = BufferManager.TYPE_UNDEFINED; |
|
100 |
break; |
|
101 |
} |
|
102 |
} |
|
103 |
//Byte UInt16 Int16 UInt32 Int32 Float32 Float64 CInt16 CInt32 CFloat32 CFloat64 |
|
104 |
switch (type) { |
|
105 |
case BufferManager.TYPE_BYTE: |
|
106 |
return "Byte"; |
|
107 |
|
|
108 |
case BufferManager.TYPE_SHORT: |
|
109 |
return "Int16"; |
|
110 |
|
|
111 |
case BufferManager.TYPE_USHORT: |
|
112 |
return "UInt16"; // OJO |
|
113 |
|
|
114 |
case BufferManager.TYPE_INT: |
|
115 |
return "Int32"; |
|
116 |
|
|
117 |
case BufferManager.TYPE_FLOAT: |
|
118 |
return "Float32"; |
|
119 |
|
|
120 |
case BufferManager.TYPE_DOUBLE: |
|
121 |
return "Float64"; |
|
122 |
|
|
123 |
default: |
|
124 |
return "Unsupported"; |
|
125 |
} |
|
126 |
|
|
127 |
} |
|
128 |
|
|
78 | 129 |
@Override |
79 |
public void create(NewDataStoreParameters arg0, boolean arg1)
|
|
130 |
public void create(NewDataStoreParameters params, boolean overwrite)
|
|
80 | 131 |
throws CreateException { |
81 |
//TODO: Parece que el antiguo raster si que lo soporta para geoprocesos. Ver como lo hace |
|
82 |
throw new UnsupportedOperationException(); |
|
83 |
|
|
132 |
if ( !canCreate(params) ){ |
|
133 |
throw new CreateException(params.getDataStoreName(), new IllegalArgumentException()); |
|
134 |
} |
|
135 |
if (params instanceof NewRasterGdalStoreParameters){ |
|
136 |
RasterGdalStoreProviderFactory providerFactory = factory.getProviderFactory(); |
|
137 |
AbstractFileRasterGdalStoreProvider provider; |
|
138 |
try { |
|
139 |
provider = (AbstractFileRasterGdalStoreProvider) providerFactory.createProvider(params); |
|
140 |
} catch (InitializeException e) { |
|
141 |
throw new CreateException(params.getDataStoreName(), e); |
|
142 |
} |
|
143 |
provider.store(overwrite); |
|
144 |
} |
|
84 | 145 |
} |
85 | 146 |
|
86 | 147 |
@Override |
87 | 148 |
public NewDataStoreParameters getCreateParameters() throws DataException { |
88 |
//TODO: Parece que el antiguo raster si que lo soporta para geoprocesos. Ver como lo hace |
|
89 |
throw new UnsupportedOperationException(); |
|
149 |
return new NewRasterGdalStoreParameters(factory.getNewParamsDefinitionName(), factory.getName()); |
|
90 | 150 |
} |
91 | 151 |
|
92 | 152 |
@Override |
93 | 153 |
public void initialize(FilesystemServerExplorerProviderServices serverExplorer) { |
94 | 154 |
this.serverExplorer = serverExplorer; |
95 |
this.acceptedExtensions=new ArrayList<>(); |
|
96 |
for (int i=0;i<gdal.GetDriverCount(); i++){ |
|
97 |
Driver drv = gdal.GetDriver(i); |
|
98 |
String extension=drv.GetMetadataItem(gdalconstConstants.GDAL_DMD_EXTENSION); |
|
99 |
if (StringUtils.isNotEmpty(extension)){ |
|
100 |
acceptedExtensions.add(extension); |
|
101 |
} |
|
102 |
} |
|
103 | 155 |
} |
104 | 156 |
|
105 | 157 |
@Override |
106 | 158 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
107 |
RasterGdalStoreProviderParameters params = (RasterGdalStoreProviderParameters) parameters;
|
|
159 |
RasterGdalFileStoreParameters params = (RasterGdalFileStoreParameters) parameters;
|
|
108 | 160 |
File file = params.getFile(); |
109 | 161 |
if (!file.exists()) { |
110 | 162 |
throw new RemoveException(this.getDataStoreProviderName(), |
... | ... | |
119 | 171 |
|
120 | 172 |
@Override |
121 | 173 |
public String getDataStoreProviderName() { |
122 |
return RasterGdalStoreProvider.NAME;
|
|
174 |
return factory.getName();
|
|
123 | 175 |
} |
124 | 176 |
|
125 | 177 |
@Override |
126 | 178 |
public String getDescription() { |
127 |
return RasterGdalStoreProvider.DESCRIPTION;
|
|
179 |
return factory.getDescription();
|
|
128 | 180 |
} |
129 | 181 |
|
130 | 182 |
@Override |
131 | 183 |
public boolean accept(File pathname) { |
132 |
return gdal.IdentifyDriver(pathname.getAbsolutePath())!=null;
|
|
184 |
return factory.accept(pathname);
|
|
133 | 185 |
} |
134 | 186 |
|
135 | 187 |
@Override |
Also available in: Unified diff