Revision 109

View differences:

org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Mon Nov 08 10:00:34 CET 2010
3
buildNumber=2021
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.intersection/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Mon Nov 08 10:02:04 CET 2010
3
buildNumber=2021
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.intersection/src/main/java/org/gvsig/sextante/app/algorithm/intersection/IntersectionOperation.java
1
/*
2
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2010 Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 */
20

  
21
package org.gvsig.sextante.app.algorithm.intersection;
22

  
23
import java.util.Iterator;
24
import java.util.List;
25

  
26
import org.gvsig.fmap.dal.exception.DataException;
27
import org.gvsig.fmap.dal.feature.EditableFeature;
28
import org.gvsig.fmap.dal.feature.Feature;
29
import org.gvsig.fmap.dal.feature.FeatureSet;
30
import org.gvsig.fmap.dal.feature.FeatureStore;
31
import org.gvsig.fmap.geom.exception.CreateGeometryException;
32
import org.gvsig.sextante.app.algorithm.base.core.GeometryOperation;
33
import org.gvsig.sextante.app.algorithm.base.util.GeometryUtil;
34
import org.gvsig.tools.dispose.DisposableIterator;
35

  
36
import com.vividsolutions.jts.geom.Geometry;
37
import com.vividsolutions.jts.precision.EnhancedPrecisionOp;
38

  
39
import es.unex.sextante.core.Sextante;
40

  
41
/**
42
 * Builds a geometry with the intersection between two layers
43
 * 
44
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
45
 */
46
public class IntersectionOperation extends GeometryOperation {
47
	private FeatureStore                     storeOverlay     = null;
48

  
49
	public IntersectionOperation(FeatureStore overlayLayer) {
50
		this.storeOverlay = overlayLayer;
51
	}
52

  
53
	/**
54
	 * Computes intersection between the geometry and the overlay layer. The fields of the
55
	 * intersected features will be added.
56
	 * @param g
57
	 * @param featureInput
58
	 * @return
59
	 */
60
	@SuppressWarnings("unchecked")
61
	public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature featureInput) {
62
		if(g == null)
63
			return lastEditFeature;
64

  
65
		Geometry jtsGeom = GeometryUtil.geomToJTS(g);
66
		
67
		FeatureSet features = null;
68
		DisposableIterator it = null;
69
		try {
70
			features = storeOverlay.getFeatureSet();
71
			it = features.iterator();
72
		} catch (DataException e) {
73
			Sextante.addErrorToLog(e);
74
			return lastEditFeature;
75
		}
76
		
77
		while( it.hasNext() ) {
78
			Feature featureOverlay = (Feature)it.next();
79
			List geomList = featureOverlay.getGeometries();
80
			if(geomList == null) {
81
				org.gvsig.fmap.geom.Geometry geom = featureOverlay.getDefaultGeometry();
82
				lastEditFeature = intersection(jtsGeom, geom, featureInput, featureOverlay);
83
				continue;
84
			}
85

  
86
			Iterator<org.gvsig.fmap.geom.Geometry> itGeom = geomList.iterator();
87
			while(itGeom.hasNext()) {
88
				org.gvsig.fmap.geom.Geometry geom = itGeom.next();
89
				lastEditFeature = intersection(jtsGeom, geom, featureInput, featureOverlay);
90
			}
91
		}
92
		it.dispose();
93
		return lastEditFeature;
94
	}
95
	
96
	private EditableFeature intersection(Geometry jtsGeom, 
97
											org.gvsig.fmap.geom.Geometry overGeom, 
98
											Feature featureInput, 
99
											Feature featureOverlay) {
100
		Geometry overlaysGeom = GeometryUtil.geomToJTS(overGeom);
101
		
102
		try {
103
			if(!jtsGeom.getEnvelope().intersects(overlaysGeom.getEnvelope())) 
104
				return lastEditFeature;
105

  
106
			if(jtsGeom.intersects(overlaysGeom)) {
107
				Geometry newGeom = EnhancedPrecisionOp.intersection(jtsGeom, overlaysGeom);
108
				if(!newGeom.isEmpty())
109
					lastEditFeature = persister.addFeature(featureInput, featureOverlay, newGeom);
110
			}
111
		} catch (CreateGeometryException e) {
112
			Sextante.addErrorToLog(e);
113
		} catch (DataException e) {
114
			Sextante.addErrorToLog(e);
115
		}
116
		return lastEditFeature;
117
	}
118
	
119
	/**
120
	 * clips feature's geometry with the clipping geometry, preserving
121
	 * feature's original attributes.
122
	 * If feature's geometry doesn't touch clipping geometry, it will be
123
	 * ignored.
124
	 */
125
	public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput) {
126
		/*if(g == null)
127
			return;
128
		
129
		Geometry jtsGeom = Converter.geometryToJts(g);
130

  
131
		if(!jtsGeom.getEnvelope().intersects(overlaysGeom.getEnvelope()))
132
			return;
133

  
134
		if(jtsGeom.intersects(overlaysGeom)) {
135
			try {
136
				Geometry newGeom = EnhancedPrecisionOp.difference(jtsGeom, overlaysGeom);
137
				persister.addFeature(feature, newGeom);
138
			} catch (CreateGeometryException e) {
139
				Sextante.addErrorToLog(e);
140
			} catch (DataException e) {
141
				Sextante.addErrorToLog(e);
142
			}
143
		} */
144
	}
