[Gvsig_desarrolladores] Re: FNullGeometry

Alvaro Zabala azabala en gmail.com
Jue Jul 12 19:24:03 CEST 2007


Ultima corrección (cosas de las tardes de verano en visperas de vacaciones
;) )

además de lo indicado en el correo anterior, hay que añadir los siguientes
cambios a MemoryDriver para que todo funcione correctamente;

public long getRowCount() throws DriverException {
  return m_TableModel.getRowCount();
 }

Esto hace que la tabla te muestre el nº correcto de filas alfanuméricas
(antes te incluia la geometria null, ahora no)

public void addGeometry(IGeometry geom, Object[] row) {
  if (geom == null) {
   return; // No añadimos nada
  }
  if(! (geom instanceof FNullGeometry)){
    Rectangle2D boundsShp = geom.getBounds();
    memShapeInfo.addShapeInfo (boundsShp, geom.getGeometryType());
    arrayGeometries.add(geom);
   if (fullExtent == null) {
    fullExtent = boundsShp;
   } else {
    fullExtent.add(boundsShp);
   }

  }
//  Rectangle2D boundsShp = geom.getBounds();
//  memShapeInfo.addShapeInfo(boundsShp, geom.getGeometryType());
//  arrayGeometries.add(geom);
  if (fieldWidth==null) {
   initializeFieldWidth(row);
  }
  actualizeFieldWidth(row);
  m_TableModel.addRow(row);

  try {
   fullExtent = getFullExtent();
  } catch (IOException e) {
   e.printStackTrace();
  }

  m_Position++;
 }


Y aquí un código de ejemplo de uso:

public void execute(String actionCommand) {
  View v = (View) PluginServices.getMDIManager().getActiveWindow();
  MapControl mapCtrl = v.getMapControl();


        // DRIVER DEFINITION (SHAPE TYPE AND FIELDS)
        ConcreteMemoryDriver driver = new ConcreteMemoryDriver();
        driver.setShapeType(FShape.LINE);

  ArrayList arrayFields = new ArrayList();
  arrayFields.add("ID");
  Value[] auxRow = new Value[1];

  driver.getTableModel().setColumnIdentifiers(arrayFields.toArray());


  // GEOMETRY DEFINITION
        GeneralPathX gp = new GeneralPathX();

        gp.moveTo(20,80);
        gp.lineTo(80,60);
        gp.lineTo(100, 140);

        FShape shp = new FPolyline2D(gp);


        // ATRIBUTES
        auxRow[0] = ValueFactory.createValue(0);
        Value[] auxRow2 = new Value[1];
        auxRow2[0] = ValueFactory.createValue(1);
        FNullGeometry nula = new FNullGeometry();

        // ADD RECORD
        driver.addShape(shp, auxRow);
        driver.addGeometry(nula, auxRow2);


        // CREATE AND ADD LAYER
     FLayer lyr;
     String layerName = "Example";
  lyr = LayerFactory.createLayer(layerName,driver, mapCtrl.getProjection());

  if (lyr != null) {
   lyr.setVisible(true);
   mapCtrl.getMapContext().getLayers().addLayer(lyr);

  }


 }


Espero que ya sí funcione todo.

Un saludo.
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: http://runas.cap.gva.es/pipermail/gvsig_desarrolladores/attachments/20070712/1c1d36bb/attachment.htm


Más información sobre la lista de distribución gvSIG_desarrolladores