55 |
55 |
import org.gvsig.raster.reproject.app.preparelayer.ReprojectionQueue;
|
56 |
56 |
import org.gvsig.raster.swing.RasterSwingLibrary;
|
57 |
57 |
import org.gvsig.tools.exception.BaseException;
|
|
58 |
import org.slf4j.Logger;
|
|
59 |
import org.slf4j.LoggerFactory;
|
58 |
60 |
|
59 |
61 |
public class PrepareLayerAskProjection implements PrepareDataStoreParameters, PrepareLayer, IProcessActions {
|
60 |
62 |
protected CRSUtils crsUtil = RasterLocator.getManager().getCRSUtils();
|
61 |
63 |
private boolean changeReprojectionOption = true;
|
62 |
64 |
private int lastReprojectionOption = RasterDataParameters.NEW_PROJETION_TO_THE_LAYER;
|
63 |
65 |
private ReprojectionQueue queue = ReprojectionQueue.getSingleton();
|
|
66 |
private Logger log = LoggerFactory.getLogger(PrepareLayerAskProjection.class);
|
64 |
67 |
|
65 |
68 |
@SuppressWarnings("deprecation")
|
66 |
69 |
public DataStoreParameters prepare(DataStoreParameters storeParameters,
|
... | ... | |
177 |
180 |
int repOption = params.getReprojectionOption();
|
178 |
181 |
|
179 |
182 |
if(repOption == RasterDataParameters.REPROJECT_DATA) {
|
180 |
|
try {
|
181 |
|
IProjection srcProj = readProjection(lyrRaster.getDataStore());
|
182 |
|
if(srcProj == null)
|
183 |
|
return null;
|
|
183 |
IProjection srcProj = readProjection(lyrRaster.getDataStore());
|
|
184 |
if(srcProj == null)
|
|
185 |
return null;
|
184 |
186 |
|
185 |
|
String uri = params.getURI();
|
186 |
|
uri = uri.substring(0, uri.lastIndexOf(".")) + "_" + dstProj.getAbrev() + uri.substring(uri.lastIndexOf("."));
|
187 |
|
uri = uri.replace(':', '_');
|
|
187 |
String uri = params.getURI();
|
|
188 |
uri = uri.substring(0, uri.lastIndexOf(".")) + "_" + dstProj.getAbrev() + uri.substring(uri.lastIndexOf("."));
|
|
189 |
uri = uri.replace(':', '_');
|
188 |
190 |
|
189 |
|
if(!new File(uri).exists()) {
|
190 |
|
DataProcess process = null;
|
191 |
|
try {
|
192 |
|
process = RasterBaseAlgorithmLibrary.getManager().createRasterTask("RasterReprojectionProcess");
|
193 |
|
} catch (ProcessException e1) {
|
194 |
|
RasterSwingLibrary.messageBoxError("error_creating_algorithm", null, e1);
|
195 |
|
return params;
|
196 |
|
}
|
197 |
|
process.setActions(this);
|
198 |
|
process.addParam(ReprojectProcess.RASTER_STORE, lyrRaster.getDataStore());
|
199 |
|
process.addParam(ReprojectProcess.SIZEX, 0); //Calculo autom?tico de tama?o
|
200 |
|
process.addParam(ReprojectProcess.SIZEY, 0);
|
201 |
|
process.addParam(ReprojectProcess.PATH, uri);
|
202 |
|
process.addParam(ReprojectProcess.SRC_PROJECTION, srcProj);
|
203 |
|
process.addParam(ReprojectProcess.DST_PROJECTION, dstProj);
|
204 |
|
process.addParam(ReprojectProcess.CELLSIZE, lyrRaster.getDataStore().getCellSize());
|
|
191 |
if(!new File(uri).exists()) {
|
|
192 |
DataProcess process = null;
|
|
193 |
try {
|
|
194 |
process = RasterBaseAlgorithmLibrary.getManager().createRasterTask("RasterReprojectionProcess");
|
|
195 |
} catch (ProcessException e1) {
|
|
196 |
RasterSwingLibrary.messageBoxError("error_creating_algorithm", null, e1);
|
|
197 |
return params;
|
|
198 |
}
|
|
199 |
process.setActions(this);
|
|
200 |
process.addParam(ReprojectProcess.RASTER_STORE, lyrRaster.getDataStore());
|
|
201 |
process.addParam(ReprojectProcess.SIZEX, 0); //Calculo autom?tico de tama?o
|
|
202 |
process.addParam(ReprojectProcess.SIZEY, 0);
|
|
203 |
process.addParam(ReprojectProcess.PATH, uri);
|
|
204 |
process.addParam(ReprojectProcess.SRC_PROJECTION, srcProj);
|
|
205 |
process.addParam(ReprojectProcess.DST_PROJECTION, dstProj);
|
|
206 |
process.addParam(ReprojectProcess.CELLSIZE, lyrRaster.getDataStore().getCellSize());
|
205 |
207 |
|
206 |
|
//Despierta la cola que reproyecta im?genes
|
207 |
|
synchronized (queue) {
|
208 |
|
queue.add(process, this);
|
209 |
|
queue.notify();
|
|
208 |
//Despierta la cola que reproyecta im?genes
|
|
209 |
synchronized (queue) {
|
|
210 |
queue.add(process, this);
|
|
211 |
queue.notify();
|
|
212 |
}
|
|
213 |
|
|
214 |
//Se suspende hasta que la cola haya terminado
|
|
215 |
try {
|
|
216 |
synchronized (this) {
|
|
217 |
this.wait();
|
210 |
218 |
}
|
|
219 |
} catch (InterruptedException e) {
|
|
220 |
}
|
211 |
221 |
|
212 |
|
//Se suspende hasta que la cola haya terminado
|
213 |
|
try {
|
214 |
|
synchronized (this) {
|
215 |
|
this.wait();
|
216 |
|
}
|
217 |
|
} catch (InterruptedException e) {
|
218 |
|
}
|
219 |
|
|
220 |
|
if(process.getResult() != null) {
|
221 |
|
HashMap<String, Object> map = (HashMap<String, Object>)process.getResult();
|
222 |
|
String filename = (String)map.get(ReprojectProcess.FILENAME);
|
223 |
|
params.setURI(filename);
|
224 |
|
return params;
|
225 |
|
}
|
226 |
|
} else {
|
227 |
|
params.setURI(uri);
|
|
222 |
if(process.getResult() != null) {
|
|
223 |
HashMap<String, Object> map = (HashMap<String, Object>)process.getResult();
|
|
224 |
String filename = (String)map.get(ReprojectProcess.FILENAME);
|
|
225 |
params.setURI(filename);
|
228 |
226 |
return params;
|
229 |
227 |
}
|
230 |
|
|
231 |
|
} catch (RasterDriverException e) {
|
232 |
|
RasterSwingLibrary.messageBoxError("Error creating layer", null, e);
|
233 |
|
}
|
|
228 |
} else {
|
|
229 |
params.setURI(uri);
|
|
230 |
return params;
|
|
231 |
}
|
|
232 |
|
234 |
233 |
} else if(repOption == RasterDataParameters.REPROJECT_VIEW) {
|
235 |
234 |
//Esto se cambia en el prepare que tiene acceso al mapcontrol. Este prepare es a nivel de datos
|
236 |
235 |
}
|
... | ... | |
278 |
277 |
* @throws RasterDriverException
|
279 |
278 |
*/
|
280 |
279 |
@SuppressWarnings("deprecation")
|
281 |
|
private IProjection readProjection(RasterDataStore dataStore) throws RasterDriverException {
|
|
280 |
private IProjection readProjection(RasterDataStore dataStore) {
|
282 |
281 |
try {
|
283 |
282 |
crsUtil.setCRSFactory(CRSFactory.cp);
|
284 |
283 |
if( dataStore == null )
|
285 |
284 |
return null;
|
286 |
285 |
return crsUtil.convertWktToIProjection(dataStore.getWktProjection());
|
287 |
286 |
} catch (Exception e) {
|
288 |
|
throw new RasterDriverException("Problems converting from WKT to IProjection", e);
|
|
287 |
//Si ha habido alg?n problema con la conversi?n metemos un log y que devuelva null
|
|
288 |
log.info("Problems converting from WKT to IProjection", e);
|
289 |
289 |
} catch (Error e) {
|
290 |
|
e.printStackTrace();
|
291 |
|
return null;
|
|
290 |
log.info("Problems converting from WKT to IProjection", e);
|
292 |
291 |
}
|
|
292 |
return null;
|
293 |
293 |
}
|
294 |
294 |
|
295 |
295 |
public String getDescription() {
|