145

  
146
}
147

  
0 148

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.intersection/src/main/java/org/gvsig/sextante/app/algorithm/intersection/IntersectionLibrary.java
1
/*
2
 * gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2010 Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 */
21
package org.gvsig.sextante.app.algorithm.intersection;
22

  
23
import org.gvsig.i18n.Messages;
24
import org.gvsig.sextante.app.algorithm.base.core.AlgorithmAbstractLibrary;
25
import org.gvsig.tools.library.LibraryException;
26

  
27
import es.unex.sextante.core.Sextante;
28

  
29
/**
30
 * Initialization of IntersectionLibrary library. 
31
 * 
32
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
33
 */
34
public class IntersectionLibrary extends AlgorithmAbstractLibrary {
35

  
36
	@Override
37
	protected void doInitialize() throws LibraryException {
38
		
39
	}
40

  
41
	@Override
42
	protected void doPostInitialize() throws LibraryException {
43
		Messages.addResourceFamily(
44
				"org.gvsig.sextante.app.algorithm.intersection.intersection",
45
				IntersectionLibrary.class.getClassLoader(),
46
				IntersectionLibrary.class.getClass().getName());
47
		setLanguageStrings("org.gvsig.sextante.app.algorithm.intersection.intersection");
48
		Sextante.addGeoProcess(IntersectionAlgorithm.class, text);
49
	}
50

  
51
}
0 52

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.intersection/src/main/java/org/gvsig/sextante/app/algorithm/intersection/IntersectionAlgorithm.java
1
/*
2
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2010 Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 */
21
package org.gvsig.sextante.app.algorithm.intersection;
22

  
23
import org.gvsig.fmap.dal.exception.DataException;
24
import org.gvsig.fmap.dal.feature.FeatureSet;
25
import org.gvsig.fmap.dal.feature.FeatureStore;
26
import org.gvsig.fmap.dal.feature.FeatureType;
27
import org.gvsig.sextante.app.extension.core.gvGeoAlgorithm;
28
import org.gvsig.sextante.app.extension.core.gvVectorLayer;
29

  
30
import es.unex.sextante.core.Sextante;
31
import es.unex.sextante.dataObjects.IVectorLayer;
32
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
33
import es.unex.sextante.exceptions.RepeatedParameterNameException;
34
import es.unex.sextante.outputs.OutputVectorLayer;
35

  
36
/**
37
 * Intersection algorithm
38
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
39
 */
40
public class IntersectionAlgorithm extends gvGeoAlgorithm {
41
	public static final String  RESULT    = "RESULT";
42
	public static final String  LAYER     = "LAYER";
43
	public static final String  INTER     = "INTER";
44
	public static final String  CHECK     = "CHECK";
45
	
46
	/*
47
	 * (non-Javadoc)
48
	 * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
49
	 */
50
	public void defineCharacteristics() {
51
		setName(Sextante.getText("Intersection"));
52
		setGroup(Sextante.getText("gvSIG_Algorithms"));
53
		setGeneratesUserDefinedRasterOutput(false);
54
		
55
		try {
56
			m_Parameters.addInputVectorLayer(LAYER, 
57
												Sextante.getText("Input_layer"), 
58
												IVectorLayer.SHAPE_TYPE_WRONG, 
59
												true);
60
			m_Parameters.addInputVectorLayer(INTER, 
61
												Sextante.getText("Overlays_layer"), 
62
												IVectorLayer.SHAPE_TYPE_WRONG, 
63
												true);
64
			m_Parameters.addBoolean(CHECK, Sextante.getText("Selected_geometries"), false);
65
		} catch (RepeatedParameterNameException e) {
66
			Sextante.addErrorToLog(e);
67
		}
68
		addOutputVectorLayer(RESULT,
69
								Sextante.getText("Intersection"),
70
								OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
71
	}
72
	
73
	/*
74
	 * (non-Javadoc)
75
	 * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
76
	 */
77
	public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
78
		IVectorLayer inter = m_Parameters.getParameterValueAsVectorLayer(INTER);
79
		IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
80
		boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
81
		
82
		try {
83
			computesIntersection(layer, inter, layer.getShapeType(), selectedGeom);
84
		} catch (DataException e) {
85
			Sextante.addErrorToLog(e);
86
			return false;
87
		}
88
		return true;
89
	}
90
	
91
	/**
92
	 * Builds a layer with the intersection between the input layer and the templateGeometry
93
	 * @param layer
94
	 *        Input layer
95
	 * @param templateGeometry
96
	 * @param shapeType
97
	 *        Output shape type
98
	 * @param selectedGeom
99
	 *        If it's true only selected geometries will be computed
100
	 */
101
	private void computesIntersection(IVectorLayer layer,
102
								IVectorLayer overlay,
103
								int shapeType, 
104
								boolean selectedGeom) throws DataException {
105
		FeatureStore storeLayer = null;
106
		FeatureStore storeOverlay = null;
107
		if(layer instanceof gvVectorLayer && 
108
			overlay instanceof gvVectorLayer) {
109
			storeLayer = ((gvVectorLayer)layer).getFeatureStore();
110
			storeOverlay = ((gvVectorLayer)overlay).getFeatureStore();
111
		} else
112
			return;
113

  
114
		FeatureSet features1 = null;
115
		features1 = storeLayer.getFeatureSet();
116
		FeatureType featureType1 = features1.getDefaultFeatureType();
117
		
118
		FeatureSet features2 = null;
119
		features2 = storeOverlay.getFeatureSet();
120
		FeatureType featureType2 = features2.getDefaultFeatureType();
121
		
122
		FeatureStore outFeatStore = null;
123
		//Si las dos capas son de lineas la resultante es de l?neas
124
		if(isLine(storeLayer) && isLine(storeOverlay))
125
			outFeatStore = buildOutPutStoreFromUnion(featureType1, featureType2, IVectorLayer.SHAPE_TYPE_POINT, 
126
													Sextante.getText("Intersection"), RESULT);
127
		else
128
			//Si alguna de las dos capas es de puntos la resultante tambi?n lo es
129
			if(isPoint(storeLayer) || isPoint(storeOverlay))
130
				outFeatStore = buildOutPutStoreFromUnion(featureType1, featureType2, IVectorLayer.SHAPE_TYPE_POINT, 
131
														Sextante.getText("Intersection"), RESULT);
132
			else
133
				outFeatStore = buildOutPutStoreFromUnion(featureType1, featureType2, shapeType, 
134
														Sextante.getText("Intersection"), RESULT);
135
		
136
		IntersectionOperation operation = new IntersectionOperation(storeOverlay);
137
		operation.computesGeometryOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
138
	}
139
	
140
}
0 141

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.intersection/src/main/resources/org/gvsig/sextante/app/algorithm/intersection/intersection_es.properties
1
gvSIG_Algorithms=Algoritmos gvSIG
2
Input_layer=Capa de entrada
3
Overlays_layer=Capa de revestimiento
4
Selected_geometries=Geometrias seleccionadas
5
Intersection=Intersecci?n
0 6

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.intersection/src/main/resources/org/gvsig/sextante/app/algorithm/intersection/intersection_en.properties
1
gvSIG_Algorithms=gvSIG algorithms
2
Input_layer=Input cover
3
Overlays_layer=Overlay layer
4
Selected_geometries=Selected geometries
5
Intersection=Intersection
0 6

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.intersection/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.sextante.app.algorithm.intersection.IntersectionLibrary
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.intersection/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
  <modelVersion>4.0.0</modelVersion>
