Revision 30 org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.convexhull/src/main/java/org/gvsig/sextante/app/algorithm/convexhull/ConvexHullOperation.java

View differences:

ConvexHullOperation.java
77 77
package org.gvsig.sextante.app.algorithm.convexhull;
78 78

  
79 79
import org.gvsig.fmap.geom.GeometryLocator;
80
import org.gvsig.fmap.geom.exception.CreateGeometryException;
81
import org.gvsig.fmap.geom.util.Converter;
80
import org.gvsig.fmap.geom.GeometryManager;
81
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
82
import org.gvsig.fmap.geom.operation.GeometryOperationException;
83
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
84
import org.gvsig.fmap.geom.operation.tojts.ToJTS;
85
import org.gvsig.fmap.geom.operation.fromjts.FromJTS;
82 86

  
83 87
import com.vividsolutions.jts.geom.Geometry;
84 88
import com.vividsolutions.jts.geom.GeometryCollection;
85 89
import com.vividsolutions.jts.geom.GeometryFactory;
86 90

  
91
import es.unex.sextante.core.Sextante;
92

  
87 93
/**
88 94
 * Convex Hull operation
89 95
 * @author Nacho Brodin (nachobrodin@gmail.com)
90 96
 */
91 97
public class ConvexHullOperation {
92
	public static final String  NAME     = "ConvexHull";
93
	public static final int     CODE     = GeometryLocator.getGeometryManager().getGeometryOperationCode(NAME);
94
	Geometry                    geometry = null;
95
	GeometryFactory             geomFact = null;
98
	public static final String  NAME             = "ConvexHull";
99
	public static final int     CODE             = GeometryLocator.getGeometryManager().getGeometryOperationCode(NAME);
100
	Geometry                    geometry         = null;
101
	GeometryFactory             geomFact         = null;
102
	private GeometryManager     geometryManager  = null;
96 103
	
97 104
	public ConvexHullOperation() {
98 105
		geometry = null;
106
		geometryManager = GeometryLocator.getGeometryManager();
99 107
	}
100 108
	
101 109
	/**
......
103 111
	 * @return
104 112
	 */
105 113
	public org.gvsig.fmap.geom.Geometry getGeometry() {
114
		if(geometry == null)
115
			return null;
116
		GeometryOperationContext ctx = new GeometryOperationContext();
117
		ctx.setAttribute(FromJTS.PARAM, geometry);
106 118
		try {
107
			return Converter.jtsToGeometry(geometry);
108
		} catch (CreateGeometryException e) {
119
			return (org.gvsig.fmap.geom.Geometry)geometryManager.invokeOperation(FromJTS.NAME, ctx);
120
		} catch (GeometryOperationNotSupportedException e) {
121
			Sextante.addErrorToLog(e);
109 122
			return null;
123
		} catch (GeometryOperationException e) {
124
			Sextante.addErrorToLog(e);
125
			return null;
110 126
		}
111 127
	}
112 128

  
......
114 130
	public org.gvsig.fmap.geom.Geometry invoke(org.gvsig.fmap.geom.Geometry g) {
115 131
		if(g == null)
116 132
			return null;
117
		com.vividsolutions.jts.geom.Geometry actualGeometry = Converter.geometryToJts(g);
133
		
134
		com.vividsolutions.jts.geom.Geometry actualGeometry = null;
135
		try {
136
			actualGeometry = (Geometry)g.invokeOperation(ToJTS.CODE, null);
137
		} catch (GeometryOperationNotSupportedException e1) {
138
			Sextante.addErrorToLog(e1);
139
		} catch (GeometryOperationException e1) {
140
			Sextante.addErrorToLog(e1);
141
		}
142
		
118 143
		if(geometry == null)
119 144
			geometry = actualGeometry;
120 145
		else {

Also available in: Unified diff