Revision 34383

View differences:

tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/prepare-workspace.xml
1
<project name="org.gvsig.initial.build" default="prepare-workspace">
2

  
3
	<dirname property="org.gvsig.initial.build.basedir" file="${ant.file.org.gvsig.initial.build}" />
4

  
5
	<property name="workspace.basedir" value="${org.gvsig.initial.build.basedir}/.." />
6
	<property name="build.basedir" value="${workspace.basedir}/org.gvsig.maven.base.build" description="Eclipse workspace location" />
7
	<property name="build.jar.version" value="1.0.6-SNAPSHOT" />
8
	<property name="build.jar.file" value="org.gvsig.maven.base.build-${build.jar.version}.jar" />
9

  
10
	<property name="ant.libs.dir" location="${build.basedir}" description="Additional ant tasks libs folder" />
11

  
12
	<target name="check-maven-base-build-available">
13
		<available file="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" property="maven-base-build-available" />
14
	</target>
15

  
16
	<target name="get-maven-base-build-local" depends="check-maven-base-build-available" if="maven-base-build-available">
17
		<!-- Unzip de build jar file from the maven repository into the workspace root folder -->
18
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
19
			<zipfileset src="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}">
20
				<patternset>
21
					<exclude name="META-INF/**" />
22
				</patternset>
23
			</zipfileset>
24
		</copy>
25
	</target>
26

  
27
	<target name="get-maven-base-build-remote" depends="check-maven-base-build-available" unless="maven-base-build-available">
28
		<!-- Download the build jar file -->
29
		<get src="http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/maven-repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" dest="target/${build.jar.file}" verbose="true" />
30

  
31
		<mkdir dir="target" />
32

  
33
		<!-- Unzip de build jar file into the workspace root folder -->
34
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
35
			<zipfileset src="target/${build.jar.file}">
36
				<patternset>
37
					<exclude name="META-INF/**" />
38
				</patternset>
39
			</zipfileset>
40
			<filterset>
41
				<filter token="GVSIG_HOME" value="/home/cordin/projects/gvsig/svn/gvSIG-2.0-build/build/product" />
42
			</filterset>
43
		</copy>
44

  
45
	</target>
46

  
47
	<target name="prepare-workspace" depends="get-maven-base-build-local,get-maven-base-build-remote">
48

  
49
		<mkdir dir="target" />
50

  
51
		<chmod dir="${build.basedir}/maven/bin" perm="u+x" includes="m2,mvn,mvnDebug" />
52

  
53
		<!-- Copy the maven launchers to the workspace metadata folder -->
54
		<copy todir="${workspace.basedir}/.metadata">
55
			<fileset dir="${build.basedir}/eclipse-launchers">
56
				<exclude name="**/org.eclipse.jdt.core.prefs" />
57
				<exclude name="**/org.eclipse.core.variables.prefs" />
58
			</fileset>
59
		</copy>
60

  
61
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" append="true">
62
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.jdt.core.prefs" />
63
		</concat>
64
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" append="true">
65
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.core.variables.prefs" />
66
		</concat>
67

  
68
		<!-- Configure the eclipse workspace -->
69
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-configure-eclipse-workspace" />
70

  
71
		<!-- Configure the gvSIG profile -->
72
		<ant antfile="${build.basedir}/check-gvsig-profile.xml" target="initialize" />
73

  
74
		<property name="user-settings-file-location" value="${user.home}/.m2/settings.xml" />
75

  
76
		<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
77
			<classpath>
78
				<pathelement location="${ant.libs.dir}/com.oopsconsultancy.xmltask-1.16.1.jar" />
79
			</classpath>
80
		</taskdef>
81

  
82
		<xmltask source="${user-settings-file-location}" dest="${user-settings-file-location}">
83
			<copy path="//:settings/:profiles/:profile[:id/text() = 'gvsig-install']/:properties/:gvsig.install.dir/text()" property="current-gvsig-location" />
84
		</xmltask>
85

  
86
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
87
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
88

  
89
		<!-- Compile, install and generate eclipse projects -->
90
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-install-and-eclipse-eclipse" />
91

  
92
		<echo>INFORMATION!!!</echo>
93
		<echo>Restart eclipse and then proceed to import the subprojects contained into the main project</echo>