5
  <artifactId>org.gvsig.sextante.app.algorithm.intersection</artifactId>
6
  <packaging>jar</packaging>
7
  <name>org.gvsig.sextante.app.algorithm.intersection</name>
8
	
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.sextante.app.algorithm</artifactId>
12
		<version>0.6.0-SNAPSHOT</version>
13
	</parent>
14
	
15
	<dependencies>
16
		<dependency>
17
		    <groupId>org.gvsig</groupId>
18
   			<artifactId>org.gvsig.sextante.app.algorithm.base</artifactId>
19
   			<version>0.6.0-SNAPSHOT</version>
20
   		</dependency>
21
	</dependencies>
22
	
23
</project>
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.intersection/distribution/distribution.xml
1
<assembly>
2
</assembly>
0 3

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.clip/distribution/distribution.xml
1
<assembly>
2
</assembly>
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.clip/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Mon Nov 08 10:01:40 CET 2010
3
buildNumber=2021
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.clip/src/main/java/org/gvsig/sextante/app/algorithm/clip/ClipOperation.java
1
/*
2

  
3
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
4
 *
5
 * Copyright (C) 2010 Generalitat Valenciana.
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
20
 */
21

  
22
package org.gvsig.sextante.app.algorithm.clip;
23

  
24
import org.gvsig.fmap.dal.exception.DataException;
25
import org.gvsig.fmap.dal.feature.EditableFeature;
26
import org.gvsig.fmap.dal.feature.Feature;
27
import org.gvsig.fmap.geom.exception.CreateGeometryException;
28
import org.gvsig.sextante.app.algorithm.base.core.DALFeaturePersister;
29
import org.gvsig.sextante.app.algorithm.base.core.GeometryOperation;
30
import org.gvsig.sextante.app.algorithm.base.util.GeometryUtil;
31

  
32
import com.vividsolutions.jts.geom.Geometry;
33

  
34
import es.unex.sextante.core.Sextante;
35
/**
36
 * This class analyzes all features of a layer, clipping its geometries
37
 * with the convex hull of another layer.
38
 * If the geometry of the feature analyzed doesnt intersect with the convex
39
 * hull geometry, the clipvisitor will ignore it.
40
 *
41
 * It intersects, computes intersection and creates a new feature with
42
 * the same attributes and the new intersection geometry.
43
 * 
44
 * @author Nacho Brodin (nachobrodin@gmail.com)
45
 */
