Statistics
| Revision:

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 / BufferOperation.java @ 43

History | View | Annotate | Download (4 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.cresques.cts.IProjection;
24
import org.gvsig.fmap.dal.exception.DataException;
25
import org.gvsig.fmap.dal.feature.EditableFeature;
26
import org.gvsig.fmap.dal.feature.Feature;
27
import org.gvsig.fmap.dal.feature.FeatureStore;
28
import org.gvsig.fmap.geom.exception.CreateGeometryException;
29
import org.gvsig.sextante.app.algorithm.base.core.DALFeaturePersister;
30
import org.gvsig.sextante.app.algorithm.base.core.GeometryOperation;
31
import org.gvsig.sextante.app.algorithm.base.util.GeometryUtil;
32

    
33
import com.vividsolutions.jts.geom.Geometry;
34
import com.vividsolutions.jts.geom.GeometryCollection;
35

    
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 abstract class BufferOperation extends GeometryOperation {        
43
        public static final byte CAP_SQUARE                   = 0;
44
        public static final byte CAP_ROUND                    = 1;
45
        
46
        protected byte           capBuffer                    = CAP_ROUND;
47
        protected int            numberOfRadialBuffers        = 1;
48
        protected IDistance      distance                     = null;
49
        
50
        protected IVectorLayer   layer                        = null;
51
        protected IProjection    projection                   = null;
52
        protected double         userDistance                 = 0D;
53
        
54
        public BufferOperation(IDistance distance, IVectorLayer layer, double userDistance) {
55
                this.distance = distance;
56
                this.layer = layer;
57
                this.projection = (IProjection)layer.getCRS();
58
                this.userDistance = userDistance;
59
        }
60
        
61
        /**
62
         * Sets the output FeatureType
63
         * @param out
64
         * @throws DataException 
65
         */
66
        public void setFeatureStore(FeatureStore out, String[] attrNames) throws DataException {
67
                persister = new DALFeaturePersister(out, attrNames);
68
        }
69

    
70
        
71
        /**
72
         * Verifys if a geometry buffer is null.
73
         * It is useful when you're working with internal buffers. If the internal
74
         * buffer distance is greater than the geometry radius, the buffer result
75
         * will be null.
76
         *
77
         * @param newGeometry
78
         * @return
79
         */
80
        protected boolean verifyNilGeometry(Geometry newGeometry){
81
                if(newGeometry instanceof GeometryCollection){
82
                        if(((GeometryCollection)newGeometry).getNumGeometries() == 0){
83
                                //we have collapsed initial geometry
84
                                return true;
85
                        }
86
                }
87
                return false;
88
        }
89
        
90
        /**
91
         * Adds a new feature
92
         * @param feature
93
         * @param newGeom
94
         * @throws CreateGeometryException
95
         * @throws DataException
96
         * @deprecated No es necesario porque no hay diferencia entre las llamadas entre ambos invoke
97
         */
98
        protected void addFeature(Feature feature, Geometry newGeom) throws CreateGeometryException, DataException {
99
                if(!(feature instanceof EditableFeature)) 
100
                        lastEditFeature = persister.addFeature(feature, newGeom);
101
                else {
102
                        org.gvsig.fmap.geom.Geometry g = GeometryUtil.jtsToGeom(newGeom);
103
                        persister.addGeometryToExistingFeature((EditableFeature)feature, g);
104
                }
105
        }
106

    
107
        /**
108
         * Sets type of cap flag
109
         * @param typeOfCap
110
         */
111
        public void setTypeOfCap(byte typeOfCap) {
112
                capBuffer = typeOfCap;
113
        }
114

    
115
        /**
116
         * Sets number of radial rings buffers
117
         * @param number
118
         */
119
        public void setNumberOfRadialBuffers(int number) {
120
                numberOfRadialBuffers = number;
121
        }
122
        
123
}