Revision 716
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.31/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.buffer/src/main/java/org/gvsig/geoprocess/algorithm/buffer/InOutBufferOperation.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.util.ArrayList; |
|
27 |
import java.util.List; |
|
28 |
import java.util.Stack; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.exception.DataException; |
|
31 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
32 |
import org.gvsig.fmap.dal.feature.Feature; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
34 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
35 |
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil; |
|
36 |
import org.gvsig.geoprocess.algorithm.base.util.JTSFacade; |
|
37 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
|
38 |
|
|
39 |
import com.vividsolutions.jts.geom.Geometry; |
|
40 |
import com.vividsolutions.jts.geom.GeometryCollection; |
|
41 |
import com.vividsolutions.jts.geom.GeometryFactory; |
|
42 |
import com.vividsolutions.jts.geom.MultiPolygon; |
|
43 |
import com.vividsolutions.jts.geom.Polygon; |
|
44 |
import com.vividsolutions.jts.operation.buffer.BufferOp; |
|
45 |
import com.vividsolutions.jts.operation.buffer.BufferParameters; |
|
46 |
import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier; |
|
47 |
|
|
48 |
import es.unex.sextante.core.Sextante; |
|
49 |
|
|
50 |
/** |
|
51 |
* Buffer operation |
|
52 |
* |
|
53 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
54 |
*/ |
|
55 |
public class InOutBufferOperation extends BufferOperation { |
|
56 |
|
|
57 |
/** |
|
58 |
* Builds an instance of this operation. |
|
59 |
* |
|
60 |
* @param distance |
|
61 |
* @param layer |
|
62 |
* @param userDistance |
|
63 |
*/ |
|
64 |
public InOutBufferOperation(IDistance distance, |
|
65 |
FeatureStore inputStore, |
|
66 |
AbstractSextanteGeoProcess p, |
|
67 |
byte tableFields) { |
|
68 |
super(distance, inputStore, p, tableFields); |
|
69 |
} |
|
70 |
|
|
71 |
public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, |
|
72 |
Feature feature) { |
|
73 |
GeometryFactory geomFact = new GeometryFactory(); |
|
74 |
Geometry newGeom = null; |
|
75 |
Geometry previousExteriorRing = null; |
|
76 |
Geometry previousInteriorRing = null; |
|
77 |
Geometry originalGeometry = GeometryUtil.geomToJTS(g); |
|
78 |
Geometry inputParam = originalGeometry; |
|
79 |
distance.setFeature(feature); |
|
80 |
double bufferDistance = |
|
81 |
distance.getBufferDistance(projection, |
|
82 |
getDistanceUnits(), getMapUnits()); |
|
83 |
|
|
84 |
if (originalGeometry.getDimension() != 0) |
|
85 |
inputParam = |
|
86 |
TopologyPreservingSimplifier.simplify(originalGeometry, |
|
87 |
bufferDistance / 10d); |
|
88 |
|
|
89 |
for (int i = 1; i <= numberOfRadialBuffers; i++) { |
|
90 |
double distRing = i * bufferDistance; |
|
91 |
BufferOp bufOp = new BufferOp(inputParam); |
|
92 |
bufOp.setEndCapStyle(capBuffer == CAP_ROUND |
|
93 |
? BufferParameters.CAP_ROUND : BufferParameters.CAP_SQUARE); |
|
94 |
Geometry out = bufOp.getResultGeometry(distRing); |
|
95 |
Geometry in = bufOp.getResultGeometry(-1 * distRing); |
|
96 |
boolean collapsedInterior = verifyNilGeometry(in); |
|
97 |
if (previousExteriorRing == null || previousInteriorRing == null) { |
|
98 |
if (collapsedInterior) |
|
99 |
newGeom = out; |
|
100 |
else |
|
101 |
newGeom = JTSFacade.difference(out, in); |
|
102 |
} else { |
|
103 |
if (collapsedInterior) |
|
104 |
newGeom = JTSFacade.difference(out, previousExteriorRing); |
|
105 |
else { |
|
106 |
Geometry outRing = |
|
107 |
JTSFacade.difference(out, previousExteriorRing); |
|
108 |
Geometry inRing = |
|
109 |
JTSFacade.difference(previousInteriorRing, in); |
|
110 |
|
|
111 |
Geometry[] geomArray = new Geometry[] { outRing, inRing }; |
|
112 |
newGeom = geomFact.createGeometryCollection(geomArray); |
|
113 |
|
|
114 |
// FMap doesnt work with GeometryCollection, so we try to |
|
115 |
// pass to a MultiPolygon. |
|
116 |
List<Geometry> polygons = new ArrayList<Geometry>(); |
|
117 |
Stack<Geometry> stack = new Stack<Geometry>(); |
|
118 |
stack.push(newGeom); |
|
119 |
while (stack.size() != 0) { |
|
120 |
GeometryCollection geCol = |
|
121 |
(GeometryCollection) stack.pop(); |
|
122 |
|
|
123 |
for (int j = 0; j < geCol.getNumGeometries(); j++) { |
|
124 |
Geometry geometry = geCol.getGeometryN(j); |
|
125 |
if (geometry instanceof GeometryCollection) |
|
126 |
stack.push(geometry); |
|
127 |
if (geometry instanceof Polygon) |
|
128 |
polygons.add(geometry); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
Polygon[] pols = new Polygon[polygons.size()]; |
|
133 |
pols = polygons.toArray(pols); |
|
134 |
MultiPolygon newSolution = |
|
135 |
geomFact.createMultiPolygon(pols); |
|
136 |
newGeom = newSolution; |
|
137 |
} |
|
138 |
} |
|
139 |
try { |
|
140 |
if (newGeom != null && !newGeom.isEmpty()) { |
|
141 |
if(getTableFieldStructure() == BufferAlgorithm.SOURCE_FIELDS) |
|
142 |
lastEditFeature = persister.addFeature(feature, newGeom); |
|
143 |
else |
|
144 |
lastEditFeature = persister.addFeature(newGeom, id, -1 * distRing, distRing); |
|
145 |
id++; |
|
146 |
} |
|
147 |
} catch (CreateGeometryException e) { |
|
148 |
Sextante.addErrorToLog(e); |
|
149 |
} catch (DataException e) { |
|
150 |
Sextante.addErrorToLog(e); |
|
151 |
} |
|
152 |
previousExteriorRing = out; |
|
153 |
if (!collapsedInterior) |
|
154 |
previousInteriorRing = in; |
|
155 |
} |
|
156 |
return lastEditFeature; |
|
157 |
} |
|
158 |
|
|
159 |
/* |
|
160 |
* (non-Javadoc) |
|
161 |
* |
|
162 |
* @see |
|
163 |
* org.gvsig.geoprocess.algorithm.base.core.GeometryOperation#invoke(org |
|
164 |
* .gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.EditableFeature) |
|
165 |
*/ |
|
166 |
public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature feature) { |
|
167 |
invoke(g, (Feature) feature); |
|
168 |
} |
|
169 |
} |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.31/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.buffer/src/main/java/org/gvsig/geoprocess/algorithm/buffer/BufferOperation.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.andami.PluginServices; |
|
28 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
29 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
|
30 |
import org.gvsig.fmap.dal.exception.DataException; |
|
31 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
32 |
import org.gvsig.fmap.dal.feature.Feature; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
34 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
35 |
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation; |
|
36 |
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil; |
|
37 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
|
38 |
|
|
39 |
import com.vividsolutions.jts.geom.Geometry; |
|
40 |
import com.vividsolutions.jts.geom.GeometryCollection; |
|
41 |
|
|
42 |
/** |
|
43 |
* Buffer operation |
|
44 |
* |
|
45 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
46 |
*/ |
|
47 |
public abstract class BufferOperation extends GeometryOperation { |
|
48 |
|
|
49 |
public static final byte CAP_SQUARE = 0; |
|
50 |
public static final byte CAP_ROUND = 1; |
|
51 |
|
|
52 |
protected byte capBuffer = CAP_ROUND; |
|
53 |
protected int numberOfRadialBuffers = 1; |
|
54 |
protected IDistance distance = null; |
|
55 |
protected int id = 0; |
|
56 |
protected IProjection projection = null; |
|
57 |
protected byte tableFieldStructure = BufferAlgorithm.SOURCE_FIELDS; |
|
58 |
|
|
59 |
public BufferOperation(IDistance distance, |
|
60 |
FeatureStore inputStore, |
|
61 |
AbstractSextanteGeoProcess p, |
|
62 |
byte tableFieldStructure) { |
|
63 |
super(p); |
|
64 |
this.distance = distance; |
|
65 |
try { |
|
66 |
this.projection = (IProjection) inputStore.getDefaultFeatureType().getDefaultSRS(); |
|
67 |
} catch (DataException e) { |
|
68 |
} |
|
69 |
this.tableFieldStructure = tableFieldStructure; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Verifys if a geometry buffer is null. |
|
74 |
* It is useful when you're working with internal buffers. If the internal |
|
75 |
* buffer distance is greater than the geometry radius, the buffer result |
|
76 |
* will be null. |
|
77 |
* |
|
78 |
* @param newGeometry |
|
79 |
* @return |
|
80 |
*/ |
|
81 |
protected boolean verifyNilGeometry(Geometry newGeometry) { |
|
82 |
if (newGeometry instanceof GeometryCollection) { |
|
83 |
if (((GeometryCollection) newGeometry).getNumGeometries() == 0) { |
|
84 |
// we have collapsed initial geometry |
|
85 |
return true; |
|
86 |
} |
|
87 |
} |
|
88 |
return false; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Adds a new feature |
|
93 |
* |
|
94 |
* @param feature |
|
95 |
* @param newGeom |
|
96 |
* @throws CreateGeometryException |
|
97 |
* @throws DataException |
|
98 |
* @deprecated No es necesario porque no hay diferencia entre las llamadas |
|
99 |
* entre ambos invoke |
|
100 |
*/ |
|
101 |
protected void addFeature(Feature feature, Geometry newGeom) |
|
102 |
throws CreateGeometryException, DataException { |
|
103 |
if (!(feature instanceof EditableFeature)) |
|
104 |
lastEditFeature = persister.addFeature(feature, newGeom); |
|
105 |
else { |
|
106 |
org.gvsig.fmap.geom.Geometry g = GeometryUtil.jtsToGeom(newGeom); |
|
107 |
persister |
|
108 |
.addGeometryToExistingFeature((EditableFeature) feature, g); |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Sets type of cap flag |
|
114 |
* |
|
115 |
* @param typeOfCap |
|
116 |
*/ |
|
117 |
public void setTypeOfCap(byte typeOfCap) { |
|
118 |
capBuffer = typeOfCap; |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* Sets number of radial rings buffers |
|
123 |
* |
|
124 |
* @param number |
|
125 |
*/ |
|
126 |
public void setNumberOfRadialBuffers(int number) { |
|
127 |
numberOfRadialBuffers = number; |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* <p> |
|
132 |
* Gets the measurement unit used by this view port for the map. |
|
133 |
* </p> |
|
134 |
* |
|
135 |
* @return Returns the current map measure unit |
|
136 |
*/ |
|
137 |
protected int getMapUnits() { |
|
138 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
|
139 |
if (!(w instanceof AbstractViewPanel)) { |
|
140 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows(); |
|
141 |
for (int i = 0; i < wList.length; i++) { |
|
142 |
if (wList[i] instanceof AbstractViewPanel) |
|
143 |
w = (IWindow) wList[i]; |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
if (w != null && w instanceof AbstractViewPanel) { |
|
148 |
IProjection proj = |
|
149 |
((AbstractViewPanel) w).getMapControl().getViewPort() |
|
150 |
.getProjection(); |
|
151 |
if (proj.isProjected()) |
|
152 |
return ((AbstractViewPanel) w).getMapControl().getViewPort() |
|
153 |
.getMapUnits(); |
|
154 |
} |
|
155 |
return 1; |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* <p> |
|
160 |
* Returns the measurement unit of this view port used for measuring |
|
161 |
* distances and displaying information. |
|
162 |
* </p> |
|
163 |
* |
|
164 |
* @return the measurement unit of this view used for measuring distances |
|
165 |
* and displaying information |
|
166 |
*/ |
|
167 |
protected int getDistanceUnits() { |
|
168 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
|
169 |
if (!(w instanceof AbstractViewPanel)) { |
|
170 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows(); |
|
171 |
for (int i = 0; i < wList.length; i++) { |
|
172 |
if (wList[i] instanceof AbstractViewPanel) |
|
173 |
w = (IWindow) wList[i]; |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
if (w != null && w instanceof AbstractViewPanel) |
|
178 |
return ((AbstractViewPanel) w).getMapControl().getViewPort() |
|
179 |
.getDistanceUnits(); |
|
180 |
else |
|
181 |
return 1; |
|
182 |
} |
|
183 |
|
|
184 |
public byte getTableFieldStructure() { |
|
185 |
return tableFieldStructure; |
|
186 |
} |
|
187 |
|
|
188 |
public IDistance getDistance() { |
|
189 |
return distance; |
|
190 |
} |
|
191 |
} |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.31/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.buffer/src/main/java/org/gvsig/geoprocess/algorithm/buffer/BufferParametersPanel.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.awt.BorderLayout; |
|
27 |
import java.awt.GridBagConstraints; |
|
28 |
import java.awt.GridBagLayout; |
|
29 |
import java.awt.Insets; |
|
30 |
import java.awt.event.ActionEvent; |
|
31 |
import java.awt.event.ActionListener; |
|
32 |
import java.util.ArrayList; |
|
33 |
import java.util.List; |
|
34 |
|
|
35 |
import javax.swing.BorderFactory; |
|
36 |
import javax.swing.ButtonGroup; |
|
37 |
import javax.swing.ComboBoxModel; |
|
38 |
import javax.swing.DefaultComboBoxModel; |
|
39 |
import javax.swing.JCheckBox; |
|
40 |
import javax.swing.JComboBox; |
|
41 |
import javax.swing.JLabel; |
|
42 |
import javax.swing.JPanel; |
|
43 |
import javax.swing.JRadioButton; |
|
44 |
import javax.swing.JScrollPane; |
|
45 |
import javax.swing.JTextField; |
|
46 |
|
|
47 |
import org.gvsig.geoprocess.lib.api.GeoProcessLocator; |
|
48 |
import org.gvsig.geoprocess.sextante.gui.algorithm.AlgorithmOutputPanel; |
|
49 |
|
|
50 |
import es.unex.sextante.core.GeoAlgorithm; |
|
51 |
import es.unex.sextante.core.ObjectAndDescription; |
|
52 |
import es.unex.sextante.core.OutputObjectsSet; |
|
53 |
import es.unex.sextante.core.ParametersSet; |
|
54 |
import es.unex.sextante.core.Sextante; |
|
55 |
import es.unex.sextante.dataObjects.IVectorLayer; |
|
56 |
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel; |
|
57 |
import es.unex.sextante.gui.algorithm.OutputChannelSelectionPanel; |
|
58 |
import es.unex.sextante.gui.core.SextanteGUI; |
|
59 |
import es.unex.sextante.outputs.Output; |
|
60 |
|
|
61 |
/** |
|
62 |
* Panel for buffer algorithm |
|
63 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
64 |
*/ |
|
65 |
public class BufferParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener { |
|
66 |
private static final long serialVersionUID = 1L; |
|
67 |
private final int marginSides = 15; |
|
68 |
private final int marginBottom = 8; |
|
69 |
private GeoAlgorithm m_Algorithm = null; |
|
70 |
private JComboBox layers = null; |
|
71 |
private JComboBox fields = null; |
|
72 |
private JComboBox influenceAreas = null; |
|
73 |
private JComboBox radialBuffers = null; |
|
74 |
private JCheckBox selectionOnly = null; |
|
75 |
private JCheckBox dissolveEntities = null; |
|
76 |
private JCheckBox roundBorder = null; |
|
77 |
private JTextField distance = null; |
|
78 |
private JRadioButton selectDistance = null; |
|
79 |
private JRadioButton selectField = null; |
|
80 |
|
|
81 |
private List<String> fieldList = new ArrayList<String>(); |
|
82 |
private AlgorithmOutputPanel algorithmOutputPanel = null; |
|
83 |
private OutputChannelSelectionPanel outputChannelSelectionPanel; |
|
84 |
private JPanel outputPanel; |
|
85 |
|
|
86 |
public BufferParametersPanel() { |
|
87 |
super(); |
|
88 |
} |
|
89 |
|
|
90 |
public void init(GeoAlgorithm algorithm) { |
|
91 |
m_Algorithm = algorithm; |
|
92 |
initGUI(); |
|
93 |
} |
|
94 |
|
|
95 |
private void initGUI() { |
|
96 |
this.setLayout(new BorderLayout()); |
|
97 |
this.add(getMainJScrollPane(), BorderLayout.CENTER); |
|
98 |
} |
|
99 |
|
|
100 |
private JScrollPane getMainJScrollPane() { |
|
101 |
JPanel panel = new JPanel(); |
|
102 |
GridBagLayout gbl = new GridBagLayout(); |
|
103 |
panel.setLayout(gbl); |
|
104 |
|
|
105 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
106 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
107 |
gbc.weightx = 1.0; |
|
108 |
gbc.gridx = 0; |
|
109 |
gbc.gridy = 0; |
|
110 |
gbc.insets = new Insets(0, marginSides, 0, marginSides); |
|
111 |
panel.add(getInputPanel(), gbc); |
|
112 |
|
|
113 |
gbc.gridy = 1; |
|
114 |
panel.add(getOptionsPanel(), gbc); |
|
115 |
|
|
116 |
gbc.gridy = 2; |
|
117 |
panel.add(getOutputsPanel(), gbc); |
|
118 |
JScrollPane scrollPane = new JScrollPane(panel); |
|
119 |
return scrollPane; |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* Gets the output panel (SEXTANTE) |
|
124 |
* @return |
|
125 |
*/ |
|
126 |
private JPanel getOutputChannelSelectionPanel() { |
|
127 |
if(outputPanel == null) { |
|
128 |
try { |
|
129 |
outputPanel = new JPanel(); |
|
130 |
outputPanel.setLayout(new BorderLayout()); |
|
131 |
final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects(); |
|
132 |
final Output out = ooSet.getOutput(BufferAlgorithm.RESULT); |
|
133 |
outputChannelSelectionPanel = new OutputChannelSelectionPanel(out, m_Algorithm.getParameters()); |
|
134 |
outputPanel.add(new JLabel(" " + GeoProcessLocator.getGeoProcessManager().getTranslation("Buffer") + |
|
135 |
" [" + GeoProcessLocator.getGeoProcessManager().getTranslation("Vectorial") + |
|
136 |
"] "), BorderLayout.WEST); |
|
137 |
outputPanel.add(outputChannelSelectionPanel, BorderLayout.CENTER); |
|
138 |
} catch (final Exception e) { |
|
139 |
Sextante.addErrorToLog(e); |
|
140 |
} |
|
141 |
} |
|
142 |
return outputPanel; |
|
143 |
} |
|
144 |
|
|
145 |
/** |
|
146 |
* Gets the output panel |
|
147 |
* @return |
|
148 |
*/ |
|
149 |
@SuppressWarnings("unused") |
|
150 |
private AlgorithmOutputPanel getAlgorithmOutputPanel() { |
|
151 |
if(algorithmOutputPanel == null) |
|
152 |
algorithmOutputPanel = new AlgorithmOutputPanel(); |
|
153 |
return algorithmOutputPanel; |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* Gets a new input panel |
|
158 |
* @param text |
|
159 |
* @param combo |
|
160 |
* @return |
|
161 |
*/ |
|
162 |
public JPanel getOutputsPanel() { |
|
163 |
JPanel panel = new JPanel(); |
|
164 |
GridBagLayout gbl = new GridBagLayout(); |
|
165 |
panel.setLayout(gbl); |
|
166 |
panel.setBorder(BorderFactory.createTitledBorder(GeoProcessLocator.getGeoProcessManager().getTranslation("outputs"))); |
|
167 |
|
|
168 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
169 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
170 |
gbc.weightx = 1.0; |
|
171 |
gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
|
172 |
panel.add(getOutputChannelSelectionPanel(), gbc); |
|
173 |
|
|
174 |
return panel; |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* Gets a new input panel |
|
179 |
* @param text |
|
180 |
* @param combo |
|
181 |
* @return |
|
182 |
*/ |
|
183 |
public JPanel getInputPanel() { |
|
184 |
JPanel panel = new JPanel(); |
|
185 |
GridBagLayout gbl = new GridBagLayout(); |
|
186 |
panel.setLayout(gbl); |
|
187 |
panel.setBorder(BorderFactory.createTitledBorder(GeoProcessLocator.getGeoProcessManager().getTranslation("input"))); |
|
188 |
|
|
189 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
190 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
191 |
gbc.weightx = 1.0; |
|
192 |
gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
|
193 |
panel.add(getComboLayers(), gbc); |
|
194 |
|
|
195 |
return panel; |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* Gets a new options panel |
|
200 |
* @param text |
|
201 |
* @param combo |
|
202 |
* @return |
|
203 |
*/ |
|
204 |
public JPanel getOptionsPanel() { |
|
205 |
JPanel panel = new JPanel(); |
|
206 |
GridBagLayout gbl = new GridBagLayout(); |
|
207 |
panel.setLayout(gbl); |
|
208 |
panel.setBorder(BorderFactory.createTitledBorder(GeoProcessLocator.getGeoProcessManager().getTranslation("options"))); |
|
209 |
|
|
210 |
ButtonGroup group = new ButtonGroup(); |
|
211 |
group.add(getRadioSelectDistance()); |
|
212 |
group.add(getRadioSelectField()); |
|
213 |
|
|
214 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
215 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
216 |
gbc.weightx = 1.0; |
|
217 |
gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
|
218 |
panel.add(getRadioSelectField(), gbc); |
|
219 |
|
|
220 |
gbc.gridy = 1; |
|
221 |
gbc.insets = new Insets(0, marginSides + 10, marginBottom, marginSides); |
|
222 |
panel.add(getComboFields(), gbc); |
|
223 |
|
|
224 |
gbc.gridy = 2; |
|
225 |
gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
|
226 |
panel.add(getRadioSelectDistance(), gbc); |
|
227 |
|
|
228 |
gbc.gridy = 3; |
|
229 |
gbc.insets = new Insets(0, marginSides + 10, marginBottom, marginSides); |
|
230 |
panel.add(getTextDistance(), gbc); |
|
231 |
|
|
232 |
gbc.gridy = 4; |
|
233 |
gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
|
234 |
panel.add(getCheckSelectedGeom(), gbc); |
|
235 |
|
|
236 |
gbc.gridy = 5; |
|
237 |
panel.add(getCheckDissolveEntities(), gbc); |
|
238 |
|
|
239 |
gbc.gridy = 6; |
|
240 |
panel.add(getCheckRoundBorder(), gbc); |
|
241 |
|
|
242 |
gbc.gridy = 7; |
|
243 |
panel.add(getComboInfluenceAreas(), gbc); |
|
244 |
|
|
245 |
gbc.gridy = 8; |
|
246 |
panel.add(getComboRadialBuffers(), gbc); |
|
247 |
|
|
248 |
checkLineLayer(); |
|
249 |
|
|
250 |
return panel; |
|
251 |
} |
|
252 |
|
|
253 |
/** |
|
254 |
* Gets a ComboBox |
|
255 |
* @return |
|
256 |
*/ |
|
257 |
public JComboBox getComboLayers() { |
|
258 |
if(layers == null) { |
|
259 |
layers = new JComboBox(); |
|
260 |
ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList()); |
|
261 |
layers.setModel(comboModel); |
|
262 |
layers.addActionListener(this); |
|
263 |
} |
|
264 |
return layers; |
|
265 |
} |
|
266 |
|
|
267 |
/** |
|
268 |
* Gets a influence areas ComboBox |
|
269 |
* @return |
|
270 |
*/ |
|
271 |
public JComboBox getComboInfluenceAreas() { |
|
272 |
if(influenceAreas == null) { |
|
273 |
influenceAreas = new JComboBox(); |
|
274 |
for (int i = 0; i < BufferAlgorithm.sOptions.length; i++) { |
|
275 |
influenceAreas.addItem(BufferAlgorithm.sOptions[i]); |
|
276 |
} |
|
277 |
influenceAreas.addActionListener(this); |
|
278 |
} |
|
279 |
return influenceAreas; |
|
280 |
} |
|
281 |
|
|
282 |
/** |
|
283 |
* Gets a influence areas ComboBox |
|
284 |
* @return |
|
285 |
*/ |
|
286 |
public JComboBox getComboRadialBuffers() { |
|
287 |
if(radialBuffers == null) { |
|
288 |
radialBuffers = new JComboBox(); |
|
289 |
radialBuffers.addItem(BufferAlgorithm.BUFFER_OUTSIDE_POLY + 1 + ""); |
|
290 |
radialBuffers.addItem(BufferAlgorithm.BUFFER_INSIDE_POLY + 1 + ""); |
|
291 |
radialBuffers.addItem(BufferAlgorithm.BUFFER_INSIDE_OUTSIDE_POLY + 1 + ""); |
|
292 |
radialBuffers.addActionListener(this); |
|
293 |
} |
|
294 |
return radialBuffers; |
|
295 |
} |
|
296 |
|
|
297 |
/** |
|
298 |
* Gets a CheckBox |
|
299 |
* @return |
|
300 |
*/ |
|
301 |
public JCheckBox getCheckSelectedGeom() { |
|
302 |
if(selectionOnly == null) { |
|
303 |
selectionOnly = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Selected_geometries")); |
|
304 |
} |
|
305 |
return selectionOnly; |
|
306 |
} |
|
307 |
|
|
308 |
/** |
|
309 |
* Gets a CheckBox |
|
310 |
* @return |
|
311 |
*/ |
|
312 |
public JCheckBox getCheckDissolveEntities() { |
|
313 |
if(dissolveEntities == null) { |
|
314 |
dissolveEntities = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Dissolve_entities")); |
|
315 |
} |
|
316 |
return dissolveEntities; |
|
317 |
} |
|
318 |
|
|
319 |
/** |
|
320 |
* Gets a CheckBox |
|
321 |
* @return |
|
322 |
*/ |
|
323 |
public JCheckBox getCheckRoundBorder() { |
|
324 |
if(roundBorder == null) { |
|
325 |
roundBorder = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Round_border")); |
|
326 |
} |
|
327 |
return roundBorder; |
|
328 |
} |
|
329 |
|
|
330 |
/** |
|
331 |
* Gets a ComboBox |
|
332 |
* @return |
|
333 |
*/ |
|
334 |
public JComboBox getComboFields() { |
|
335 |
if(fields == null) { |
|
336 |
fields = new JComboBox(); |
|
337 |
loadFieldsInAreaCombo(); |
|
338 |
fields.setEnabled(true); |
|
339 |
} |
|
340 |
return fields; |
|
341 |
} |
|
342 |
|
|
343 |
private void loadFieldsInAreaCombo() { |
|
344 |
List<String> fieldList = getFieldList(); |
|
345 |
getComboFields().removeAllItems(); |
|
346 |
for (int i = 0; i < fieldList.size(); i++) |
|
347 |
getComboFields().addItem(fieldList.get(i)); |
|
348 |
} |
|
349 |
|
|
350 |
private void checkLineLayer() { |
|
351 |
IVectorLayer vectorLyr = getSelectedVectorLayer(); |
|
352 |
if(vectorLyr.getShapeType() == IVectorLayer.SHAPE_TYPE_LINE || vectorLyr.getShapeType() == IVectorLayer.SHAPE_TYPE_POINT) { |
|
353 |
getComboInfluenceAreas().setSelectedIndex(BufferAlgorithm.BUFFER_OUTSIDE_POLY); |
|
354 |
getComboInfluenceAreas().setEnabled(false); |
|
355 |
} else { |
|
356 |
getComboInfluenceAreas().setEnabled(true); |
|
357 |
} |
|
358 |
} |
|
359 |
|
|
360 |
/** |
|
361 |
* Gets a CheckBox |
|
362 |
* @return |
|
363 |
*/ |
|
364 |
public JTextField getTextDistance() { |
|
365 |
if(distance == null) { |
|
366 |
distance = new JTextField("0.0"); |
|
367 |
distance.setEnabled(false); |
|
368 |
} |
|
369 |
return distance; |
|
370 |
} |
|
371 |
|
|
372 |
/** |
|
373 |
* Gets a JRadioButton |
|
374 |
* @return |
|
375 |
*/ |
|
376 |
public JRadioButton getRadioSelectDistance() { |
|
377 |
if(selectDistance == null) { |
|
378 |
selectDistance = new JRadioButton(GeoProcessLocator.getGeoProcessManager().getTranslation("area_distance")); |
|
379 |
selectDistance.addActionListener(this); |
|
380 |
selectDistance.setSelected(false); |
|
381 |
} |
|
382 |
return selectDistance; |
|
383 |
} |
|
384 |
|
|
385 |
/** |
|
386 |
* Gets a JRadioButton |
|
387 |
* @return |
|
388 |
*/ |
|
389 |
public JRadioButton getRadioSelectField() { |
|
390 |
if(selectField == null) { |
|
391 |
selectField = new JRadioButton(GeoProcessLocator.getGeoProcessManager().getTranslation("area_field")); |
|
392 |
selectField.addActionListener(this); |
|
393 |
selectField.setSelected(true); |
|
394 |
} |
|
395 |
return selectField; |
|
396 |
} |
|
397 |
|
|
398 |
//------------------------------------------------------------ |
|
399 |
|
|
400 |
/* |
|
401 |
* (non-Javadoc) |
|
402 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) |
|
403 |
*/ |
|
404 |
public void actionPerformed(ActionEvent e) { |
|
405 |
if(e.getSource() == getRadioSelectDistance()) { |
|
406 |
getTextDistance().setEnabled(true); |
|
407 |
getComboFields().setEnabled(false); |
|
408 |
} |
|
409 |
|
|
410 |
if(e.getSource() == getRadioSelectField()) { |
|
411 |
getTextDistance().setEnabled(false); |
|
412 |
getTextDistance().setText("0.0"); |
|
413 |
getComboFields().setEnabled(true); |
|
414 |
} |
|
415 |
|
|
416 |
if(e.getSource() == getComboLayers()) { |
|
417 |
loadFieldsInAreaCombo(); |
|
418 |
checkLineLayer(); |
|
419 |
} |
|
420 |
} |
|
421 |
|
|
422 |
@Override |
|
423 |
public void assignParameters() { |
|
424 |
try { |
|
425 |
ParametersSet params = m_Algorithm.getParameters(); |
|
426 |
params.getParameter(BufferAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer()); |
|
427 |
params.getParameter(BufferAlgorithm.FIELD).setParameterValue(getFieldPosition()); |
|
428 |
params.getParameter(BufferAlgorithm.SELECTED_GEOM).setParameterValue(getCheckSelectedGeom().isSelected()); |
|
429 |
double dist = 0; |
|
430 |
try { |
|
431 |
dist = new Double(getTextDistance().getText()); |
|
432 |
} catch(NumberFormatException e) { |
|
433 |
} |
|
434 |
params.getParameter(BufferAlgorithm.DISTANCE).setParameterValue(dist); |
|
435 |
params.getParameter(BufferAlgorithm.DISSOLVE).setParameterValue(getCheckDissolveEntities().isSelected()); |
|
436 |
params.getParameter(BufferAlgorithm.ROUND_BORDER).setParameterValue(getCheckRoundBorder().isSelected()); |
|
437 |
params.getParameter(BufferAlgorithm.AREA).setParameterValue(getComboInfluenceAreas().getSelectedIndex()); |
|
438 |
params.getParameter(BufferAlgorithm.RING_NUMBER).setParameterValue(getComboRadialBuffers().getSelectedIndex()); |
|
439 |
|
|
440 |
OutputObjectsSet ooSet = m_Algorithm.getOutputObjects(); |
|
441 |
Output out = ooSet.getOutput(BufferAlgorithm.RESULT); |
|
442 |
|
|
443 |
//Reponer estas l?neas para cambiar el panel de salida y comentar la siguiente |
|
444 |
//AlgorithmOutputPanel fsp = getAlgorithmOutputPanel(); |
|
445 |
//out.setOutputChannel(new CompositeSourceOutputChannel(fsp.getOutputParameters())); |
|
446 |
out.setOutputChannel(outputChannelSelectionPanel.getOutputChannel()); |
|
447 |
} catch (Exception e) { |
|
448 |
Sextante.addErrorToLog(e); |
|
449 |
} |
|
450 |
} |
|
451 |
|
|
452 |
|
|
453 |
|
|
454 |
@Override |
|
455 |
public void setOutputValue(String arg0, String arg1) { |
|
456 |
|
|
457 |
} |
|
458 |
|
|
459 |
@Override |
|
460 |
public void setParameterValue(String arg0, String arg1) { |
|
461 |
|
|
462 |
} |
|
463 |
|
|
464 |
/** |
|
465 |
* Gets the input layer list |
|
466 |
* @return |
|
467 |
*/ |
|
468 |
private ObjectAndDescription[] getLayerList() { |
|
469 |
IVectorLayer[] layers = SextanteGUI.getInputFactory() |
|
470 |
.getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG); |
|
471 |
ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
|
472 |
for (int i = 0; i < layers.length; i++) |
|
473 |
oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]); |
|
474 |
return oad; |
|
475 |
} |
|
476 |
|
|
477 |
/** |
|
478 |
* Gets the selected vector layer in the JComboBox |
|
479 |
* @return |
|
480 |
*/ |
|
481 |
private IVectorLayer getSelectedVectorLayer() { |
|
482 |
if(layers.getSelectedItem() != null) |
|
483 |
return (IVectorLayer)((ObjectAndDescription)layers.getSelectedItem()).getObject(); |
|
484 |
return null; |
|
485 |
} |
|
486 |
|
|
487 |
/** |
|
488 |
* Gets the field list of the selected layer |
|
489 |
* @return |
|
490 |
*/ |
|
491 |
@SuppressWarnings("unchecked") |
|
492 |
public List<String> getFieldList() { |
|
493 |
IVectorLayer layer = getSelectedVectorLayer(); |
|
494 |
List<String> data = new ArrayList<String>(); |
|
495 |
fieldList.clear(); |
|
496 |
for (int i = 0; i < layer.getFieldCount(); i++) { |
|
497 |
Class type = layer.getFieldType(i); |
|
498 |
fieldList.add(layer.getFieldName(i)); |
|
499 |
if(Number.class.isAssignableFrom(type)) |
|
500 |
data.add(layer.getFieldName(i)); |
|
501 |
} |
|
502 |
return data; |
|
503 |
} |
|
504 |
|
|
505 |
private int getFieldPosition() { |
|
506 |
if(getComboFields().getSelectedItem() != null) { |
|
507 |
String label = getComboFields().getSelectedItem().toString(); |
|
508 |
for (int i = 0; i < fieldList.size(); i++) { |
|
509 |
if(fieldList.get(i).equals(label)) { |
|
510 |
return i; |
|
511 |
} |
|
512 |
} |
|
513 |
} |
|
514 |
return -1; |
|
515 |
} |
|
516 |
} |
|
0 | 517 |
org.gvsig.geoprocess/tags/org.gvsig.geoprocess-2.2.31/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.31/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.31/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.31/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 |
} |
Also available in: Unified diff