46
public class ClipOperation extends GeometryOperation {
47

  
48
	/**
49
	 * Clipping geometry: the convex hull of the
50
	 * clipping layer
51
	 */
52
	private Geometry                         clippingConvexHull   = null;
53
	private DALFeaturePersister              persister            = null;
54

  
55
	public ClipOperation(org.gvsig.fmap.geom.Geometry clip) {
56
		this.clippingConvexHull = GeometryUtil.geomToJTS(clip);
57
	}
58

  
59
	/**
60
	 * clips feature's geometry with the clipping geometry, preserving
61
	 * feature's original attributes.
62
	 * If feature's geometry doesnt touch clipping geometry, it will be
63
	 * ignored.
64
	 */
65
	public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature feature) {
66
		if(g == null)
67
			return lastEditFeature;
68
		
69
		Geometry jtsGeom = GeometryUtil.geomToJTS(g);
70
		
71
		if(!jtsGeom.getEnvelope().intersects(clippingConvexHull.getEnvelope()))
72
			return lastEditFeature;
73
		
74
		if(jtsGeom.intersects(clippingConvexHull)) {
75
			try {
76
				Geometry newGeom = jtsGeom.intersection(clippingConvexHull);
77
				lastEditFeature = persister.addFeature(feature, newGeom);
78
			} catch(com.vividsolutions.jts.geom.TopologyException e){
79
				Sextante.addErrorToLog(e);
80
				if(! jtsGeom.isValid()) {
81
					System.out.println("La geometria de entrada no es valida");
82
					jtsGeom = GeometryUtil.removeDuplicatesFrom(jtsGeom);
83
				}
84
				if(! clippingConvexHull.isValid()) {
85
					System.out.println("La geometria de recorte no es valida");
86
					clippingConvexHull = GeometryUtil.removeDuplicatesFrom(clippingConvexHull);
87
				}
88
				try {
89
					Geometry newGeom = jtsGeom.intersection(clippingConvexHull);
90
					lastEditFeature = persister.addFeature(feature, newGeom);
91
				} catch(com.vividsolutions.jts.geom.TopologyException ee){
92
					Sextante.addErrorToLog(ee);
93
				} catch (CreateGeometryException ee) {
94
					Sextante.addErrorToLog(ee);
95
				} catch (DataException ee) {
96
					Sextante.addErrorToLog(ee);
97
				}
98
			} catch (CreateGeometryException e) {
99
				Sextante.addErrorToLog(e);
100
			} catch (DataException e) {
101
				Sextante.addErrorToLog(e);
102
			}
103
		}
104
		return lastEditFeature;
105
	}
106
	
107
	/**
108
	 * clips feature's geometry with the clipping geometry, preserving
109
	 * feature's original attributes.
110
	 * If feature's geometry doesnt touch clipping geometry, it will be
111
	 * ignored.
112
	 */
113
	public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature feature) {
114
		if(g == null)
115
			return;
116
		
117
		lastEditFeature = feature;
118
		
119
		Geometry jtsGeom = GeometryUtil.geomToJTS(g);
120
		
121
		if(!jtsGeom.getEnvelope().intersects(clippingConvexHull.getEnvelope()))
122
			return;
123
		
124
		if(jtsGeom.intersects(clippingConvexHull)) {
125
			try {
126
				Geometry newGeom = jtsGeom.intersection(clippingConvexHull);
127
				persister.addFeature(feature, newGeom);
128
			} catch(com.vividsolutions.jts.geom.TopologyException e){
129
				Sextante.addErrorToLog(e);
130
				if(! jtsGeom.isValid()) {
131
					System.out.println("La geometria de entrada no es valida");
132
					jtsGeom = GeometryUtil.removeDuplicatesFrom(jtsGeom);
133
				}
134
				if(! clippingConvexHull.isValid()) {
135
					System.out.println("La geometria de recorte no es valida");
136
					clippingConvexHull = GeometryUtil.removeDuplicatesFrom(clippingConvexHull);
137
				}
138
				try {
139
					Geometry newGeom = jtsGeom.intersection(clippingConvexHull);
140
					persister.addFeature(feature, newGeom);
141
				} catch(com.vividsolutions.jts.geom.TopologyException ee){
142
					Sextante.addErrorToLog(ee);
143
				} catch (CreateGeometryException ee) {
144
					Sextante.addErrorToLog(ee);
145
				} catch (DataException ee) {
146
					Sextante.addErrorToLog(ee);
147
				}
148
			} catch (CreateGeometryException e) {
149
				Sextante.addErrorToLog(e);
150
			} catch (DataException e) {
151
				Sextante.addErrorToLog(e);
152
			}
153
		}
154
	}
155
	
156
	/**
157
	 * Ends the edition and closes the FeatureStore
158
	 */
159
	public void end() {
160
		persister.end();
161
	}
162

  
163
	public String getProcessDescription() {
164
		return "Clipping features agaisnt a clip geometry";
165
	}
166
}
167

  
0 168

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.clip/src/main/java/org/gvsig/sextante/app/algorithm/clip/ClipLibrary.java
1
/*
2
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2010 Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 */
21
package org.gvsig.sextante.app.algorithm.clip;
22

  
23
import org.gvsig.i18n.Messages;
24
import org.gvsig.sextante.app.algorithm.base.core.AlgorithmAbstractLibrary;
25
import org.gvsig.tools.library.LibraryException;
26

  
27
import es.unex.sextante.core.Sextante;
28

  
29
/**
30
 * Initialization of ClipLibrary library. 
31
 * 
32
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
33
 */
