set attribute value to a selected element

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

set attribute value to a selected element

Giovanni Virdis

Hi,

 

How i can get a selected item of editable layer. I want , if is possible set a attribute of the selected geometry

 This is my code

 

Layerable[] selectedLayers = (Layerable[]) (getWorkbench().getContext().getLayerNamePanel()).selectedNodes(Layerable.class).toArray(new Layerable[]{});

Layer player = (Layer)  selectedLayers[0];

FeatureCollectionWrapper FeatureColl = player.getFeatureCollectionWrapper();        

FeatureIterator itFeats = null;

try

{

//Prendo l'iteratore

  itFeats = FeatureColl.iterator();

//Scorro l'iteratore

  while(itFeats.hasNext())

  {

  //Prendo la feature

    Feature element = itFeats.next();

  //Imposto il valor per il campo ID_BENE

    element.setAttribute("link_scheda","C:\\PPC\\Schede_compilate\\Censimento_MaterialiMezzi_el1.pdf");

    featuresModificate.add(element);           

  }

}

 

My code set the attribute “link_scheda” for all element (geometry) in selected layer I want set the attribute only for the selected layer

 

Thanks

 

 


_______________________________________________
Kosmo_int mailing list
[hidden email]
http://lists.saig.es/mailman/listinfo/kosmo_int
Reply | Threaded
Open this post in threaded view
|

Re: set attribute value to a selected element

Sergio Baños Calvo
Good morning Giovanni.

The code that you have sent is ok for setting the attribute value for
all the layer features. If you want to change the value for only the
selected ones, try the next:

SelectionManager selectionManager =
context.getLayerViewPanel().getSelectionManager();

// In order to get the tree selected one (the first of them)
Layerable[] layers = context.getLayerNamePanel().getSelectedLayers();
Layer pLayer = (Layer) selectedLayers[0];

// In order to get the editable layer
Layer editableLayer = (Layer)
context.getLayerManager().getEditableLayers().iterator()
.next();

// Iterate over the selected features, the layer must be editable in
order to perform changes
Collection selectedFeatures =
selectionManager.getFeaturesWithSelectedItems(editableLayer);

for(Iterator itFeats = selectedFeatures.iterator; itFeats.hasNext())
{
Feature currentFeat = itFeats.next();

// Change here the attributes
.....
}

// Update the features at the layer
selectionManager.unselectItems(editableLayer,
selectedFeatures);
layer.getFeatureCollectionWrapper().update(selectedFeatures);
selectionManager.getFeatureSelection().selectItems(editableLayer,
selectedFeatures);

Hope this helps.

Regards,

Giovanni Virdis escribió:

>
> Hi,
>
> How i can get a selected item of editable layer. I want , if is
> possible set a attribute of the selected geometry
>
> This is my code
>
> Layerable[] selectedLayers = (Layerable[])
> (getWorkbench().getContext().getLayerNamePanel()).selectedNodes(Layerable.
> * class * ).toArray( * new * Layerable[]{});
>
> Layer player = (Layer) selectedLayers[0];
>
> FeatureCollectionWrapper FeatureColl =
> player.getFeatureCollectionWrapper();
>
> FeatureIterator itFeats = * null * ;
>
> * try *
>
> {
>
> //Prendo l'iteratore
>
> itFeats = FeatureColl.iterator();
>
> //Scorro l'iteratore
>
> while(itFeats.hasNext())
>
> {
>
> //Prendo la feature
>
> Feature element = itFeats.next();
>
> //Imposto il valor per il campo ID_BENE
>
> element.setAttribute( "link_scheda" ,
> "C:\\PPC\\Schede_compilate\\Censimento_MaterialiMezzi_el1.pdf" );
>
> featuresModificate.add(element);
>
> }
>
> }
>
> My code set the attribute “link_scheda” for all element (geometry) in
> selected layer I want set the attribute only for the selected layer
>
> Thanks
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Kosmo_int mailing list
> [hidden email]
> http://lists.saig.es/mailman/listinfo/kosmo_int
>  

--

Sergio Baños Calvo

Jefe de desarrollos
Sistemas Abiertos de Información Geográfica, S.L. (SAIG S.L.)
Tlfno. móvil: 685005960
Tlfno. fijo: (+34) 954788876

E-mail: [hidden email]

_______________________________________________
Kosmo_int mailing list
[hidden email]
http://lists.saig.es/mailman/listinfo/kosmo_int