gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.algorithm / org.gvsig.sextante.app.algorithm.buffer / src / main / java / org / gvsig / sextante / app / algorithm / buffer / OutBufferOperation.java @ 44
History | View | Annotate | Download (3.74 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2010 Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
*/
|
21 |
package org.gvsig.sextante.app.algorithm.buffer; |
22 |
|
23 |
import org.gvsig.fmap.dal.exception.DataException; |
24 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
25 |
import org.gvsig.fmap.dal.feature.Feature; |
26 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
27 |
import org.gvsig.sextante.app.algorithm.base.util.GeometryUtil; |
28 |
import org.gvsig.sextante.app.algorithm.base.util.JTSFacade; |
29 |
import org.gvsig.sextante.app.extension.core.MapTools; |
30 |
|
31 |
import com.vividsolutions.jts.geom.Geometry; |
32 |
import com.vividsolutions.jts.operation.buffer.BufferOp; |
33 |
import com.vividsolutions.jts.operation.buffer.BufferParameters; |
34 |
import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier; |
35 |
|
36 |
import es.unex.sextante.core.Sextante; |
37 |
import es.unex.sextante.dataObjects.IVectorLayer; |
38 |
|
39 |
/**
|
40 |
* Buffer operation
|
41 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
42 |
*/
|
43 |
public class OutBufferOperation extends BufferOperation { |
44 |
|
45 |
/**
|
46 |
* Builds an instance of this operation.
|
47 |
* @param distance
|
48 |
* @param layer
|
49 |
* @param userDistance
|
50 |
*/
|
51 |
public OutBufferOperation(IDistance distance, IVectorLayer layer, double userDistance) { |
52 |
super(distance, layer, userDistance);
|
53 |
} |
54 |
|
55 |
/*
|
56 |
* (non-Javadoc)
|
57 |
* @see org.gvsig.sextante.app.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.Feature)
|
58 |
*/
|
59 |
public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature feature) {
|
60 |
Geometry newGeom = null;
|
61 |
Geometry previousExteriorRing = null;
|
62 |
Geometry originalGeometry = GeometryUtil.geomToJTS(g); |
63 |
Geometry inputParam = originalGeometry; |
64 |
distance.setFeature(feature); |
65 |
double bufferDistance = distance.getBufferDistance(userDistance, projection, MapTools.getDistanceUnits(), MapTools.getMapUnits());
|
66 |
|
67 |
if(originalGeometry.getDimension() != 0) |
68 |
inputParam = TopologyPreservingSimplifier.simplify(originalGeometry, bufferDistance / 10d);
|
69 |
|
70 |
|
71 |
for(int i = 1; i <= numberOfRadialBuffers; i++) { |
72 |
double distRing = i * bufferDistance;
|
73 |
BufferOp bufOp = new BufferOp(inputParam);
|
74 |
bufOp.setEndCapStyle(capBuffer == CAP_ROUND ? BufferParameters.CAP_ROUND : BufferParameters.CAP_SQUARE); |
75 |
Geometry newGeometry = bufOp.getResultGeometry(distRing); |
76 |
if(previousExteriorRing != null) |
77 |
newGeom = JTSFacade.difference(newGeometry, previousExteriorRing); |
78 |
else
|
79 |
newGeom = newGeometry; |
80 |
|
81 |
try {
|
82 |
if(newGeom != null) { |
83 |
lastEditFeature = persister.addFeature(newGeom, id, distRing); |
84 |
id ++; |
85 |
previousExteriorRing = newGeom; |
86 |
} |
87 |
} catch (CreateGeometryException e) {
|
88 |
Sextante.addErrorToLog(e); |
89 |
} catch (DataException e) {
|
90 |
Sextante.addErrorToLog(e); |
91 |
} |
92 |
} |
93 |
return lastEditFeature;
|
94 |
} |
95 |
|
96 |
/*
|
97 |
* (non-Javadoc)
|
98 |
* @see org.gvsig.sextante.app.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.EditableFeature)
|
99 |
*/
|
100 |
public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature feature) { |
101 |
invoke(g, (Feature)feature); |
102 |
} |
103 |
} |