34
public class ClipLibrary extends AlgorithmAbstractLibrary {
35

  
36
	@Override
37
	protected void doInitialize() throws LibraryException {
38
		
39
	}
40

  
41
	@Override
42
	protected void doPostInitialize() throws LibraryException {
43
		Messages.addResourceFamily(
44
				"org.gvsig.sextante.app.algorithm.clip.clip",
45
				ClipLibrary.class.getClassLoader(),
46
				ClipLibrary.class.getClass().getName());
47
		setLanguageStrings("org.gvsig.sextante.app.algorithm.clip.clip");
48
		Sextante.addGeoProcess(ClipAlgorithm.class, text);
49
	}
50

  
51
}
0 52

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.clip/src/main/java/org/gvsig/sextante/app/algorithm/clip/ClipAlgorithm.java
1
/*
2
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2010 Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 */
21
package org.gvsig.sextante.app.algorithm.clip;
22

  
23
import org.gvsig.fmap.dal.exception.DataException;
24
import org.gvsig.fmap.dal.feature.FeatureSet;
25
import org.gvsig.fmap.dal.feature.FeatureStore;
26
import org.gvsig.fmap.dal.feature.FeatureType;
27
import org.gvsig.sextante.app.algorithm.base.core.ScalableUnionOperation;
28
import org.gvsig.sextante.app.extension.core.gvGeoAlgorithm;
29
import org.gvsig.sextante.app.extension.core.gvVectorLayer;
30

  
31
import es.unex.sextante.core.Sextante;
32
import es.unex.sextante.dataObjects.IVectorLayer;
33
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
34
import es.unex.sextante.exceptions.RepeatedParameterNameException;
35
import es.unex.sextante.outputs.OutputVectorLayer;
36

  
37
/**
38
 * Clip algorithm
39
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
40
 */
41
public class ClipAlgorithm extends gvGeoAlgorithm {
42
	public static final String  RESULT    = "RESULT";
43
	public static final String  LAYER     = "LAYER";
44
	public static final String  CLIP      = "CLIP";
45
	public static final String  CHECK     = "CHECK";
46
	
47
	/*
48
	 * (non-Javadoc)
49
	 * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
50
	 */
51
	public void defineCharacteristics(){
52
		setName(Sextante.getText("Clip"));
53
		setGroup(Sextante.getText("gvSIG_Algorithms"));
54
		setGeneratesUserDefinedRasterOutput(false);
55
		
56
		try {
57
			m_Parameters.addInputVectorLayer(LAYER, 
58
												Sextante.getText("Input_layer"), 
59
												IVectorLayer.SHAPE_TYPE_WRONG, 
60
												true);
61
			m_Parameters.addInputVectorLayer(CLIP, 
62
												Sextante.getText("Clip_layer"), 
63
												IVectorLayer.SHAPE_TYPE_WRONG, 
64
												true);
65
			m_Parameters.addBoolean(CHECK, Sextante.getText("Selected_geometries"), false);
66
		} catch (RepeatedParameterNameException e) {
67
			Sextante.addErrorToLog(e);
68
		}
69
		addOutputVectorLayer(RESULT,
70
								Sextante.getText( "Clip"),
71
								OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
72
	}
73
	
74
	/*
75
	 * (non-Javadoc)
76
	 * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
77
	 */
78
	public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
79
		org.gvsig.fmap.geom.Geometry clippingGeometry = null;
80
		IVectorLayer clip = m_Parameters.getParameterValueAsVectorLayer(CLIP);
81
		IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
82
		boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
83
		
84
		try {
85
			clippingGeometry = ScalableUnionOperation.joinLayerGeometries(clip);
86
		} catch (Exception e) {
87
			Sextante.addErrorToLog(e);
88
			return false;
89
		}
90
		
91
		FeatureStore storeLayer = null;
92
		if(layer instanceof gvVectorLayer && clippingGeometry != null)
93
			storeLayer = ((gvVectorLayer)layer).getFeatureStore();
94
		else
95
			return false;
96
		
97
		try {
98
			FeatureSet features = null;
99
			features = storeLayer.getFeatureSet();
100
			FeatureType featureType = features.getDefaultFeatureType();
101
			FeatureStore outFeatStore = buildOutPutStore(featureType, layer.getShapeType(), Sextante.getText("Clip"), RESULT);
102
			
103
			ClipOperation operation = new ClipOperation(clippingGeometry);
104
			operation.setProgressModel(this);
105
			operation.computesGeometryOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
106
		} catch (DataException e) {
107
			Sextante.addErrorToLog(e);
108
			return false;
109
		}
110
		
111
		return true;
112
	}
113
	
114
}
0 115

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.clip/src/main/resources/org/gvsig/sextante/app/algorithm/clip/clip_es.properties
1
gvSIG_Algorithms=Algoritmos gvSIG
2
Clip_layer=Capa de recorte
3
Clip=Recorte
4
Input_layer=Capa de entrada
5
Clip_layer=Capa de recorte
6
Selected_geometries=Geometrias seleccionadas
0 7

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.clip/src/main/resources/org/gvsig/sextante/app/algorithm/clip/clip_en.properties
1
gvSIG_Algorithms=gvSIG algorithms
2
Clip_layer=Clip cover
3
Clip=Clip
4
Input_layer=Input cover
5
Selected_geometries=Selected features
0 6

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.clip/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.sextante.app.algorithm.clip.ClipLibrary
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.clip/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
  <modelVersion>4.0.0</modelVersion>
