Revision 218

View differences:

org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/pom.xml
17 17
	</parent>
18 18

  
19 19
	<scm>
20
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-geoprocess/org.gvsig.geoprocess/trunk/org.gvsig.geoprocess</connection>
21
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-geoprocess/org.gvsig.geoprocess/trunk/org.gvsig.geoprocess</developerConnection>
22
        <url>https://devel.gvsig.org/redmine/projects/gvsig-geoprocess/repository/show/org.gvsig.geoprocess/trunk/org.gvsig.geoprocess</url>
23
    </scm>
20
		<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-geoprocess/org.gvsig.geoprocess/trunk/org.gvsig.geoprocess</connection>
21
		<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-geoprocess/org.gvsig.geoprocess/trunk/org.gvsig.geoprocess</developerConnection>
22
		<url>https://devel.gvsig.org/redmine/projects/gvsig-geoprocess/repository/show/org.gvsig.geoprocess/trunk/org.gvsig.geoprocess</url>
23
	</scm>
24 24

  
25 25
	<repositories>
26 26
		<repository>
......
40 40
		</repository>
41 41
	</repositories>
42 42

  
43
    <dependencyManagement>
44
        <dependencies>
45
            <dependency>
46
                <groupId>org.gvsig</groupId>
47
                <artifactId>org.gvsig.core.maven.dependencies</artifactId>
48
                <version>2.0.1-SNAPSHOT</version>
49
                <type>pom</type>
50
                <scope>import</scope>
51
            </dependency>
52
            <dependency>
53
            	<groupId>org.gvsig</groupId>
54
            	<artifactId>org.gvsig.raster.lib.api</artifactId>
55
            	<version>2.0.0-SNAPSHOT</version>
56
            </dependency>
57
            <dependency>
58
                <groupId>es.unex.sextante</groupId>
59
                <artifactId>sextante-libmath</artifactId>
60
                <version>20111019-SNAPSHOT</version>
61
            </dependency>            
62
            <dependency>
63
                <groupId>es.unex.sextante</groupId>
64
                <artifactId>sextante</artifactId>
65
                <version>20111019-SNAPSHOT</version>
66
            </dependency>            
67
            <dependency>
68
                <groupId>es.unex.sextante</groupId>
69
                <artifactId>sextante-gui</artifactId>
70
                <version>20111019-SNAPSHOT</version>
71
            </dependency>            
72
            <dependency>
73
                <groupId>es.unex.sextante</groupId>
74
                <artifactId>sextante-algorithms</artifactId>
75
                <version>20111019-SNAPSHOT</version>
76
            </dependency>
77
            <dependency>
78
            	<groupId>org.gvsig</groupId>
79
            	<artifactId>org.gvsig.raster.fmap</artifactId>
80
            	<version>2.0.0-SNAPSHOT</version>
81
            </dependency>            
82
            <dependency>
83
            	<groupId>org.gvsig</groupId>
84
            	<artifactId>org.gvsig.app.document.table.app.mainplugin</artifactId>
85
            	<version>2.0.0-SNAPSHOT</version>
86
            </dependency>
87
        </dependencies>
88
    </dependencyManagement>
43
	<dependencyManagement>
44
		<dependencies>
45
			<dependency>
46
				<groupId>org.gvsig</groupId>
47
				<artifactId>org.gvsig.core.maven.dependencies</artifactId>
48
				<version>2.0.1-SNAPSHOT</version>
49
				<type>pom</type>
50
				<scope>import</scope>
51
			</dependency>
52
			<dependency>
53
				<groupId>org.gvsig</groupId>
54
				<artifactId>org.gvsig.raster.lib.api</artifactId>
55
				<version>2.0.0-SNAPSHOT</version>
56
			</dependency>
57
			<dependency>
58
				<groupId>es.unex.sextante</groupId>
59
				<artifactId>sextante-libmath</artifactId>
60
				<version>20111019-SNAPSHOT</version>
61
			</dependency>
62
			<dependency>
63
				<groupId>es.unex.sextante</groupId>
64
				<artifactId>sextante</artifactId>
65
				<version>20111019-SNAPSHOT</version>
66
			</dependency>
67
			<dependency>
68
				<groupId>es.unex.sextante</groupId>
69
				<artifactId>sextante-gui</artifactId>
70
				<version>20111019-SNAPSHOT</version>
71
			</dependency>
72
			<dependency>
73
				<groupId>es.unex.sextante</groupId>
74
				<artifactId>sextante-algorithms</artifactId>
75
				<version>20111019-SNAPSHOT</version>
76
			</dependency>
77
			<dependency>
78
				<groupId>org.gvsig</groupId>
79
				<artifactId>org.gvsig.raster.fmap</artifactId>
80
				<version>2.0.0-SNAPSHOT</version>
81
			</dependency>
82
			<dependency>
83
				<groupId>org.gvsig</groupId>
84
				<artifactId>org.gvsig.app.document.table.app.mainplugin</artifactId>
85
				<version>2.0.0-SNAPSHOT</version>
86
			</dependency>
87
			<dependency>
88
				<groupId>org.gvsig</groupId>
89
				<artifactId>org.gvsig.app</artifactId>
90
				<version>2.0-SNAPSHOT</version>
91
			</dependency>
92
		</dependencies>
93
	</dependencyManagement>
89 94

  
90 95
	<modules>
91 96
		<module>org.gvsig.geoprocess.lib</module>
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/pom.xml
15 15
	<dependencies>
16 16
		<dependency>
17 17
			<groupId>org.gvsig</groupId>
18
			<artifactId>org.gvsig.geoprocess.lib.api</artifactId>
19
			<version>1.0.0-SNAPSHOT</version>
20
			<scope>compile</scope>
21
		</dependency>
22
		<dependency>
23
			<groupId>org.gvsig</groupId>
24
			<artifactId>org.gvsig.geoprocess.lib.sextante</artifactId>
25
			<version>1.0.0-SNAPSHOT</version>
26
			<scope>compile</scope>
27
		</dependency>
28
		<dependency>
29
			<groupId>org.gvsig</groupId>
18 30
			<artifactId>org.gvsig.about.api</artifactId>
19 31
			<scope>compile</scope>
20 32
		</dependency>
......
41 53
		<dependency>
42 54
			<groupId>org.gvsig</groupId>
43 55
			<artifactId>org.gvsig.app</artifactId>
44
			<version>2.0-SNAPSHOT</version>
45 56
			<scope>compile</scope>
46 57
		</dependency>
47 58
		<dependency>
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/distribution/distribution.xml
45 45
			</outputDirectory>
46 46
			<includes>
47 47
				<include>org.gvsig:org.gvsig.geoprocess.app.mainplugin</include>
48
				<include>org.gvsig:org.gvsig.geoprocess.lib.api</include>
49
				<include>org.gvsig:org.gvsig.geoprocess.lib.sextante</include>
48 50
				<include>es.unex.sextante:sextante-libmath</include>
49 51
				<include>gnu.trove:trove</include>
50 52
				<include>gov.nist.math:jama</include>
......
57 59
				<include>jgraph:jgraph</include>
58 60
				<include>tablelayout:TableLayout</include>
59 61
				<include>org.japura:org.japura</include>
60
				<!-- Sextante algorithms -->
61
				<include>es.unex.sextante:sextante-algorithms</include>
62
				<include>gishur:gishur_core</include>
63
				<include>gishur:gishur_x</include>
64 62
			</includes>
65 63
		</dependencySet>
66 64
	</dependencySets>
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/GeoProcessLocator.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.geoprocess;
23

  
24
import org.gvsig.tools.locator.BaseLocator;
25
import org.gvsig.tools.locator.Locator;
26

  
27
/**
28
 * Locator to access the GeoProcess library.
29
 * 
30
 * @author gvSIG Team
31
 * @version $Id$
32
 */
