[Gvsig_desarrolladores] cargando capas raster para una vista modificada
Romel Vazquez
romelvazquez en gmail.com
Jue Dic 9 17:30:32 CET 2010
*Hola lista. Estoy teniendo un problema para cargar mapas raster en una
vista modificada, en el siguiente código les marco en rojo como lo hacía con
capas vectoriales, he intentado modificarlo para que me sirva con mapas
raster y no me encuentra el driver. Vean como lo estoy tratando de hacer en
la 2da clase. Cuando cargo los mapas por la opción normal de gvSIG si se me
ponen en el TOC. Se me hace muy complicado explicarlo todo porque hay
muchas mas cosas, espero que alguien me diga posibles causas, o como debería
hacerlo. *
package
org.gvsig.scientificvisualization.coordinatedVisualization.extensions.addProject;
import java.awt.Component;
import java.io.File;
import javax.swing.JOptionPane;
import org.cresques.cts.ICoordTrans;
import org.cresques.cts.IProjection;
import com.hardcode.driverManager.Driver;
import com.hardcode.driverManager.DriverLoadException;
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
import com.iver.andami.PluginServices;
import com.iver.cit.gvsig.AddLayer;
import com.iver.cit.gvsig.fmap.MapControl;
import com.iver.cit.gvsig.fmap.ViewPort;
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
import com.iver.cit.gvsig.fmap.layers.CancelationException;
import com.iver.cit.gvsig.fmap.layers.FLayer;
import com.iver.cit.gvsig.fmap.layers.FLayers;
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter;
public class MyAddLayer {
/**
* @uml.property name="driverName"
*/
private String driverName = "gvSIG shp driver";
/**
* @uml.property name="proj"
* @uml.associationEnd multiplicity="(1 1)"
*/
private IProjection proj;
/**
* @uml.property name="flag"
*/
private boolean flag = false;
/**
* Proyeccion que utilizare por defecto. es la misma que trae
por defecto el gvSIG.
* @uml.property name="projection"
*/
private String projection = "EPSG:23030";
public MyAddLayer(){
//proj = CRSFactory.getCRS(projection);
}
/**
* Anadir una capa a al MapControl.
* */
public void addLayer(MapControl mapControl, File file)throws
DriverLoadException,ReadDriverException{
FLayer lyr = null;
Driver driver = null;
proj = mapControl.getProjection();
driver = LayerFactory.getDM().getDriver(driverName);
String layerName = file.getName();
if (driver instanceof VectorialFileDriver) {
lyr = LayerFactory.createLayer(layerName,
(VectorialFileDriver) driver, file, proj);
}
if( (lyr != null) && !(lyr.isOk()) )
processErrorsOfLayer(lyr, mapControl);
if (lyr != null) {
lyr.setVisible(true);
mapControl.getMapContext().beginAtomicEvent();
AddLayer.checkProjection(lyr,
mapControl.getViewPort());
try {
mapControl.getMapContext().getLayers().addLayer(lyr);
} catch (CancelationException e)
{e.printStackTrace();}
mapControl.getMapContext().endAtomicEvent();
if(!flag){
mapControl.getMapContext().getViewPort().setExtent(lyr.getFullExtent());
flag = true;
}
}
}
/**Procesamiento de los errores de las capas.*/
private void processErrorsOfLayer(FLayer lyr, MapControl
mapControl){
mapControl.getMapContext().callNewErrorEvent(null);
}
}
package
org.gvsig.scientificvisualization.coordinatedVisualization.extensions.addProject;
import java.awt.Component;
import java.io.File;
import javax.swing.JOptionPane;
import org.cresques.cts.ICoordTrans;
import org.cresques.cts.IProjection;
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
import com.hardcode.driverManager.Driver;
import com.hardcode.driverManager.DriverLoadException;
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
import com.iver.andami.PluginServices;
import com.iver.cit.gvsig.AddLayer;
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
import com.iver.cit.gvsig.fmap.MapControl;
import com.iver.cit.gvsig.fmap.ViewPort;
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
import com.iver.cit.gvsig.fmap.layers.CancelationException;
import com.iver.cit.gvsig.fmap.layers.FLayer;
import com.iver.cit.gvsig.fmap.layers.FLayers;
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter;
import com.iver.cit.gvsig.fmap.drivers.raster.*;;
public class MyAddLayerRaster {
/**
* @uml.property name="driverName"
*/
private String driverName = "gvSIG Raster Driver";
/**
* @uml.property name="proj"
* @uml.associationEnd multiplicity="(1 1)"
*/
private IProjection proj;
/**
* @uml.property name="flag"
*/
private boolean flag = false;
/**
* Proyeccion que utilizare por defecto. es la misma que trae
por defecto el gvSIG.
* @uml.property name="projection"
*/
private String projection = "EPSG:23030";
public MyAddLayerRaster(){
//proj = CRSFactory.getCRS(projection);
}
/**
* Anadir una capa a al MapControl.
* */
public void addLayer(MapControl mapControl, File file)throws
DriverLoadException,ReadDriverException{
FLayer lyr = null;
proj = mapControl.getProjection();
// driver = LayerFactory.getDM().getDriver(driverName);
String layerName = file.getName();
try {
//FLyrRasterSE r=new
FLyrRasterSE();
lyr =
LayerFactory.createLayer(layerName,"gvSIG raster driver", file, proj);
} catch (LoadLayerException e) {
// TODO Auto-generated catch
block
e.printStackTrace();
}
if( (lyr != null) && !(lyr.isOk()) )
processErrorsOfLayer(lyr, mapControl);
if (lyr != null) {
lyr.setVisible(true);
mapControl.getMapContext().beginAtomicEvent();
AddLayer.checkProjection(lyr,
mapControl.getViewPort());
try {
mapControl.getMapContext().getLayers().addLayer(lyr);
} catch (CancelationException e)
{e.printStackTrace();}
mapControl.getMapContext().endAtomicEvent();
if(!flag){
mapControl.getMapContext().getViewPort().setExtent(lyr.getFullExtent());
flag = true;
}
}
}
/**Procesamiento de los errores de las capas.*/
private void processErrorsOfLayer(FLayer lyr, MapControl
mapControl){
mapControl.getMapContext().callNewErrorEvent(null);
}
}
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: http://listserv.gva.es/pipermail/gvsig_desarrolladores/attachments/20101209/0622b614/attachment.htm
Más información sobre la lista de distribución gvSIG_desarrolladores