Revision 171

View differences:

org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/distribution/distribution.xml
1
<assembly>
2
</assembly>
0 3

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.geoprocess.extension/distribution/distribution.xml
1
<assembly>
2
  <id>distribution</id>
3
  
4
  <formats>
5
    <format>dir</format>
6
  </formats>
7
  
8
  <fileSets>
9
    <fileSet>
10
      <directory>src/main/resources/config</directory>
11
	  <outputDirectory>${extension.install.dir.name}</outputDirectory>
12
    </fileSet>
13
  </fileSets>
14
  
15
  <files>
16
    <file>
17
      <source>package.info</source>
18
      <outputDirectory>${extension.install.dir.name}</outputDirectory>
19
    </file>
20
  </files>
21
  
22
  <dependencySets>
23
	<dependencySet>
24
		<outputDirectory>./gvSIG/extensiones/org.gvsig.sextante.app.geoprocess.extension/lib</outputDirectory>
25
		<includes>
26
			<include>org.gvsig:org.gvsig.sextante.app.geoprocess.extension</include>
27
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.base</include>
28
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.buffer</include>
29
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.clip</include>
30
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.convexhull</include>
31
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.difference</include>
32
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.dissolve</include>
33
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.intersection</include>
34
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.merge</include>
35
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.reproject</include>
36
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.spatialjoin</include>
37
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.union</include>
38
			<include>org.gvsig:org.gvsig.sextante.app.algorithm.xyshift</include>
39
		</includes>
40
	</dependencySet>
41
  </dependencySets>
42
</assembly>
0 43

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.geoprocess.extension/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Thu Aug 18 10:21:58 CEST 2011
3
buildNumber=2040
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.geoprocess.extension/src/main/resources/config/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<depends plugin-name="org.gvsig.sextante.app.extension" />
4
	<resourceBundle name="text" />
5
	<libraries library-dir="lib" />
6
	<extensions>
7
		<extension class-name="org.gvsig.sextante.app.geoprocess.extension.GeoprocessModule"
8
			active="true" 
9
			priority="1">
10
		</extension>
11
	</extensions>
12
</plugin-config>
0 13

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.geoprocess.extension/src/main/java/org/gvsig/sextante/app/geoprocess/extension/GeoprocessModule.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.geoprocess.extension;
20

  
21
import javax.swing.Icon;
22

  
23
import org.gvsig.andami.plugins.Extension;
24
import org.gvsig.app.project.documents.view.toc.ITocItem;
25
import org.gvsig.fmap.mapcontext.layers.FLayer;
26

  
27

  
28
/**
29
 *
30
 * 05/02/2008
31
 * @author Nacho Brodin nachobrodin@gmail.com
32
 */
33
public class GeoprocessModule  extends Extension {
34
	//private ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager();
35

  
36
	/*
37
	 * (non-Javadoc)
38
	 * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
39
	 */
40
	public void execute(String actionCommand) {
41
		
42
	}
43

  
44
	/*
45
	 * (non-Javadoc)
46
	 * @see com.iver.andami.plugins.IExtension#initialize()
47
	 */
48
	public void initialize() {
49
	}
50

  
51
	/*
52
	 * (non-Javadoc)
53
	 * @see com.iver.andami.plugins.IExtension#isEnabled()
54
	 */
55
	public boolean isEnabled() {
56
		return true;
57
	}
58

  
59
	/*
60
	 * (non-Javadoc)
61
	 * @see com.iver.andami.plugins.IExtension#isVisible()
62
	 */
63
	public boolean isVisible() {
64
		return true;
65
	}
66

  
67
	/*
68
	 * (non-Javadoc)
69
	 * @see org.gvsig.raster.gui.IGenericToolBarMenuItem#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
70
	 */
71
	public void execute(ITocItem item, FLayer[] selectedItems) {
72

  
73
	}
74

  
75
	/*
76
	 * (non-Javadoc)
77
	 * @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getGroup()
78
	 */
79
	public String getGroup() {
80
		return null;
81
	}
82

  
83
	/*
84
	 * (non-Javadoc)
85
	 * @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getIcon()
86
	 */
87
	public Icon getIcon() {
88
		return null;
89
	}
90

  
91
	/*
92
	 * (non-Javadoc)
93
	 * @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getOrder()
94
	 */
95
	public int getOrder() {
96
		return 0;
97
	}
98

  
99
	/*
100
	 * (non-Javadoc)
101
	 * @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getText()
102
	 */
103
	public String getText() {
104
		return null;
105
	}
106

  
107
	/*
108
	 * (non-Javadoc)
109
	 * @see org.gvsig.raster.gui.IGenericToolBarMenuItem#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
110
	 */
111
	public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
112
		return this.isEnabled();
113
	}
114

  
115
	/*
116
	 * (non-Javadoc)
117
	 * @see org.gvsig.raster.gui.IGenericToolBarMenuItem#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
118
	 */
119
	public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
120
		return this.isVisible();
121
	}
122

  
123
	/*
124
	 * (non-Javadoc)
125
	 * @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getGroupOrder()
126
	 */
127
	public int getGroupOrder() {
128
		return 0;
129
	}
130
}
0 131

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.geoprocess.extension/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
    <modelVersion>4.0.0</modelVersion>
4
    <artifactId>org.gvsig.sextante.app.geoprocess.extension</artifactId>
5
    <packaging>jar</packaging>
