[Gvsig_desarrolladores] Cosas raras al copiar geomtrias de un shape a otro en la vesión 1.9

Domingo Baeza Domingo.Baeza en blomasa.com
Jue Nov 11 13:09:25 CET 2010


Buenas tardes, vuelvo a hacer la pregunta en el foro correcto.


Tengo un problema con una funcionalidad que necesito que es copiar geometrías de una shapefile a otro shapefile. Para este caso uso el siguiente código.
No puedo cambiar la versión de gvsig, que es la 1.9



            View vista = (View) PluginServices.getMDIManager().getActiveWindow();
            ProjectView model = (ProjectView) vista.getModel();
            MapContext mapa = model.getMapContext();
            MapControl mapCtrl = vista.getMapControl();

            //recorrer la capa activa, para generar la geometria unión de las seleccionadas
            FLayer lActive = vista.getModel().getMapContext().getLayers().getActives()[0];
            VectorialAdapter adapter = (VectorialAdapter) ((SingleLayer) lActive).getSource();
            try {
                  dataSource = adapter.getRecordset();
            } catch (ReadDriverException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            if (lActive instanceof FLyrVect){
                  BitSet sel = ((FLyrVect)lActive).getSelectionSupport().getSelection();
                  for (int i = sel.nextSetBit(0); i >= 0; i = sel.nextSetBit(i+1)) {
                        try {
                             ig = ((FLyrVect)lActive).getSource().getShape(i);
                             Geometry geometriaJts1 = ig.toJTSGeometry();

                             if (union == null){
                                   gTemp =geometriaJts1;
                             }else{
                                   gTemp = EnhancedPrecisionOp.union(geometriaJts1, union);
                             }
                             union = gTemp;
                        } catch (ExpansionFileReadException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        } catch (ReadDriverException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        }
                  }
                  if (union==null){
                        JOptionPane.showMessageDialog(null, "union null");
                  }
                  IGeometry unionGvSig = FConverter.jts_to_igeometry (union);
                  /////
                  FLayer[] selected = mapa.getLayers().getActives();
                  FLayer lyrActive = selected[0];
                  lyrActive.setActive(false);

                  // buscar el indice de la capa
                  for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) {
                        if (mapa.getLayers().getLayer(i).getName().toUpperCase().equals(sCapaDestino)){
                             iIndiceCapa = i;
                        }
                  }
                  //
                  FLayer lyrMont = mapa.getLayers().getLayer(sCapaDestino);
                  try {
                        lyrMont.setActive(true);
                        lyrMont.setEditing(true);
                  } catch (StartEditionLayerException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                  }
                  try {
                        writer =(ShpWriter) LayerFactory.getWM().getWriter("Shape Writer");
                        writer.setFile(new File(fg.obtenerRutaProyecto() +"\\Shapes\\<file:///\\Shapes\>"  + sCapaDestino2));
                        writer.initialize(lyrMont);
                        writer.preProcess();

                        ReadableVectorial rv2=((FLyrVect)lyrMont).getSource();

                        for (int i=0; i < rv2.getShapeCount(); i++)
                        {
                             IFeature feat = rv2.getFeature(i);
                             IRowEdited editFeat = new DefaultRowEdited(feat, IRowEdited.STATUS_MODIFIED, i);
                             writer.process(editFeat);
                        }

                        //Ahora hay que crear la nueva Feature
                        IFeature xx =null;
                        Value[] featureAttr= null;
                        xx = FeatureFactory.createFeature(featureAttr,unionGvSig);
                        DefaultRowEdited edRow;
                        iNumFeat = rv2.getShapeCount();
                        //JOptionPane.showMessageDialog(null, iNumFeat);
                        edRow = new DefaultRowEdited(xx,DefaultRowEdited.STATUS_ADDED, (rv2.getShapeCount()+1));
                        if (edRow == null){
                             JOptionPane.showMessageDialog(null, "edRow null");
                        }

                        writer.process(edRow);
                        writer.postProcess();




Este código funciona, porque veo en la nueva capa la geometría (que en este caso viene de una unión de dos features de otro shape). Pero cuando con el punto de información pido la información de esta nueva geometría no la reconoce.
Sin embargo si edito la capa, no hago ningún cambio, y salvo la capa de nuevo, entonces es cuando vuelvo a pedir información de la nueva feature y ahora si me da la información.

Alguien sabe a que se debe, o que me falta en el código. (Este código está basado en la versión 1.1.2).

Un saludo


Domingo Baeza Díaz
Sale Support Spain
[cid:image001.jpg en 01CB81A1.A9D3D120]
Paseo Arco Ladrillo 90
47006 Valladolid
Phone: +34 983 456048
E-mail:domingo.baeza en blomasa.com
http://www.blomasa.com<Web: http://www.blomasa.com>

------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: http://listserv.gva.es/pipermail/gvsig_desarrolladores/attachments/20101111/be5dfde1/attachment.htm 
------------ próxima parte ------------
Se ha borrado un mensaje que no está en formato texto plano...
Nombre     : image001.jpg
Tipo       : image/jpeg
Tamaño     : 1789 bytes
Descripción: image001.jpg
Url        : http://listserv.gva.es/pipermail/gvsig_desarrolladores/attachments/20101111/be5dfde1/attachment.jpg 


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