5
  <artifactId>org.gvsig.sextante.app.algorithm.clip</artifactId>
6
  <packaging>jar</packaging>
7
  <name>org.gvsig.sextante.app.algorithm.clip</name>
8
	
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.sextante.app.algorithm</artifactId>
12
		<version>0.6.0-SNAPSHOT</version>
13
	</parent>
14
	
15
	<dependencies>
16
		<dependency>
17
		    <groupId>org.gvsig</groupId>
18
   			<artifactId>org.gvsig.sextante.app.algorithm.base</artifactId>
19
   			<version>0.6.0-SNAPSHOT</version>
20
   		</dependency>
21
	</dependencies>
22
	
23
</project>
0 24

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.convexhull/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.sextante.app.algorithm.convexhull.ConvexHullLibrary
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.convexhull/src/main/resources/org/gvsig/sextante/app/algorithm/convexhull/convexhull_en.properties
1
gvSIG_Algorithms=gvSIG algorithms
2
Input_layer=Input cover
3
ConvexHull=Convex Hull
4
Selected_geometries=Selected features
0 5

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.convexhull/src/main/resources/org/gvsig/sextante/app/algorithm/convexhull/convexhull_es.properties
1
gvSIG_Algorithms=Algoritmos gvSIG
2
Input_layer=Capa de entrada
3
ConvexHull=Convex Hull
4
Selected_geometries=Geometrias seleccionadas
0 5

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.convexhull/src/main/java/org/gvsig/sextante/app/algorithm/convexhull/ConvexHullParametersPanel.java
1
package org.gvsig.sextante.app.algorithm.convexhull;
2

  
3
import java.awt.Dimension;
4
import java.awt.GridBagConstraints;
5
import java.awt.GridBagLayout;
6
import java.awt.Insets;
7
import java.awt.event.ActionEvent;
8
import java.awt.event.ActionListener;
9
import java.util.ArrayList;
10
import java.util.Iterator;
11
import java.util.List;
12

  
13
import javax.swing.JButton;
14
import javax.swing.JComboBox;
15

  
16
import es.unex.sextante.core.GeoAlgorithm;
17
import es.unex.sextante.core.Sextante;
18
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
19

  
20
import org.slf4j.Logger;
21
import org.slf4j.LoggerFactory;
22

  
23
import org.gvsig.fmap.dal.DALLocator;
24
import org.gvsig.fmap.dal.DataManager;
25
import org.gvsig.fmap.dal.DataStoreParameters;
26
import org.gvsig.fmap.dal.exception.InitializeException;
27
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
28
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.DynObjectEditor;
29
import org.gvsig.tools.service.ServiceException;
30

  
31
/**
32
 * @deprecated
33
 * @author Nacho Brodin (nachobrodin@gmail.com)
34
 */
35
public class ConvexHullParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener {
36

  
37
    private static final long serialVersionUID = 3260891769310434508L;
38

  
39
    private static final Logger LOG =
40
        LoggerFactory.getLogger(ConvexHullParametersPanel.class);
41
    
42
	private JComboBox                        combo               = null;
43
	private JButton                          button              = null;
44
	private ArrayList<DataStoreParameters>   paramList           = new ArrayList<DataStoreParameters>();
45
	
46
	public ConvexHullParametersPanel() {
47
		super();
48
	}
49

  
50
    public void init(GeoAlgorithm algorithm) {
51
    	initGUI();
52
    }
53

  
54
	private void initGUI() {
55
		GridBagLayout gbl = new GridBagLayout();
56
		this.setLayout(gbl);
57
		
58
		GridBagConstraints gbc = new GridBagConstraints();
59
		gbc.fill = GridBagConstraints.HORIZONTAL;
60
		gbc.weightx = 1.0;
61
		gbc.gridx = 0;
62
		gbc.gridy = 0;
63
		gbc.insets = new Insets(0, 2, 0, 0);
64
		this.add(getCombo(), gbc);
65
		
66
		gbc.fill = GridBagConstraints.NONE;
67
		gbc.weightx = 0;
68
		gbc.gridx = 1;
69
		gbc.insets = new Insets(0, 5, 0, 2);
70
		this.add(getButton(), gbc);
71
	}
72

  
73
	/**
74
	 * Gets a ComboBox
75
	 * @return
76
	 */
77
	public JComboBox getCombo() {
78
		if(combo == null) {
79
			combo = new JComboBox();
80
			loadProviderList(combo, paramList);
81
			combo.addActionListener(this);
82
			combo.setPreferredSize(new Dimension(0, 18));
83
		}
84
		return combo;
85
	}
86
	
87
	/**
88
	 * Gets a JButton
89
	 * @return
90
	 */
91
	public JButton getButton() {
92
		if(button == null) {
93
			button = new JButton("...");
94
			button.setPreferredSize(new Dimension(60, 18));
95
			button.addActionListener(this);
96
		}
97
		return button;
98
	}
99
	
100
	@Override
101
	public boolean assignParameters() {
102
		return false;
103
	}
104

  
105
	@Override
106
	public void setOutputValue(String arg0, String arg1) {
107
		
108
	}
109

  
110
	@Override
111
	public void setParameterValue(String arg0, String arg1) {
112
		
113
	}
114
	
115
	@SuppressWarnings("unchecked")
116
	private void loadProviderList(JComboBox c, ArrayList<DataStoreParameters> paramList) {
117
		try {
118
		DataManager manager = DALLocator.getDataManager();
119
		List list = manager.getStoreProviders();
120
		Iterator it = list.iterator();
121
		c.removeAllItems();
122
		paramList.clear();
123
		while(it.hasNext()) {
124
			try {
125
				String provider = it.next().toString();
126
				DataStoreParameters param = manager.createStoreParameters(provider);
127
				c.addItem(provider);
128
				paramList.add(param);
129
			} catch (InitializeException e1) {
130
				Sextante.addErrorToLog(e1);
131
			} catch (ProviderNotRegisteredException e1) {
132
				Sextante.addErrorToLog(e1);
133
			}
134
		}
135
		}catch(Exception e){}
136
	}
137

  
138
	public void actionPerformed(ActionEvent e) {
139
		if(e.getSource() == getButton()) {
140
			int index = getCombo().getSelectedIndex();
141
			
142
            try {
143
                DynObjectEditor editor = new DynObjectEditor(paramList.get(index));
144
                editor.editObject(true);
145
            } catch (ServiceException ex) {
146
                LOG.error(
147
                    "Error creating a Swing component for the DynObject: "
148
                        + paramList.get(index), ex);
149
                Sextante.addErrorToLog(ex);
150
            }
151

  
152
		}
153
		
154
		if(e.getSource() == getCombo()) {
155
			
156
		}
157
	}
158
}
0 159

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.convexhull/src/main/java/org/gvsig/sextante/app/algorithm/convexhull/ConvexHullLibrary.java
1
/*
2
 * gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2010 Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 */
21
package org.gvsig.sextante.app.algorithm.convexhull;
22

  
23
import org.gvsig.i18n.Messages;
24
import org.gvsig.sextante.app.algorithm.base.core.AlgorithmAbstractLibrary;
25
import org.gvsig.tools.library.LibraryException;
26

  
27
import es.unex.sextante.core.Sextante;
28

  
29
/**
30
 * Initialization of ConvexHullLibrary library. 
31
 * 
32
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
33
 */
34
public class ConvexHullLibrary extends AlgorithmAbstractLibrary {
35

  
36
	@Override
37
	protected void doInitialize() throws LibraryException {
38
		
39
	}
40

  
41
	@Override
42
	protected void doPostInitialize() throws LibraryException {
43
		Messages.addResourceFamily(
44
				"org.gvsig.sextante.app.algorithm.convexhull.convexhull",
45
				ConvexHullLibrary.class.getClassLoader(),
46
				ConvexHullLibrary.class.getClass().getName());
47
		setLanguageStrings("org.gvsig.sextante.app.algorithm.convexhull.convexhull");
48
		Sextante.addGeoProcess(ConvexHullAlgorithm.class, text);
49
	}
50

  
51
}
0 52

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.convexhull/src/main/java/org/gvsig/sextante/app/algorithm/convexhull/ConvexHullAlgorithm.java
1
/*
2
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2010 Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 */
21
package org.gvsig.sextante.app.algorithm.convexhull;
22

  
23
import java.util.Iterator;
24
import java.util.List;
25

  
26
import org.gvsig.fmap.dal.DataSet;
27
import org.gvsig.fmap.dal.exception.DataException;
28
import org.gvsig.fmap.dal.feature.Feature;
29
import org.gvsig.fmap.dal.feature.FeatureSet;
30
import org.gvsig.fmap.dal.feature.FeatureStore;
31
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection;
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.sextante.app.algorithm.base.util.GeometryUtil;
34
import org.gvsig.sextante.app.extension.core.gvVectorLayer;
35
import org.gvsig.tools.dispose.DisposableIterator;
36

  
37
import es.unex.sextante.core.GeoAlgorithm;
38
import es.unex.sextante.core.Sextante;
39
import es.unex.sextante.dataObjects.IVectorLayer;
40
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
41
import es.unex.sextante.exceptions.RepeatedParameterNameException;
42
import es.unex.sextante.outputs.OutputVectorLayer;
43

  
44
/**
45
 * Convex Hull Algorithm
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class ConvexHullAlgorithm extends GeoAlgorithm {
49
	public static final String  LAYER     = "LAYER";
50
	public static final String  RESULT    = "RESULT";
51
	public static final String  CHECK     = "CHECK";
52
	
53
	public void defineCharacteristics(){
54
		setName(Sextante.getText("Convex Hull"));
55
		setGroup(Sextante.getText("gvSIG_Algorithms"));
56
		setGeneratesUserDefinedRasterOutput(false);
57
		try {
58
			m_Parameters.addInputVectorLayer(LAYER, 
59
												Sextante.getText("Input_layer"), 
60
												IVectorLayer.SHAPE_TYPE_WRONG, 
61
												true);
62
			addOutputVectorLayer(RESULT,
63
									Sextante.getText("ConvexHull"),
64
									OutputVectorLayer.SHAPE_TYPE_POLYGON);
65
			m_Parameters.addBoolean(CHECK, Sextante.getText("Selected_geometries"), false);
66
		} catch (RepeatedParameterNameException e) {
67
			Sextante.addErrorToLog(e);
68
		}
69
	}
70
	
71
	/*
72
	 * (non-Javadoc)
73
	 * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
74
	 */