6
    <name>org.gvsig.sextante.app.geoprocess.extension</name>
7
    <description>gvSIG Geoprocess</description>
8

  
9
    <parent>
10
        <groupId>org.gvsig</groupId>
11
        <artifactId>org.gvsig.sextante.app</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.buffer</artifactId>
19
            <version>0.6.0-SNAPSHOT</version>
20
            <scope>compile</scope>
21
        </dependency>
22
        <dependency>
23
            <groupId>org.gvsig</groupId>
24
            <artifactId>org.gvsig.sextante.app.algorithm.clip</artifactId>
25
            <version>0.6.0-SNAPSHOT</version>
26
            <scope>compile</scope>
27
        </dependency>
28
        <dependency>
29
            <groupId>org.gvsig</groupId>
30
            <artifactId>org.gvsig.sextante.app.algorithm.convexhull</artifactId>
31
            <version>0.6.0-SNAPSHOT</version>
32
            <scope>compile</scope>
33
        </dependency>
34
        <dependency>
35
            <groupId>org.gvsig</groupId>
36
            <artifactId>org.gvsig.sextante.app.algorithm.difference</artifactId>
37
            <version>0.6.0-SNAPSHOT</version>
38
            <scope>compile</scope>
39
        </dependency>
40
        <dependency>
41
            <groupId>org.gvsig</groupId>
42
            <artifactId>org.gvsig.sextante.app.algorithm.dissolve</artifactId>
43
            <version>0.6.0-SNAPSHOT</version>
44
            <scope>compile</scope>
45
        </dependency>
46
        <dependency>
47
            <groupId>org.gvsig</groupId>
48
            <artifactId>org.gvsig.sextante.app.algorithm.intersection</artifactId>
49
            <version>0.6.0-SNAPSHOT</version>
50
            <scope>compile</scope>
51
        </dependency>
52
        <dependency>
53
            <groupId>org.gvsig</groupId>
54
            <artifactId>org.gvsig.sextante.app.algorithm.merge</artifactId>
55
            <version>0.6.0-SNAPSHOT</version>
56
            <scope>compile</scope>
57
        </dependency>
58
        <dependency>
59
            <groupId>org.gvsig</groupId>
60
            <artifactId>org.gvsig.sextante.app.algorithm.reproject</artifactId>
61
            <version>0.6.0-SNAPSHOT</version>
62
            <scope>compile</scope>
63
        </dependency>
64
        <dependency>
65
            <groupId>org.gvsig</groupId>
66
            <artifactId>org.gvsig.sextante.app.algorithm.spatialjoin</artifactId>
67
            <version>0.6.0-SNAPSHOT</version>
68
            <scope>compile</scope>
69
        </dependency>
70
        <dependency>
71
            <groupId>org.gvsig</groupId>
72
            <artifactId>org.gvsig.sextante.app.algorithm.union</artifactId>
73
            <version>0.6.0-SNAPSHOT</version>
74
            <scope>compile</scope>
75
        </dependency>
76
        <dependency>
77
            <groupId>org.gvsig</groupId>
78
            <artifactId>org.gvsig.sextante.app.algorithm.xyshift</artifactId>
79
            <version>0.6.0-SNAPSHOT</version>
80
            <scope>compile</scope>
81
        </dependency>
82
    </dependencies>
83

  
84
    <profiles>
85
        <profile>
86
            <id>gvsig-install</id>
87
            <activation>
88
                <activeByDefault>true</activeByDefault>
89
            </activation>
90
            <properties>
91
                <!--  gvSIG installation folder -->
92
                <gvsig.install.dir>${basedir}/../../build/product</gvsig.install.dir>
93
            </properties>
94
        </profile>
95
    </profiles>
96
    <properties>
97
    	<package.info.dependencies>required: org.gvsig.sextante.app.extension -ge 0.6</package.info.dependencies>
98
	</properties>
99
</project>
0 100

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Thu Aug 18 10:20:48 CEST 2011
3
buildNumber=2040
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/distribution/distribution.xml
1
<assembly>
2
</assembly>
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.reproject/distribution/distribution.xml
1
<assembly>
2
</assembly>
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.reproject/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Thu Aug 18 10:21:39 CEST 2011
3
buildNumber=2042
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.reproject/src/main/java/org/gvsig/sextante/app/algorithm/reproject/ReprojectOperation.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.reproject;
22

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

  
26
import org.cresques.cts.ICoordTrans;
27
import org.cresques.cts.IProjection;
28
import org.gvsig.fmap.dal.exception.DataException;
29
import org.gvsig.fmap.dal.feature.EditableFeature;
30
import org.gvsig.fmap.dal.feature.Feature;
31
import org.gvsig.fmap.geom.exception.CreateGeometryException;
32
import org.gvsig.sextante.app.algorithm.base.core.GeometryOperation;
33

  
34
import es.unex.sextante.core.Sextante;
35

  
36
/**
37
 * Operation to reproject a Feature
38
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
39
 */
