Revision 204

View differences:

org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.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.geoprocess.algorithm.intersection</artifactId>
6
  <packaging>jar</packaging>
7
  <name>org.gvsig.geoprocess.algorithm.intersection</name>
8
	
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.geoprocess.algorithm</artifactId>
12
		<version>1.0.0-SNAPSHOT</version>
13
	</parent>
14
	
15
	<dependencies>
16
		<dependency>
17
		    <groupId>org.gvsig</groupId>
18
   			<artifactId>org.gvsig.geoprocess.algorithm.base</artifactId>
19
   			<version>1.0.0-SNAPSHOT</version>
20
            <scope>compile</scope>
21
   		</dependency>
22
	</dependencies>
23
	
24
</project>
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/distribution/distribution.xml
1
<assembly>
2
<!-- Empty distribution file -->
3
</assembly>
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Thu Aug 18 10:21:29 CEST 2011
3
buildNumber=2042
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/resources/org/gvsig/geoprocess/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
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/resources/org/gvsig/geoprocess/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
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.geoprocess.algorithm.intersection.IntersectionLibrary
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/java/org/gvsig/geoprocess/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.geoprocess.algorithm.intersection;
22

  
23
import es.unex.sextante.core.Sextante;
24
import es.unex.sextante.dataObjects.IVectorLayer;
25
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
26
import es.unex.sextante.exceptions.RepeatedParameterNameException;
27
import es.unex.sextante.outputs.OutputVectorLayer;
28

  
29
import org.gvsig.fmap.dal.exception.DataException;
30
import org.gvsig.fmap.dal.feature.FeatureSet;
31
import org.gvsig.fmap.dal.feature.FeatureStore;
32
import org.gvsig.fmap.dal.feature.FeatureType;
33
import org.gvsig.geoprocess.core.gvVectorLayer;
34
import org.gvsig.geoprocess.sextante.AbstractSextanteGeoProcess;
35

  
36
/**
37
 * Intersection algorithm
38
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
39
 */
