Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / primitive / surface / filledspline / FilledSpline2DM.java @ 47432

History | View | Annotate | Download (9.2 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.geom.jts.primitive.surface.filledspline;
24

    
25
import com.vividsolutions.jts.geom.Coordinate;
26
import com.vividsolutions.jts.geom.CoordinateSequence;
27
import org.cresques.cts.ICoordTrans;
28
import org.gvsig.fmap.geom.Geometry;
29
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate;
30
import org.gvsig.fmap.geom.jts.primitive.curve.spline.BaseSpline2DM;
31
import org.gvsig.fmap.geom.jts.primitive.surface.split.SurfaceSplitOperation;
32
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
33
import org.gvsig.fmap.geom.jts.util.JTSUtils;
34
import org.gvsig.fmap.geom.operation.GeometryOperationException;
35
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
36
import org.gvsig.fmap.geom.primitive.FilledSpline;
37
import org.gvsig.fmap.geom.primitive.Line;
38
import org.gvsig.fmap.geom.primitive.Polygon;
39
import org.gvsig.fmap.geom.primitive.Ring;
40
import org.gvsig.fmap.geom.primitive.SurfaceAppearance;
41

    
42

    
43
/**
44
 * @author fdiaz
45
 *
46
 */
47
public class FilledSpline2DM extends BaseSpline2DM implements FilledSpline {
48

    
49
    /**
50
     *
51
     */
52
    private static final long serialVersionUID = 5991348858703093647L;
53

    
54
    /**
55
     *
56
     */
57
    public FilledSpline2DM() {
58
        super(Geometry.TYPES.FILLEDSPLINE);
59
    }
60

    
61
    /**
62
     * @param coordinates
63
     */
64
    public FilledSpline2DM(Coordinate[] coordinates) {
65
        super(Geometry.TYPES.FILLEDSPLINE, coordinates);
66
        closePrimitive();
67
    }
68

    
69
    public FilledSpline2DM(ArrayListCoordinateSequence coordinates) {
70
        super(Geometry.TYPES.FILLEDSPLINE, coordinates);
71
        closePrimitive();
72
    }
73

    
74
    /* (non-Javadoc)
75
     * @see org.gvsig.fmap.geom.primitive.Surface#setSurfaceAppearance(org.gvsig.fmap.geom.primitive.SurfaceAppearance)
76
     */
77
    public void setSurfaceAppearance(SurfaceAppearance app) {
78
        // TODO Auto-generated method stub
79

    
80
    }
81

    
82
    /* (non-Javadoc)
83
     * @see org.gvsig.fmap.geom.primitive.Surface#getSurfaceAppearance()
84
     */
85
    public SurfaceAppearance getSurfaceAppearance() {
86
        // TODO Auto-generated method stub
87
        return null;
88
    }
89

    
90
    /* (non-Javadoc)
91
     * @see org.gvsig.fmap.geom.primitive.Surface#getNumInteriorRings()
92
     */
93
    public int getNumInteriorRings() {
94
        String message = "Calling deprecated method getNumInteriorRings of a filled spline";
95
        notifyDeprecated(message);
96
        throw new UnsupportedOperationException(message);
97
    }
98

    
99
    /* (non-Javadoc)
100
     * @see org.gvsig.fmap.geom.primitive.Surface#getInteriorRing(int)
101
     */
102
    public Ring getInteriorRing(int index) {
103
        String message = "Calling deprecated method getInteriorRing of a filled spline";
104
        notifyDeprecated(message);
105
        throw new UnsupportedOperationException(message);
106
    }
107

    
108
    /* (non-Javadoc)
109
     * @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Ring)
110
     */
111
    public void addInteriorRing(Ring ring) {
112
        String message = "Calling deprecated method addInteriorRing of a filled spline";
113
        notifyDeprecated(message);
114
        throw new UnsupportedOperationException(message);
115
    }
116

    
117
    /* (non-Javadoc)
118
     * @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Line)
119
     */
120
    public void addInteriorRing(Line line) {
121
        String message = "Calling deprecated method addInteriorRing of a filled spline";
122
        notifyDeprecated(message);
123
        throw new UnsupportedOperationException(message);
124
    }
125

    
126
    /* (non-Javadoc)
127
     * @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Polygon)
128
     */
129
    public void addInteriorRing(Polygon polygon) {
130
        String message = "Calling deprecated method addInteriorRing of a filled spline";
131
        notifyDeprecated(message);
132
        throw new UnsupportedOperationException(message);
133
    }
134

    
135
    /* (non-Javadoc)
136
     * @see org.gvsig.fmap.geom.primitive.Surface#removeInteriorRing(int)
137
     */
138
    public void removeInteriorRing(int index) {
139
        String message = "Calling deprecated method removeInteriorRing of a circle";
140
        notifyDeprecated(message);
141
        throw new UnsupportedOperationException(message);
142
    }
143

    
144
    /* (non-Javadoc)
145
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
146
     */
147
    @Override
148
    public Geometry cloneGeometry() {
149
        FilledSpline2DM clone = new FilledSpline2DM(cloneCoordinates().toCoordinateArray());
150
        clone.setProjection(this.getProjection());
151
        return clone;
152
        }
153

    
154
    /*
155
     * (non-Javadoc)
156
     *
157
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
158
     */
159
    public com.vividsolutions.jts.geom.Geometry getJTS() {
160
        return JTSUtils.createJTSPolygon(getSplineCoordinates());
161
    }
162

    
163

    
164
    /* (non-Javadoc)
165
     * @see org.gvsig.fmap.geom.Geometry#offset(double)
166
     */
167
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
168
        return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance));
