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 / FilledSpline3DM.java @ 47432

History | View | Annotate | Download (9.52 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

    
28
import org.cresques.cts.ICoordTrans;
29

    
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate;
32
import org.gvsig.fmap.geom.jts.primitive.curve.spline.BaseSpline3DM;
33
import org.gvsig.fmap.geom.jts.primitive.curve.spline.Spline3DM;
34
import org.gvsig.fmap.geom.jts.primitive.surface.split.SurfaceSplitOperation;
35
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
36
import org.gvsig.fmap.geom.jts.util.JTSUtils;
37
import org.gvsig.fmap.geom.operation.GeometryOperationException;
38
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
39
import org.gvsig.fmap.geom.primitive.FilledSpline;
40
import org.gvsig.fmap.geom.primitive.Line;
41
import org.gvsig.fmap.geom.primitive.Polygon;
42
import org.gvsig.fmap.geom.primitive.Ring;
43
import org.gvsig.fmap.geom.primitive.SurfaceAppearance;
44

    
45

    
46
/**
47
 * @author fdiaz
48
 *
49
 */
50
public class FilledSpline3DM extends BaseSpline3DM implements FilledSpline {
51

    
52
    /**
53
     *
54
     */
55
    private static final long serialVersionUID = -1127282615744603309L;
56

    
57
    /**
58
     *
59
     */
60
    public FilledSpline3DM() {
61
        super(Geometry.TYPES.FILLEDSPLINE);
62
    }
63

    
64
    /**
65
     * @param coordinates
66
     */
67
    public FilledSpline3DM(Coordinate[] coordinates) {
68
        super(Geometry.TYPES.FILLEDSPLINE, coordinates);
69
        closePrimitive();
70
    }
71

    
72
    public FilledSpline3DM(ArrayListCoordinateSequence coordinates) {
73
        super(Geometry.TYPES.FILLEDSPLINE, coordinates);
74
        closePrimitive();
75
    }
76

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

    
83
    }
84

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

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

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

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

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

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

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

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

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

    
166

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

    
174
    public Geometry offset(int jointStyle, double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
175
        return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance, JTSUtils.calculateQuadrantSegments(jointStyle)));
176
    }
177

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

    
189
    @Override
190
    public boolean equals(Object obj) {
191
        boolean res = super.equals(obj);
192
        if(res && obj instanceof FilledSpline3DM){
193
            FilledSpline3DM other = (FilledSpline3DM)obj;
194
            if(this.getNumVertices() != other.getNumVertices()){
195
                return false;
196
            }
197
            for (int i = 0; i < this.getNumVertices(); i++) {
198
                Coordinate coordinate = this.coordinates.get(i);
199
                Coordinate otherCoordinate = other.coordinates.get(i);
200
                if (otherCoordinate.getOrdinate(2) != coordinate.getOrdinate(2)) {
201
                    return false;
202
                }
203
                if (otherCoordinate.getOrdinate(3) != coordinate.getOrdinate(3)) {
204
                    return false;
205
                }
206
            }
207
            return true;
208
        } else {
209
            return false;
210
        }
211
    }
212

    
213
    @Override
214
    public Geometry split(Geometry splitter) {
215
        SurfaceSplitOperation op = new SurfaceSplitOperation();
216
        return op.split(this, splitter);
217
    }
218
    
219
    @Override
220
    public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException {
221
        ArrayListCoordinateSequence coordinates2D = new ArrayListCoordinateSequence(coordinates.size());
222
        for (Coordinate coordinate : this.coordinates) {
223
            coordinates2D.add(new Coordinate(
224
                    coordinate.x, 
225
                    coordinate.y
226
            ));
227
        }
228
        FilledSpline2D s = new FilledSpline2D(coordinates2D);
229
        s.setProjection(this.getProjection());
230
        return s;
231
    }
232
        
233
    @Override
234
    public Geometry force2DM() throws GeometryOperationNotSupportedException, GeometryOperationException {
235
        ArrayListCoordinateSequence coordinates2DM = new ArrayListCoordinateSequence(coordinates.size());
236
        for (Coordinate coordinate : this.coordinates) {
237
            coordinates2DM.add(MCoordinate.create2dWithMeasure(
238
                    coordinate.x, 
239
                    coordinate.y, 
240
                    (coordinate instanceof MCoordinate)?coordinate.getOrdinate(CoordinateSequence.M):0
241
            ));
242
        }
243
        FilledSpline2DM s = new FilledSpline2DM(coordinates2DM);
244
        s.setProjection(this.getProjection());
245
        return s;
246
    }
247

    
248
    @Override
249
    public Geometry force3D() throws GeometryOperationNotSupportedException, GeometryOperationException {
250
        ArrayListCoordinateSequence coordinates3D = new ArrayListCoordinateSequence(coordinates.size());
251
        for (Coordinate coordinate : this.coordinates) {
252
            coordinates3D.add(new Coordinate(
253
                    coordinate.x, 
254
                    coordinate.y,
255
                    coordinate.z
256
            ));
257
        }
258
        FilledSpline3D s = new FilledSpline3D(coordinates3D);
259
        s.setProjection(this.getProjection());
260
        return s;
261
    }
262

    
263
    @Override
264
    public Geometry force3DM() throws GeometryOperationNotSupportedException, GeometryOperationException {
265
        Geometry geom = this.cloneGeometry();
266
        return geom;
267
    }
268
    
269
}