40
public class IntersectionAlgorithm extends AbstractSextanteGeoProcess {
41

  
42
	public static final String  RESULT    = "RESULT";
43
	public static final String  LAYER     = "LAYER";
44
	public static final String  INTER     = "INTER";
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("Intersection"));
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(INTER, 
62
												Sextante.getText("Overlays_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("Intersection"),
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
		IVectorLayer inter = m_Parameters.getParameterValueAsVectorLayer(INTER);
80
		IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
81
		boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
82
		
83
		try {
84
			computesIntersection(layer, inter, layer.getShapeType(), selectedGeom);
85
		} catch (DataException e) {
86
			Sextante.addErrorToLog(e);
87
			return false;
88
		}
89
		return true;
90
	}
91
	
92
	/**
93
	 * Builds a layer with the intersection between the input layer and the templateGeometry
94
	 * @param layer
95
	 *        Input layer
96
	 * @param templateGeometry
97
	 * @param shapeType
98
	 *        Output shape type
99
	 * @param selectedGeom
100
	 *        If it's true only selected geometries will be computed
101
	 */
102
	private void computesIntersection(IVectorLayer layer,
103
								IVectorLayer overlay,
104
								int shapeType, 
105
								boolean selectedGeom) throws DataException {
106
		FeatureStore storeLayer = null;
107
		FeatureStore storeOverlay = null;
108
		if(layer instanceof gvVectorLayer && 
109
			overlay instanceof gvVectorLayer) {
110
			storeLayer = ((gvVectorLayer)layer).getFeatureStore();
111
			storeOverlay = ((gvVectorLayer)overlay).getFeatureStore();
112
		} else
113
			return;
114

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

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

  
26
import com.vividsolutions.jts.geom.Geometry;
27
import com.vividsolutions.jts.precision.EnhancedPrecisionOp;
28

  
29
import es.unex.sextante.core.Sextante;
30

  
31
import org.gvsig.fmap.dal.exception.DataException;
32
import org.gvsig.fmap.dal.feature.EditableFeature;
33
import org.gvsig.fmap.dal.feature.Feature;
34
import org.gvsig.fmap.dal.feature.FeatureSet;
35
import org.gvsig.fmap.dal.feature.FeatureStore;
36
import org.gvsig.fmap.geom.exception.CreateGeometryException;
37
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation;
38
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil;
39
import org.gvsig.tools.dispose.DisposableIterator;
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

  
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/java/org/gvsig/geoprocess/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.geoprocess.algorithm.intersection;
22

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

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

  
34
    @Override
35
    protected void doInitialize() throws LibraryException {
36

  
37
    }
38

  
39
    @Override
40
    protected void doPostInitialize() throws LibraryException {
41
        Messages.addResourceFamily(
42
            "org.gvsig.geoprocess.algorithm.intersection.intersection",
43
            IntersectionLibrary.class.getClassLoader(),
44
            IntersectionLibrary.class.getClass().getName());
45

  
46
        registerGeoProcess(
47
            IntersectionAlgorithm.class,
48
            getLanguageStrings("org.gvsig.geoprocess.algorithm.intersection.intersection"));
49
    }
50

  
51
}
0 52

  
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.clip/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Thu Aug 18 10:21:15 CEST 2011
3
buildNumber=2042
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.clip/src/main/java/org/gvsig/geoprocess/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.geoprocess.algorithm.clip;
22

  
23
import es.unex.sextante.core.Sextante;
24
import es.unex.sextante.dataObjects.IVectorLayer;
25
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
26
import es.unex.sextante.exceptions.RepeatedParameterNameException;
27
import es.unex.sextante.outputs.OutputVectorLayer;
28

  
29
import org.gvsig.fmap.dal.exception.DataException;
30
import org.gvsig.fmap.dal.feature.FeatureSet;
31
import org.gvsig.fmap.dal.feature.FeatureStore;
32
import org.gvsig.fmap.dal.feature.FeatureType;
33
import org.gvsig.geoprocess.algorithm.base.core.ScalableUnionOperation;
34
import org.gvsig.geoprocess.core.gvVectorLayer;
35
import org.gvsig.geoprocess.sextante.AbstractSextanteGeoProcess;
36

  
37
/**
38
 * Clip algorithm
39
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
40
 */
41
public class ClipAlgorithm extends AbstractSextanteGeoProcess {
42

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

  
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.clip/src/main/java/org/gvsig/geoprocess/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.geoprocess.algorithm.clip;
22

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

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

  
34
    @Override
35
    protected void doInitialize() throws LibraryException {
36

  
37
    }
38

  
39
    @Override
40
    protected void doPostInitialize() throws LibraryException {
41
        Messages.addResourceFamily("org.gvsig.geoprocess.algorithm.clip.clip",
42
            ClipLibrary.class.getClassLoader(), ClipLibrary.class.getClass()
43
                .getName());
44

  
45
        registerGeoProcess(ClipAlgorithm.class,
46
            getLanguageStrings("org.gvsig.geoprocess.algorithm.clip.clip"));
47
    }
48

  
49
}
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.clip/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.geoprocess.algorithm.clip.ClipLibrary
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.clip/src/main/resources/org/gvsig/geoprocess/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
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.clip/src/main/resources/org/gvsig/geoprocess/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
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.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.geoprocess.algorithm.clip</artifactId>
6
  <packaging>jar</packaging>
7
  <name>org.gvsig.geoprocess.algorithm.clip</name>
8
	
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.geoprocess.algorithm</artifactId>
12
		<version>1.0.0-SNAPSHOT</version>
13
	</parent>
14
	
15
	<dependencies>
16
		<dependency>
17
		    <groupId>org.gvsig</groupId>
18
   			<artifactId>org.gvsig.geoprocess.algorithm.base</artifactId>
19
   			<version>1.0.0-SNAPSHOT</version>
20
            <scope>compile</scope>
21
   		</dependency>
22
	</dependencies>
23
	
24
</project>
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.clip/distribution/distribution.xml
1
<assembly>
2
<!-- Empty distribution file -->
3
</assembly>
0 4

  
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.convexhull/src/main/java/org/gvsig/geoprocess/algorithm/convexhull/ConvexHullParametersPanel.java
1
package org.gvsig.geoprocess.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.mapcontrol.swing.dynobject.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 void assignParameters() {
102
        // Nothing to do
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
}
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.convexhull/src/main/java/org/gvsig/geoprocess/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.geoprocess.algorithm.convexhull;
22

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

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

  
34
    @Override
35
    protected void doInitialize() throws LibraryException {
36

  
37
    }
38

  
39
    @Override
40
    protected void doPostInitialize() throws LibraryException {
41
        Messages.addResourceFamily(
42
            "org.gvsig.geoprocess.algorithm.convexhull.convexhull",
43
            ConvexHullLibrary.class.getClassLoader(), ConvexHullLibrary.class
44
                .getClass().getName());
45

  
46
        registerGeoProcess(
47
            ConvexHullAlgorithm.class,
48
            getLanguageStrings("org.gvsig.geoprocess.algorithm.convexhull.convexhull"));
49
    }
50

  
51
}
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.convexhull/src/main/java/org/gvsig/geoprocess/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.geoprocess.algorithm.convexhull;
22

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

  
26
import es.unex.sextante.core.Sextante;
27
import es.unex.sextante.dataObjects.IVectorLayer;
28
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
29
import es.unex.sextante.exceptions.RepeatedParameterNameException;
30
import es.unex.sextante.outputs.OutputVectorLayer;
31

  
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.feature.Feature;
34
import org.gvsig.fmap.dal.feature.FeatureSelection;
35
import org.gvsig.fmap.dal.feature.FeatureSet;
36
import org.gvsig.fmap.dal.feature.FeatureStore;
37
import org.gvsig.fmap.geom.Geometry;
38
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil;
39
import org.gvsig.geoprocess.core.gvVectorLayer;
40
import org.gvsig.geoprocess.sextante.AbstractSextanteGeoProcess;
41
import org.gvsig.tools.dispose.DisposableIterator;
42

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

  
79
import com.vividsolutions.jts.geom.Geometry;
80
import com.vividsolutions.jts.geom.GeometryCollection;
81
import com.vividsolutions.jts.geom.GeometryFactory;
82

  
83
import es.unex.sextante.core.Sextante;
84

  
85
import org.gvsig.fmap.dal.exception.DataException;
86
import org.gvsig.fmap.dal.feature.FeatureStore;
87
import org.gvsig.fmap.geom.GeometryLocator;
88
import org.gvsig.fmap.geom.GeometryManager;
89
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
90
import org.gvsig.fmap.geom.operation.GeometryOperationException;
91
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
92
import org.gvsig.fmap.geom.operation.fromjts.FromJTS;
93
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil;
94

  
95
/**
96
 * Convex Hull operation
97
 * @author Nacho Brodin (nachobrodin@gmail.com)
98
 */
