Hi all,
here 2 simple plugins.
MergeAllGeometryLayersPlugIn
Merge all Polygons for all selected layers into a single MultiPolygon
Quite efficient because use a trick from JTS suggestion create a
createGeometryCollection and perform a buffer(0.0) on it

From3Dto2DPlugIn
Flat a 3D geometry; sometimes it's needed also the 2D :-)


I attach them in java code because is for developers but if you prefer
I'll do jar directly, with souce

luca

luca marletta
www.beopen.it
/* Merge all Polygons for all selected layers into a single MultiPolygon
 * Quite efficient because use a trick from JTS suggestion 
 * create a createGeometryCollection and perform a buffer(0.0) on it
 * @author <a href="mailto:i...@beopen.it">Luca Marletta</a> beOpen
 */
package it.beopen.dbtopo.Tools;

import java.util.List;

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jump.feature.AttributeType;
import com.vividsolutions.jump.feature.BasicFeature;
import com.vividsolutions.jump.feature.Feature;
import com.vividsolutions.jump.feature.FeatureDataset;
import com.vividsolutions.jump.feature.FeatureSchema;
import com.vividsolutions.jump.task.TaskMonitor;
import com.vividsolutions.jump.workbench.model.Layer;
import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
import com.vividsolutions.jump.workbench.plugin.PlugInContext;
import com.vividsolutions.jump.workbench.plugin.ThreadedBasePlugIn;

public class MergeAllGeometryLayersPlugIn extends ThreadedBasePlugIn {
	
	public MergeAllGeometryLayersPlugIn() { }

	public void initialize(PlugInContext context) throws Exception {
		context.getFeatureInstaller().addMainMenuItem( this, new String[] { "DBTopo", "Tools", "Simplify" },
				"Merge all geometry",
				false, null, new MultiEnableCheck()
		.add(context.getCheckFactory().createTaskWindowMustBeActiveCheck())
		.add(context.getCheckFactory().createAtLeastNLayersMustExistCheck(1)) );
	}

	public boolean execute(PlugInContext context) {
		reportNothingToUndoYet(context);
		if (context.getSelectedLayers().length == 0){
			return false;
		}
		return true;
	}

	public void run(TaskMonitor monitor, PlugInContext context) throws Exception {

		FeatureSchema fs = new FeatureSchema();
		fs.addAttribute("GEOMETRY", AttributeType.GEOMETRY);
		FeatureDataset mergedAllLFC = new FeatureDataset(fs);
		Layer[] selectedLayers = context.getSelectedLayers();

		Geometry[] allLayerGeom = new Geometry[selectedLayers.length];

		for (int i = 0; i < selectedLayers.length; i++) {
			List fc = selectedLayers[i].getFeatureCollectionWrapper().getFeatures();
			Geometry[] layerGeom = new Geometry[fc.size()];
			for (int j = 0 ; j < fc.size() ; j++) {
				Geometry g = ((Feature) fc.get(j)).getGeometry();
				if (!(g instanceof Polygon)) continue;
				layerGeom[j] = g;
			}
			allLayerGeom[i] = new GeometryFactory().createGeometryCollection(layerGeom).buffer(0.0);
		}
		BasicFeature mergedAllLayerGeom = new BasicFeature(fs);
		mergedAllLayerGeom.setGeometry( new GeometryFactory().createGeometryCollection(allLayerGeom).buffer(0.0) );
		mergedAllLFC.add(mergedAllLayerGeom);
		context.getLayerManager().addLayer("DBTopo_temp", "all_geom_merged" , mergedAllLFC);

	}

}
package it.beopen.dbtopo.Elev;

import com.vividsolutions.jump.workbench.plugin.ThreadedPlugIn;


import java.util.Iterator;


import com.vividsolutions.jts.geom.*;
import com.vividsolutions.jump.feature.Feature;
import com.vividsolutions.jump.feature.FeatureCollection;
import com.vividsolutions.jump.task.TaskMonitor;
import com.vividsolutions.jump.workbench.model.Layer;
import com.vividsolutions.jump.workbench.plugin.PlugInContext;
import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;

/**
 * 
 */
public class From3Dto2DPlugIn implements ThreadedPlugIn {

	protected static String name = "From3Dto2D"; 
	private Layer layer;

	public From3Dto2DPlugIn() {
	}

	public void initialize(PlugInContext context) throws Exception {
		context.getFeatureInstaller().addMainMenuItem(this,new String[] { "DBTopo", "3D" }, 
				"flat geometry to 2D",
				false, null, new MultiEnableCheck()
		.add(context.getCheckFactory().createTaskWindowMustBeActiveCheck())
		.add(context.getCheckFactory().createAtLeastNLayersMustExistCheck(1)));
	}

	public boolean execute(PlugInContext context) {
		//		reportNothingToUndoYet(context);
		//
		//		layer = context.getCandidateLayer(0);
		return true;
	}

	private void reportNothingToUndoYet(PlugInContext context) {
		// TODO Auto-generated method stub
	}

	private void initDialog(PlugInContext context) {
	}

	public void run(TaskMonitor monitor, PlugInContext context) throws Exception {
		monitor.allowCancellationRequests();
		monitor.report("Converting geometry to 2D...");
		if (context.getSelectedLayer(0) == null ) context.getWorkbenchFrame().warnUser("At least 1 layer must be selected");
		FeatureCollection fc = context.getSelectedLayer(0).getFeatureCollectionWrapper();
		//        FeatureSchema fs = fc.getFeatureSchema();

		for (Iterator i = fc.iterator(); i.hasNext();) {
			Feature f = (Feature)i.next();
			to2D( f.getGeometry());
		}
	}

	private Geometry to2D(Geometry geometry) {
		geometry.apply(new CoordinateFilter() {
			public void filter(Coordinate coordinate) {
				//            	coordinate.setCoordinate((coordinate.x, coordinate.y), 2);
				coordinate.x = coordinate.x;
				coordinate.y = coordinate.y;
				coordinate.z = Double.NaN;
			}
		});
		return geometry;
	}


	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return null;
	}

}
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to