94

  
95
		<!-- TODO: copiar al proyecto de configuraciĆ³n general -->
96
	</target>
97

  
98
	<target name="clean">
99
		<delete dir="target" />
100
	</target>
101

  
102
</project>
0 103

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<groupId>org.gvsig</groupId>
7
	<artifactId>org.gvsig.geometrymeasurement.app</artifactId>
8
	<packaging>pom</packaging>
9
	<version>1.0.0-SNAPSHOT</version>
10
	<name>org.gvsig.geometrymeasurement.app</name>
11
	<description>Extension of the GeometryMeasurement example project</description>
12
	<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.geometrymeasurement/${pom.version}/basic/org.gvsig.geometrymeasurement.app</url>
13
    <parent>
14
        <groupId>org.gvsig</groupId>
15
        <artifactId>gvsig-base-extension-pom</artifactId>
16
        <version>2.0-SNAPSHOT</version>
17
    </parent>
18
	<scm>
19
		<connection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-geometrymeasurement/org.gvsig.geometrymeasurement/extension/trunk</connection>
20
		<developerConnection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-geometrymeasurement/org.gvsig.geometrymeasurement/extension/trunk</developerConnection>
21
		<url>https://forge.osor.eu/plugins/scmsvn/viewcvs.php/org.gvsig.geometrymeasurement/extension/trunk/?root=gvsig-geometrymeasurement</url>
22
	</scm>
23

  
24
	<developers>
25
		<developer>
26
			<id>vcaballero</id>
27
			<name>Vicente Caballero Navarro</name>
28
			<email>vicente.caballero@iver.es</email>
29
			<roles>				
30
				<role>Developer</role>
31
			</roles>
32
		</developer>
33
		<developer>
34
			<id>jpiera</id>
35
			<name>Jorge Piera Llodr?</name>
36
			<email>jpiera@gvsig.org</email>
37
			<roles>
38
				<role>Developer</role>
39
			</roles>
40
		</developer>		
41
	</developers>
42

  
43
	<distributionManagement>
44
		<site>
45
			<id>gvsig-repository</id>
46
			<url>scp://shell.forge.osor.eu/home/groups/gvsig-desktop/www/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.geometrymeasurement/${pom.version}/basic/org.gvsig.geometrymeasurement.app</url>
47
		</site>
48
	</distributionManagement>
49
	<repositories>
50
		<repository>
51
			<id>gvsig-public-http-repository</id>
52
			<name>gvSIG maven public HTTP repository</name>
53
			<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/maven-repository</url>
54
			<releases>
55
				<enabled>true</enabled>
56
				<updatePolicy>daily</updatePolicy>
57
				<checksumPolicy>warn</checksumPolicy>
58
			</releases>
59
			<snapshots>
60
				<enabled>true</enabled>
61
				<updatePolicy>daily</updatePolicy>
62
				<checksumPolicy>warn</checksumPolicy>
63
			</snapshots>
64
		</repository>
65
	</repositories>
66
	<build>
67
		<plugins>
68
			<plugin>
69
				<groupId>org.apache.maven.plugins</groupId>
70
				<artifactId>maven-release-plugin</artifactId>
71
				<configuration>
72
					<tagBase>https://svn.forge.osor.eu/svn/gvsig-geometrymeasurement/org.gvsig.geometrymeasurement/extension/tags</tagBase>
73
				</configuration>
74
			</plugin>
75
		</plugins>
76
	</build>
77
	<dependencyManagement>
78
		<dependencies>
79
			<dependency>
80
				<groupId>org.gvsig</groupId>
81
				<artifactId>org.gvsig.andami</artifactId>
82
				<version>2.0-SNAPSHOT</version>
83
			</dependency>
84
			<dependency>
85
				<groupId>org.gvsig</groupId>
86
				<artifactId>org.gvsig.i18n</artifactId>
87
				<version>2.0-SNAPSHOT</version>
88
			</dependency>
89
			<dependency>
90
				<groupId>org.gvsig</groupId>
91
				<artifactId>org.gvsig.tools.lib</artifactId>
92
				<version>2.1.0-SNAPSHOT</version>
93
			</dependency>			
94
		</dependencies>
95
	</dependencyManagement>
96

  
97
	<modules>
98
		<module>org.gvsig.geometrymeasurement.app.extension</module>
99
	</modules>
100
    <properties>
101
        <build-dir>${basedir}/../build</build-dir>
102
    </properties>
103
</project>
0 104

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/README.txt
1
The first time you checkout the current project to a new workspace, 
2
you have to prepare it to be able to work easily with maven from
3
eclipse itself.
4

  
5
Perform the following steps:
6

  
7
1.- Launch the *prepare-workspace.xml* ant build file. 
8
    You can do it by loading the file into the ant view, 
9
    and running the default task, or right-clicking the 
10
    file from the package explorer or the navigator and
11
    select the option: *Run as > Ant build*. 
12
    
13
2.- Restart eclipse.
14

  
15
3.- Import the subprojects of the project you have just checked out.
16

  
17
Those steps are only needed once per workspace.     
18

  
0 19

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/distribution/distribution.xml
1
<assembly>
2
</assembly>
0 3

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/distribution/distribution.xml
1
<assembly>
2
	<id>distribution</id>
3
	<formats>
4
		<format>dir</format>
5
	</formats>
6
	<fileSets>
7
		<!-- Estructure for the extension -->
8
		<fileSet>
9
			<directory>src/main/resources</directory>
10
			<outputDirectory>${extension.install.dir.name}
11
			</outputDirectory>
12
		</fileSet>
13
	</fileSets>
14
    <files>
15
        <file>
16
            <source>package.info</source>
17
            <outputDirectory>${extension.install.dir.name}</outputDirectory>
18
        </file>
19
    </files>
20
	<dependencySets>
21
		<dependencySet>
22
			<outputDirectory>${extension.install.dir.name}/${library-dir}
23
			</outputDirectory>
24
			<includes>
25
				<include>org.gvsig:org.gvsig.geometrymeasurement.app.extension</include>
26
				<include>org.gvsig:org.gvsig.geometrymeasurement.lib.api</include>
27
				<include>org.gvsig:org.gvsig.geometrymeasurement.lib.impl</include>
28
			</includes>
29
		</dependencySet>
30
	</dependencySets>
31
</assembly>
0 32

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Tue Jan 11 12:25:20 CET 2011
3
buildNumber=2023
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/package.info
1
#
2
#Tue Jan 11 12:25:21 CET 2011
3
state=devel
4
name=org.gvsig.geometrymeasurement.app.extension
5
official=true
6
code=org.gvsig.geometrymeasurement.app.extension
7
operating-system=all
8
architecture=all
9
java-version=j1_5
10
gvSIG-version=2.0.0
11
version=1.0.0-SNAPSHOT
12
type=plugin
13
build=2023
14
description=Add 3 tools to gvSIG\:\n- Add a new attribute to the data source with the geometry area\n- Add a new attribute to the data source with the geometry perimeter\n- Add a new attribute to a Point type data source two new columns, one with the X Point value, and another with the Y Point value.
15
model-version=1.0.0
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/AreaMeasurementExtension.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.geometrymeasurement.app.extension;
23

  
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

  
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.messages.NotificationManager;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.app.project.documents.view.gui.IView;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.exception.ReadException;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
38
import org.gvsig.fmap.mapcontext.MapContext;
39
import org.gvsig.fmap.mapcontext.layers.FLayer;
40
import org.gvsig.fmap.mapcontext.layers.FLayers;
41
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
42
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
43

  
44
/**
45
 * Andami extension to show AreaMeasurementExtension in the application.
46
 * 
47
 * @author gvSIG Team
48
 * @version $Id$
49
 */