33
public class GeoProcessLocator extends BaseLocator {
34

  
35
    private static final String LOCATOR_NAME = "GeoProcess.locator";
36

  
37
    public static final String GEOPROCESS_MANAGER_NAME = "GeoProcess.manager";
38

  
39
    public static final String GEOPROCESS_MANAGER_DESCRIPTION =
40
        "GeoProcess Manager";
41

  
42
    /**
43
     * Unique instance.
44
     */
45
    private static final GeoProcessLocator instance = new GeoProcessLocator();
46

  
47
    /**
48
     * Return the Singleton instance.
49
     * 
50
     * @return the Singleton instance
51
     */
52
    public static GeoProcessLocator getInstance() {
53
        return instance;
54
    }
55

  
56
    /**
57
     * Return the {@link Locator}'s name.
58
     * 
59
     * @return a String with the {@link Locator}'s name
60
     */
61
    @Override
62
    public String getLocatorName() {
63
        return LOCATOR_NAME;
64
    }
65

  
66
    /**
67
     * Gets the instance of the {@link GeoProcessManager} registered.
68
     * 
69
     * @return {@link GeoProcessManager}
70
     */
71
    public static GeoProcessManager getGeoProcessManager() {
72
        return (GeoProcessManager) getInstance().get(GEOPROCESS_MANAGER_NAME);
73
    }
74

  
75
    /**
76
     * Registers the Class implementing the {@link GeoProcessManager} interface.
77
     * 
78
     * @param clazz
79
     *            implementing the {@link GeoProcessManager} interface
80
     */
81
    public static void registerGeoProcessManager(
82
        Class<? extends GeoProcessManager> clazz) {
83
        getInstance().register(GEOPROCESS_MANAGER_NAME,
84
            GEOPROCESS_MANAGER_DESCRIPTION, clazz);
85
    }
86

  
87
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/GeoProcessLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.geoprocess;
23

  
24
import org.gvsig.tools.library.AbstractLibrary;
25
import org.gvsig.tools.library.LibraryException;
26

  
27
/**
28
 * GeoProcess API library.
29
 * 
30
 * @author gvSIG Team
31
 * @version $Id$
32
 */
33
public class GeoProcessLibrary extends AbstractLibrary {
34

  
35
    @Override
36
    public void doRegistration() {
37
        registerAsAPI(GeoProcessLibrary.class);
38
    }
39

  
40
    @Override
41
    protected void doInitialize() throws LibraryException {
42
        // Nothing to do
43
    }
44

  
45
    @Override
46
    protected void doPostInitialize() throws LibraryException {
47
        // Nothing to do
48
    }
49

  
50
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/GeoProcessManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.geoprocess;
23

  
24
import java.util.Map;
25

  
26
import org.cresques.cts.IProjection;
27

  
28
/**
29
 * Manager for the GeoProcess API.
30
 * 
31
 * @author gvSIG Team
32
 * @version $Id$
33
 */
34
public interface GeoProcessManager {
35

  
36
    public static final double EARTH_RADIUS = 6378137d;
37

  
38
    /**
39
     * For computing with geodetic coordinates:
40
     * returns the angular measure (in radians)
41
     * for a distance over the earth along a
42
     * meridiam.
43
     * Because this consideration is an approximation,
44
     * we consideer the eart like an sphere (not an
45
     * ellipsoid)
46
     * 
47
     * @param dist
48
     *            distance in meters
49
     * @return arc of meridian whose length is the specified
50
     *         distance
51
     */
52
    double toSexaAngularMeasure(double dist);
53

  
54
    /**
55
     * Converts a distance entered by user in the GUI in the same distance
56
     * in internal units (measure units)
57
     */
58
    double getInInternalUnits(double userEntryDistance, IProjection proj,
59
        int distanceUnits, int mapUnits);
60

  
61
    /**
62
     * <p>
63
     * Gets the measurement unit used by this view port for the map.
64
     * </p>
65
     * 
66
     * @return Returns the current map measure unit
67
     */
68
    int getMapUnits();
69

  
70
    /**
71
     * <p>
72
     * Returns the measurement unit of this view port used for measuring
73
     * distances and displaying information.
74
     * </p>
75
     * 
76
     * @return the measurement unit of this view used for measuring distances
77
     *         and displaying information
78
     */
79
    int getDistanceUnits();
80

  
81
    void registerGeoProcess(Class<? extends GeoProcess> geoProcessClazz,
82
        Map<String, String> localeStrings);
83
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/ProgressModel.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;
22

  
23
/**
24
 * Interface to assign the bar increment
25
 * 
26
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
27
 * @author gvSIG Team
28
 */
29
public interface ProgressModel {
30
	/**
31
	 * Assigns the new bar position
32
	 * @param iStep
33
	 */
34
	public void setProgress(int iStep);
35
	/**
36
	 * Sets the number of steps
37
	 * @param nSteps
38
	 */
39
	public void setTotalNumberOfSteps(int nSteps);
40
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/GeoProcess.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.geoprocess;
23

  
24
/**
25
 * GeoProcess API.
26
 * 
27
 * @author gvSIG Team
28
 * @version $Id$
29
 */
30
public interface GeoProcess extends ProgressModel {
31

  
32
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/gui/gvPostProcessTaskFactory.java
1
package org.gvsig.geoprocess.gui;
2

  
3
import es.unex.sextante.core.GeoAlgorithm;
4
import es.unex.sextante.gui.core.IPostProcessTaskFactory;
5

  
6
public class gvPostProcessTaskFactory
7
         implements
8
            IPostProcessTaskFactory {
9

  
10
   public Runnable getPostProcessTask(final GeoAlgorithm alg,
11
                                      final boolean bShowResultsWindow) {
12

  
13
      return new gvPostProcessTask(alg, bShowResultsWindow);
14

  
15
   }
16

  
17
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/gui/gvInputFactory.java
1
package org.gvsig.geoprocess.gui;
2

  
3
import java.awt.geom.Rectangle2D;
4
import java.util.ArrayList;
5
import java.util.List;
6

  
7
import es.unex.sextante.core.AbstractInputFactory;
8
import es.unex.sextante.core.NamedExtent;
9
import es.unex.sextante.dataObjects.I3DRasterLayer;
10
import es.unex.sextante.dataObjects.IDataObject;
11

  
12
import org.gvsig.andami.PluginServices;
13
import org.gvsig.app.extension.ProjectExtension;
14
import org.gvsig.app.project.Project;
15
import org.gvsig.app.project.documents.Document;
16
import org.gvsig.app.project.documents.table.TableDocument;
17
import org.gvsig.app.project.documents.table.TableManager;
18
import org.gvsig.app.project.documents.view.DefaultViewDocument;
19
import org.gvsig.app.project.documents.view.ViewManager;
20
import org.gvsig.fmap.mapcontext.layers.FLayer;
21
import org.gvsig.fmap.mapcontext.layers.FLayers;
22
import org.gvsig.fmap.mapcontext.layers.LayersIterator;
23
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
24
import org.gvsig.geoprocess.core.FileTools;
25
import org.gvsig.geoprocess.core.gvRasterLayerRead;
26
import org.gvsig.geoprocess.core.gvTable;
27
import org.gvsig.geoprocess.core.gvVectorLayer;
28
import org.gvsig.raster.fmap.layers.FLyrRaster;
29

  
30
public class gvInputFactory extends AbstractInputFactory {
31

  
32
    public void createDataObjects() {
33

  
34
        final List<IDataObject> list = new ArrayList<IDataObject>();
35

  
36
        final Project project =
37
            ((ProjectExtension) PluginServices
38
                .getExtension(ProjectExtension.class)).getProject();
39
        final List<Document> views = project.getDocuments(ViewManager.TYPENAME);
40
        for (int i = 0; i < views.size(); i++) {
41
            final DefaultViewDocument view = (DefaultViewDocument) views.get(i);
42
            final FLayers layers = view.getMapContext().getLayers();
43
            final LayersIterator iter = new LayersIterator(layers);
44
            while (iter.hasNext()) {
45
                final FLayer layer = iter.nextLayer();
46
                if (layer instanceof FLyrRaster) {
47
                    final gvRasterLayerRead rasterLayer =
48
                        new gvRasterLayerRead();
49
                    rasterLayer.create((FLyrRaster) layer);
50
                    list.add(rasterLayer);
51
                } else
52
                    if (layer instanceof FLyrVect) {
53
                        final gvVectorLayer vectorLayer = new gvVectorLayer();
54
                        vectorLayer.create((FLyrVect) layer);
55
                        list.add(vectorLayer);
56
                    }
57
            }
58
        }
59

  
60
        final List<Document> tables =
61
            project.getDocuments(TableManager.TYPENAME);
62
        for (int i = 0; i < tables.size(); i++) {
63
            final gvTable table = new gvTable();
64
            table.create((TableDocument) tables.get(i));
65
            list.add(table);
66
        }
67

  
68
        m_Objects = list.toArray(new IDataObject[list.size()]);
69
    }
70

  
71
    public NamedExtent[] getPredefinedExtents() {
72

  
73
        final Project project =
74
            ((ProjectExtension) PluginServices
75
                .getExtension(ProjectExtension.class)).getProject();
76
        final List<Document> views = project.getDocuments(ViewManager.TYPENAME);
77
        final NamedExtent ne[] = new NamedExtent[views.size()];
78
        for (int i = 0; i < views.size(); i++) {
79
            final DefaultViewDocument view = (DefaultViewDocument) views.get(i);
80
            final Rectangle2D extent =
81
                view.getMapContext().getViewPort().getExtent();
82
            final String sName = view.getName();
83
            ne[i] = new NamedExtent(sName, extent);
84
        }
85

  
86
        return ne;
87
    }
88

  
89
    public String[] getRasterLayerInputExtensions() {
90

  
91
        return FileTools.RASTER_EXT_IN;
92

  
93
    }
94

  
95
    public String[] get3DRasterLayerInputExtensions() {
96

  
97
        return FileTools.RASTER3D_EXT_IN;
98

  
99
    }
100

  
101
    public String[] getVectorLayerInputExtensions() {
102

  
103
        return FileTools.VECTOR_EXT_IN;
104

  
105
    }
106

  
107
    public String[] getTableInputExtensions() {
108

  
109
        return FileTools.TABLE_EXT;
110

  
111
    }
112

  
113
    public IDataObject openDataObjectFromFile(final String sFilename) {
114

  
115
        final Object object = FileTools.open(sFilename);
116

  
117
        if (object == null) {
118
            return null;
119
        } else
120
            if (object instanceof FLyrRaster) {
121
                final gvRasterLayerRead layer = new gvRasterLayerRead();
122
                layer.create((FLyrRaster) object);
123
                return layer;
124
            } else
125
                if (object instanceof FLyrVect) {
126
                    final gvVectorLayer layer = new gvVectorLayer();
127
                    layer.create((FLyrVect) object);
128
                    return layer;
129
                } else
130
                    if (object instanceof I3DRasterLayer) {
131
                        return (I3DRasterLayer) object;
132
                    } else {
133
                        return null;
134
                    }
135

  
136
    }
137

  
138
    public void close(final String sName) {
139

  
140
        final IDataObject dataObject = this.getInputFromName(sName);
141

  
142
        final Object obj = dataObject.getBaseDataObject();
143
        if (obj instanceof FLayer) {
144
            removeLayer((FLayer) obj);
145
        } else {
146
            final Project project =
147
                ((ProjectExtension) PluginServices
148
                    .getExtension(ProjectExtension.class)).getProject();
149
            project.remove((Document) obj);
150
        }
151

  
152
    }
153

  
154
    private static void removeLayer(final FLayer baseLayer) {
155

  
156
        final Project project =
157
            ((ProjectExtension) PluginServices
158
                .getExtension(ProjectExtension.class)).getProject();
159
        final List<Document> views = project.getDocuments(ViewManager.TYPENAME);
160
        for (int i = 0; i < views.size(); i++) {
161
            final DefaultViewDocument view = (DefaultViewDocument) views.get(i);
162
            final FLayers layers = view.getMapContext().getLayers();
163
            final LayersIterator iter = new LayersIterator(layers);
164
            while (iter.hasNext()) {
165
                final FLayer layer = iter.nextLayer();
166
                if (layer.equals(baseLayer)) {
167
                    layers.removeLayer(baseLayer);
168
                    return;
169
                }
170
            }
171

  
172
        }
173

  
174
    }
175

  
176
    @Override
177
    public I3DRasterLayer[] get3DRasterLayers() {
178

  
179
        return new I3DRasterLayer[0];
180

  
181
    }
182

  
183
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/gui/gvPostProcessTask.java
1
package org.gvsig.geoprocess.gui;
2

  
3
import java.awt.Component;
4
import java.util.List;
5

  
6
import javax.swing.BorderFactory;
7
import javax.swing.JOptionPane;
8
import javax.swing.JScrollPane;
9
import javax.swing.JTextPane;
10
import javax.swing.ScrollPaneConstants;
11
import javax.swing.SwingUtilities;
12
import javax.swing.border.BevelBorder;
13

  
14
import es.unex.sextante.core.GeoAlgorithm;
15
import es.unex.sextante.core.ObjectAndDescription;
16
import es.unex.sextante.core.OutputObjectsSet;
17
import es.unex.sextante.core.ParametersSet;
18
import es.unex.sextante.core.Sextante;
19
import es.unex.sextante.dataObjects.ILayer;
20
import es.unex.sextante.dataObjects.IRasterLayer;
21
import es.unex.sextante.dataObjects.IVectorLayer;
22
import es.unex.sextante.gui.additionalResults.AdditionalResults;
23
import es.unex.sextante.gui.algorithm.iterative.SingleFeatureVectorLayer;
24
import es.unex.sextante.gui.core.SextanteGUI;
25
import es.unex.sextante.gui.settings.SextanteGeneralSettings;
26
import es.unex.sextante.outputs.FileOutputChannel;
27
import es.unex.sextante.outputs.IOutputChannel;
28
import es.unex.sextante.outputs.NullOutputChannel;
29
import es.unex.sextante.outputs.Output;
30
import es.unex.sextante.outputs.Output3DRasterLayer;
31
import es.unex.sextante.outputs.OutputRasterLayer;
32
import es.unex.sextante.outputs.OutputTable;
33
import es.unex.sextante.outputs.OutputText;
34
import es.unex.sextante.outputs.OutputVectorLayer;
35
import es.unex.sextante.outputs.OverwriteOutputChannel;
36
import es.unex.sextante.parameters.Parameter;
37
import es.unex.sextante.parameters.RasterLayerAndBand;
38

  
39
import org.cresques.cts.IProjection;
40

  
41
import org.gvsig.andami.PluginServices;
42
import org.gvsig.andami.ui.mdiManager.IWindow;
43
import org.gvsig.app.ApplicationLocator;
44
import org.gvsig.app.extension.ProjectExtension;
45
import org.gvsig.app.project.Project;
46
import org.gvsig.app.project.ProjectManager;
47
import org.gvsig.app.project.documents.Document;
48
import org.gvsig.app.project.documents.table.TableDocument;
49
import org.gvsig.app.project.documents.view.ViewDocument;
50
import org.gvsig.app.project.documents.view.ViewManager;
51
import org.gvsig.app.project.documents.view.gui.IView;
52
import org.gvsig.fmap.dal.coverage.RasterLocator;
53
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
54
import org.gvsig.fmap.mapcontext.MapContext;
55
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException;
56
import org.gvsig.fmap.mapcontext.layers.FLayer;
57
import org.gvsig.fmap.mapcontext.layers.FLayers;
58
import org.gvsig.fmap.mapcontext.layers.LayersIterator;
59
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
60
import org.gvsig.geoprocess.core.FileTools;
61
import org.gvsig.raster.fmap.layers.FLyrRaster;
62

  
63
public class gvPostProcessTask implements Runnable {
64

  
65
    private MapContext m_MapContext;
66
    private final GeoAlgorithm m_Algorithm;
67
    private final OutputObjectsSet m_Output;
68
    private final boolean m_bShowResultsWindows;
69

  
70
    public gvPostProcessTask(final GeoAlgorithm algorithm,
71
        final boolean bShowResultsWindow) {
72

  
73
        m_Output = algorithm.getOutputObjects();
74
        m_Algorithm = algorithm;
75
        m_bShowResultsWindows = bShowResultsWindow;
76

  
77
    }
78

  
79
    public void run() {
80

  
81
        if (m_Output.hasLayers()) {
82
            setOutputView();
83
        }
84

  
85
        addResults();
86

  
87
    }
88

  
89
    private void setOutputView() {
90

  
91
        ViewDocument view = null;
92
        final ParametersSet parameters = m_Algorithm.getParameters();
93
        for (int i = 0; i < parameters.getNumberOfParameters(); i++) {
94
            final Parameter param = parameters.getParameter(i);
95
            final Object object = param.getParameterValueAsObject();
96
            if (object instanceof ILayer) {
97
                view = getViewFromLayer((ILayer) object);
98
                m_MapContext = view.getMapContext();
99
                return;
100
            } else
101
                if (object instanceof List) {
102
                    final List list = (List) object;
103
                    for (int j = 0; j < list.size(); j++) {
104
                        final Object obj = list.get(j);
105
                        if (obj instanceof ILayer) {
106
                            view = getViewFromLayer((ILayer) obj);
107
                            m_MapContext = view.getMapContext();
108
                            return;
109
                        } else
110
                            if (obj instanceof RasterLayerAndBand) {
111
                                final RasterLayerAndBand rlab =
112
                                    (RasterLayerAndBand) obj;
113
                                view = getViewFromLayer(rlab.getRasterLayer());
114
                                m_MapContext = view.getMapContext();
115
                                return;
116
                            }
117
                    }
118
                }
119
        }
120

  
121
        // if there is no input view, ask the user
122
        final Project project =
123
            ((ProjectExtension) PluginServices
124
                .getExtension(ProjectExtension.class)).getProject();
125
        final List<Document> views = project.getDocuments(ViewManager.TYPENAME);
126
        final Object[] options = new Object[views.size() + 1];
127
        options[0] = Sextante.getText("Create_new_view");
128
        for (int i = 0; i < views.size(); i++) {
129
            options[i + 1] = views.get(i);
130
        }
131

  
132
        final Object selectedObject =
133
            JOptionPane.showInputDialog(null,
134
                Sextante.getText("Select_output_view"),
135
                Sextante.getText("Output_view"), JOptionPane.PLAIN_MESSAGE,
136
                null, options, null);
137

  
138
        if (selectedObject instanceof IView) {
139
            m_MapContext =
140
                ((IView) selectedObject).getMapControl().getMapContext();
141
        } else {
142
            final Document newView =
143
                ProjectManager.getInstance().createDocument(
144
                    ViewManager.TYPENAME,
145
                    "SEXTANTE (" + m_Algorithm.getName() + ")");
146
            ((ProjectExtension) PluginServices
147
                .getExtension(ProjectExtension.class)).getProject()
148
                .add(newView);
149
            final IWindow window = newView.getFactory().getMainWindow(newView);
150
            final Runnable doWorkRunnable = new Runnable() {
151

  
152
                public void run() {
153
                    PluginServices.getMDIManager().addWindow(window);
154
                    m_MapContext = ((ViewDocument) newView).getMapContext();
155
                }
156
            };
157
            try {
158
                SwingUtilities.invokeAndWait(doWorkRunnable);
159
            } catch (final Exception e) {
160
                Sextante.addErrorToLog(e);
161
            }
162
        }
163

  
164
    }
165

  
166
    private ViewDocument getViewFromLayer(ILayer layer) {
167

  
168
        if (layer instanceof SingleFeatureVectorLayer) {
169
            layer = ((SingleFeatureVectorLayer) layer).getOriginalLayer();
170
        }
171

  
172
        final FLayer gvSIGBaseLayer = (FLayer) layer.getBaseDataObject();
173
        final Project project =
174
            ((ProjectExtension) PluginServices
175
                .getExtension(ProjectExtension.class)).getProject();
176
        final List<Document> docs = project.getDocuments(ViewManager.TYPENAME);
177

  
178
        for (int i = 0; i < docs.size(); i++) {
179
            final ViewDocument viewDoc = (ViewDocument) docs.get(i);
180
            final FLayers layers = viewDoc.getMapContext().getLayers();
181
            final LayersIterator iter = new LayersIterator(layers);
182
            while (iter.hasNext()) {
183
                final FLayer gvSIGLayer = iter.nextLayer();
184
                if (gvSIGLayer.equals(gvSIGBaseLayer)) {
185
                    return viewDoc;
186
                }
187
            }
188

  
189
        }
190

  
191
        return null;
192

  
193
    }
194

  
195
    private void addResults() {
196

  
197
        final boolean bUseInternalNames =
198
            new Boolean(
199
                SextanteGUI
200
                    .getSettingParameterValue(SextanteGeneralSettings.USE_INTERNAL_NAMES))
201
                .booleanValue();
202
        final boolean bModiFyResultsNames =
203
            new Boolean(
204
                SextanteGUI
205
                    .getSettingParameterValue(SextanteGeneralSettings.MODIFY_NAMES))
206
                .booleanValue();
207

  
208
        String sDescription;
209
        boolean bInvalidate = false;
210
        boolean bShowAdditionalPanel = false;
211

  
212
        if (m_MapContext != null) {
213
            m_MapContext.beginAtomicEvent();
214
        }
215

  
216
        for (int i = 0; i < m_Output.getOutputObjectsCount(); i++) {
217

  
218
            final Output out = m_Output.getOutput(i);
219
            sDescription = out.getDescription();
220
            final IOutputChannel channel = out.getOutputChannel();
221
            final Object object = out.getOutputObject();
222

  
223
            if ((out instanceof OutputRasterLayer)
224
                || (out instanceof Output3DRasterLayer)
225
                || (out instanceof OutputTable)
226
                || (out instanceof OutputVectorLayer)) {
227
                if (bUseInternalNames) {
228
                    sDescription = out.getName();
229
                } else
230
                    if (bModiFyResultsNames) {
231
                        sDescription =
232
                            SextanteGUI.modifyResultName(sDescription);
233
                    }
234
                if ((channel instanceof NullOutputChannel) || (channel == null)) {
235
                    continue;
236
                }
237
            }
238
            if (out instanceof OutputVectorLayer) {
239
                String sFilename = null;
240
                if (channel instanceof FileOutputChannel) {
241
                    sFilename = ((FileOutputChannel) channel).getFilename();
242
                    final FLyrVect flayer =
243
                        (FLyrVect) FileTools.openLayer(sFilename, sDescription,
244
                            (IProjection) m_Algorithm.getOutputCRS());
245
                    if (flayer != null) {
246
                        flayer.setName(sDescription);
247
                        m_MapContext.getLayers().addLayer(flayer);
248
                        bInvalidate = true;
249
                    }
250

  
251
                } else
252
                    if (channel instanceof OverwriteOutputChannel) {
253
                        // TODO:add support for non file based layer
254
                        final FLyrVect flayer =
255
                            (FLyrVect) ((OverwriteOutputChannel) channel)
256
                                .getLayer().getBaseDataObject();
257
                        try {
258
                            flayer.reload();
259
                            bInvalidate = true;
260
                        } catch (final ReloadLayerException e) {
261

  
262
                        }
263
                    }
264

  
265
                if (object != null) {
266
                    ((IVectorLayer) object).close();
267
                }
268

  
269
            } else
270
                if (out instanceof OutputTable) {
271
                    try {
272
                        final String sFilename =
273
                            ((FileOutputChannel) channel).getFilename();
274
                        final TableDocument table =
275
                            FileTools.openTable(sFilename, sDescription);
276
                        if (table != null) {
277
                            table.setName(sDescription);
278
                            ApplicationLocator.getManager().getProjectManager()
279
                                .getCurrentProject().add(table);
280

  
281
                            // final JScrollPane jScrollPane =
282
                            // TableTools
283
                            // .getScrollableTablePanelFromITable((ITable)
284
                            // object);
285
                            // AdditionalResults
286
                            // .addComponent(new ObjectAndDescription(
287
                            // sDescription, jScrollPane));
288
                            // bShowAdditionalPanel = true;
289
                        }
290
                    } catch (final Exception e) {
291
                        Sextante.addErrorToLog(e);
292
                    }
293
                } else
294
                    if (out instanceof OutputRasterLayer) {
295
                        final IRasterLayer rasterLayer = (IRasterLayer) object;
296
                        if (channel instanceof FileOutputChannel) {
297
                            final String sFilename =
298
                                ((FileOutputChannel) channel).getFilename();
299
                            final FLyrRaster flayer =
300
                                (FLyrRaster) FileTools.openLayer(
301
                                    sFilename,
302
                                    sDescription,
303
                                    (IProjection) m_Algorithm.getOutputCRS());
304
                            if (flayer != null) {
305
                                if (rasterLayer != null) {
306
                                    try {
307

  
308
                                        NoData nodata =
309
                                            RasterLocator
310
                                                .getManager()
311
                                                .getDataStructFactory()
312
                                                .createNoData(
313
                                                    rasterLayer
314
                                                        .getNoDataValue(),
315
                                                    null, sFilename);
316

  
317
                                        flayer.setNoDataValue(nodata);
318
                                        nodata.save();
319

  
320
                                        rasterLayer.close();
321
                                    } catch (final Exception e) {
322
                                        Sextante.addErrorToLog(e);
323
                                    }
324
                                }
325
                                flayer.setName(sDescription);
326
                                m_MapContext.getLayers().addLayer(flayer);
327
                                bInvalidate = true;
328

  
329
                            }
330
                        }
331
                    } else
332
                        if (out instanceof OutputText) {
333
                            JTextPane jTextPane;
334
                            JScrollPane jScrollPane;
335
                            jTextPane = new JTextPane();
336
                            jTextPane.setEditable(false);
337
                            jTextPane.setContentType("text/html");
338
                            jTextPane.setText((String) object);
339
                            jScrollPane = new JScrollPane();
340
                            jScrollPane.setViewportView(jTextPane);
341
                            jScrollPane
342
                                .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
343
                            jTextPane.setBorder(BorderFactory
344
                                .createEtchedBorder(BevelBorder.LOWERED));
345
                            AdditionalResults
346
                                .addComponent(new ObjectAndDescription(
347
                                    sDescription, jScrollPane));
348
                            bShowAdditionalPanel = true;
349
                        } else
350
                            if (object instanceof Component) {
351
                                AdditionalResults
352
                                    .addComponent(new ObjectAndDescription(
353
                                        sDescription, object));
354
                                bShowAdditionalPanel = true;
355
                            } else
356
                                if (out instanceof Output3DRasterLayer) {
357
                                    JOptionPane.showMessageDialog(
358
                                        SextanteGUI.getMainFrame(),
359
                                        Sextante.getText("3d_not_supported"),
360
                                        Sextante.getText("Warning"),
361
                                        JOptionPane.WARNING_MESSAGE);
362
                                }
363

  
364
        }
365

  
366
        if (m_MapContext != null) {
367
            m_MapContext.endAtomicEvent();
368
        }
369

  
370
        if (bInvalidate) {
371
            m_MapContext.invalidate();
372
        }
373

  
374
        if (bShowAdditionalPanel && m_bShowResultsWindows) {
375
            AdditionalResults.showPanel();
376
        }
377

  
378
    }
379
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/gui/gvDefaultParametersPanel.java
30 30
import es.unex.sextante.outputs.Output;
31 31

  
32 32
import org.gvsig.geoprocess.core.CompositeSourceOutputChannel;
33
import org.gvsig.geoprocess.core.OutputParameters;
33
import org.gvsig.geoprocess.lib.sextante.dataObjects.OutputParameters;
34 34

  
35 35
/**
36 36
 * Default panel for gvSIG algorithms
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/gui/AlgorithmOutputPanel.java
32 32
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
33 33
import org.gvsig.fmap.mapcontrol.dal.swing.datastore.DataStoreParametersCreationPanel;
34 34
import org.gvsig.fmap.mapcontrol.dal.swing.datastore.DefaultDataStoreParametersCreationPanel;
35
import org.gvsig.geoprocess.core.OutputParameters;
35
import org.gvsig.geoprocess.lib.sextante.dataObjects.OutputParameters;
36 36

  
37 37
/**
38 38
 * 
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/core/gvFeatureIterator.java
1
package org.gvsig.geoprocess.core;
2

  
3
import java.util.ArrayList;
4
import java.util.Iterator;
5
import java.util.List;
6
import java.util.NoSuchElementException;
7

  
8
import com.vividsolutions.jts.geom.Geometry;
9

  
10
import es.unex.sextante.core.Sextante;
11
import es.unex.sextante.dataObjects.FeatureImpl;
12
import es.unex.sextante.dataObjects.IFeature;
13
import es.unex.sextante.dataObjects.IFeatureIterator;
14
import es.unex.sextante.dataObjects.vectorFilters.IVectorLayerFilter;
15

  
16
import org.gvsig.fmap.dal.exception.DataException;
17
import org.gvsig.fmap.dal.feature.Feature;
18
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
19
import org.gvsig.fmap.dal.feature.FeatureSet;
20
import org.gvsig.fmap.dal.feature.FeatureType;
21
import org.gvsig.fmap.geom.operation.tojts.ToJTS;
22
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
23
import org.gvsig.tools.dispose.DisposableIterator;
24

  
25
public class gvFeatureIterator implements IFeatureIterator {
26

  
27
    private final List<IVectorLayerFilter> m_Filters;
28
    private boolean m_bIsNextConsumed;
29
    private IFeature m_CurrentValue;
30
    private boolean m_bFinished;
31
    private DisposableIterator m_FeatureIterator;
32

  
33
    public gvFeatureIterator(final FLyrVect layer,
34
        final List<IVectorLayerFilter> filters) {
35

  
36
        m_bIsNextConsumed = true;
37
        m_Filters = filters;
38

  
39
        FeatureSet set = null;
40
        try {
41
            set = layer.getFeatureStore().getFeatureSet();
42
            m_FeatureIterator = set.fastIterator();
43
        } catch (final DataException e) {
44
            if (m_FeatureIterator != null) {
45
                m_FeatureIterator.dispose();
46
            }
47
            if (set != null) {
48
                set.dispose();
49
            }
50
        }
51
    }
52

  
53
    public gvFeatureIterator() {
54

  
55
        m_Filters = null;
56

  
57
    }
58

  
59
    private boolean accept(final IFeature value) {
60

  
61
        for (final IVectorLayerFilter filter : m_Filters) {
62
            if (!filter.accept(value, 0)) {
63
                return false;
64
            }
65
        }
66
        return true;
67
    }
68

  
69
    public boolean moveToNextValid() {
70

  
71
        if (m_FeatureIterator == null) {
72
            return false;
73
        }
74

  
75
        boolean bFound = false;
76
        ;
77
        while (!bFound && m_FeatureIterator.hasNext()) {
78
            try {
79
                final Feature f = (Feature) m_FeatureIterator.next();
80
                final org.gvsig.fmap.geom.Geometry geometry =
81
                    f.getDefaultGeometry();
82
                final Geometry geom =
83
                    (Geometry) geometry.invokeOperation(ToJTS.CODE, null);
84
                final FeatureType type = f.getType();
85
                @SuppressWarnings("unchecked")
86
                final Iterator<FeatureAttributeDescriptor> iter =
87
                    type.iterator();
88
                final List<Object> objects = new ArrayList<Object>();
89
                while (iter.hasNext()) {
90
                    final FeatureAttributeDescriptor descriptor = iter.next();
91
                    final String name = descriptor.getName();
92
                    // Comment this as if the geometry field is in the middle of
93
                    // the fields it will be problematic elsewhere
94
                    if (!type.getDefaultGeometryAttributeName().equals(name)) {
95
                        objects.add(f.get(name));
96
                    }
97
                }
98
                final FeatureImpl feature =
99
                    new FeatureImpl(geom, objects.toArray(new Object[objects
100
                        .size()]));
101
                if (accept(feature)) {
102
                    bFound = true;
103
                    m_CurrentValue = feature;
104
                    m_bIsNextConsumed = false;
105
                }
106
            } catch (final Exception e) {
107
                Sextante.addErrorToLog(e);
108
                return false;
109
            }
110
        }
111
        if (!bFound) {
112
            m_bFinished = true;
113
        }
114
        return bFound;
115
    }
116

  
117
    public IFeature next() {
118

  
119
        if (!m_bIsNextConsumed) {
120
            m_bIsNextConsumed = true;
121
            return m_CurrentValue;
122
        }
123

  
124
        if (!m_bFinished) {
125
            if (moveToNextValid()) {
126
                m_bIsNextConsumed = true;
127
                return m_CurrentValue;
128
            }
129
        }
130

  
131
        throw new NoSuchElementException();
132
    }
133

  
134
    public boolean hasNext() {
135

  
136
        if (m_bFinished) {
137
            return false;
138
        }
139

  
140
        if (!m_bIsNextConsumed) {
141
            return true;
142
        }
143

  
144
        return moveToNextValid();
145

  
146
    }
147

  
148
    public void close() {
149
    }
150

  
151
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/core/OutputParameters.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.geoprocess.core;
20

  
21
import org.gvsig.fmap.dal.DataServerExplorer;
22
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
23

  
24
/**
25
 * Parameters to build a DAL data store.
26
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
27
 */
28
public class OutputParameters {
29
	private NewFeatureStoreParameters       parameters   = null;
30
	private DataServerExplorer              explorer     = null;
31
	
32
	public OutputParameters(NewFeatureStoreParameters parameters, DataServerExplorer explorer) {
33
		this.parameters = parameters;
34
		this.explorer = explorer;
35
	}
36
	
37
	/**
38
	 * Gets the name of the data store
39
	 * @return
40
	 */
41
	public NewFeatureStoreParameters getDataParameters() {
42
		return parameters;
43
	}
44

  
45
	/**
46
	 * Gets the DataServerExplorer to build the data store
47
	 * @return
48
	 */
49
	public DataServerExplorer getExplorer() {
50
		return explorer;
51
	}
52
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.app/org.gvsig.geoprocess.app.mainplugin/src/main/java/org/gvsig/geoprocess/core/gvTable.java
1
package org.gvsig.geoprocess.core;
2

  
3
import java.io.File;
4
import java.util.Iterator;
5

  
6
import es.unex.sextante.core.Sextante;
7
import es.unex.sextante.dataObjects.AbstractTable;
8
import es.unex.sextante.dataObjects.IRecordsetIterator;
9
import es.unex.sextante.outputs.FileOutputChannel;
10
import es.unex.sextante.outputs.IOutputChannel;
11

  
12
import org.gvsig.app.project.ProjectManager;
13
import org.gvsig.app.project.documents.table.TableDocument;
14
import org.gvsig.app.project.documents.table.TableManager;
15
import org.gvsig.fmap.dal.DALLocator;
16
import org.gvsig.fmap.dal.DataManager;
17
import org.gvsig.fmap.dal.exception.DataException;
18
import org.gvsig.fmap.dal.feature.EditableFeature;
19
import org.gvsig.fmap.dal.feature.EditableFeatureType;
20
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
21
import org.gvsig.fmap.dal.feature.FeatureStore;
22
import org.gvsig.fmap.dal.feature.FeatureType;
23
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
24
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
25
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
26
import org.gvsig.tools.ToolsLocator;
27
import org.gvsig.tools.dataTypes.DataTypesManager;
28

  
29
public class gvTable extends AbstractTable {
30

  
31
    private final int PRECISION = 5;
32
    private TableDocument m_Table;
33
    private String m_sName;
34
    private String m_sFilename;
35
    private FeatureType featureType;
36
    private FeatureStore featureStore;
37

  
38
    public String getName() {
39

  
40
        if (m_Table != null) {
41
            return m_Table.getName();
42
        } else {
43
            return m_sName;
44
        }
45

  
46
    }
47

  
48
    public void create(final TableDocument table) {
49

  
50
        try {
51
            m_Table = table;
52
            featureStore = table.getStore();
53
            featureType = featureStore.getDefaultFeatureType();
54
        } catch (final DataException e) {
55
            Sextante.addErrorToLog(e);
56
        }
57

  
58
    }
59

  
60
    public void create(final String sName, final String sFilename,
61
        final Class<?>[] types, final String[] sFields) {
62

  
63
        try {
64
            m_sName = sName;
65

  
66
            final DataManager datamanager = DALLocator.getDataManager();
67
            final FilesystemServerExplorerParameters explorerParams =
68
                (FilesystemServerExplorerParameters) datamanager
69
                    .createServerExplorerParameters(FilesystemServerExplorer.NAME);
70
            explorerParams.setRoot(new File(sFilename).getParent());
71
            final FilesystemServerExplorer explorer =
72
                (FilesystemServerExplorer) datamanager.openServerExplorer(
73
                    FilesystemServerExplorer.NAME, explorerParams);
74
            final NewFeatureStoreParameters newParams =
75
                (NewFeatureStoreParameters) explorer.getAddParameters(new File(
76
                    sFilename));
77

  
78
            EditableFeatureType editableFeatureType =
79
                newParams.getDefaultFeatureType();
80
            featureType = editableFeatureType;
81
            loadFeatureType(sFields, types, editableFeatureType);
82

  
83
            newParams.setDefaultFeatureType(featureType);
84

  
85
            explorer.add(newParams.getDataStoreName(), newParams, true);
86
            final DataManager manager = DALLocator.getDataManager();
87
            featureStore =
88
                (FeatureStore) manager.openStore(newParams.getDataStoreName(),
89
                    newParams);
90
            featureStore.edit(FeatureStore.MODE_APPEND);
91
            featureType = featureStore.getDefaultFeatureType();
92
            m_sFilename = sFilename;
93

  
94
        } catch (final Exception e) {
95
            Sextante.addErrorToLog(e);
96
        }
97

  
98
    }
99

  
100
    private void loadFeatureType(final String[] fields, final Class<?>[] types,
101
        final EditableFeatureType featureType) {
102
        final int[] iTypes = getTypes(types);
103

  
104
        for (int i = 0; i < fields.length; i++) {
105
            featureType.add(fields[i], iTypes[i]).setPrecision(PRECISION);
106
        }
107
    }
108

  
109
    private int[] getTypes(Class<?>[] classes) {
110
        DataTypesManager typesManager = ToolsLocator.getDataTypesManager();
111
        int[] types = new int[classes.length];
112
        for (int i = 0; i < classes.length; i++) {
113
            types[i] = typesManager.getDataType(classes[i]).getType();
114
        }
115
        return types;
116
    }
117

  
118
    public void addRecord(final Object[] record) {
119
        try {
120
            final EditableFeature ef = featureStore.createNewFeature();
121
            @SuppressWarnings("unchecked")
122
            final Iterator<FeatureAttributeDescriptor> features =
123
                featureType.iterator();
124

  
125
            int i = 0;
126
            while (features.hasNext()) {
127
                final FeatureAttributeDescriptor featureAttributeDescriptor =
128
                    features.next();
129
                ef.set(featureAttributeDescriptor.getName(), record[i]);
130
                i++;
131
            }
132
            featureStore.insert(ef);
133
        } catch (final Exception e) {
134
            e.printStackTrace();
135
        }
136

  
137
    }
138

  
139
    public IRecordsetIterator iterator() {
140
        try {
141
            return new gvRecordsetIterator(featureStore.getFeatureSet(m_Table
142
                .getQuery()));
143
        } catch (final DataException e) {
144
            throw new RuntimeException(e);
145
        }
146
    }
147

  
148
    public String getFieldName(final int i) {
149
        return ((FeatureAttributeDescriptor) featureType.get(i)).getName();
150
    }
151

  
152
    public Class<?> getFieldType(final int i) {
153
        return featureType.getAttributeDescriptor(i).getDataType()
154
            .getDefaultClass();
155
    }
156

  
157
    public int getFieldCount() {
158
        return featureType.size();
159
    }
160

  
161
    public long getRecordCount() {
162
        try {
163
            return featureStore.getFeatureSet(m_Table.getQuery()).getSize();
164
        } catch (final DataException e) {
165
            e.printStackTrace();
166
        }
167
        return 0;
168
    }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff