Revision 938 org.gvsig.raster.postgis/trunk/org.gvsig.raster.postgis/org.gvsig.raster.postgis.io/src/main/java/org/gvsig/raster/postgis/io/PostGISRasterProvider.java
PostGISRasterProvider.java | ||
---|---|---|
22 | 22 |
package org.gvsig.raster.postgis.io; |
23 | 23 |
|
24 | 24 |
import java.awt.geom.AffineTransform; |
25 |
import java.awt.geom.Point2D; |
|
26 |
import java.awt.geom.Rectangle2D; |
|
25 | 27 |
import java.util.ArrayList; |
26 | 28 |
import java.util.Collections; |
27 | 29 |
import java.util.Iterator; |
... | ... | |
30 | 32 |
import org.gvsig.fmap.dal.DALLocator; |
31 | 33 |
import org.gvsig.fmap.dal.DataStore; |
32 | 34 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
35 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
36 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
|
37 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
33 | 38 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
39 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
40 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
34 | 41 |
import org.gvsig.fmap.dal.exception.DataException; |
35 | 42 |
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer; |
36 | 43 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
... | ... | |
38 | 45 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
39 | 46 |
import org.gvsig.jgdal.GdalException; |
40 | 47 |
import org.gvsig.metadata.MetadataLocator; |
48 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
|
41 | 49 |
import org.gvsig.raster.gdal.io.GdalNative; |
42 | 50 |
import org.gvsig.raster.gdal.io.GdalProvider; |
51 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
|
43 | 52 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
44 | 53 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
45 | 54 |
import org.gvsig.tools.ToolsLocator; |
... | ... | |
50 | 59 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
51 | 60 |
*/ |
52 | 61 |
public class PostGISRasterProvider extends GdalProvider { |
53 |
public static String NAME = "PostGIS Raster Store"; |
|
54 |
public static String DESCRIPTION = "PostGIS Raster file"; |
|
55 |
public static final String METADATA_DEFINITION_NAME = "PostGISRasterStore"; |
|
56 |
private DBServerExplorer dbServerExplorer = null; |
|
57 |
private DBStoreParameters dbParameters = null; |
|
58 |
private ArrayList<Overview> overviews = new ArrayList<Overview>(); |
|
62 |
public static String NAME = "PostGIS Raster Store"; |
|
63 |
public static String DESCRIPTION = "PostGIS Raster file"; |
|
64 |
public static final String METADATA_DEFINITION_NAME = "PostGISRasterStore"; |
|
65 |
private static final String OVERVIEW_PREFIX = "o_"; |
|
59 | 66 |
|
67 |
private DBServerExplorer dbServerExplorer = null; |
|
68 |
private DBStoreParameters dbParameters = null; |
|
69 |
private ArrayList<Overview> overviews = new ArrayList<Overview>(); |
|
70 |
|
|
60 | 71 |
class Overview implements Comparable<Overview> { |
61 |
public int width = 0; |
|
62 |
public int height = 0; |
|
63 |
public int factor = 0; |
|
64 |
public DBStoreParameters param = null; |
|
72 |
public int width = 0; |
|
73 |
public int height = 0; |
|
74 |
public int factor = 0; |
|
75 |
public double pxSizeOverview = 0; |
|
76 |
public DBStoreParameters param = null; |
|
65 | 77 |
|
78 |
public Overview() { |
|
79 |
|
|
80 |
} |
|
81 |
|
|
82 |
public Overview(int f, int w, int h, DBStoreParameters p) { |
|
83 |
this.width = w; |
|
84 |
this.height = h; |
|
85 |
this.factor = f; |
|
86 |
this.param = p; |
|
87 |
this.pxSizeOverview = getExtent().width() / (double)w; |
|
88 |
} |
|
89 |
|
|
66 | 90 |
public int compareTo(Overview o) { |
67 | 91 |
if(factor < o.factor) |
68 | 92 |
return -1; |
... | ... | |
91 | 115 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
92 | 116 |
} |
93 | 117 |
|
118 |
public PostGISRasterProvider() { |
|
119 |
|
|
120 |
} |
|
121 |
|
|
94 | 122 |
public PostGISRasterProvider (PostGISRasterDataParameters params, |
95 | 123 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException { |
96 | 124 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
... | ... | |
131 | 159 |
setDataType(dt); |
132 | 160 |
|
133 | 161 |
PostGISRasterDataParameters p = (PostGISRasterDataParameters)params; |
134 |
dbParameters = (DBStoreParameters)p.getDBStoreParameters(); |
|
135 |
dbServerExplorer = p.getDBExplorer(); |
|
162 |
//Object obj = p.getDynValue(PostGISRasterDataParameters.FIELD_DBPARAMS); |
|
163 |
dbParameters = (DBStoreParameters)p.getDynValue(PostGISRasterDataParameters.FIELD_DBPARAMS); |
|
164 |
dbServerExplorer = (DBServerExplorer)p.getDynValue(PostGISRasterDataParameters.FIELD_DBEXPLORER); |
|
136 | 165 |
try { |
137 | 166 |
readOverviews(); |
138 | 167 |
} catch (DataException e) { |
... | ... | |
140 | 169 |
} |
141 | 170 |
} |
142 | 171 |
|
172 |
/** |
|
173 |
* Reads overviews from database. The overviews in PostGIS raster are loaded |
|
174 |
* in separated tables. The name of those tables is the same that the original table |
|
175 |
* with a overview prefix. Now this prefix is "o_X_" where the X is a factor scale. |
|
176 |
* |
|
177 |
* For that reason the overview object contains the DataParameter which correspond |
|
178 |
* to each table. |
|
179 |
* |
|
180 |
* @throws DataException |
|
181 |
*/ |
|
143 | 182 |
private void readOverviews() throws DataException { |
183 |
overviews.clear(); |
|
184 |
overviews.add(new Overview(1, (int)getWidth(), (int)getHeight(), (DBStoreParameters)param)); |
|
185 |
|
|
144 | 186 |
String table = dbParameters.getTable(); |
145 | 187 |
List parameters = dbServerExplorer.list(); |
146 | 188 |
|
... | ... | |
149 | 191 |
while (iter.hasNext()) { |
150 | 192 |
DBStoreParameters p = (DBStoreParameters) iter.next(); |
151 | 193 |
String tname = p.getTable(); |
152 |
if(tname.endsWith(table) && tname.startsWith("o_")) {
|
|
194 |
if(tname.endsWith(table) && tname.startsWith(OVERVIEW_PREFIX)) {
|
|
153 | 195 |
String factor = tname.substring(tname.indexOf('_') + 1); |
154 |
factor = tname.substring(0, tname.indexOf('_'));
|
|
196 |
factor = factor.substring(0, factor.indexOf('_'));
|
|
155 | 197 |
try { |
156 | 198 |
Overview o = new Overview(); |
157 | 199 |
o.factor = new Integer(factor); |
158 | 200 |
o.width = (int)(getWidth() / o.factor); |
159 | 201 |
o.height = (int)(getHeight() / o.factor); |
202 |
o.pxSizeOverview = getExtent().width() / (double)o.width; |
|
160 | 203 |
o.param = p; |
161 | 204 |
overviews.add(o); |
162 | 205 |
} catch (NumberFormatException e) { |
... | ... | |
165 | 208 |
} |
166 | 209 |
Collections.sort(overviews); |
167 | 210 |
} |
211 |
|
|
212 |
/** |
|
213 |
* Selects the right overview. The right overview means the first |
|
214 |
* one with a pixel size lesser or equals than the original. |
|
215 |
* @param pixels |
|
216 |
* @param mts |
|
217 |
*/ |
|
218 |
private void overviewSelector(int pixels, double mts) { |
|
219 |
this.param = overviews.get(0).param; |
|
220 |
double pxSizeRequest = mts / (double)pixels; |
|
221 |
for (int i = overviews.size() - 1; i > 0; i--) { |
|
222 |
Overview ovb = overviews.get(i); |
|
223 |
if(pxSizeRequest <= ovb.pxSizeOverview) { |
|
224 |
this.param = ovb.param; |
|
225 |
} |
|
226 |
} |
|
227 |
|
|
228 |
} |
|
229 |
|
|
230 |
/* |
|
231 |
* (non-Javadoc) |
|
232 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener) |
|
233 |
*/ |
|
234 |
public void getWindow(Extent ex, int bufWidth, int bufHeight, |
|
235 |
BandList bandList, TileListener listener) throws ProcessInterruptedException, RasterDriverException { |
|
236 |
super.getWindow(ex, bufWidth, bufHeight, bandList, listener); |
|
237 |
} |
|
168 | 238 |
|
239 |
/* |
|
240 |
* (non-Javadoc) |
|
241 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer) |
|
242 |
*/ |
|
243 |
public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf) |
|
244 |
throws ProcessInterruptedException, RasterDriverException { |
|
245 |
return super.getWindow(ex, bandList, rasterBuf); |
|
246 |
} |
|
247 |
|
|
248 |
/* |
|
249 |
* (non-Javadoc) |
|
250 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean) |
|
251 |
*/ |
|
252 |
public Buffer getWindow(double ulx, double uly, double w, double h, |
|
253 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException { |
|
254 |
return super.getWindow(ulx, uly, w, h, bandList, rasterBuf, adjustToExtent); |
|
255 |
} |
|
256 |
|
|
257 |
/* |
|
258 |
* (non-Javadoc) |
|
259 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean) |
|
260 |
*/ |
|
261 |
public Buffer getWindow(Extent extent, |
|
262 |
int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException { |
|
263 |
return super.getWindow(extent, bufWidth, bufHeight, bandList, rasterBuf, adjustToExtent); |
|
264 |
} |
|
265 |
|
|
266 |
/* |
|
267 |
* (non-Javadoc) |
|
268 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer) |
|
269 |
*/ |
|
270 |
public Buffer getWindow(int x, int y, |
|
271 |
BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException { |
|
272 |
return super.getWindow(x, y, bandList, rasterBuf); |
|
273 |
} |
|
274 |
|
|
275 |
/* |
|
276 |
* (non-Javadoc) |
|
277 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer) |
|
278 |
*/ |
|
279 |
public Buffer getWindow(int x, int y, int w, int h, |
|
280 |
int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException { |
|
281 |
return super.getWindow(x, y, w, h, bufWidth, bufHeight, bandList, rasterBuf); |
|
282 |
} |
|
283 |
|
|
284 |
|
|
169 | 285 |
} |
Also available in: Unified diff