169
    }
170
    
171
    public Geometry offset(int jointStyle, double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
172
        return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance, JTSUtils.calculateQuadrantSegments(jointStyle)));
173
    }
174
    
175

    
176
    /* (non-Javadoc)
177
     * @see org.gvsig.fmap.geom.jts.primitive.curve.spline.AbstractSpline#reProject(org.cresques.cts.ICoordTrans)
178
     */
179
    @Override
180
    public void reProject(ICoordTrans ct) {
181
        super.reProject(ct);
182
        if (coordinates.size()>=2 && !isClosed()) {
183
            closePrimitive();
184
        }
185
    }
186

    
187
    @Override
188
    public boolean equals(Object obj) {
189
        boolean res = super.equals(obj);
190
        if(res && obj instanceof FilledSpline2DM){
191
            FilledSpline2DM other = (FilledSpline2DM)obj;
192
            if(this.getNumVertices() != other.getNumVertices()){
193
                return false;
194
            }
195
            for(int i=0; i < this.getNumVertices(); i++){
196
                if(other.coordinates.get(i).getOrdinate(2)!=this.coordinates.get(i).getOrdinate(2)){
197
                    return false;
198
                };
199
            }
200
            return true;
201
        } else {
202
            return false;
203
        }
204
    }
205

    
206
    @Override
207
    public Geometry split(Geometry splitter) {
208
        SurfaceSplitOperation op = new SurfaceSplitOperation();
209
        return op.split(this, splitter);
210
    }
211
    
212
    @Override
213
    public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException {
214
        ArrayListCoordinateSequence coordinates2D = new ArrayListCoordinateSequence(coordinates.size());
215
        for (Coordinate coordinate : this.coordinates) {
216
            coordinates2D.add(new Coordinate(
217
                    coordinate.x, 
218
                    coordinate.y
219
            ));
220
        }
221
        FilledSpline2D s = new FilledSpline2D(coordinates2D);
222
        s.setProjection(this.getProjection());
223
        return s;
224
    }
225
        
226
    @Override
227
    public Geometry force2DM() throws GeometryOperationNotSupportedException, GeometryOperationException {
228
        Geometry geom = this.cloneGeometry();
229
        return geom;
230
    }
231

    
232
    @Override
233
    public Geometry force3D() throws GeometryOperationNotSupportedException, GeometryOperationException {
234
        ArrayListCoordinateSequence coordinates3D = new ArrayListCoordinateSequence(coordinates.size());
235
        for (Coordinate coordinate : this.coordinates) {
236
            coordinates3D.add(new Coordinate(
237
                    coordinate.x, 
238
                    coordinate.y,
239
                    0
240
            ));
241
        }
242
        FilledSpline3D s = new FilledSpline3D(coordinates3D);
243
        s.setProjection(this.getProjection());
244
        return s;
245
    }
246

    
247
    @Override
248
    public Geometry force3DM() throws GeometryOperationNotSupportedException, GeometryOperationException {
249
        ArrayListCoordinateSequence coordinates3DM = new ArrayListCoordinateSequence(coordinates.size());
250
        for (Coordinate coordinate : this.coordinates) {
251
            coordinates3DM.add(MCoordinate.create3dWithMeasure(
252
                    coordinate.x, 
253
                    coordinate.y, 
254
                    0, 
255
                    coordinate.getOrdinate(CoordinateSequence.M)
256
            ));
257
        }
258
        FilledSpline3DM s = new FilledSpline3DM(coordinates3DM);
259
        s.setProjection(this.getProjection());
260
        return s;
261
    }
262
    
263
}