50
public class AreaMeasurementExtension extends Extension {
51
    private static final Logger LOG = LoggerFactory.getLogger(AreaMeasurementExtension.class);
52
    private MapContext mapContext;
53
    private FLyrVect fLyrVect;
54

  
55
    public void initialize() {
56
        // Do nothing
57
    }
58

  
59
    @Override
60
    public void postInitialize() {
61
        super.postInitialize();      
62
    }
63

  
64
    public void execute(String actionCommand) {       
65
        Operations operations = new Operations();
66
        FeatureStore featureStore = fLyrVect.getFeatureStore();
67
        
68
        try {
69
            operations.addDoubleFieldFromOperation(featureStore, "AREA", "area");
70
        } catch (DataException e) {
71
           LOG.error("Not possible to create the area field", e);
72
           NotificationManager.addError(e);
73
        } catch (GeometryOperationNotSupportedException e) {
74
            LOG.error("Not possible to create the area field", e);
75
            NotificationManager.addError(e);
76
        } catch (GeometryOperationException e) {
77
            LOG.error("Not possible to create the area field", e);
78
            NotificationManager.addError(e);
79
        }  
80
    }  
81

  
82
    public boolean isEnabled() {
83
        return true;
84
    }
85

  
86
    public boolean isVisible() {
87
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
88

  
89
        if (window == null){
90
            return false;
91
        }
92
        if (window instanceof IView){
93
            IView view = (IView) window;            
94
            FLayers layers = view.getMapControl().getMapContext().getLayers();
95
            FLayer[] activeLayers = layers.getActives();
96

  
97
            if (activeLayers.length == 1){
98
                if (activeLayers[0] instanceof FLyrVect){
99
                    fLyrVect = (FLyrVect) activeLayers[0];
100
                    try {
101
                        int type = fLyrVect.getShapeType();
102
                        if (Geometry.TYPES.CIRCLE == type
103
                            || Geometry.TYPES.ELLIPSE == type
104
                            || Geometry.TYPES.SURFACE == type
105
                            || Geometry.TYPES.MULTISURFACE == type){
106
                            return true;
107
                        }
108
                    } catch (ReadException e) {
109
                        LOG.error("Error reading the geometry type", e);
110
                        return false;
111
                    }
112
                }
113
            }
114
        }
115
        return false;
116
    }
117

  
118
}
0 119

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/PerimeterMeasurementExtension.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.geometrymeasurement.app.extension;
23

  
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

  
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.messages.NotificationManager;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.app.project.documents.view.gui.IView;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.exception.ReadException;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
38
import org.gvsig.fmap.mapcontext.layers.FLayer;
39
import org.gvsig.fmap.mapcontext.layers.FLayers;
40
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
41
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
42

  
43
/**
44
 * Andami extension to show PerimeterMeasurementExtension in the application.
45
 * 
46
 * @author gvSIG Team
47
 * @version $Id$
48
 */
49
public class PerimeterMeasurementExtension extends Extension {
50
    private static final Logger LOG = LoggerFactory.getLogger(AreaMeasurementExtension.class);
51
    private FLyrVect fLyrVect;
52

  
53
    public void initialize() {
54
        // Do nothing
55
    }
56

  
57
    @Override
58
    public void postInitialize() {
59
        super.postInitialize();       
60
    }
61

  
62
    public void execute(String actionCommand) {        
63
        Operations operations = new Operations();
64
        FeatureStore featureStore = fLyrVect.getFeatureStore();
65
        
66
        try {
67
            operations.addDoubleFieldFromOperation(featureStore, "PERIMETER", "perimeter");
68
        } catch (DataException e) {
69
           LOG.error("Not possible to create the perimeter field", e);
70
           NotificationManager.addError(e);
71
        } catch (GeometryOperationNotSupportedException e) {
72
            LOG.error("Not possible to create the perimeter field", e);
73
            NotificationManager.addError(e);
74
        } catch (GeometryOperationException e) {
75
            LOG.error("Not possible to create the perimeter field", e);
76
            NotificationManager.addError(e);
77
        }  
78
    }
79

  
80
    public boolean isEnabled() {
81
        return true;
82
    }
83

  
84
    public boolean isVisible() {
85
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
86

  
87
        if (window == null){
88
            return false;
89
        }
90
        if (window instanceof IView){
91
            IView view = (IView) window;
92
            FLayers layers = view.getMapControl().getMapContext().getLayers();
93
            FLayer[] activeLayers = layers.getActives();
94

  
95
            if (activeLayers.length == 1){
96
                if (activeLayers[0] instanceof FLyrVect){
97
                    fLyrVect = (FLyrVect) activeLayers[0];
98
                    try {
99
                        int type = fLyrVect.getShapeType();
100
                        if (Geometry.TYPES.POINT != type){                           
101
                            return true;
102
                        }
103
                    } catch (ReadException e) {
104
                        LOG.error("Error reading the geometry type", e);
105
                        return false;
106
                    }
107
                }
108
            }
109
        }
110
        return false;
111
    }
112

  
113
}
0 114

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/utils/Operations.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.geometrymeasurement.app.extension.utils;
23

  
24
import java.util.Iterator;
25

  
26
import org.gvsig.app.project.documents.table.TableOperations;
27
import org.gvsig.fmap.dal.exception.DataException;
28
import org.gvsig.fmap.dal.feature.EditableFeature;
29
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
30
import org.gvsig.fmap.dal.feature.EditableFeatureType;
31
import org.gvsig.fmap.dal.feature.Feature;
32
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
33
import org.gvsig.fmap.dal.feature.FeatureSet;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.dal.feature.FeatureType;
36
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
38
import org.gvsig.fmap.geom.primitive.Point;
39
import org.gvsig.tools.dataTypes.DataTypes;
40
import org.gvsig.tools.dispose.DisposableIterator;
41

  
42
/**
43
 * Andami extension to show PerimeterMeasurementExtension in the application.
44
 * 
45
 * @author gvSIG Team
46
 * @version $Id$
47
 */
48
public class Operations {
49
    private static final int NUM_DECIMALS = 5;
50

  
51
    public void addDoubleFieldFromOperation(FeatureStore featureStore, String fieldName, String operationName) throws DataException, GeometryOperationNotSupportedException, GeometryOperationException{
52
        boolean isEditing = false;
53
        if (featureStore.isEditing()){
54
            isEditing = true;
55
        }else{
56
            featureStore.edit();
57
        }        
58

  
59
        //Adding the new attribute type
60
        FeatureType featureType = featureStore.getDefaultFeatureType();
61
        EditableFeatureType editableFeatureType = featureType.getEditable();
62

  
63
        String realFieldName = getFieldName(featureStore, fieldName, 0);
64
        EditableFeatureAttributeDescriptor editableFeatureAttributeDescriptor = 
65
            editableFeatureType.add(realFieldName, DataTypes.DOUBLE);
66
        editableFeatureAttributeDescriptor.setPrecision(NUM_DECIMALS);
67
        editableFeatureAttributeDescriptor.setSize(TableOperations.MAX_FIELD_LENGTH);
68

  
69
        featureStore.update(editableFeatureType);        
70

  
71
        //Adding the attribute value
72
        FeatureSet featureSet = featureStore.getFeatureSet();
73
        DisposableIterator disposableIterator = featureSet.iterator();
74
        while (disposableIterator.hasNext()){
75
            Feature feature = (Feature)disposableIterator.next();
76
            EditableFeature editableFeature = feature.getEditable();        
77
            editableFeature.setDouble(realFieldName, (Double)feature.getDefaultGeometry().invokeOperation(operationName, null));
78
            featureSet.update(editableFeature);
79
        }    
80

  
81
        featureSet.dispose();            
82

  
83
        if (!isEditing){
84
            featureStore.finishEditing();             
85
        }        
86
    }
87

  
88
    public String getFieldName(FeatureStore featureStore, String fieldName, int index) throws DataException{
89
        String fullName = fieldName;
90
        if (index != 0){
91
            fullName = fullName + index;
92
        }
93
        Iterator it = featureStore.getDefaultFeatureType().iterator();        
94
        while (it.hasNext()){
95
            FeatureAttributeDescriptor featureAttributeDescriptor = (FeatureAttributeDescriptor)it.next();
96
            if (featureAttributeDescriptor.getName().equals(fullName)){
97
                return getFieldName(featureStore, fieldName, index+1);
98
            }
99
        }    
100
        return fullName;
101
    }
102

  
103
    /**
104
     * @param featureStore
105
     * @param string
106
     * @param string2
107
     * @throws DataException 
108
     */
109
    public void addXYPoints(FeatureStore featureStore, String xFieldName,
110
        String yFieldName) throws DataException {
111
        boolean isEditing = false;
112
        if (featureStore.isEditing()){
113
            isEditing = true;
114
        }else{
115
            featureStore.edit();
116
        }        
117

  
118
        //Adding the new attribute type
119
        FeatureType featureType = featureStore.getDefaultFeatureType();
120
        EditableFeatureType editableFeatureType = featureType.getEditable();
121

  
122
        String realXFieldName = getFieldName(featureStore, xFieldName, 0);
123
        EditableFeatureAttributeDescriptor editableFeatureAttributeDescriptor = 
124
            editableFeatureType.add(realXFieldName, DataTypes.DOUBLE);
125
        editableFeatureAttributeDescriptor.setPrecision(NUM_DECIMALS);
126
        editableFeatureAttributeDescriptor.setSize(TableOperations.MAX_FIELD_LENGTH);
127
        
128
        String realYFieldName = getFieldName(featureStore, yFieldName, 0);
129
        editableFeatureAttributeDescriptor = editableFeatureType.add(realYFieldName, DataTypes.DOUBLE);
130
        editableFeatureAttributeDescriptor.setPrecision(NUM_DECIMALS);
131
        editableFeatureAttributeDescriptor.setSize(TableOperations.MAX_FIELD_LENGTH);
132

  
133
        featureStore.update(editableFeatureType);        
134

  
135
        //Adding the attribute value
136
        FeatureSet featureSet = featureStore.getFeatureSet();
137
        DisposableIterator disposableIterator = featureSet.iterator();
138
        while (disposableIterator.hasNext()){
139
            Feature feature = (Feature)disposableIterator.next();
140
            EditableFeature editableFeature = feature.getEditable();        
141
            editableFeature.setDouble(realXFieldName, ((Point)feature.getDefaultGeometry()).getX());
142
            editableFeature.setDouble(realYFieldName, ((Point)feature.getDefaultGeometry()).getY());
143
            featureSet.update(editableFeature);
144
        }    
145

  
146
        featureSet.dispose();            
147

  
148
        if (!isEditing){
149
            featureStore.finishEditing();             
150
        }        
151

  
152
    }
153

  
154

  
155
}
0 156

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/AddXYPointThemeExtension.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.geometrymeasurement.app.extension;
23

  
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

  
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.messages.NotificationManager;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.app.project.documents.view.gui.IView;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.exception.ReadException;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.FLayers;
38
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
39
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
40

  
41
/**
42
 * Andami extension to show PerimeterMeasurementExtension in the application.
43
 * 
44
 * @author gvSIG Team
45
 * @version $Id$
46
 */
47
public class AddXYPointThemeExtension extends Extension {
48
    private static final Logger LOG = LoggerFactory.getLogger(AreaMeasurementExtension.class);
49
    private FLyrVect fLyrVect;  
50

  
51
    public void initialize() {
52
        // Do nothing
53
    }
54

  
55
    @Override
56
    public void postInitialize() {
57
        super.postInitialize();       
58
    }
59

  
60
    public void execute(String actionCommand) {
61
        Operations operations = new Operations();
62
        FeatureStore featureStore = fLyrVect.getFeatureStore();
63
        
64
        try {
65
            operations.addXYPoints(featureStore, "X", "Y");
66
        } catch (DataException e) {
67
           LOG.error("Not possible to create the X and Y fields", e);
68
           NotificationManager.addError(e);
69
        }    
70
    }
71
   
72
    public boolean isEnabled() {
73
        return true;
74
    }
75

  
76
    public boolean isVisible() {
77
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
78

  
79
        if (window == null){
80
            return false;
81
        }
82
        if (window instanceof IView){
83
            IView view = (IView) window;
84
            FLayers layers = view.getMapControl().getMapContext().getLayers();
85
            FLayer[] activeLayers = layers.getActives();
86

  
87
            if (activeLayers.length == 1){
88
                if (activeLayers[0] instanceof FLyrVect){
89
                    fLyrVect = (FLyrVect) activeLayers[0];
90
                    try {
91
                        int type = fLyrVect.getShapeType();
92
                        if (Geometry.TYPES.POINT == type){                           
93
                            return true;
94
                        }
95
                    } catch (ReadException e) {
96
                        LOG.error("Error reading the geometry type", e);
97
                        return false;
98
                    }
99
                }
100
            }
101
        }
102
        return false;
103
    }
104

  
105
}
0 106

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/resources/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<depends plugin-name="org.gvsig.app" />
4
	<resourceBundle name="text"/>
5
	<libraries library-dir="lib"/>
6
	<extensions>
7
		<extension class-name="org.gvsig.geometrymeasurement.app.extension.AreaMeasurementExtension"
8
			description="Extension that measures the area of all the polygonos they selected."
9
            active="true">
10
            <menu text="Vista/area" tooltip="area"
11
                action-command="AREA"
12
                icon="images/area.png" />
13
            <tool-bar name="area">
14
                <action-tool icon="images/area.png"
15
                    action-command="AREA" tooltip="area"
16
                    enable-text="deber?a de estar activada" last="true"/>
17
            </tool-bar>
18
		</extension>	
19
		<extension class-name="org.gvsig.geometrymeasurement.app.extension.PerimeterMeasurementExtension"
20
           description="Extension that measures the perimeter of all the lines they selected."
21
            active="true">
22
            <menu text="Vista/perimeter" tooltip="perimeter"
23
                action-command="PERIMETER"
24
                icon="images/perimeter.png" />
25
            <tool-bar name="perimeter">
26
                <action-tool icon="images/perimeter.png"
27
                    action-command="PERIMETER" tooltip="perimeter"
28
                    enable-text="deber?a de estar activada" last="true"/>
29
            </tool-bar>
30
        </extension>
31
        <extension class-name="org.gvsig.geometrymeasurement.app.extension.AddXYPointThemeExtension"
32
            description="Extension that add the coordinates x and y."
33
            active="true">
34
            <menu text="Vista/add_x_y" tooltip="add_x_y"
35
                action-command="ADDXYPOINT"
36
                icon="images/xypoint.png" />
37
            <tool-bar name="add_x_y">
38
                <action-tool icon="images/xypoint.png"
39
                    action-command="ADDXYPOINT" tooltip="add_x_y"
40
                    enable-text="deber?a de estar activada" last="true"/>
41
            </tool-bar>
42
        </extension>    	
43
	</extensions>
44
</plugin-config>
0 45

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/resources/build.number
1
#Build Number for ANT. Do not edit!
2
#Tue Apr 28 16:00:47 CEST 2009
3
build.number=2005
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.geometrymeasurement">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
0 38

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
0 9

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<artifactId>org.gvsig.geometrymeasurement.app.extension</artifactId>
7
	<packaging>jar</packaging>
8
	<name>org.gvsig.geometrymeasurement.app.extension</name>
9
    <description>Add 3 tools to gvSIG:
10
- Add a new attribute to the data source with the geometry area
11
- Add a new attribute to the data source with the geometry perimeter
12
- Add a new attribute to a Point type data source two new columns, one with the X Point value, and another with the Y Point value. 
13
    </description>
14
	<parent>
15
		<groupId>org.gvsig</groupId>
16
		<artifactId>org.gvsig.geometrymeasurement.app</artifactId>
17
		<version>1.0.0-SNAPSHOT</version>
18
	</parent>
19

  
20
	<dependencies>
21
		<dependency>
22
			<groupId>org.gvsig</groupId>
23
			<artifactId>org.gvsig.andami</artifactId>
24
		</dependency>
25
		<dependency>
26
           <groupId>org.gvsig</groupId>
27
            <artifactId>org.gvsig.app</artifactId>
28
            <version>2.0-SNAPSHOT</version>
29
        </dependency>
30
		<dependency>
31
			<groupId>org.gvsig</groupId>
32
			<artifactId>org.gvsig.i18n</artifactId>
33
		</dependency>
34
		<dependency>
35
			<groupId>org.gvsig</groupId>
36
			<artifactId>org.gvsig.tools.lib</artifactId>
37
		</dependency>	
38
	</dependencies>
39
	<profiles>
40
		<profile>
41
			<id>gvsig-install</id>
42
			<activation>
43
				<activeByDefault>true</activeByDefault>
44
			</activation>
45
			<properties>
46
				<!--
47
					Default gvSIG installation folder relative to the current workspace
48
				-->
49
				<gvsig.install.dir>${basedir}/../../build/product</gvsig.install.dir>
50
			</properties>
51
		</profile>
52
	</profiles>
53
    <properties>
54
        <build-dir>${basedir}/../../build</build-dir>
55
    </properties>    
56
</project>
0 57

  
tags/v2_0_0_Build_2023/extensions/org.gvsig.geometrymeasurement.app/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Tue Jan 11 12:25:20 CET 2011
3
buildNumber=2023
0 4

  

Also available in: Unified diff