Hi Luca,

I've not a good understanding of how OpenJUMP transaction work, but if 
you can't recover original geometry with your code, I suspect this is 
because you actually replace the geometry of the first selected feature 
by the unioned geometry before you enter the transaction.
In previous code, the new geometry replace the old one "in" the transaction
edtr.setGeometry(f1.g); // where g is the unioned geometry

I think you have first to union your geometries in a new object (you can 
clone your first geometry or even take one point of it, then union in a 
loop as you did, or even better, use UnaryUnion).

I have also one concern about what to do if attributes are different. 
Wouldn't it be more safe to inform the user that attributes maybe lost. 
Of course, the remark is also right for the current tool.

Michaël

luca marletta a écrit :
> Hi All,
> I did a modification to MergeTowSelectedPolygonsPlugin to works with
> more than two polygon.
> Below the execute to use. It works with geometry union and in my case
> is useful to merge more than 2 polygon
>
> maybe something must be correct for undo because it works but it
> doesn't recovery exactly to original state.
>
> could you someone in development team check it and evalutate if could
> be used to modify the function in oj core code?
>
> thanks
>
> luca
>
>       public boolean execute(PlugInContext context) throws Exception{
>
>               Collection features =
> context.getWorkbenchContext().getLayerViewPanel().getSelectionManager().getFeaturesWithSelectedItems();
>               Feature mergedF = (Feature) ((ArrayList) features).get(0);
>               ArrayList fToDelete = new ArrayList();
>               for (int j = 1 ; j < features.size() ; j++) {
>                       Geometry g = ((Feature) ((ArrayList) 
> features).get(j)).getGeometry();
>                       if (!(g instanceof Polygon)) continue;
>                       
> mergedF.setGeometry((Geometry)mergedF.getGeometry().union (g));
>                       fToDelete.add((Feature) ((ArrayList) features).get(j));
>                       
>               }
>               //-- merge using an edit transaction to enable undo
>               ArrayList fToEdit = new ArrayList();
>               fToEdit.add(mergedF);
>               Map layer2FeatList = LayerTools.getLayer2FeatureMap(fToEdit, 
> context);
>               Layer[] layersWithFeatures =
> (Layer[])layer2FeatList.keySet().toArray(new Layer[0]);
>               EditTransaction edtr = new
> EditTransaction(fToEdit,"setgeom",layersWithFeatures[0],true,false,context.getLayerViewPanel());
>               Geometry g = mergedF.getGeometry();
>               edtr.setGeometry(mergedF,g);
>               edtr.commit();
>               edtr.clearEnvelopeCaches();
>               //-- delete other feature
>               FeatureCollectionTools.deleteFeatures(fToDelete,context);
>               return true;
>       }
>
>
>
> luca marletta
> www.beopen.it
>
> ------------------------------------------------------------------------------
> ThinkGeek and WIRED's GeekDad team up for the Ultimate 
> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
> lucky parental unit.  See the prize list and enter to win: 
> http://p.sf.net/sfu/thinkgeek-promo
> _______________________________________________
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
>
>   


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to