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 @ 237
History | View | Annotate | Download (5.8 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 |
package org.gvsig.geoprocess.algorithm.buffer; |
22 |
|
23 |
import com.vividsolutions.jts.geom.Geometry; |
24 |
import com.vividsolutions.jts.geom.GeometryCollection; |
25 |
|
26 |
import es.unex.sextante.dataObjects.IVectorLayer; |
27 |
|
28 |
import org.cresques.cts.IProjection; |
29 |
|
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
32 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
33 |
import org.gvsig.fmap.dal.exception.DataException; |
34 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
35 |
import org.gvsig.fmap.dal.feature.Feature; |
36 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
37 |
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation; |
38 |
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil; |
39 |
|
40 |
/**
|
41 |
* Buffer operation
|
42 |
*
|
43 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
44 |
*/
|
45 |
public abstract class BufferOperation extends GeometryOperation { |
46 |
|
47 |
public static final byte CAP_SQUARE = 0; |
48 |
public static final byte CAP_ROUND = 1; |
49 |
|
50 |
protected byte capBuffer = CAP_ROUND; |
51 |
protected int numberOfRadialBuffers = 1; |
52 |
protected IDistance distance = null; |
53 |
protected int id = 0; |
54 |
|
55 |
protected IVectorLayer layer = null; |
56 |
protected IProjection projection = null; |
57 |
protected double userDistance = 0D; |
58 |
|
59 |
public BufferOperation(IDistance distance, IVectorLayer layer,
|
60 |
double userDistance) {
|
61 |
this.distance = distance;
|
62 |
this.layer = layer;
|
63 |
this.projection = (IProjection) layer.getCRS();
|
64 |
this.userDistance = userDistance;
|
65 |
} |
66 |
|
67 |
/**
|
68 |
* Verifys if a geometry buffer is null.
|
69 |
* It is useful when you're working with internal buffers. If the internal
|
70 |
* buffer distance is greater than the geometry radius, the buffer result
|
71 |
* will be null.
|
72 |
*
|
73 |
* @param newGeometry
|
74 |
* @return
|
75 |
*/
|
76 |
protected boolean verifyNilGeometry(Geometry newGeometry) { |
77 |
if (newGeometry instanceof GeometryCollection) { |
78 |
if (((GeometryCollection) newGeometry).getNumGeometries() == 0) { |
79 |
// we have collapsed initial geometry
|
80 |
return true; |
81 |
} |
82 |
} |
83 |
return false; |
84 |
} |
85 |
|
86 |
/**
|
87 |
* Adds a new feature
|
88 |
*
|
89 |
* @param feature
|
90 |
* @param newGeom
|
91 |
* @throws CreateGeometryException
|
92 |
* @throws DataException
|
93 |
* @deprecated No es necesario porque no hay diferencia entre las llamadas
|
94 |
* entre ambos invoke
|
95 |
*/
|
96 |
protected void addFeature(Feature feature, Geometry newGeom) |
97 |
throws CreateGeometryException, DataException {
|
98 |
if (!(feature instanceof EditableFeature)) |
99 |
lastEditFeature = persister.addFeature(feature, newGeom); |
100 |
else {
|
101 |
org.gvsig.fmap.geom.Geometry g = GeometryUtil.jtsToGeom(newGeom); |
102 |
persister |
103 |
.addGeometryToExistingFeature((EditableFeature) feature, g); |
104 |
} |
105 |
} |
106 |
|
107 |
/**
|
108 |
* Sets type of cap flag
|
109 |
*
|
110 |
* @param typeOfCap
|
111 |
*/
|
112 |
public void setTypeOfCap(byte typeOfCap) { |
113 |
capBuffer = typeOfCap; |
114 |
} |
115 |
|
116 |
/**
|
117 |
* Sets number of radial rings buffers
|
118 |
*
|
119 |
* @param number
|
120 |
*/
|
121 |
public void setNumberOfRadialBuffers(int number) { |
122 |
numberOfRadialBuffers = number; |
123 |
} |
124 |
|
125 |
/**
|
126 |
* <p>
|
127 |
* Gets the measurement unit used by this view port for the map.
|
128 |
* </p>
|
129 |
*
|
130 |
* @return Returns the current map measure unit
|
131 |
*/
|
132 |
protected int getMapUnits() { |
133 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
134 |
if (!(w instanceof AbstractViewPanel)) { |
135 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
|
136 |
for (int i = 0; i < wList.length; i++) { |
137 |
if (wList[i] instanceof AbstractViewPanel) |
138 |
w = (IWindow) wList[i]; |
139 |
} |
140 |
} |
141 |
|
142 |
if (w != null && w instanceof AbstractViewPanel) { |
143 |
IProjection proj = |
144 |
((AbstractViewPanel) w).getMapControl().getViewPort() |
145 |
.getProjection(); |
146 |
if (proj.isProjected())
|
147 |
return ((AbstractViewPanel) w).getMapControl().getViewPort()
|
148 |
.getMapUnits(); |
149 |
} |
150 |
return 1; |
151 |
} |
152 |
|
153 |
/**
|
154 |
* <p>
|
155 |
* Returns the measurement unit of this view port used for measuring
|
156 |
* distances and displaying information.
|
157 |
* </p>
|
158 |
*
|
159 |
* @return the measurement unit of this view used for measuring distances
|
160 |
* and displaying information
|
161 |
*/
|
162 |
protected int getDistanceUnits() { |
163 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
164 |
if (!(w instanceof AbstractViewPanel)) { |
165 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
|
166 |
for (int i = 0; i < wList.length; i++) { |
167 |
if (wList[i] instanceof AbstractViewPanel) |
168 |
w = (IWindow) wList[i]; |
169 |
} |
170 |
} |
171 |
|
172 |
if (w != null && w instanceof AbstractViewPanel) |
173 |
return ((AbstractViewPanel) w).getMapControl().getViewPort()
|
174 |
.getDistanceUnits(); |
175 |
else
|
176 |
return 1; |
177 |
} |
178 |
|
179 |
} |