75
	@SuppressWarnings("unchecked")
76
	public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
77
		IVectorLayer input = m_Parameters.getParameterValueAsVectorLayer(LAYER);
78
		boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
79
		
80
		FeatureStore store = null;
81
		
82
		if(input instanceof gvVectorLayer)
83
			store = ((gvVectorLayer)input).getFeatureStore();
84
		else
85
			return false;
86
		
87
		ConvexHullOperation convexHullOperation = new ConvexHullOperation();
88
		
89
		FeatureSet features = null;
90
		try {
91
			features = store.getFeatureSet();
92
			
93
			DisposableIterator it = null;
94
			if(selectedGeom) {
95
				DataSet ds = store.getSelection();
96
				it = ((DefaultFeatureSelection)ds).iterator();
97
				//if(!it.hasNext())Mensaje de no hay geometrias seleccionadas
98
			} else
99
				it = features.iterator();
100
			
101
			int numberOfFeatures = (int)features.getSize();
102
			int iCount = 0;
103
			
104
			while( it.hasNext() ) {
105
				Feature feature = (Feature)it.next();
106
				List geomList = feature.getGeometries();
107
				setProgress(iCount, numberOfFeatures);
108
				iCount ++;
109
				if(geomList == null) {
110
					Geometry geom = feature.getDefaultGeometry();
111
					if(geom != null)
112
						convexHullOperation.invoke(geom);
113
					continue;
114
				}
115
				Iterator<Geometry> itGeom = geomList.iterator();
116
				while(itGeom.hasNext()) {
117
					Geometry g = itGeom.next();
118
					convexHullOperation.invoke(g);
119
				}
120
			}
121
			Geometry g = convexHullOperation.getGeometry();
122
			if(g == null)
123
				return false;
124
			String[] sNames = {"ID"};
125
			Class [] types = {Integer.class};
126
			IVectorLayer output = getNewVectorLayer(RESULT,
127
													Sextante.getText("ConvexHull"),
128
													OutputVectorLayer.SHAPE_TYPE_POLYGON, types, sNames);
129
			
130
			com.vividsolutions.jts.geom.Geometry jtsGeom = GeometryUtil.geomToJTS(g);
131
			
132
			output.addFeature(jtsGeom, new Object[]{new Integer(0)});
133
			it.dispose();
134
		} catch (DataException e) {
135
			Sextante.addErrorToLog(e);
136
		}
137
		return !m_Task.isCanceled();
138
	}
139
}
0 140

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.convexhull/src/main/java/org/gvsig/sextante/app/algorithm/convexhull/TestPanel.java
1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.sextante.app.algorithm.convexhull;
20

  
21
import javax.swing.JFrame;
22
import javax.swing.UIManager;
23

  
24
public class TestPanel {
25
	private JFrame 			            frame = new JFrame();
26
	@SuppressWarnings("deprecation")
27
	private ConvexHullParametersPanel	hp = null;
28

  
29
	public TestPanel() {
30
		super();
31
		initialize();
32
	}
33

  
34
	public static void main(String[] args){
35
		try {
36
			UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
37
		} catch( Exception e ) {
38
			System.err.println( "No se puede cambiar al LookAndFeel");
39
		}
40
		new TestPanel();
41
	}
42

  
43
	@SuppressWarnings("deprecation")
44
	private void initialize() {
45
		frame.setSize(new java.awt.Dimension(370, 50));
46
		hp = new ConvexHullParametersPanel();
47
		hp.init(null);
48
		frame.setContentPane(hp);
49
		frame.setResizable(true);
50
		frame.setTitle("Panel");
51
		frame.setVisible(true);
52
		frame.addWindowListener(new java.awt.event.WindowAdapter() {
53
			public void windowClosing(java.awt.event.WindowEvent e) {
54
				System.exit(0);
55
			}
56
		});
57
	}
58
}
0 59

  
org.gvsig.sextante/tags/gvsig-v2_0_0_Build_2021/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.convexhull/src/main/java/org/gvsig/sextante/app/algorithm/convexhull/ConvexHullOperation.java
1
/*
2
 * Created on 16-feb-2006
3
 *
4
 * gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib��ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: ScalableConvexHullVisitor.java 10626 2007-03-06 16:55:54Z caballero $
47
* $Log$
48
* Revision 1.2  2007-03-06 16:47:58  caballero
49
* Exceptions
50
*
51
* Revision 1.1  2006/06/20 18:20:45  azabala
52
* first version in cvs
53
*
54
* Revision 1.2  2006/06/02 18:21:28  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.1  2006/05/24 21:13:31  azabala
58
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
59
*
60
* Revision 1.3  2006/03/15 18:31:06  azabala
61
* *** empty log message ***
62
*
63
* Revision 1.2  2006/03/07 21:01:33  azabala
64
* *** empty log message ***
65
*
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff