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 / InBufferOperation.java @ 351
History | View | Annotate | Download (5.22 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 org.gvsig.fmap.dal.exception.DataException; |
27 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
28 |
import org.gvsig.fmap.dal.feature.Feature; |
29 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
30 |
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil; |
31 |
import org.gvsig.geoprocess.algorithm.base.util.JTSFacade; |
32 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
33 |
|
34 |
import com.vividsolutions.jts.geom.Geometry; |
35 |
import com.vividsolutions.jts.operation.buffer.BufferOp; |
36 |
import com.vividsolutions.jts.operation.buffer.BufferParameters; |
37 |
import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier; |
38 |
|
39 |
import es.unex.sextante.core.Sextante; |
40 |
import es.unex.sextante.dataObjects.IVectorLayer; |
41 |
|
42 |
/**
|
43 |
* Buffer operation
|
44 |
*
|
45 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
46 |
* @author gvSIG Team
|
47 |
*/
|
48 |
public class InBufferOperation extends BufferOperation { |
49 |
|
50 |
/**
|
51 |
* Builds an instance of this operation.
|
52 |
*
|
53 |
* @param distance
|
54 |
* @param layer
|
55 |
* @param userDistance
|
56 |
*/
|
57 |
public InBufferOperation(IDistance distance, IVectorLayer layer,
|
58 |
double userDistance, AbstractSextanteGeoProcess p) {
|
59 |
super(distance, layer, userDistance, p);
|
60 |
} |
61 |
|
62 |
public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g,
|
63 |
Feature feature) { |
64 |
// if we have radial internal buffers, we start by most interior buffer
|
65 |
Geometry newGeom = null;
|
66 |
Geometry previousInteriorRing = null;
|
67 |
Geometry originalGeometry = GeometryUtil.geomToJTS(g); |
68 |
Geometry inputParam = originalGeometry; |
69 |
distance.setFeature(feature); |
70 |
double bufferDistance =
|
71 |
distance.getBufferDistance(userDistance, projection, |
72 |
getDistanceUnits(), getMapUnits()); |
73 |
|
74 |
if (originalGeometry.getDimension() != 0) |
75 |
inputParam = |
76 |
TopologyPreservingSimplifier.simplify(originalGeometry, |
77 |
bufferDistance / 10d);
|
78 |
|
79 |
/*for (int i = 1; i <= numberOfRadialBuffers; i++) {
|
80 |
double distRing = i * bufferDistance;
|
81 |
BufferOp bufOp = new BufferOp(inputParam);
|
82 |
bufOp.setEndCapStyle(capBuffer == CAP_ROUND
|
83 |
? BufferParameters.CAP_ROUND : BufferParameters.CAP_SQUARE);
|
84 |
Geometry newGeometry = bufOp.getResultGeometry(-1 * distRing);
|
85 |
|
86 |
if (verifyNilGeometry(newGeometry))
|
87 |
return lastEditFeature;
|
88 |
|
89 |
try {
|
90 |
if (newGeometry != null && !newGeometry.isEmpty()) {
|
91 |
lastEditFeature = persister.addFeature(newGeometry, id, distRing);
|
92 |
id++;
|
93 |
}
|
94 |
} catch (CreateGeometryException e) {
|
95 |
Sextante.addErrorToLog(e);
|
96 |
} catch (DataException e) {
|
97 |
Sextante.addErrorToLog(e);
|
98 |
}
|
99 |
}*/
|
100 |
|
101 |
for (int i = numberOfRadialBuffers; i >= 1; i--) { |
102 |
double distRing = i * bufferDistance;
|
103 |
BufferOp bufOp = new BufferOp(inputParam);
|
104 |
bufOp.setEndCapStyle(capBuffer == CAP_ROUND |
105 |
? BufferParameters.CAP_ROUND : BufferParameters.CAP_SQUARE); |
106 |
newGeom = bufOp.getResultGeometry(-1 * distRing);
|
107 |
|
108 |
if (verifyNilGeometry(newGeom))
|
109 |
continue;
|
110 |
|
111 |
if(previousInteriorRing == null) |
112 |
previousInteriorRing = newGeom; |
113 |
else {
|
114 |
Geometry complete = newGeom; |
115 |
newGeom = JTSFacade.difference(newGeom, previousInteriorRing); |
116 |
previousInteriorRing = complete; |
117 |
} |
118 |
|
119 |
try {
|
120 |
if (newGeom != null && !newGeom.isEmpty()) { |
121 |
lastEditFeature = persister.addFeature(newGeom, id, distRing); |
122 |
id++; |
123 |
} |
124 |
} catch (CreateGeometryException e) {
|
125 |
Sextante.addErrorToLog(e); |
126 |
} catch (DataException e) {
|
127 |
Sextante.addErrorToLog(e); |
128 |
} |
129 |
} |
130 |
return lastEditFeature;
|
131 |
} |
132 |
|
133 |
/*
|
134 |
* (non-Javadoc)
|
135 |
*
|
136 |
* @see
|
137 |
* org.gvsig.geoprocess.algorithm.base.core.GeometryOperation#invoke(org
|
138 |
* .gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.EditableFeature)
|
139 |
*/
|
140 |
public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature feature) { |
141 |
invoke(g, (Feature) feature); |
142 |
} |
143 |
} |