40
public class ReprojectOperation extends GeometryOperation {
41
	private ICoordTrans                      transf           = null;
42

  
43
	public ReprojectOperation(IProjection srcProj, IProjection dstProj) {
44
		this.transf = srcProj.getCT(dstProj);
45
	}
46

  
47
	/*
48
	 * (non-Javadoc)
49
	 * @see org.gvsig.sextante.app.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.Feature)
50
	 */
51
	@SuppressWarnings("unchecked")
52
	public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature feature) {
53
		List geomList = feature.getGeometries();
54
		try {
55
			if(geomList == null) {
56
				org.gvsig.fmap.geom.Geometry geom = feature.getDefaultGeometry();
57
				geom.reProject(transf);
58
				EditableFeature editFeat = feature.getEditable();
59
				editFeat.setDefaultGeometry(geom);
60
				persister.addFeature(feature, geom);
61
			} else {
62
				Iterator<org.gvsig.fmap.geom.Geometry> itGeom = geomList.iterator();
63
				EditableFeature editFeat = null;
64
				boolean first = true;
65
				int nGeom = 0;
66
				while(itGeom.hasNext()) {
67
					org.gvsig.fmap.geom.Geometry geom = itGeom.next();
68
					geom.reProject(transf);
69
					editFeat = feature.getEditable();
70
					editFeat.setGeometry(nGeom, geom);
71
					nGeom ++;
72
					if(first) 
73
						persister.addFeature(editFeat, geom);
74
					else 
75
						persister.addGeometryToExistingFeature(editFeat, geom);
76
				}
77
			}
78
		} catch (DataException e) {
79
			Sextante.addErrorToLog(e);
80
		} catch (CreateGeometryException e) {
81
			Sextante.addErrorToLog(e);
82
		}
83
		
84
		return lastEditFeature;
85
	}
86
	
87
	@Override
88
	public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput) {
89
	}
90
}
91

  
0 92

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.reproject/src/main/java/org/gvsig/sextante/app/algorithm/reproject/ReprojectParametersPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2010 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.reproject;
20

  
21
import java.awt.Dimension;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.Insets;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27

  
28
import javax.swing.ComboBoxModel;
29
import javax.swing.DefaultComboBoxModel;
30
import javax.swing.JCheckBox;
31
import javax.swing.JComboBox;
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34

  
35
import org.cresques.cts.IProjection;
36
import org.gvsig.app.gui.panels.CRSSelectPanel;
37
import org.gvsig.fmap.crs.CRSFactory;
38
import org.gvsig.sextante.app.extension.core.CompositeSourceOutputChannel;
39
import org.gvsig.sextante.app.extension.gui.AlgorithmOutputPanel;
40

  
41
import es.unex.sextante.core.GeoAlgorithm;
42
import es.unex.sextante.core.ObjectAndDescription;
43
import es.unex.sextante.core.OutputObjectsSet;
44
import es.unex.sextante.core.ParametersSet;
45
import es.unex.sextante.core.Sextante;
46
import es.unex.sextante.dataObjects.IVectorLayer;
47
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
48
import es.unex.sextante.gui.core.SextanteGUI;
49
import es.unex.sextante.outputs.Output;
50

  
51
/**
52
 * Panel for reproject algorithm
53
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
54
 */
55
public class ReprojectParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener {
56
	private static final long                serialVersionUID       = 1L;
57
	private GeoAlgorithm                     m_Algorithm            = null;
58
	private JComboBox                        layersCombo            = null;
59
	private JCheckBox                        selectionOnly          = null;
60
	//private AlgorithmOutputPanel             output                 = null;
61
	private JLabel                           projLabel              = null;
62
	private CRSSelectPanel                   projectionSrcSelector  = null;
63
	private IProjection                      targetLayerProjection  = null;
64
	private AlgorithmOutputPanel             algorithmOutputPanel   = null;
65
	public ReprojectParametersPanel() {
66
		super();
67
	}
68

  
69
    public void init(GeoAlgorithm algorithm) {
70
    	m_Algorithm = algorithm;
71
    	initGUI();
72
    	init();
73
    }
74

  
75
	private void initGUI() {
76
		GridBagLayout gbl = new GridBagLayout();
77
		this.setLayout(gbl);
78
		
79
		GridBagConstraints gbc = new GridBagConstraints();
80
		gbc.fill = GridBagConstraints.HORIZONTAL;
81
		gbc.weightx = 1.0;
82
		gbc.gridx = 0;
83
		gbc.gridy = 0;
84
		gbc.insets = new Insets(15, 5, 15, 0);
85
		this.add(getComboPanel(Sextante.getText("Input_layer"), getLayersCombo()), gbc);
86
		
87
		gbc.gridy = 1;
88
		gbc.insets = new Insets(0, 5, 15, 0);
89
		this.add(getSelectionCheck(), gbc);
90
		
91
		gbc.gridy = 2;
92
		this.add(getCurrentProjLabel(), gbc);
93
		
94
		gbc.gridy = 3;
95
		this.add(getProjectionSelector(), gbc);
96
		
97
		gbc.gridy = 4;
98
		gbc.fill = GridBagConstraints.BOTH;
99
		gbc.weighty = 1.0;
100
		gbc.weightx = 1.0;
101
		this.add(new JPanel(), gbc);
102
		
103
		gbc.gridy = 5;
104
		gbc.fill = GridBagConstraints.HORIZONTAL;
105
		gbc.weighty = 0.0;
106
		this.add(getAlgorithmOutputPanel(), gbc);
107
	}
108
	
109
	/**
110
	 * Gets the output panel
111
	 * @return
112
	 */
113
	private AlgorithmOutputPanel getAlgorithmOutputPanel() {
114
		if(algorithmOutputPanel == null)
115
		    algorithmOutputPanel = new AlgorithmOutputPanel();
116
		return algorithmOutputPanel;
117
	}
118
	
119
	/**
120
	 * Gets a new JPanel with the text and JComboBox 
121
	 * @param text
122
	 * @param combo
123
	 * @return
124
	 */
125
	public JPanel getComboPanel(String text, JComboBox combo) {
126
		JPanel panel = new JPanel();
127
		GridBagLayout gbl = new GridBagLayout();
128
		panel.setLayout(gbl);
129

  
130
		GridBagConstraints gbc = new GridBagConstraints();
131
		gbc.fill = GridBagConstraints.NONE;
132
		gbc.weightx = 0;
133
		gbc.gridx = 0;
134
		gbc.insets = new Insets(0, 2, 0, 50);
135
		JLabel label = new JLabel(text);
136
		label.setPreferredSize(new Dimension(80, 18));
137
		panel.add(label, gbc);
138

  
139
		gbc.fill = GridBagConstraints.HORIZONTAL;
140
		gbc.weightx = 1.0;
141
		gbc.gridx = 1;
142
		gbc.anchor = GridBagConstraints.EAST;
143
		gbc.insets = new Insets(0, 2, 0, 0);
144
		panel.add(combo, gbc);
145
		return panel;
146
	}
147
	
148
	/**
149
	 * Gets a ComboBox
150
	 * @return
151
	 */
152
	public JComboBox getLayersCombo() {
153
		if(layersCombo == null) {
154
			layersCombo = new JComboBox();
155
			layersCombo.setPreferredSize(new Dimension(0, 18));
156
			ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList());
157
			layersCombo.setModel(comboModel);
158
			layersCombo.addActionListener(this);
159
		}
160
		return layersCombo;
161
	}
162
	
163
	
164
	/**
165
	 * Gets a CheckBox
166
	 * @return
167
	 */
168
	public JCheckBox getSelectionCheck() {
169
		if(selectionOnly == null) {
170
			selectionOnly = new JCheckBox(Sextante.getText("Selected_geometries"));
171
		}
172
		return selectionOnly;
173
	}
174
	
175
	/**
176
	 * Panel with the projection selector
177
	 * @return
178
	 */
179
	private CRSSelectPanel getProjectionSelector() {
180
		if (projectionSrcSelector == null) {
181
			targetLayerProjection = CRSFactory.getCRS("EPSG:23030");
182
			projectionSrcSelector = CRSSelectPanel.getPanel(targetLayerProjection);
183
			projectionSrcSelector.getJLabel().setText(Sextante.getText("Proyeccion_Destino"));
184
			projectionSrcSelector.setPreferredSize(new java.awt.Dimension(330,35));
185
			projectionSrcSelector.addActionListener(new java.awt.event.ActionListener() {
186
				public void actionPerformed(java.awt.event.ActionEvent e) {
187
					if (projectionSrcSelector.isOkPressed()) {
188
						targetLayerProjection = projectionSrcSelector.getCurProj();
189
					}
190
				}
191
			});
192
		}
193
		projectionSrcSelector.setTransPanelActive(true);
194
		return projectionSrcSelector;
195
	}
196
	
197
	/**
198
	 * Gets the label with the current projection
199
	 * @return
200
	 */
201
	public JLabel getCurrentProjLabel() {
202
		if(projLabel == null)
203
			projLabel = new JLabel();
204
		return projLabel;
205
	}
206
	
207
	//------------------------------------------------------------
208
	
209
	/**
210
	 * Initialize actions
211
	 */
212
	private void init() {
213
		IVectorLayer layer = getSelectedVectorLayer();
214
		IProjection currentProj = (IProjection)layer.getCRS();
215
		getCurrentProjLabel().setText("Proj: " + currentProj.getAbrev());
216
	}
217
	
218
	/*
219
	 * (non-Javadoc)
220
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
221
	 */
222
	public void actionPerformed(ActionEvent e) {
223
		if(e.getSource() ==  getLayersCombo()) {
224

  
225
		}
226
	}
227
	
228
	@Override
229
	public boolean assignParameters() {
230
		try {
231
			ParametersSet params = m_Algorithm.getParameters();
232
			params.getParameter(ReprojectAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer());
233
			params.getParameter(ReprojectAlgorithm.SELECTED_GEOM).setParameterValue(getSelectionCheck().isSelected());
234
			String proj = getProjectionSelector().getCurProj().getAbrev();
235
			params.getParameter(ReprojectAlgorithm.DST_PROJECTION).setParameterValue(proj);
236
			
237
			OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
238
			Output out = ooSet.getOutput(ReprojectAlgorithm.RESULT);
239
			out.setOutputChannel(new CompositeSourceOutputChannel(getAlgorithmOutputPanel().getOutputParameters()));
240
			return true;
241
		} catch (Exception e) {
242
			Sextante.addErrorToLog(e);
243
			return false;
244
		}
245
	}
246

  
247
	@Override
248
	public void setOutputValue(String arg0, String arg1) {
249
		
250
	}
251

  
252
	@Override
253
	public void setParameterValue(String arg0, String arg1) {
254
		
255
	}
256
	
257
	/**
258
	 * Gets the input layer list
259
	 * @return
260
	 */
261
	private ObjectAndDescription[] getLayerList() {
262
		IVectorLayer[] layers = SextanteGUI.getInputFactory()
263
					.getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG);
264
		ObjectAndDescription[] oad = new ObjectAndDescription[layers.length];
265
		for (int i = 0; i < layers.length; i++)
266
			oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
267
		return oad;
268
	}
269
	
270
	/**
271
	 * Gets the selected vector layer in the JComboBox
272
	 * @return
273
	 */
274
	private IVectorLayer getSelectedVectorLayer() {
275
		if(layersCombo.getSelectedItem() != null)
276
			return (IVectorLayer)((ObjectAndDescription)layersCombo.getSelectedItem()).getObject();
277
		return null;
278
	}
279
	
280
	/**
281
	 * Gets the field list of the selected layer
282
	 * @return
283
	 */
284
	public String[] getFieldList() {
285
		IVectorLayer layer = getSelectedVectorLayer();
286
		String[] data = new String[layer.getFieldCount()];
287
		for (int i = 0; i < layer.getFieldCount(); i++) 
288
			data[i] = layer.getFieldName(i);
289
		return data;
290
	}
291
}
0 292

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.reproject/src/main/java/org/gvsig/sextante/app/algorithm/reproject/ReprojectLibrary.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.reproject;
22

  
23
import es.unex.sextante.core.Sextante;
24
import es.unex.sextante.gui.core.SextanteGUI;
25

  
26
import org.gvsig.i18n.Messages;
27
import org.gvsig.sextante.app.algorithm.base.core.AlgorithmAbstractLibrary;
28
import org.gvsig.tools.library.LibraryException;
29

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

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

  
42
	@Override
43
	protected void doPostInitialize() throws LibraryException {
44
		Messages.addResourceFamily(
45
				"org.gvsig.sextante.app.algorithm.reproject.reproject",
46
				ReprojectLibrary.class.getClassLoader(),
47
				ReprojectLibrary.class.getClass().getName());
48
		setLanguageStrings("org.gvsig.sextante.app.algorithm.reproject.reproject");
49
		Sextante.addGeoProcess(ReprojectAlgorithm.class, text);
50
		SextanteGUI.addCustomParametersPanel(ReprojectAlgorithm.class, ReprojectParametersPanel.class, null);
51
	}
52

  
53
}
0 54

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.reproject/src/main/java/org/gvsig/sextante/app/algorithm/reproject/ReprojectAlgorithm.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2010 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.reproject;
20

  
21
import org.cresques.cts.IProjection;
22
import org.gvsig.fmap.crs.CRSFactory;
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
 * Reproject algorithm
38
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
39
 */
40
public class ReprojectAlgorithm extends gvGeoAlgorithm {
41
	public static final String        RESULT            = "RESULT";
42
	public static final String        LAYER             = "LAYER";
43
	public static final String        SELECTED_GEOM     = "SELECTED_GEOM";
44
	public static final String        DST_PROJECTION    = "DST_PROJECTION";
45
	
46
	/*
47
	 * (non-Javadoc)
48
	 * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
49
	 */
50
	public void defineCharacteristics() {
51
		setName(Sextante.getText("Reproject"));
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.addBoolean(SELECTED_GEOM, 
61
									Sextante.getText("Selected_geometries"), 
62
									false);
63
			m_Parameters.addString(DST_PROJECTION, Sextante.getText("Projection"));
64
			addOutputVectorLayer(RESULT,
65
								Sextante.getText("Reproject"),
66
								OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
67
		} catch (RepeatedParameterNameException e) {
68
			Sextante.addErrorToLog(e);
69
		}
70
	}
71
	
72
	/*
73
	 * (non-Javadoc)
74
	 * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
75
	 */
76
	public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
77
		IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
78
		boolean selectedGeom = m_Parameters.getParameterValueAsBoolean(SELECTED_GEOM);
79
		String dstProj = m_Parameters.getParameterValueAsString(DST_PROJECTION);
80
		
81
		FeatureStore storeLayer = null;
82
		if(layer instanceof gvVectorLayer)
83
			storeLayer = ((gvVectorLayer)layer).getFeatureStore();
84
		else
85
			return false;
86
		
87
		try {
88
			FeatureSet features = null;
89
			features = storeLayer.getFeatureSet();
90
			FeatureType featureType = features.getDefaultFeatureType();
91
			FeatureStore outFeatStore = buildOutPutStore(featureType, layer.getShapeType(), Sextante.getText("Reproject"), RESULT);
92
			IProjection projOutput = CRSFactory.getCRS(dstProj);
93
			ReprojectOperation operation = new ReprojectOperation(((IProjection)layer.getCRS()), projOutput);
94
			operation.setProgressModel(this);
95
			operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
96
		} catch (DataException e) {
97
			Sextante.addErrorToLog(e);
98
			return false;
99
		}
100
		return true;
101
	}
102
}
0 103

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.reproject/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.sextante.app.algorithm.reproject.ReprojectLibrary
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.reproject/src/main/resources/org/gvsig/sextante/app/algorithm/reproject/reproject_en.properties
1
gvSIG_Algorithms=gvSIG algorithms
2
Reproject=Reproject
3
Input_layer=Input cover
4
Selected_geometries=Selected geometries
5
Projection=Projection
0 6

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.reproject/src/main/resources/org/gvsig/sextante/app/algorithm/reproject/reproject_es.properties
1
gvSIG_Algorithms=Algoritmos gvSIG
2
Reproject=Reproyecci?n
3
Input_layer=Capa de entrada
4
Selected_geometries=Geometrias seleccionadas
5
Projection=Proyecci?n
0 6

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.reproject/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.reproject</artifactId>
6
  <packaging>jar</packaging>
7
  <name>org.gvsig.sextante.app.algorithm.reproject</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
            <scope>compile</scope>
21
   		</dependency>
22
   		<dependency>
23
			<groupId>org.geotools</groupId>
24
			<artifactId>gt2-main</artifactId>
25
            <scope>compile</scope>
26
		</dependency>
27
	</dependencies>
28
	
29
</project>
0 30

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.spatialjoin/src/main/resources/org/gvsig/sextante/app/algorithm/spatialjoin/spatialjoin_en.properties
1
gvSIG_Algorithms=gvSIG algorithms
2
Spatialjoin=Spatial Join
3
Input_layer=Input cover
4
Selected_geometries=Selected geometries
5
use_the_nearest=Use the nearest
6
input_layers=Input coverages
7
input_layers_join=Overlay layer
8
summary_function=Summary function
9
selected_geometries=Selected features
0 10

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.spatialjoin/src/main/resources/org/gvsig/sextante/app/algorithm/spatialjoin/spatialjoin_es.properties
1
gvSIG_Algorithms=Algoritmos gvSIG
2
Spatialjoin=Spatial Join
3
Input_layer=Capa de entrada
4
Selected_geometries=Geometrias seleccionadas
5
use_the_nearest=Usar el m?s cercano
6
input_layers=Capas de entrada
7
input_layers_join=Capa de revestimiento
8
summary_function=Funci?n resumen
9
selected_geometries=Geometrias seleccionadas
10
use_the_nearest=Usar el m?s cercano
0 11

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.spatialjoin/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.sextante.app.algorithm.spatialjoin.SpatialJoinLibrary
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.spatialjoin/src/main/java/org/gvsig/sextante/app/algorithm/spatialjoin/SpatialJoinAlgorithm.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2010 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.spatialjoin;
20

  
21
import java.util.ArrayList;
22
import java.util.HashMap;
23
import java.util.Iterator;
24

  
25
import org.gvsig.fmap.dal.DALLocator;
26
import org.gvsig.fmap.dal.DataManager;
27
import org.gvsig.fmap.dal.DataTypes;
28
import org.gvsig.fmap.dal.exception.DataException;
29
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
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.sextante.app.algorithm.base.core.GeometryOperation;
34
import org.gvsig.sextante.app.algorithm.dissolve.DissolveRule;
35
import org.gvsig.sextante.app.algorithm.dissolve.IDissolveRule;
36
import org.gvsig.sextante.app.algorithm.dissolve.Summary;
37
import org.gvsig.sextante.app.extension.core.gvGeoAlgorithm;
38
import org.gvsig.sextante.app.extension.core.gvVectorLayer;
39

  
40
import es.unex.sextante.core.Sextante;
41
import es.unex.sextante.dataObjects.IVectorLayer;
42
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
43
import es.unex.sextante.exceptions.RepeatedParameterNameException;
44
import es.unex.sextante.exceptions.UnsupportedOutputChannelException;
45
import es.unex.sextante.outputs.OutputVectorLayer;
46

  
47
/**
48
 * Spatial join algorithm
49
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
50
 */
51
public class SpatialJoinAlgorithm extends gvGeoAlgorithm {
52
	public static final String        NEW_FIELD         = "NUM_RELA";
53
	public static final String        RESULT            = "RESULT";
54
	public static final String        LAYER1            = "LAYER1";
55
	public static final String        LAYER2            = "LAYER2";
56
	public static final String        SELECTED_GEOM     = "SELECTED_GEOM";
57
	public static final String        NEAREST           = "NEAREST";
58
	public static final String        FUNCTION_LIST     = "FUNCTION_LIST";
59
	public static final String        Summary[]         = {"Min", "Max", "Sum", "Avg"};
60
	private boolean                   funcList[]        = new boolean[Summary.length];
61
	private HashMap<String, String>   funcMap           = new HashMap<String, String>();
62
	
63
	/*
64
	 * (non-Javadoc)
65
	 * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
66
	 */
67
	public void defineCharacteristics(){
68
		setName(Sextante.getText("Spatialjoin"));
69
		setGroup(Sextante.getText("gvSIG_Algorithms"));
70
		setGeneratesUserDefinedRasterOutput(false);
71
		
72
		try {
73
			m_Parameters.addInputVectorLayer(LAYER1, 
74
												Sextante.getText("Input_layer"), 
75
												IVectorLayer.SHAPE_TYPE_WRONG, 
76
												true);
77
			m_Parameters.addInputVectorLayer(LAYER2, 
78
												Sextante.getText( "Input_layer"), 
79
												IVectorLayer.SHAPE_TYPE_WRONG, 
80
												true);
81
			m_Parameters.addBoolean(SELECTED_GEOM, Sextante.getText("Selected_geometries"), false);
82
			m_Parameters.addBoolean(NEAREST, Sextante.getText("use_the_nearest"), false);
83
			m_Parameters.addString(FUNCTION_LIST, Sextante.getText("Function_list"));
84
		} catch (RepeatedParameterNameException e) {
85
			Sextante.addErrorToLog(e);
86
		}
87
		addOutputVectorLayer(RESULT,
88
								Sextante.getText("Spatialjoin"),
89
								OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
90
	}
91
	
92
	/*
93
	 * (non-Javadoc)
94
	 * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
95
	 */
96
	public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
97
		IVectorLayer layer1 = m_Parameters.getParameterValueAsVectorLayer(LAYER1);
98
		IVectorLayer layer2 = m_Parameters.getParameterValueAsVectorLayer(LAYER2);
99
		boolean selectedGeom = m_Parameters.getParameterValueAsBoolean(SELECTED_GEOM);
100
		boolean nearest = m_Parameters.getParameterValueAsBoolean(NEAREST);
101
		String functionList = m_Parameters.getParameterValueAsString(FUNCTION_LIST);
102
		loadSummary(functionList);
103

  
104
		gvVectorLayer lyr1 = null;
105
		gvVectorLayer lyr2 = null;
106
		if(layer2 instanceof gvVectorLayer && layer1 instanceof gvVectorLayer) { 
107
			lyr2 = ((gvVectorLayer)layer2);
108
			lyr1 = ((gvVectorLayer)layer1);
109
		} else 
110
			return false;
111

  
112
		DataManager dataManager = DALLocator.getDataManager();
113

  
114
		//Builds a new JSIRTree index. To do that we have to replace the default index and 
115
		//when the operation has finished then it restores the original default index 
116
		String indexName = "GEOMETRY";
117
		
118
		try {
119
			indexName = lyr2.getFeatureStore().getDefaultFeatureType().getDefaultGeometryAttributeName();
120
			FeatureAttributeDescriptor fat = lyr2.getFeatureStore().getDefaultFeatureType().getAttributeDescriptor(indexName);
121
			String defaultIndex = dataManager
122
					.getDefaultFeatureIndexProviderName(fat.getDataType()
123
							.getType());
124
			dataManager.setDefaultFeatureIndexProviderName(fat.getDataType()
125
					.getType(), "JSIRTree");
126
			lyr2.getFeatureStore().createIndex(lyr2.getFeatureStore().getDefaultFeatureType(), indexName, indexName + "_idx");
127
			dataManager.setDefaultFeatureIndexProviderName(fat.getDataType()
128
					.getType(), defaultIndex);
129
		} catch (DataException e) {
130
			Sextante.addErrorToLog(e);
131
		}
132

  
133
		//Builds the output and computes the operation
134
		try {
135
			FeatureSet features = null;
136
			features = lyr1.getFeatureStore().getFeatureSet();
137
			FeatureType featureType1 = features.getDefaultFeatureType();
138
			features = lyr2.getFeatureStore().getFeatureSet();
139
			FeatureType featureType2 = features.getDefaultFeatureType();
140
			
141
			GeometryOperation operation = null;
142
			FeatureStore outFeatStore = null;
143
			
144
			if(nearest) {
145
				outFeatStore = buildOutPutStoreFromUnion(featureType1, 
146
						featureType2, 
147
						lyr1.getShapeType(), 
148
						Sextante.getText("SpatialJoin"), 
149
						RESULT, 
150
						"DIST", 
151
						Double.class);
152

  
153
				operation = new SpatiallyIndexedSpatialJoinOperation(lyr2, indexName + "_idx");
154
			} else {
155
				outFeatStore = buildSpatialJoinOutPutStore(featureType1,
156
						lyr1.getShapeType(), 
157
						Sextante.getText("SpatialJoin"), 
158
						RESULT);
159
				IDissolveRule rule = new DissolveRule(0, funcMap);
160
				Summary summary = new Summary(rule, outFeatStore.getDefaultFeatureType());
161
				operation = new IntersectsSpatialJoinOperation(lyr2, indexName + "_idx", summary);
162
			}
163
			
164
			operation.setProgressModel(this);
165
			operation.computesGeometryOperation(lyr1.getFeatureStore(), 
166
					outFeatStore, 
167
					attrNames, 
168
					selectedGeom, 
169
					true);		
170
		} catch (DataException e) {
171
			Sextante.addErrorToLog(e);
172
		}
173

  
174
		return true;
175
	}
176

  
177
	/**
178
	 * Checks if the parameter is in Summary list
179
	 * @param it
180
	 * @return the position in the list
181
	 */
182
	private int isInList(String it) {
183
		for (int i = 0; i < Summary.length; i++) {
184
			if(Summary[i].compareTo(it) == 0)
185
				return i;
186
		}
187
		return -1;
188
	}
189
	
190
	/**
191
	 * Loads the list of functions to use
192
	 * @param functionList
193
	 */
194
	private void loadSummary(String functionList) {
195
		String[] attrList = functionList.split(";");
196
		for (int i = 0; i < attrList.length; i++) {
197
			String[] func = attrList[i].split(",");
198
			for (int j = 1; j < func.length; j++) {
199
				int pos = isInList(func[j]);
200
				if(pos != -1) {
201
					funcList[pos] = true;
202
					funcMap.put(Summary[pos], func[0]);
203
				}
204
			}
205
		}
206
	}
207
	
208
	/**
209
	 * Builds the output FeatureStore 
210
	 * @param featureType
211
	 * @return FeatureStore
212
	 */
213
	@SuppressWarnings("unchecked")
214
	protected FeatureStore buildSpatialJoinOutPutStore(FeatureType featureType1,
215
											int shapeType,
216
											String sextanteLayerName, 
217
											String sextanteLayerLabel) {
218
		ArrayList<Class> typesList = new ArrayList<Class>();
219
		ArrayList<String> attr = new ArrayList<String>();
220
		
221
		Iterator it = featureType1.iterator();
222
		while( it.hasNext() ) {
223
			FeatureAttributeDescriptor attribute = (FeatureAttributeDescriptor)it.next();
224
			if (attribute.getDataType().getType() != DataTypes.GEOMETRY) {
225
				attr.add(attribute.getName());
226
				typesList.add(attribute.getObjectClass());
227
			}
228
		}
229
		
230
		for (int i = 0; i < funcList.length; i++) {
231
			if(funcList[i]) {
232
				String fieldName = funcMap.get(Summary[i]);
233
				if(fieldName.length() >= 6)
234
					fieldName = fieldName.substring(0, 7);
235
				attr.add(fieldName + "_" + Summary[i]);
236
				typesList.add(Double.class);
237
			}
238
		}
239
		
240
		attr.add(NEW_FIELD);
241
		typesList.add(Integer.class);
242
		
243
		attrNames = new String[attr.size()];
244
		attr.toArray(attrNames);
245
		Class[] types = new Class[typesList.size()];
246
		typesList.toArray(types);
247
		
248
		try {
249
			IVectorLayer output = getNewVectorLayer(sextanteLayerLabel,
250
													sextanteLayerName,
251
													shapeType, types, attrNames);
252
			return ((gvVectorLayer)output).getFeatureStore();
253
		} catch (UnsupportedOutputChannelException e) {
254
			Sextante.addErrorToLog(e);
255
		}
256
		return null;
257
	}
258
	
259
}
0 260

  
org.gvsig.sextante/tags/gvSIG_v2_0_0_Build_2041/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.spatialjoin/src/main/java/org/gvsig/sextante/app/algorithm/spatialjoin/SpatialJoinParametersPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2010 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.spatialjoin;
20

  
21
import java.awt.Dimension;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.Insets;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27

  
28
import javax.swing.ComboBoxModel;
29
import javax.swing.DefaultComboBoxModel;
30
import javax.swing.JCheckBox;
31
import javax.swing.JComboBox;
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34

  
35
import org.gvsig.gui.beans.table.TableContainer;
36
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
37
import org.gvsig.sextante.app.extension.core.CompositeSourceOutputChannel;
38
import org.gvsig.sextante.app.extension.gui.AlgorithmOutputPanel;
39

  
40
import es.unex.sextante.core.GeoAlgorithm;
41
import es.unex.sextante.core.ObjectAndDescription;
42
import es.unex.sextante.core.OutputObjectsSet;
43
import es.unex.sextante.core.ParametersSet;
44
import es.unex.sextante.core.Sextante;
45
import es.unex.sextante.dataObjects.IVectorLayer;
46
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
47
import es.unex.sextante.gui.core.SextanteGUI;
48
import es.unex.sextante.outputs.Output;
49

  
50
/**
51
 * Panel for dissolve algorithm
52
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
53
 */
54
public class SpatialJoinParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener {
55
	private static final long                serialVersionUID   = 1L;
56
	private GeoAlgorithm                     m_Algorithm        = null;
57
	private JComboBox                        layersCombo        = null;
58
	private JComboBox                        layersJoinCombo    = null;
59
	private JCheckBox                        selectionOnly      = null;
60
	private JCheckBox                        nearest       = null;
61
	private AlgorithmOutputPanel             output             = null;
62
	private final String[]                   columnNames        = { "Min", "Max", "Sum", "Avg", "Field ID" };
63
	private final int[]                      columnWidths       = { 35, 35, 35, 35, 334 };
64
	private TableContainer                   table              = null;
65
 	
66
	public SpatialJoinParametersPanel() {
67
		super();
68
	}
69

  
70
    public void init(GeoAlgorithm algorithm) {
71
    	m_Algorithm = algorithm;
72
    	initGUI();
73
    }
74

  
75
	private void initGUI() {
76
		GridBagLayout gbl = new GridBagLayout();
77
		this.setLayout(gbl);
78
		
79
		GridBagConstraints gbc = new GridBagConstraints();
80
		gbc.fill = GridBagConstraints.HORIZONTAL;
81
		gbc.weightx = 1.0;
82
		gbc.gridx = 0;
83
		gbc.gridy = 0;
84
		gbc.insets = new Insets(0, 0, 8, 0);
85
		this.add(getComboPanel(Sextante.getText("input_layers"), getLayers1Combo()), gbc);
86
		
87
		gbc.gridy = 1;
88
		this.add(getComboPanel(Sextante.getText("input_layers_join"), getLayers2Combo()), gbc);
89
		
90
		gbc.gridy = 2;
91
		this.add(getSelectionCheck(), gbc);
92
		
93
		gbc.gridy = 3;
94
		this.add(getNearestCheck(), gbc);
95
		
96
		gbc.gridy = 4;
97
		this.add(new JLabel(Sextante.getText("summary_function")), gbc);
98
		
99
		gbc.gridy = 5;
100
		gbc.fill = GridBagConstraints.BOTH;
101
		gbc.insets = new Insets(0, 0, 12, 0);
102
		gbc.weighty = 1.0;
103
		this.add(getRadioButtonTable(), gbc);
104
		
105
		gbc.gridy = 6;
106
		gbc.fill = GridBagConstraints.HORIZONTAL;
107
		gbc.weighty = 0.0;
108
		this.add(getAlgorithmOutputPanel(), gbc);
109
		
110
		initTable();
111
		getRadioButtonTable().setVisible(false);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff