gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.buffer / src / main / java / org / gvsig / geoprocess / algorithm / buffer / BufferOperation.java @ 321
History | View | Annotate | Download (6.04 KB)
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 com.vividsolutions.jts.geom.Geometry; |
27 |
import com.vividsolutions.jts.geom.GeometryCollection; |
28 |
|
29 |
import es.unex.sextante.dataObjects.IVectorLayer; |
30 |
|
31 |
import org.cresques.cts.IProjection; |
32 |
|
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
35 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
36 |
import org.gvsig.fmap.dal.exception.DataException; |
37 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
38 |
import org.gvsig.fmap.dal.feature.Feature; |
39 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
40 |
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation; |
41 |
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil; |
42 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
43 |
|
44 |
/**
|
45 |
* Buffer operation
|
46 |
*
|
47 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
48 |
*/
|
49 |
public abstract class BufferOperation extends GeometryOperation { |
50 |
|
51 |
public static final byte CAP_SQUARE = 0; |
52 |
public static final byte CAP_ROUND = 1; |
53 |
|
54 |
protected byte capBuffer = CAP_ROUND; |
55 |
protected int numberOfRadialBuffers = 1; |
56 |
protected IDistance distance = null; |
57 |
protected int id = 0; |
58 |
|
59 |
protected IVectorLayer layer = null; |
60 |
protected IProjection projection = null; |
61 |
protected double userDistance = 0D; |
62 |
|
63 |
public BufferOperation(IDistance distance, IVectorLayer layer,
|
64 |
double userDistance, AbstractSextanteGeoProcess p) {
|
65 |
super(p);
|
66 |
this.distance = distance;
|
67 |
this.layer = layer;
|
68 |
this.projection = (IProjection) layer.getCRS();
|
69 |
this.userDistance = userDistance;
|
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 |
} |