99
public class ConvexHullOperation {
100
	public static final String  NAME             = "ConvexHull";
101
	public static final int     CODE             = GeometryLocator.getGeometryManager().getGeometryOperationCode(NAME);
102
	Geometry                    geometry         = null;
103
	GeometryFactory             geomFact         = null;
104
	private GeometryManager     geometryManager  = null;
105
	
106
	public ConvexHullOperation() {
107
		geometry = null;
108
		geometryManager = GeometryLocator.getGeometryManager();
109
	}
110
	
111
	public void setFeatureStore(FeatureStore out, String[] attrNames) throws DataException {
112
	}
113
	
114
	/**
115
	 * Returns FMap convex hull geometry.
116
	 * @return
117
	 */
118
	public org.gvsig.fmap.geom.Geometry getGeometry() {
119
		if(geometry == null)
120
			return null;
121
		GeometryOperationContext ctx = new GeometryOperationContext();
122
		ctx.setAttribute(FromJTS.PARAM, geometry);
123
		try {
124
			return (org.gvsig.fmap.geom.Geometry)geometryManager.invokeOperation(FromJTS.NAME, ctx);
125
		} catch (GeometryOperationNotSupportedException e) {
126
			Sextante.addErrorToLog(e);
127
			return null;
128
		} catch (GeometryOperationException e) {
129
			Sextante.addErrorToLog(e);
130
			return null;
131
		}
132
	}
133

  
134
	
135
	public org.gvsig.fmap.geom.Geometry invoke(org.gvsig.fmap.geom.Geometry g) {
136
		if(g == null)
137
			return null;
138
		
139
		com.vividsolutions.jts.geom.Geometry actualGeometry = GeometryUtil.geomToJTS(g);
140
		
141
		if(geometry == null)
142
			geometry = actualGeometry;
143
		else {
144
			com.vividsolutions.jts.geom.Geometry[] geoms = new com.vividsolutions.jts.geom.Geometry[2];
145
			geoms[0] = geometry;
146
			geoms[1] = actualGeometry;
147
			if(geomFact == null)
148
				geomFact = new GeometryFactory();
149
			GeometryCollection gc = geomFact.createGeometryCollection(geoms);
150
			geometry = gc.convexHull();	
151
		}
152
		return getGeometry();
153
	}
154

  
155
	/*
156
	 * (non-Javadoc)
157
	 * @see org.gvsig.fmap.geom.operation.GeometryOperation#getOperationIndex()
158
	 */
159
	public int getOperationIndex() {
160
		return CODE;
161
	}
162

  
163
}
164

  
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.convexhull/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.geoprocess.algorithm.convexhull.ConvexHullLibrary
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.convexhull/src/main/resources/org/gvsig/geoprocess/algorithm/convexhull/convexhull_en.properties
1
gvSIG_Algorithms=gvSIG algorithms
2
Input_layer=Input cover
3
ConvexHull=Convex Hull
4
Selected_geometries=Selected features
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.convexhull/src/main/resources/org/gvsig/geoprocess/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
org.gvsig.geoprocess/tags/b2042/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.convexhull/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.geoprocess.algorithm.convexhull</artifactId>
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff