Hola,
Lo que hago es cargar una capa por codigo. A esta capa, si le paso el
geoproceso por la interfaz, todo funciona bien. Es cuando lo hago por código
que parece no hacer nada. El código donde intento hacer el geoproceso es:
void execute(String actionCommand) {
public
com.iver.andami.ui.mdiManager.IWindow view =
PluginServices.getMDIManager().getActiveWindow();
//el geoproceso solo se puede usar si estamos en una vista
if(view instanceof View)
{
View vista=(View)view;
//IProjectView model = vista.getModel();
//MapContext mapa = model.getMapContext();
MapControl mapCtrl = vista.getMapControl();
CargadorCapas cargador = new CargadorCapas();
JOptionPane.showMessageDialog(null, "Esto es una vista");
//cargar capa de la bbdd->bien
FLyrVect capa = cargador.cargarTabla("emisiones", 0, mapCtrl, vista);//la capa
en la que leo la bbdd
/*****************************************************/
//copiamos la capa original en otra para aplicarle el geoproceso y le cambiamos
el nombre para diferenciarlas
FLyrVect inputLayer = null;
try{
inputLayer = (FLyrVect)capa.cloneLayer();//(FLyrVect) newLayer("parcelas.shp",
SHP_DRIVER_NAME);
inputLayer.setName("emisionesGB");
//fichero de salida del geoproceso
File outputFile = new File("buffer1275732458594.shp");
//un nuevo geopreceso con la capa que queremos cambiar
BufferGeoprocess geoprocess = new BufferGeoprocess(inputLayer);
//parametros del geoproceso, de BufferTest.java
HashMap params = new HashMap();
//buffer all features (onlySelection = false)
//buffer distance = 10m, buffer type = outside, number of radial polygons = 1
params.put("layer_selection", new Boolean(true));
params.put("dissolve_buffers", new Boolean(false));
params.put("buffer_distance", new Double(1000));
params.put("strategy_flag", new
Byte(BufferGeoprocess.ATTRIBUTE_DISTANCE_STRATEGY));
params.put("numRings", new Integer(3));
params.put("typePolBuffer", new Byte(BufferVisitor.BUFFER_OUTSIDE_POLY));
params.put("cap", new Byte(BufferVisitor.CAP_ROUND));
params.put("projection", PROJECTION_DEFAULT);
params.put("distanceunits", new Integer(100));
params.put("mapunits", new Integer(100));
params.put("attr_name", "cantidadcontaminate");
geoprocess.setParameters(params);
//capa de salida, de BufferTest.java
SHPLayerDefinition definition = (SHPLayerDefinition)
geoprocess.createLayerDefinition();
definition.setFile(outputFile);
ShpSchemaManager schemaManager = new
ShpSchemaManager(outputFile.getAbsolutePath());
IWriter writer = null;
int shapeType = definition.getShapeType();
if(shapeType != XTypes.MULTI){
writer = new ShpWriter();
((ShpWriter) writer).setFile(definition.getFile());
writer.initialize(definition);
}else{
writer = new MultiShpWriter();
((MultiShpWriter) writer).setFile(definition.getFile());
writer.initialize(definition);
}
geoprocess.setResultLayerProperties(writer, schemaManager);
//se comprueba que los parametros están bien
geoprocess.checkPreconditions();
System.out.println("Inicio geoproceso....");
geoprocess.process();
System.out.println("Fin geoproceso");
/*****************************************************/
}catch (Exception e) {
String error = PluginServices.getText(this, "!!!!Error_ejecucion");
String errorDescription = PluginServices.getText(this,
"Error_fallo_geoproceso");
System.out.println(error + ": " + errorDescription);
}
//mostramos las capas
if (inputLayer!= null) {
//pinto la capa del geoproceso
inputLayer.setVisible(true);
vista.getMapControl().getMapContext().beginAtomicEvent();
vista.getMapControl().getMapContext().getLayers().addLayer(inputLayer);
vista.getMapControl().getMapContext().endAtomicEvent();
//pinto la capa original
//capa.setVisible(true);
//vista.getMapControl().getMapContext().beginAtomicEvent();
//vista.getMapControl().getMapContext().getLayers().addLayer(capa);
//vista.getMapControl().getMapContext().endAtomicEvent();
}
}
else
{
JOptionPane.showMessageDialog(null, "Esto no es una vista");
}
}
Pero no se si estoy llamando bien al geoproceso. Puede que lo atributos del
geoprocesso no sean correctos aunque los he estado cambiando a ver que hace y
nunca hace nada. Sin embargo, no da ningun mensaje de error ni excepciones.
Un saludo
_______________________________________________
gvSIG_desarrolladores mailing list
[email protected]
http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores