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 / InBufferOperation.java @ 43
History | View | Annotate | Download (3.54 KB)
1 | 43 | nbrodin | /*
|
---|---|---|---|
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 | |||
35 | import es.unex.sextante.core.Sextante; |
||
36 | import es.unex.sextante.dataObjects.IVectorLayer; |
||
37 | |||
38 | /**
|
||
39 | * Buffer operation
|
||
40 | * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
||
41 | */
|
||
42 | public class InBufferOperation extends BufferOperation { |
||
43 | |||
44 | /**
|
||
45 | * Builds an instance of this operation.
|
||
46 | * @param distance
|
||
47 | * @param layer
|
||
48 | * @param userDistance
|
||
49 | */
|
||
50 | public InBufferOperation(IDistance distance, IVectorLayer layer, double userDistance) { |
||
51 | super(distance, layer, userDistance);
|
||
52 | } |
||
53 | |||
54 | /*
|
||
55 | * (non-Javadoc)
|
||
56 | * @see org.gvsig.sextante.app.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.Feature)
|
||
57 | */
|
||
58 | public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature feature) {
|
||
59 | //if we have radial internal buffers, we start by most interior buffer
|
||
60 | Geometry newGeom = null;
|
||
61 | Geometry previousInteriorRing = null;
|
||
62 | Geometry inputParam = GeometryUtil.geomToJTS(g); |
||
63 | distance.setFeature(feature); |
||
64 | double bufferDistance = distance.getBufferDistance(userDistance, projection, MapTools.getDistanceUnits(), MapTools.getMapUnits());
|
||
65 | |||
66 | for(int i = numberOfRadialBuffers; i >= 1; i--) { |
||
67 | double distRing = i * bufferDistance;
|
||
68 | BufferOp bufOp = new BufferOp(inputParam);
|
||
69 | bufOp.setEndCapStyle(capBuffer == CAP_ROUND ? BufferParameters.CAP_ROUND : BufferParameters.CAP_SQUARE); |
||
70 | Geometry newGeometry = bufOp.getResultGeometry(-1 * distRing);
|
||
71 | |||
72 | if(verifyNilGeometry(newGeometry))
|
||
73 | return lastEditFeature;
|
||
74 | |||
75 | if(previousInteriorRing != null) |
||
76 | newGeom = JTSFacade.difference(newGeometry, previousInteriorRing); |
||
77 | else
|
||
78 | newGeom = newGeometry; |
||
79 | |||
80 | try {
|
||
81 | lastEditFeature = persister.addFeature(feature, newGeom); |
||
82 | } catch (CreateGeometryException e) {
|
||
83 | Sextante.addErrorToLog(e); |
||
84 | } catch (DataException e) {
|
||
85 | Sextante.addErrorToLog(e); |
||
86 | } |
||
87 | } |
||
88 | return lastEditFeature;
|
||
89 | } |
||
90 | |||
91 | /*
|
||
92 | * (non-Javadoc)
|
||
93 | * @see org.gvsig.sextante.app.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.EditableFeature)
|
||
94 | */
|
||
95 | public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature feature) { |
||
96 | invoke(g, (Feature)feature); |
||
97 | } |
||
98 | } |