Revision 541
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/distrib | ||
---|---|---|
1 |
#/bin/bash |
|
2 |
|
|
3 |
#USER= |
|
4 |
#PASS= |
|
5 |
|
|
6 |
REPO="https://devel.gvsig.org/svn/gvsig-geoprocess" |
|
7 |
|
|
8 |
INCREMENT=3 #1:major number 2:minor number 3:bug number |
|
9 |
PARAMETERS_LIN="-Dnative-platform=linux -Dnative-compiler=gcc4 -Dnative-arch=i386 -Dnative-distribution=all -Dlibrary-type=dynamic -Dnative-classifier=linux-all-gcc4-i386-dynamic -Dnative_classifier=linux-all-gcc4-i386-dynamic -Dmaven.test.skip" |
|
10 |
|
|
11 |
VERSION_TO_FIX=`cat pom.xml | grep "<version>" | head -n 1 | sed 's/<version>//g' | sed 's/-SNAPSHOT<\/version>//g'`; |
|
12 |
MAJOR_NUMBER=`echo $VERSION_TO_FIX | cut -d"." -f 1`; |
|
13 |
MINOR_NUMBER=`echo $VERSION_TO_FIX | cut -d"." -f 2`; |
|
14 |
BUG_NUMBER=`echo $VERSION_TO_FIX | cut -d"." -f 3`; |
|
15 |
|
|
16 |
VERSION_TO_FIX=$MAJOR_NUMBER"."$MINOR_NUMBER"."$BUG_NUMBER |
|
17 |
|
|
18 |
if [ $INCREMENT -eq 1 ]; then |
|
19 |
MAJOR_NUMBER=$((MAJOR_NUMBER+1)); |
|
20 |
fi |
|
21 |
|
|
22 |
if [ $INCREMENT -eq 2 ]; then |
|
23 |
MINOR_NUMBER=$((MINOR_NUMBER+1)); |
|
24 |
fi |
|
25 |
|
|
26 |
if [ $INCREMENT -eq 3 ]; then |
|
27 |
BUG_NUMBER=$((BUG_NUMBER+1)); |
|
28 |
fi |
|
29 |
|
|
30 |
NEXT_DEV_VERSION=$MAJOR_NUMBER"."$MINOR_NUMBER"."$BUG_NUMBER"-SNAPSHOT" |
|
31 |
|
|
32 |
echo Fixed version:$VERSION_TO_FIX |
|
33 |
echo New development version:$NEXT_DEV_VERSION |
|
34 |
#VERSION_TO_FIX=2.2.2 |
|
35 |
#NEXT_DEV_VERSION=2.2.3-SNAPSHOT |
|
36 |
|
|
37 |
#mvn release:prepare -B -DdryRun=false -Dtag=v$VERSION_TO_FIX -DreleaseVersion=$VERSION_TO_FIX -DdevelopmentVersion=$NEXT_DEV_VERSION -DpreparationGoals="clean install" -Dusername=$USER -Dpassword=$PASS -DignoreSnapshots=true -Darguments=$PARAMETERS_LIN |
|
38 |
|
|
39 |
read -p "¿Prepare de $i correcto? ¿Continuar? s/n: " CONTINUE |
|
40 |
if [ "$CONTINUE" == "n" ]; then |
|
41 |
mvn release:rollback |
|
42 |
exit; |
|
43 |
fi |
|
44 |
|
|
45 |
mvn release:perform -Dusername=$USER -Dpassword=$PASS -Darguments=$PARAMETERS_LIN |
|
46 |
|
|
47 |
read -p "¿Perform de $i correcto? ¿Continuar? s/n: " CONTINUE |
|
48 |
if [ "$CONTINUE" == "n" ]; then |
|
49 |
mvn release:rollback |
|
50 |
exit; |
|
51 |
fi |
|
52 |
|
|
0 | 53 |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.geoprocess.algorithm.intersection.IntersectionLibrary |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/resources/org/gvsig/geoprocess/algorithm/intersection/intersection.properties | ||
---|---|---|
1 |
# |
|
2 |
# gvSIG. Desktop Geographic Information System. |
|
3 |
# |
|
4 |
# Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
# For any additional information, do not hesitate to contact us |
|
22 |
# at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
# |
|
24 |
|
|
25 |
basic_vect_algorithms=Capas vectoriales |
|
26 |
Input_layer=Capa de entrada |
|
27 |
Overlays_layer=Capa de intersecci?n |
|
28 |
Selected_geometries=Geometrias seleccionadas |
|
29 |
Intersection=Intersecci?n |
|
30 |
Selected_geometries_input_layer_inters=Geom. seleccionadas (Capa entrada) |
|
31 |
Selected_geometries_overlay_layer_inters=Geom. seleccionadas (Capa intersecci?n) |
|
32 |
problems_with_some_geometries=El proceso ha terminado pero ocurri? un error en alguna geometr?a. Es posible que el resultado no sea del todo exacto. Consulte el log. |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/resources/org/gvsig/geoprocess/algorithm/intersection/intersection_en.properties | ||
---|---|---|
1 |
# |
|
2 |
# gvSIG. Desktop Geographic Information System. |
|
3 |
# |
|
4 |
# Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
# For any additional information, do not hesitate to contact us |
|
22 |
# at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
# |
|
24 |
|
|
25 |
basic_vect_algorithms=Vector layers tools |
|
26 |
Input_layer=Input cover |
|
27 |
Overlays_layer=Intersection cover |
|
28 |
Selected_geometries=Selected geometries |
|
29 |
Intersection=Intersection |
|
30 |
Selected_geometries_input_layer_inters=Selected features (Input cover) |
|
31 |
Selected_geometries_overlay_layer_inters=Selected features (Intersection cover) |
|
32 |
problems_with_some_geometries=The process has ended but an error happened in some geometry. Maybe the result not be totally accuracy. See the log. |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/resources/help/IntersectionAlgorithm.xml | ||
---|---|---|
1 |
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?> |
|
2 |
<!-- |
|
3 |
|
|
4 |
gvSIG. Desktop Geographic Information System. |
|
5 |
|
|
6 |
Copyright (C) 2007-2012 gvSIG Association. |
|
7 |
|
|
8 |
This program is free software; you can redistribute it and/or |
|
9 |
modify it under the terms of the GNU General Public License |
|
10 |
as published by the Free Software Foundation; either version 2 |
|
11 |
of the License, or (at your option) any later version. |
|
12 |
|
|
13 |
This program is distributed in the hope that it will be useful, |
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
GNU General Public License for more details. |
|
17 |
|
|
18 |
You should have received a copy of the GNU General Public License |
|
19 |
along with this program; if not, write to the Free Software |
|
20 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
MA 02110-1301, USA. |
|
22 |
|
|
23 |
For any additional information, do not hesitate to contact us |
|
24 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
25 |
|
|
26 |
--> |
|
27 |
<help> |
|
28 |
<element name="DESCRIPTION" text='Este geoproceso opera sobre dos capas, la "capa de entrada" y la "capa de solape", las geometrías de estas capas pueden ser de polígonos, líneas o puntos. Para cada geometría de la capa de entrada, calcula la interseccion con las diferentes geometrías de la capa de solape, originando un nuevo elemento por cada intersección. Este elemento tomará todos los atributos alfanuméricos de las geometrías que lo originaron (de entrada y solape). Por este motivo (modela zonas del espacio que cumplen la condición de pertenecer a los dos polígonos que lo han originado) a este geoproceso se le conoce como operador AND espacial. Un ejemplo de aplicación de este geoproceso sería para, dada una capa de usos del suelo Corine 2000, y una capa del mapa geológico nacional, obtener una capa de polígonos con información homogénea de uso del suelo y material geológico.' description="Descripción" type="0"> |
|
29 |
<image description="" file="intersectdesc.png"> |
|
30 |
</image> |
|
31 |
</element> |
|
32 |
<element name="ADDITIONAL_INFO" text="" description="Información adicional" type="0"> |
|
33 |
</element> |
|
34 |
<element name="EXTENSION_AUTHOR" text="Nacho Brodin" description="Algoritmo creado por" type="0"> |
|
35 |
</element> |
|
36 |
<element name="HELP_AUTHOR" text="" description="Ayuda creada por" type="0"> |
|
37 |
</element> |
|
38 |
<element name="USER_NOTES" text="" description="Notas de usuario" type="0"> |
|
39 |
</element> |
|
40 |
<element name="LAYER" text="" description="Capa de entrada" type="3"> |
|
41 |
</element> |
|
42 |
<element name="INTER" text="" description="Capa de revestimiento" type="3"> |
|
43 |
</element> |
|
44 |
<element name="CHECK" text="" description="Geometrias seleccionadas" type="3"> |
|
45 |
</element> |
|
46 |
<element name="OUTPUT_DESCRIPTION" text="" description="Descripción" type="2"> |
|
47 |
</element> |
|
48 |
<element name="RESULT" text="" description="Intersección" type="2"> |
|
49 |
</element> |
|
50 |
</help> |
|
51 |
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?> |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/resources/help/IntersectionAlgorithm_en.xml | ||
---|---|---|
1 |
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?> |
|
2 |
<!-- |
|
3 |
|
|
4 |
gvSIG. Desktop Geographic Information System. |
|
5 |
|
|
6 |
Copyright (C) 2007-2012 gvSIG Association. |
|
7 |
|
|
8 |
This program is free software; you can redistribute it and/or |
|
9 |
modify it under the terms of the GNU General Public License |
|
10 |
as published by the Free Software Foundation; either version 2 |
|
11 |
of the License, or (at your option) any later version. |
|
12 |
|
|
13 |
This program is distributed in the hope that it will be useful, |
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
GNU General Public License for more details. |
|
17 |
|
|
18 |
You should have received a copy of the GNU General Public License |
|
19 |
along with this program; if not, write to the Free Software |
|
20 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
MA 02110-1301, USA. |
|
22 |
|
|
23 |
For any additional information, do not hesitate to contact us |
|
24 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
25 |
|
|
26 |
--> |
|
27 |
<help> |
|
28 |
<element name="DESCRIPTION" text='This geoprocess works with two layers: the input layer and the overlay layer. For each geometry in the input layer, it computes its intersections with the geometries of the overlay layer. For each intersection, it adds a new feature with the intersection as geometry and all attributes of the features which originates it. It is called "Spatial AND", because features of the result layer models a space common to both layers.' description="Descripción" type="0"> |
|
29 |
<image description="" file="intersectdesc.png"> |
|
30 |
</image> |
|
31 |
</element> |
|
32 |
<element name="ADDITIONAL_INFO" text="" description="Información adicional" type="0"> |
|
33 |
</element> |
|
34 |
<element name="EXTENSION_AUTHOR" text="Nacho Brodin" description="Algoritmo creado por" type="0"> |
|
35 |
</element> |
|
36 |
<element name="HELP_AUTHOR" text="" description="Ayuda creada por" type="0"> |
|
37 |
</element> |
|
38 |
<element name="USER_NOTES" text="" description="Notas de usuario" type="0"> |
|
39 |
</element> |
|
40 |
<element name="LAYER" text="" description="Capa de entrada" type="3"> |
|
41 |
</element> |
|
42 |
<element name="INTER" text="" description="Capa de revestimiento" type="3"> |
|
43 |
</element> |
|
44 |
<element name="CHECK" text="" description="Geometrias seleccionadas" type="3"> |
|
45 |
</element> |
|
46 |
<element name="OUTPUT_DESCRIPTION" text="" description="Descripción" type="2"> |
|
47 |
</element> |
|
48 |
<element name="RESULT" text="" description="Intersección" type="2"> |
|
49 |
</element> |
|
50 |
</help> |
|
51 |
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?> |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/java/org/gvsig/geoprocess/algorithm/intersection/IntersectionOperation.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.geoprocess.algorithm.intersection; |
|
25 |
|
|
26 |
import java.util.Iterator; |
|
27 |
import java.util.List; |
|
28 |
|
|
29 |
import org.gvsig.fmap.dal.exception.DataException; |
|
30 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
31 |
import org.gvsig.fmap.dal.feature.Feature; |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
34 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
35 |
import org.gvsig.fmap.geom.GeometryManager; |
|
36 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
37 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
38 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
|
39 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
40 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
41 |
import org.gvsig.fmap.geom.operation.fromjts.FromJTS; |
|
42 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
43 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
44 |
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation; |
|
45 |
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil; |
|
46 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
|
47 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
48 |
import org.slf4j.Logger; |
|
49 |
import org.slf4j.LoggerFactory; |
|
50 |
|
|
51 |
import com.vividsolutions.jts.geom.Geometry; |
|
52 |
import com.vividsolutions.jts.geom.GeometryCollection; |
|
53 |
import com.vividsolutions.jts.geom.LineString; |
|
54 |
import com.vividsolutions.jts.geom.MultiLineString; |
|
55 |
import com.vividsolutions.jts.geom.MultiPoint; |
|
56 |
import com.vividsolutions.jts.geom.MultiPolygon; |
|
57 |
import com.vividsolutions.jts.geom.Point; |
|
58 |
import com.vividsolutions.jts.geom.Polygon; |
|
59 |
import com.vividsolutions.jts.precision.EnhancedPrecisionOp; |
|
60 |
|
|
61 |
import es.unex.sextante.core.Sextante; |
|
62 |
|
|
63 |
/** |
|
64 |
* Builds a geometry with the intersection between two layers |
|
65 |
* |
|
66 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
67 |
*/ |
|
68 |
public class IntersectionOperation extends GeometryOperation { |
|
69 |
private FeatureStore storeOverlay = null; |
|
70 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
71 |
private Logger log = LoggerFactory.getLogger(IntersectionOperation.class); |
|
72 |
private boolean errorInfo = false; |
|
73 |
|
|
74 |
public IntersectionOperation(FeatureStore overlayLayer, AbstractSextanteGeoProcess p) { |
|
75 |
super(p); |
|
76 |
this.storeOverlay = overlayLayer; |
|
77 |
} |
|
78 |
|
|
79 |
public boolean getErrorInfo() { |
|
80 |
return errorInfo; |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* Computes intersection between the geometry and the overlay layer. The fields of the |
|
85 |
* intersected features will be added. |
|
86 |
* @param g |
|
87 |
* @param featureInput |
|
88 |
* @return |
|
89 |
*/ |
|
90 |
@SuppressWarnings({ "unchecked", "deprecation" }) |
|
91 |
public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature featureInput) { |
|
92 |
if(g == null) |
|
93 |
return lastEditFeature; |
|
94 |
|
|
95 |
FeatureSet features = null; |
|
96 |
DisposableIterator it = null; |
|
97 |
try { |
|
98 |
if(selectedGeomOverlay) { |
|
99 |
features = (FeatureSet)storeOverlay.getSelection(); |
|
100 |
} else { |
|
101 |
features = storeOverlay.getFeatureSet(); |
|
102 |
} |
|
103 |
it = features.iterator(); |
|
104 |
} catch (DataException e) { |
|
105 |
Sextante.addErrorToLog(e); |
|
106 |
return lastEditFeature; |
|
107 |
} |
|
108 |
|
|
109 |
while( it.hasNext() ) { |
|
110 |
Feature featureOverlay = (Feature)it.next(); |
|
111 |
List geomList = featureOverlay.getGeometries(); |
|
112 |
if(geomList == null) { |
|
113 |
org.gvsig.fmap.geom.Geometry geom = featureOverlay.getDefaultGeometry(); |
|
114 |
lastEditFeature = intersection(g, geom, featureInput, featureOverlay); |
|
115 |
continue; |
|
116 |
} |
|
117 |
|
|
118 |
Iterator<org.gvsig.fmap.geom.Geometry> itGeom = geomList.iterator(); |
|
119 |
while(itGeom.hasNext()) { |
|
120 |
org.gvsig.fmap.geom.Geometry geom = itGeom.next(); |
|
121 |
lastEditFeature = intersection(g, geom, featureInput, featureOverlay); |
|
122 |
} |
|
123 |
} |
|
124 |
it.dispose(); |
|
125 |
return lastEditFeature; |
|
126 |
} |
|
127 |
|
|
128 |
private EditableFeature intersection( org.gvsig.fmap.geom.Geometry g1, |
|
129 |
org.gvsig.fmap.geom.Geometry g2, |
|
130 |
Feature featureInput, |
|
131 |
Feature featureOverlay) { |
|
132 |
Geometry overlaysGeom = null; |
|
133 |
Geometry jtsGeom = null; |
|
134 |
int outPutType = TYPES.SURFACE; |
|
135 |
|
|
136 |
try { |
|
137 |
outPutType = persister.getOutputFeatureStore().getDefaultFeatureType() |
|
138 |
.getDefaultGeometryAttribute().getGeomType().getType(); |
|
139 |
} catch (DataException e2) { |
|
140 |
Sextante.addErrorToLog(e2); |
|
141 |
} |
|
142 |
|
|
143 |
try { |
|
144 |
if( ((g1 instanceof Surface && g2 instanceof Curve) || |
|
145 |
(g2 instanceof Surface && g1 instanceof Curve)) && |
|
146 |
outPutType == TYPES.MULTIPOINT) { |
|
147 |
org.gvsig.fmap.geom.Geometry overGeom = (g1 instanceof Surface) ? g1 : g2; |
|
148 |
jtsGeom = (g1 instanceof Surface) ? GeometryUtil.geomToJTS(g2) : GeometryUtil.geomToJTS(g1); |
|
149 |
overlaysGeom = (Geometry)overGeom.invokeOperation("toJTSLineString", null); |
|
150 |
} else { |
|
151 |
if( g1 instanceof Surface && |
|
152 |
g2 instanceof Surface && |
|
153 |
(outPutType == TYPES.MULTIPOINT)) { |
|
154 |
jtsGeom = (Geometry)g1.invokeOperation("toJTSLineString", null); |
|
155 |
overlaysGeom = (Geometry)g2.invokeOperation("toJTSLineString", null); |
|
156 |
} else { |
|
157 |
jtsGeom = GeometryUtil.geomToJTS(g1); |
|
158 |
overlaysGeom = GeometryUtil.geomToJTS(g2); |
|
159 |
} |
|
160 |
} |
|
161 |
|
|
162 |
if(!jtsGeom.getEnvelope().intersects(overlaysGeom.getEnvelope())) |
|
163 |
return lastEditFeature; |
|
164 |
|
|
165 |
if(jtsGeom.intersects(overlaysGeom)) { |
|
166 |
Geometry newGeom = EnhancedPrecisionOp.intersection(jtsGeom, overlaysGeom); |
|
167 |
if(!newGeom.isEmpty()) { |
|
168 |
if(typesMatch(outPutType, newGeom) || newGeom instanceof GeometryCollection) { |
|
169 |
lastEditFeature = persister.addFeature(featureInput, featureOverlay, newGeom); |
|
170 |
} else { |
|
171 |
//Para intersecciones entre pol?gonos cuando la salida es de tipo l?nea |
|
172 |
//la generamos a partir del pol?gono resultante de la intersecci?n |
|
173 |
if( g1 instanceof Surface && |
|
174 |
g2 instanceof Surface && |
|
175 |
outPutType == TYPES.MULTICURVE && |
|
176 |
(newGeom instanceof Polygon || newGeom instanceof MultiPolygon)) { |
|
177 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
178 |
ctx.setAttribute(FromJTS.PARAM, newGeom); |
|
179 |
org.gvsig.fmap.geom.Geometry newDalGeom = (org.gvsig.fmap.geom.Geometry)geomManager.invokeOperation(FromJTS.NAME, ctx); |
|
180 |
newGeom = (Geometry)newDalGeom.invokeOperation("toJTSLineString", null); |
|
181 |
} |
|
182 |
|
|
183 |
lastEditFeature = persister.addFeature(featureInput, featureOverlay, newGeom); |
|
184 |
} |
|
185 |
} |
|
186 |
} |
|
187 |
} catch (CreateGeometryException e) { |
|
188 |
Sextante.addErrorToLog(e); |
|
189 |
} catch (DataException e) { |
|
190 |
Sextante.addErrorToLog(e); |
|
191 |
} catch (GeometryOperationNotSupportedException e1) { |
|
192 |
Sextante.addErrorToLog(e1); |
|
193 |
} catch (GeometryOperationException e1) { |
|
194 |
Sextante.addErrorToLog(e1); |
|
195 |
} catch (com.vividsolutions.jts.geom.TopologyException e) { |
|
196 |
/*try { |
|
197 |
Shape shape1 = g1.getShape(); |
|
198 |
Area area1 = new Area(shape1); |
|
199 |
|
|
200 |
Shape shape2 = g2.getShape(); |
|
201 |
Area area2 = new Area(shape2); |
|
202 |
area1.intersect(area2); |
|
203 |
PathIterator it = area1.getPathIterator(null); |
|
204 |
Surface s = null; |
|
205 |
MultiSurface ms = (MultiSurface)geomManager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D); |
|
206 |
float coords[] = new float[6]; |
|
207 |
while(!it.isDone()) { |
|
208 |
switch (it.currentSegment(coords)) { |
|
209 |
case PathIterator.SEG_MOVETO: |
|
210 |
s = (Surface)geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D); |
|
211 |
case PathIterator.SEG_LINETO: |
|
212 |
org.gvsig.fmap.geom.primitive.Point p = (org.gvsig.fmap.geom.primitive.Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D); |
|
213 |
p.setX(coords[0]); |
|
214 |
p.setY(coords[1]); |
|
215 |
s.addVertex(p); |
|
216 |
break; |
|
217 |
case PathIterator.SEG_CLOSE: |
|
218 |
p = (org.gvsig.fmap.geom.primitive.Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D); |
|
219 |
p.setX(coords[0]); |
|
220 |
p.setY(coords[1]); |
|
221 |
s.addVertex(p); |
|
222 |
ms.addSurface(s); |
|
223 |
break; |
|
224 |
} |
|
225 |
it.next(); |
|
226 |
} |
|
227 |
lastEditFeature = persister.addFeature(featureInput, featureOverlay, ms); |
|
228 |
} catch (CreateGeometryException e1) { |
|
229 |
} catch (DataException e1) { |
|
230 |
}*/ |
|
231 |
|
|
232 |
errorInfo = true; |
|
233 |
log.info("Problems operating intersection: ", e); |
|
234 |
} |
|
235 |
return lastEditFeature; |
|
236 |
} |
|
237 |
|
|
238 |
private boolean typesMatch(int dalType, Geometry newGeom) { |
|
239 |
return |
|
240 |
((dalType == TYPES.MULTICURVE && |
|
241 |
(newGeom instanceof MultiLineString || newGeom instanceof LineString)) || |
|
242 |
(dalType == TYPES.MULTIPOINT && |
|
243 |
(newGeom instanceof MultiPoint || newGeom instanceof Point)) || |
|
244 |
(dalType == TYPES.MULTISURFACE && |
|
245 |
(newGeom instanceof Polygon || newGeom instanceof MultiPolygon)) || |
|
246 |
(dalType == TYPES.CURVE && newGeom instanceof LineString) || |
|
247 |
(dalType == TYPES.SURFACE && newGeom instanceof Polygon) || |
|
248 |
(dalType == TYPES.POINT && newGeom instanceof Point)); |
|
249 |
|
|
250 |
} |
|
251 |
|
|
252 |
// private MultiCurve convertPolygonJTS2LineJTS(Polygon p) { |
|
253 |
// |
|
254 |
// } |
|
255 |
|
|
256 |
/** |
|
257 |
* clips feature's geometry with the clipping geometry, preserving |
|
258 |
* feature's original attributes. |
|
259 |
* If feature's geometry doesn't touch clipping geometry, it will be |
|
260 |
* ignored. |
|
261 |
*/ |
|
262 |
public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput) { |
|
263 |
/*if(g == null) |
|
264 |
return; |
|
265 |
|
|
266 |
Geometry jtsGeom = Converter.geometryToJts(g); |
|
267 |
|
|
268 |
if(!jtsGeom.getEnvelope().intersects(overlaysGeom.getEnvelope())) |
|
269 |
return; |
|
270 |
|
|
271 |
if(jtsGeom.intersects(overlaysGeom)) { |
|
272 |
try { |
|
273 |
Geometry newGeom = EnhancedPrecisionOp.difference(jtsGeom, overlaysGeom); |
|
274 |
persister.addFeature(feature, newGeom); |
|
275 |
} catch (CreateGeometryException e) { |
|
276 |
Sextante.addErrorToLog(e); |
|
277 |
} catch (DataException e) { |
|
278 |
Sextante.addErrorToLog(e); |
|
279 |
} |
|
280 |
} */ |
|
281 |
} |
|
282 |
|
|
283 |
} |
|
284 |
|
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/java/org/gvsig/geoprocess/algorithm/intersection/IntersectionLibrary.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.geoprocess.algorithm.intersection; |
|
25 |
|
|
26 |
import org.gvsig.geoprocess.algorithm.base.core.AlgorithmAbstractLibrary; |
|
27 |
import org.gvsig.i18n.Messages; |
|
28 |
import org.gvsig.tools.library.LibraryException; |
|
29 |
|
|
30 |
/** |
|
31 |
* Initialization of IntersectionLibrary library. |
|
32 |
* |
|
33 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
34 |
*/ |
|
35 |
public class IntersectionLibrary extends AlgorithmAbstractLibrary { |
|
36 |
|
|
37 |
@Override |
|
38 |
protected void doInitialize() throws LibraryException { |
|
39 |
|
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
protected void doPostInitialize() throws LibraryException { |
|
44 |
Messages.addResourceFamily( |
|
45 |
"org.gvsig.geoprocess.algorithm.intersection.intersection", |
|
46 |
IntersectionLibrary.class.getClassLoader(), |
|
47 |
IntersectionLibrary.class.getClass().getName()); |
|
48 |
registerGeoProcess(new IntersectionAlgorithm()); |
|
49 |
} |
|
50 |
|
|
51 |
} |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/src/main/java/org/gvsig/geoprocess/algorithm/intersection/IntersectionAlgorithm.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.geoprocess.algorithm.intersection; |
|
25 |
|
|
26 |
import javax.swing.JOptionPane; |
|
27 |
|
|
28 |
import org.gvsig.fmap.dal.exception.DataException; |
|
29 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
30 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
31 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
|
32 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer; |
|
33 |
|
|
34 |
import es.unex.sextante.core.Sextante; |
|
35 |
import es.unex.sextante.dataObjects.IVectorLayer; |
|
36 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
|
37 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
|
38 |
import es.unex.sextante.outputs.OutputVectorLayer; |
|
39 |
|
|
40 |
/** |
|
41 |
* Intersection algorithm |
|
42 |
* <UL> |
|
43 |
* <LI>Pol-Pol: 3 layers (polygon, point, line)</LI> |
|
44 |
* <LI>Pol-Line: 2 layers (point, line)</LI> |
|
45 |
* <LI>Pol-Point: 1 layer (point)</LI> |
|
46 |
* <LI>Line-Point: 1 layer (point)</LI> |
|
47 |
* <LI>Line-Line: 2 layers (point, line)</LI> |
|
48 |
* <LI>Point-Point: 1 layer (point)</LI> |
|
49 |
* </UL> |
|
50 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
51 |
*/ |
|
52 |
public class IntersectionAlgorithm extends AbstractSextanteGeoProcess { |
|
53 |
|
|
54 |
public static final String RESULT_POL = "RESULT_POL"; |
|
55 |
public static final String RESULT_POINT = "RESULT_POINT"; |
|
56 |
public static final String RESULT_LINE = "RESULT_LINE"; |
|
57 |
public static final String LAYER = "LAYER"; |
|
58 |
public static final String INTER = "INTER"; |
|
59 |
public static final String SELECTGEOM_INPUT = "SELECTGEOM_INPUT"; |
|
60 |
public static final String SELECTGEOM_OVERLAY = "SELECTGEOM_OVERLAY"; |
|
61 |
|
|
62 |
/* |
|
63 |
* (non-Javadoc) |
|
64 |
* @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics() |
|
65 |
*/ |
|
66 |
public void defineCharacteristics() { |
|
67 |
setName(getTranslation("Intersection")); |
|
68 |
setGroup(getTranslation("basic_vect_algorithms")); |
|
69 |
// setGeneratesUserDefinedRasterOutput(false); |
|
70 |
|
|
71 |
try { |
|
72 |
m_Parameters.addInputVectorLayer(LAYER, |
|
73 |
getTranslation("Input_layer"), |
|
74 |
IVectorLayer.SHAPE_TYPE_WRONG, |
|
75 |
true); |
|
76 |
m_Parameters.addInputVectorLayer(INTER, |
|
77 |
getTranslation("Overlays_layer"), |
|
78 |
IVectorLayer.SHAPE_TYPE_WRONG, |
|
79 |
true); |
|
80 |
m_Parameters.addBoolean(SELECTGEOM_INPUT, |
|
81 |
getTranslation("Selected_geometries_input_layer_inters"), false); |
|
82 |
m_Parameters.addBoolean(SELECTGEOM_OVERLAY, |
|
83 |
getTranslation("Selected_geometries_overlay_layer_inters"), false); |
|
84 |
} catch (RepeatedParameterNameException e) { |
|
85 |
Sextante.addErrorToLog(e); |
|
86 |
} |
|
87 |
addOutputVectorLayer(RESULT_POL, getTranslation("Intersection_polygon"), |
|
88 |
OutputVectorLayer.SHAPE_TYPE_POLYGON); |
|
89 |
addOutputVectorLayer(RESULT_LINE, getTranslation("Intersection_line"), |
|
90 |
OutputVectorLayer.SHAPE_TYPE_LINE); |
|
91 |
addOutputVectorLayer(RESULT_POINT, getTranslation("Intersection_point"), |
|
92 |
OutputVectorLayer.SHAPE_TYPE_POINT); |
|
93 |
} |
|
94 |
|
|
95 |
/* |
|
96 |
* (non-Javadoc) |
|
97 |
* @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm() |
|
98 |
*/ |
|
99 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
|
100 |
if(existsOutPutFile(IntersectionAlgorithm.RESULT_LINE, 0)) { |
|
101 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
|
102 |
} |
|
103 |
if(existsOutPutFile(IntersectionAlgorithm.RESULT_POINT, 0)) { |
|
104 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
|
105 |
} |
|
106 |
if(existsOutPutFile(IntersectionAlgorithm.RESULT_LINE, 0)) { |
|
107 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
|
108 |
} |
|
109 |
IVectorLayer inter = m_Parameters.getParameterValueAsVectorLayer(INTER); |
|
110 |
IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
|
111 |
boolean selectedGeomInput = m_Parameters.getParameter(SELECTGEOM_INPUT).getParameterValueAsBoolean(); |
|
112 |
boolean selectedGeomOverlay = m_Parameters.getParameter(SELECTGEOM_OVERLAY).getParameterValueAsBoolean(); |
|
113 |
boolean error = false; |
|
114 |
|
|
115 |
try { |
|
116 |
error = computesIntersection(layer, inter, layer.getShapeType(), selectedGeomInput, selectedGeomOverlay); |
|
117 |
} catch (DataException e) { |
|
118 |
Sextante.addErrorToLog(e); |
|
119 |
return false; |
|
120 |
} |
|
121 |
|
|
122 |
if(getTaskMonitor().isCanceled()) |
|
123 |
return false; |
|
124 |
if(error) |
|
125 |
JOptionPane.showMessageDialog(null, |
|
126 |
getTranslation("problems_with_some_geometries"), "Error", |
|
127 |
JOptionPane.WARNING_MESSAGE); |
|
128 |
return true; |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* Builds a layer with the intersection between the input layer and the templateGeometry |
|
133 |
* @param layer |
|
134 |
* Input layer |
|
135 |
* @param templateGeometry |
|
136 |
* @param shapeType |
|
137 |
* Output shape type |
|
138 |
* @param selectedGeom |
|
139 |
* If it's true only selected geometries will be computed |
|
140 |
* @throws GeoAlgorithmExecutionException |
|
141 |
*/ |
|
142 |
private boolean computesIntersection(IVectorLayer layer, |
|
143 |
IVectorLayer overlay, |
|
144 |
int shapeType, |
|
145 |
boolean selectedGeomInput, |
|
146 |
boolean selectedGeomOverlay) throws DataException, GeoAlgorithmExecutionException { |
|
147 |
FeatureStore storeLayer = null; |
|
148 |
FeatureStore storeOverlay = null; |
|
149 |
if(layer instanceof FlyrVectIVectorLayer && |
|
150 |
overlay instanceof FlyrVectIVectorLayer) { |
|
151 |
storeLayer = ((FlyrVectIVectorLayer)layer).getFeatureStore(); |
|
152 |
storeOverlay = ((FlyrVectIVectorLayer)overlay).getFeatureStore(); |
|
153 |
} else |
|
154 |
return false; |
|
155 |
|
|
156 |
FeatureType featureType1 = storeLayer.getDefaultFeatureType(); |
|
157 |
FeatureType featureType2 = storeOverlay.getDefaultFeatureType(); |
|
158 |
|
|
159 |
FeatureStore outFeatStorePol = null; |
|
160 |
FeatureStore outFeatStoreLine = null; |
|
161 |
FeatureStore outFeatStorePoint = null; |
|
162 |
|
|
163 |
IntersectionOperation operation = new IntersectionOperation(storeOverlay, this); |
|
164 |
operation.setTaskStatus(getStatus()); |
|
165 |
|
|
166 |
//La de puntos se genera siempre |
|
167 |
outFeatStorePoint = |
|
168 |
buildOutPutStoreFromUnion(featureType1, featureType2, |
|
169 |
IVectorLayer.SHAPE_TYPE_POINT, |
|
170 |
getTranslation("Intersection_point"), RESULT_POINT); |
|
171 |
|
|
172 |
getStatus().setTitle("Point"); |
|
173 |
operation.computesGeometryOperation(storeLayer, outFeatStorePoint, attrNames, |
|
174 |
selectedGeomInput, selectedGeomOverlay, true); |
|
175 |
|
|
176 |
//La de pol?gonos solo si es intersecci?n entre pol?gonos |
|
177 |
if (isPolygon(storeLayer) && isPolygon(storeOverlay)) { |
|
178 |
outFeatStorePol = |
|
179 |
buildOutPutStoreFromUnion(featureType1, featureType2, |
|
180 |
IVectorLayer.SHAPE_TYPE_POLYGON, getTranslation("Intersection_polygon"), RESULT_POL); |
|
181 |
getStatus().setTitle("Polygon"); |
|
182 |
operation.computesGeometryOperation(storeLayer, outFeatStorePol, attrNames, |
|
183 |
selectedGeomInput, selectedGeomOverlay, true); |
|
184 |
} |
|
185 |
|
|
186 |
//La capa de l?neas se genera cuando ning?na de las dos es de puntos |
|
187 |
if (!isPoint(storeLayer) && !isPoint(storeOverlay)) { |
|
188 |
outFeatStoreLine = |
|
189 |
buildOutPutStoreFromUnion(featureType1, featureType2, |
|
190 |
IVectorLayer.SHAPE_TYPE_LINE, getTranslation("Intersection_line"), RESULT_LINE); |
|
191 |
getStatus().setTitle("Line"); |
|
192 |
operation.computesGeometryOperation(storeLayer, outFeatStoreLine, attrNames, |
|
193 |
selectedGeomInput, selectedGeomOverlay, true); |
|
194 |
} |
|
195 |
|
|
196 |
if(outFeatStorePol == null) { |
|
197 |
getNewVectorLayer(RESULT_POL, getTranslation("Null_polygon"), |
|
198 |
OutputVectorLayer.SHAPE_TYPE_POLYGON, new Class[]{Integer.class}, new String[]{""}); |
|
199 |
} |
|
200 |
|
|
201 |
if(outFeatStoreLine == null) { |
|
202 |
getNewVectorLayer(RESULT_LINE, getTranslation("Null_line"), |
|
203 |
OutputVectorLayer.SHAPE_TYPE_LINE, new Class[]{Integer.class}, new String[]{""}); |
|
204 |
} |
|
205 |
|
|
206 |
if(outFeatStorePoint == null) { |
|
207 |
getNewVectorLayer(RESULT_POINT, getTranslation("Null_point"), |
|
208 |
OutputVectorLayer.SHAPE_TYPE_POINT, new Class[]{Integer.class}, new String[]{""}); |
|
209 |
} |
|
210 |
|
|
211 |
return operation.getErrorInfo(); |
|
212 |
} |
|
213 |
|
|
214 |
} |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.intersection/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.geoprocess.algorithm.intersection</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>org.gvsig.geoprocess.algorithm.intersection</name> |
|
7 |
|
|
8 |
<parent> |
|
9 |
<groupId>org.gvsig</groupId> |
|
10 |
<artifactId>org.gvsig.geoprocess.algorithm</artifactId> |
|
11 |
<version>2.2.3</version> |
|
12 |
</parent> |
|
13 |
|
|
14 |
<dependencies> |
|
15 |
<dependency> |
|
16 |
<groupId>org.gvsig</groupId> |
|
17 |
<artifactId>org.gvsig.geoprocess.algorithm.base</artifactId> |
|
18 |
<scope>compile</scope> |
|
19 |
</dependency> |
|
20 |
</dependencies> |
|
21 |
|
|
22 |
</project> |
|
0 | 23 |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.buffer/src/main/java/org/gvsig/geoprocess/algorithm/buffer/AbstractDistance.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.geoprocess.algorithm.buffer; |
|
25 |
|
|
26 |
import org.cresques.cts.IProjection; |
|
27 |
import org.gvsig.fmap.dal.feature.Feature; |
|
28 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
29 |
|
|
30 |
/** |
|
31 |
* Abstract distance implementation. |
|
32 |
* |
|
33 |
* @author gvSIG Team |
|
34 |
* @version $Id$ |
|
35 |
*/ |
|
36 |
public abstract class AbstractDistance implements IDistance { |
|
37 |
|
|
38 |
public static final double EARTH_RADIUS = 6378137d; |
|
39 |
protected int numberOfRings = 1; |
|
40 |
protected Feature feature = null; |
|
41 |
|
|
42 |
public void setFeature(Feature feature) { |
|
43 |
this.feature = feature; |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* For computing with geodetic coordinates: |
|
48 |
* returns the angular measure (in radians) |
|
49 |
* for a distance over the earth along a |
|
50 |
* meridiam. |
|
51 |
* Because this consideration is an approximation, |
|
52 |
* we consideer the eart like an sphere (not an |
|
53 |
* ellipsoid) |
|
54 |
* |
|
55 |
* @param dist |
|
56 |
* distance in meters |
|
57 |
* @return arc of meridian whose length is the specified |
|
58 |
* distance |
|
59 |
*/ |
|
60 |
private double toSexaAngularMeasure(double dist) { |
|
61 |
/* |
|
62 |
* dist = 6378km(terrestrial radius) -> 2PI |
|
63 |
* passed distance -> incognite |
|
64 |
*/ |
|
65 |
return Math.toDegrees((2 * Math.PI * dist) / EARTH_RADIUS); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Converts a distance entered by user in the GUI in the same distance |
|
70 |
* in internal units (measure units) |
|
71 |
*/ |
|
72 |
protected double getInInternalUnits(double userEntryDistance, |
|
73 |
IProjection proj, int distanceUnits, int mapUnits) { |
|
74 |
|
|
75 |
/* double[] trans2Meter = MapContext.getDistanceTrans2Meter(); |
|
76 |
double distInInternalUnits = |
|
77 |
(userEntryDistance / trans2Meter[mapUnits]) |
|
78 |
* trans2Meter[distanceUnits]; |
|
79 |
|
|
80 |
if ((proj != null) && !(proj.isProjected())) |
|
81 |
distInInternalUnits = toSexaAngularMeasure(distInInternalUnits); |
|
82 |
|
|
83 |
return distInInternalUnits;*/ |
|
84 |
|
|
85 |
/* |
|
86 |
* En caso de que el sistema de referencia sea proyectado se usa la distancia |
|
87 |
* que el usuario ha definido, ya que esta se supone en metros. En caso de que |
|
88 |
* las coordenadas sean en geogr?ficas se toma la distancia que el usuario ha |
|
89 |
* definido en metros en el ecuador. Esto supone una desviaci?n a medida que |
|
90 |
* nos alejamos del ecuador. Una posible soluci?n ser?a obtener esa distancia |
|
91 |
* para la posici?n en el planeta en la que se encuentra la cartograf?a en la |
|
92 |
* proyecci?n en la que est? definida. |
|
93 |
*/ |
|
94 |
|
|
95 |
if ((proj != null) && !(proj.isProjected())) |
|
96 |
return userEntryDistance / 111352D; |
|
97 |
return userEntryDistance; |
|
98 |
} |
|
99 |
|
|
100 |
public void setNumberOfRings(int n) { |
|
101 |
numberOfRings = n; |
|
102 |
} |
|
103 |
|
|
104 |
} |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.buffer/src/main/java/org/gvsig/geoprocess/algorithm/buffer/BufferLibrary.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.geoprocess.algorithm.buffer; |
|
25 |
|
|
26 |
import org.gvsig.geoprocess.algorithm.base.core.AlgorithmAbstractLibrary; |
|
27 |
import org.gvsig.i18n.Messages; |
|
28 |
import org.gvsig.tools.library.LibraryException; |
|
29 |
|
|
30 |
/** |
|
31 |
* Initialization of BufferLibrary library. |
|
32 |
* |
|
33 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
34 |
* @author gvSIG Team |
|
35 |
*/ |
|
36 |
public class BufferLibrary extends AlgorithmAbstractLibrary { |
|
37 |
|
|
38 |
@Override |
|
39 |
protected void doInitialize() throws LibraryException { |
|
40 |
// Nothing to do |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void doPostInitialize() throws LibraryException { |
|
45 |
Messages.addResourceFamily( |
|
46 |
"org.gvsig.geoprocess.algorithm.buffer.buffer", BufferLibrary.class |
|
47 |
.getClassLoader(), BufferLibrary.class.getClass().getName()); |
|
48 |
registerGeoProcess(new BufferAlgorithm()); |
|
49 |
} |
|
50 |
|
|
51 |
} |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.buffer/src/main/java/org/gvsig/geoprocess/algorithm/buffer/FieldDistance.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.geoprocess.algorithm.buffer; |
|
25 |
|
|
26 |
import org.cresques.cts.IProjection; |
|
27 |
|
|
28 |
/** |
|
29 |
* Computes a constant size of each geometry built |
|
30 |
* |
|
31 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
32 |
*/ |
|
33 |
public class FieldDistance extends AbstractDistance { |
|
34 |
|
|
35 |
private int attributePosition = 0; |
|
36 |
|
|
37 |
public FieldDistance(int attributePosition) { |
|
38 |
this.attributePosition = attributePosition; |
|
39 |
} |
|
40 |
|
|
41 |
public double getBufferDistance(IProjection projection, int distanceUnits, int mapUnits) { |
|
42 |
double attr = 0D; |
|
43 |
Object obj = feature.get(attributePosition); |
|
44 |
if (obj instanceof Double) |
|
45 |
attr = ((Double) obj).doubleValue(); |
|
46 |
else |
|
47 |
if (obj instanceof Integer) |
|
48 |
attr = ((Integer) obj).doubleValue(); |
|
49 |
else |
|
50 |
if (obj instanceof Float) |
|
51 |
attr = ((Float) obj).doubleValue(); |
|
52 |
else |
|
53 |
return 0; |
|
54 |
|
|
55 |
return getInInternalUnits(attr, projection, distanceUnits, mapUnits) * numberOfRings; |
|
56 |
} |
|
57 |
|
|
58 |
} |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.3/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.buffer/src/main/java/org/gvsig/geoprocess/algorithm/buffer/BufferAlgorithm.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.geoprocess.algorithm.buffer; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
import javax.swing.JOptionPane; |
|
29 |
|
|
30 |
import org.cresques.cts.IProjection; |
|
31 |
import org.gvsig.fmap.dal.DALLocator; |
|
32 |
import org.gvsig.fmap.dal.DataManager; |
|
33 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
34 |
import org.gvsig.fmap.dal.DataTypes; |
|
35 |
import org.gvsig.fmap.dal.exception.DataException; |
|
36 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
37 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
38 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
39 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
40 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
41 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
42 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
43 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
44 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
|
45 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
|
46 |
import org.gvsig.fmap.geom.Geometry; |
|
47 |
import org.gvsig.geoprocess.lib.api.GeoProcessLocator; |
|
48 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
|
49 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer; |
|
50 |
|
|
51 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
|
52 |
import es.unex.sextante.core.Sextante; |
|
53 |
import es.unex.sextante.dataObjects.IVectorLayer; |
|
54 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
|
55 |
import es.unex.sextante.exceptions.NullParameterValueException; |
|
56 |
import es.unex.sextante.exceptions.OptionalParentParameterException; |
|
57 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
|
58 |
import es.unex.sextante.exceptions.UndefinedParentParameterNameException; |
|
59 |
import es.unex.sextante.exceptions.UnsupportedOutputChannelException; |
|
60 |
import es.unex.sextante.exceptions.WrongParameterIDException; |
|
61 |
import es.unex.sextante.exceptions.WrongParameterTypeException; |
|
62 |
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel; |
|
63 |
import es.unex.sextante.outputs.OutputVectorLayer; |
|
64 |
|
|
65 |
/** |
|
66 |
* Geoprocess that computes a buffer area around each feature's geometry of the |
|
67 |
* input layer. <br> |
|
68 |
* All the points interior to this buffer area has to be at a distance inferior |
|
69 |
* to "buffer distance" to the original geometry. This buffer distance could be |
|
70 |
* constant, or it could be a function of the value of a feature attribute.<br> |
|
71 |
* |
|
72 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
73 |
* @author gvSIG Team |
|
74 |
*/ |
|
75 |
public class BufferAlgorithm extends AbstractSextanteGeoProcess { |
|
76 |
|
|
77 |
public static final String RESULT = "RESULT"; |
|
78 |
public static final String LAYER = "LAYER"; |
|
79 |
public static final String SELECTED_GEOM = "SELECTED_GEOM"; |
|
80 |
public static final String DISTANCE = "DISTANCE"; |
|
81 |
public static final String FIELD = "FIELD"; |
|
82 |
public static final String DISSOLVE = "DISSOLVE"; |
|
83 |
public static final String ROUND_BORDER = "ROUND_BORDER"; |
|
84 |
public static final String AREA = "AREA"; |
|
85 |
public static final String RING_NUMBER = "RING_NUMBER"; |
|
86 |
|
|
87 |
/** |
|
88 |
* For polygonal buffers, only compute exterior buffers |
|
89 |
* (is the default operation, it applies to any geometry type) |
|
90 |
*/ |
|
91 |
public static final byte BUFFER_OUTSIDE_POLY = 0; |
|
92 |
/** |
|
93 |
* For polygonal buffers, only compute interior buffers |
|
94 |
*/ |
|
95 |
public static final byte BUFFER_INSIDE_POLY = 1; |
|
96 |
/** |
|
97 |
* For polygonal buffers, compute interior and exterior buffers |
|
98 |
*/ |
|
99 |
public static final byte BUFFER_INSIDE_OUTSIDE_POLY = 2; |
|
100 |
|
|
101 |
public static final byte SOURCE_FIELDS = 0; |
|
102 |
public static final byte FID_DIST_FIELDS = 1; |
|
103 |
public static final byte FID_FROM_TO_FIELDS = 2; |
|
104 |
protected byte tableFields = -1; |
|
105 |
|
|
106 |
private int inflArea = BUFFER_OUTSIDE_POLY; |
|
107 |
protected boolean dissolve = false; |
|
108 |
protected int rings = 0; |
|
109 |
protected boolean selectedGeom = false; |
|
110 |
protected FeatureStore inputStore = null; |
|
111 |
protected FeatureStore outputStore = null; |
|
112 |
protected IVectorLayer sextanteInputLayer = null; |
|
113 |
protected boolean round_border = false; |
|
114 |
|
|
115 |
public static String[] sOptions = { |
|
116 |
GeoProcessLocator.getGeoProcessManager().getTranslation("poly_out"), |
|
117 |
GeoProcessLocator.getGeoProcessManager().getTranslation("poly_in"), |
|
118 |
GeoProcessLocator.getGeoProcessManager().getTranslation("poly_inandout") |
|
119 |
}; |
|
120 |
|
|
121 |
public void defineCharacteristics() { |
|
122 |
setName(getTranslation("Buffer")); |
|
123 |
setGroup(getTranslation("basic_vect_algorithms")); |
|
124 |
// setGeneratesUserDefinedRasterOutput(false); |
|
125 |
|
|
126 |
try { |
|
127 |
m_Parameters.addInputVectorLayer(LAYER, getTranslation("Input_layer"), |
|
128 |
IVectorLayer.SHAPE_TYPE_WRONG, true); |
|
129 |
m_Parameters.addBoolean(SELECTED_GEOM, getTranslation("Selected_geometries"), false); |
|
130 |
m_Parameters.addNumericalValue(DISTANCE, getTranslation("area_distance"), 0, |
|
131 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE); |
|
132 |
m_Parameters.addTableField(FIELD, getTranslation("area_field"), "LAYER"); |
|
133 |
m_Parameters.addBoolean(DISSOLVE, getTranslation("Dissolve_entities"), false); |
|
134 |
m_Parameters.addBoolean(ROUND_BORDER, getTranslation("Round_border"), true); |
|
135 |
m_Parameters.addSelection(AREA, getTranslation("Builds_influence_area"), sOptions); |
|
136 |
m_Parameters.addSelection(RING_NUMBER, getTranslation("Number_of_rings"), |
|
137 |
new String[] { "1", "2", "3" }); |
|
138 |
} catch (RepeatedParameterNameException e) { |
|
139 |
Sextante.addErrorToLog(e); |
|
140 |
} catch (UndefinedParentParameterNameException e) { |
|
141 |
Sextante.addErrorToLog(e); |
|
142 |
} catch (OptionalParentParameterException e) { |
|
143 |
Sextante.addErrorToLog(e); |
|
144 |
} |
|
145 |
addOutputVectorLayer(RESULT, getTranslation("Buffer"), |
|
146 |
OutputVectorLayer.SHAPE_TYPE_POLYGON); |
|
147 |
} |
|
148 |
|
|
149 |
protected void readParameters() throws WrongParameterTypeException, NullParameterValueException, WrongParameterIDException { |
|
150 |
sextanteInputLayer = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
|
151 |
selectedGeom = m_Parameters.getParameter(SELECTED_GEOM).getParameterValueAsBoolean(); |
|
152 |
rings = m_Parameters.getParameterValueAsInt(RING_NUMBER); |
|
153 |
dissolve = m_Parameters.getParameter(DISSOLVE).getParameterValueAsBoolean(); |
|
154 |
round_border = m_Parameters.getParameter(ROUND_BORDER).getParameterValueAsBoolean(); |
|
155 |
} |
|
156 |
|
|
157 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
|
158 |
if(existsOutPutFile(BufferAlgorithm.RESULT, 0)) { |
|
159 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
|
160 |
} |
|
161 |
|
|
162 |
double distanceValue = m_Parameters.getParameter(DISTANCE).getParameterValueAsDouble(); |
|
163 |
int attributePosition = m_Parameters.getParameterValueAsInt(FIELD); |
|
164 |
inflArea = m_Parameters.getParameterValueAsInt(AREA); |
|
165 |
readParameters(); |
|
166 |
|
|
167 |
if (sextanteInputLayer.getShapeType() != IVectorLayer.SHAPE_TYPE_POLYGON |
|
168 |
&& inflArea != BUFFER_OUTSIDE_POLY) { |
|
169 |
JOptionPane.showMessageDialog(null, |
|
170 |
getTranslation("Wrong_type_for_this_shapetype"), "Error", |
|
171 |
JOptionPane.WARNING_MESSAGE); |
|
172 |
inflArea = BUFFER_OUTSIDE_POLY; |
|
173 |
} |
|
174 |
|
|
175 |
if (sextanteInputLayer instanceof FlyrVectIVectorLayer) |
|
176 |
inputStore = ((FlyrVectIVectorLayer) sextanteInputLayer).getFeatureStore(); |
|
177 |
else |
|
178 |
return false; |
|
179 |
|
|
180 |
try { |
|
181 |
// Object to compute the distance |
|
182 |
IDistance distance = null; |
|
183 |
if (distanceValue == 0) |
|
184 |
distance = new FieldDistance(attributePosition); |
|
185 |
else |
|
186 |
distance = new ConstantDistance(distanceValue); |
|
187 |
|
|
188 |
// Object to compute the buffer operation |
|
189 |
BufferOperation operation = null; |
|
190 |
switch (inflArea) { |
|
191 |
case BUFFER_OUTSIDE_POLY: |
|
192 |
operation = new OutBufferOperation(distance, inputStore, this, getTableFieldsStructure()); |
|
193 |
break; |
|
194 |
case BUFFER_INSIDE_POLY: |
|
195 |
operation = new InBufferOperation(distance, inputStore, this, getTableFieldsStructure()); |
|
196 |
break; |
|
197 |
case BUFFER_INSIDE_OUTSIDE_POLY: |
|
198 |
operation = new InOutBufferOperation(distance, inputStore, this, getTableFieldsStructure()); |
|
199 |
break; |
|
200 |
} |
|
201 |
operation.setTypeOfCap(round_border ? BufferOperation.CAP_ROUND : BufferOperation.CAP_SQUARE); |
|
202 |
operation.setGeoProcess(this, 100); |
|
203 |
|
|
204 |
// Builds the output FeatureStore |
|
205 |
outputStore = buildOutPutStore(IVectorLayer.SHAPE_TYPE_POLYGON, |
|
206 |
getTranslation("Buffer"), RESULT); |
|
207 |
|
|
208 |
if(!dissolve) { |
|
209 |
computesBufferAlgWithoutDissolve(operation); |
|
210 |
} else { |
|
211 |
computesBufferAlgWithDissolve(operation); |
|
212 |
} |
|
213 |
|
|
214 |
} catch (DataException e) { |
|
215 |
Sextante.addErrorToLog(e); |
|
216 |
return false; |
|
217 |
} |
|
218 |
|
|
219 |
if(getTaskMonitor().isCanceled()) |
|
220 |
return false; |
|
221 |
|
|
222 |
return true; |
|
223 |
} |
|
224 |
|
|
225 |
private void computesOneRingBufferWithDissolve( |
|
226 |
BufferOperation operation, |
|
227 |
FuseOperation fuseOp, |
|
228 |
String idFile, |
|
229 |
int initialPosition, |
|
230 |
int ringPosition) throws ValidateDataParametersException, DataException { |
|
231 |
String file = System.getProperty("java.io.tmpdir") + File.separator + (idFile) + ".shp"; |
|
232 |
FeatureStore outAuxFeatStore = buildTemporalStore(org.gvsig.fmap.geom.Geometry.TYPES.SURFACE, file, |
|
233 |
inputStore.getDefaultFeatureType().getDefaultSRS()); |
|
234 |
|
|
235 |
operation.getDistance().setNumberOfRings(ringPosition + 1); |
|
236 |
|
|
237 |
operation.setNumberOfRadialBuffers(1); |
|
238 |
operation.setTaskStatus(getStatus()); |
|
239 |
m_Task.setProgressText(getTranslation("calc_buffer") + " [Ring:" + (rings - ringPosition) + "]"); |
|
240 |
operation.computesGeometryOperation(inputStore, outAuxFeatStore, |
|
241 |
attrNames, selectedGeom, false, true); |
|
242 |
|
|
243 |
outAuxFeatStore = open(file, inputStore.getDefaultFeatureType().getDefaultSRS()); |
|
244 |
|
|
245 |
m_Task.setProgressText(getTranslation("fuse_spatially") + " [Ring:" + (rings - ringPosition) + "]"); |
|
246 |
fuseOp.computesGeometryOperation(outAuxFeatStore, outputStore, attrNames, ringPosition == initialPosition ? true : false); |
|
247 |
outAuxFeatStore.dispose(); |
|
248 |
} |
|
249 |
|
|
250 |
protected void computesBufferAlgWithDissolve(BufferOperation operation) throws DataException { |
|
251 |
long fileTmpId = System.currentTimeMillis(); |
|
252 |
FuseOperation fuseOp = new FuseOperation(this); |
|
253 |
|
|
254 |
if(inflArea == BUFFER_OUTSIDE_POLY || inflArea == BUFFER_INSIDE_OUTSIDE_POLY) { |
|
255 |
try { |
|
256 |
for (int i = rings; i >= 0 ; i--) { |
|
257 |
computesOneRingBufferWithDissolve( |
|
258 |
operation, |
|
259 |
fuseOp, |
|
260 |
fileTmpId + i + "", |
|
261 |
rings, |
|
262 |
i); |
|
263 |
} |
|
264 |
} catch (ValidateDataParametersException e) { |
|
265 |
Sextante.addErrorToLog(e); |
|
266 |
} |
|
267 |
} |
|
268 |
|
|
269 |
if(inflArea == BUFFER_INSIDE_POLY) { |
|
270 |
try { |
|
271 |
for (int i = 0; i < rings + 1 ; i++) { |
|
272 |
computesOneRingBufferWithDissolve( |
|
273 |
operation, |
|
274 |
fuseOp, |
|
275 |
fileTmpId + i + "", |
|
276 |
0, |
|
277 |
i); |
|
278 |
} |
|
279 |
} catch (ValidateDataParametersException e) { |
|
280 |
Sextante.addErrorToLog(e); |
|
281 |
} |
|
282 |
} |
|
283 |
|
|
284 |
fuseOp.end(); |
|
285 |
} |
|
286 |
|
|
287 |
protected void computesBufferAlgWithoutDissolve(BufferOperation operation) throws DataException { |
|
288 |
operation.setNumberOfRadialBuffers(rings + 1); |
|
289 |
operation.setTaskStatus(getStatus()); |
|
290 |
operation.computesGeometryOperation(inputStore, |
|
291 |
outputStore, |
|
292 |
attrNames, |
|
293 |
selectedGeom, |
|
294 |
false, |
|
295 |
true); |
|
296 |
} |
|
297 |
|
|
298 |
|
|
299 |
/** |
|
300 |
* Gets the constant with the table structure |
|
301 |
* @return |
|
302 |
*/ |
|
303 |
protected byte getTableFieldsStructure() { |
|
304 |
if(tableFields == -1) { |
|
305 |
if(!dissolve) { |
|
306 |
tableFields = SOURCE_FIELDS; |
|
307 |
} else { |
|
308 |
if (inflArea == BUFFER_INSIDE_OUTSIDE_POLY) |
|
309 |
tableFields = FID_FROM_TO_FIELDS; |
|
310 |
else |
|
311 |
tableFields = FID_DIST_FIELDS; |
|
312 |
} |
|
313 |
} |
|
314 |
return tableFields; |
|
315 |
} |
|
316 |
|
|
317 |
/** |
|
318 |
* Open a <code>DataStore</code> |
|
319 |
* @param file |
|
320 |
* @param proj |
|
321 |
* @return |
|
322 |
* @throws InitializeException |
|
323 |
* @throws ProviderNotRegisteredException |
|
324 |
* @throws ValidateDataParametersException |
|
325 |
*/ |
|
326 |
private FeatureStore open(String file, IProjection proj) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
|
327 |
DataManager manager = DALLocator.getDataManager(); |
|
328 |
DataStoreParameters params = manager.createStoreParameters("Shape"); |
|
329 |
params.setDynValue("shpfile", file); |
|
330 |
params.setDynValue("crs", proj); |
|
331 |
FeatureStore featureStore = (FeatureStore) manager.openStore(params.getDataStoreName(), params); |
|
332 |
return featureStore; |
|
333 |
} |
|
334 |
|
|
335 |
/** |
|
336 |
* Builds the output FeatureStore |
|
337 |
* |
|
338 |
* @param featureType |
|
339 |
* @return FeatureStore |
|
340 |
* @throws DataException |
|
341 |
*/ |
|
342 |
protected FeatureStore buildOutPutStore(int shapeType, |
|
343 |
String sextanteLayerName, |
|
344 |
String sextanteLayerLabel) throws DataException { |
|
345 |
FeatureType featureType = inputStore.getDefaultFeatureType(); |
|
346 |
|
|
347 |
if(getTableFieldsStructure() == SOURCE_FIELDS) { |
|
348 |
return super.buildOutPutStore(featureType, shapeType,sextanteLayerName, sextanteLayerLabel); |
|
349 |
} |
|
350 |
Class<?>[] types = null; |
|
351 |
if (getTableFieldsStructure() == FID_FROM_TO_FIELDS) { |
|
352 |
types = new Class[] { Integer.class, Double.class, Double.class }; |
|
353 |
attrNames = new String[] { "FID", "FROM", "TO" }; |
|
354 |
} |
|
355 |
if (getTableFieldsStructure() == FID_DIST_FIELDS) { |
|
356 |
types = new Class[] { Integer.class, Double.class }; |
|
357 |
attrNames = new String[] { "FID", "DIST" }; |
|
358 |
} |
|
359 |
try { |
|
360 |
IVectorLayer output = |
|
361 |
getNewVectorLayer(sextanteLayerLabel, sextanteLayerName, |
|
362 |
shapeType, types, attrNames); |
|
363 |
return ((FlyrVectIVectorLayer) output).getFeatureStore(); |
|
364 |
} catch (UnsupportedOutputChannelException e) { |
|
365 |
Sextante.addErrorToLog(e); |
|
366 |
} catch (GeoAlgorithmExecutionException e) { |
|
367 |
Sextante.addErrorToLog(e); |
|
368 |
} |
|
369 |
|
|
370 |
return null; |
|
371 |
} |
|
372 |
|
|
373 |
/** |
|
374 |
* Builds the output FeatureStore |
|
375 |
* |
|
376 |
* @param featureType |
|
377 |
* @return FeatureStore |
|
378 |
* @throws DataException |
|
379 |
* @throws ValidateDataParametersException |
|
380 |
*/ |
|
381 |
protected FeatureStore buildTemporalStore(int shapeType, |
|
382 |
String file, |
|
383 |
IProjection crs) throws DataException, ValidateDataParametersException { |
|
384 |
FeatureType featureType = inputStore.getDefaultFeatureType(); |
|
385 |
|
|
386 |
int[] types = null; |
|
387 |
if(getTableFieldsStructure() == SOURCE_FIELDS) { |
|
388 |
FeatureAttributeDescriptor[] desc = featureType.getAttributeDescriptors(); |
|
389 |
types = new int[desc.length - 1]; |
|
390 |
attrNames = new String[desc.length - 1]; |
|
391 |
int attrCount = 0; |
|
392 |
for (int i = 0; i < desc.length; i++) { |
|
393 |
if(desc[i].getType() != DataTypes.GEOMETRY) { |
|
394 |
types[attrCount] = desc[i].getType(); |
|
395 |
attrNames[attrCount] = desc[i].getName(); |
|
396 |
attrCount ++; |
|
397 |
} |
|
398 |
} |
|
399 |
} |
Also available in: Unified diff