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

History | View | Annotate | Download (9.29 KB)

1 42304 fdiaz
/* 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 47432 fdiaz
import com.vividsolutions.jts.geom.CoordinateSequence;
27 42304 fdiaz
28 42464 fdiaz
import org.cresques.cts.ICoordTrans;
29
30 42304 fdiaz
import org.gvsig.fmap.geom.Geometry;
31 47432 fdiaz
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate;
32 42304 fdiaz
import org.gvsig.fmap.geom.jts.primitive.curve.spline.BaseSpline3D;
33 46332 fdiaz
import org.gvsig.fmap.geom.jts.primitive.surface.split.SurfaceSplitOperation;
34 47432 fdiaz
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
35 42304 fdiaz
import org.gvsig.fmap.geom.jts.util.JTSUtils;
36 42441 fdiaz
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
38 42304 fdiaz
import org.gvsig.fmap.geom.primitive.FilledSpline;
39
import org.gvsig.fmap.geom.primitive.Line;
40
import org.gvsig.fmap.geom.primitive.Polygon;
41
import org.gvsig.fmap.geom.primitive.Ring;
42
import org.gvsig.fmap.geom.primitive.SurfaceAppearance;
43
44
45
/**
46
 * @author fdiaz
47
 *
48
 */
49
public class FilledSpline3D extends BaseSpline3D implements FilledSpline {
50
51
    /**
52
     *
53
     */
54
    private static final long serialVersionUID = -8947796452807902242L;
55
56
    /**
57
     *
58
     */
59
    public FilledSpline3D() {
60
        super(Geometry.TYPES.FILLEDSPLINE);
61
    }
62
63
    /**
64
     * @param coordinates
65
     */
66
    public FilledSpline3D(Coordinate[] coordinates) {
67
        super(Geometry.TYPES.FILLEDSPLINE, coordinates);
68 42477 fdiaz
        closePrimitive();
69 42304 fdiaz
    }
70
71 47432 fdiaz
    public FilledSpline3D(ArrayListCoordinateSequence coordinates) {
72
        super(Geometry.TYPES.FILLEDSPLINE, coordinates);
73
        closePrimitive();
74
    }
75
76 42304 fdiaz
    /* (non-Javadoc)
77
     * @see org.gvsig.fmap.geom.primitive.Surface#setSurfaceAppearance(org.gvsig.fmap.geom.primitive.SurfaceAppearance)
78
     */
79
    public void setSurfaceAppearance(SurfaceAppearance app) {
80
        // TODO Auto-generated method stub
81
82
    }
83
84
    /* (non-Javadoc)
85
     * @see org.gvsig.fmap.geom.primitive.Surface#getSurfaceAppearance()
86
     */
87
    public SurfaceAppearance getSurfaceAppearance() {
88
        // TODO Auto-generated method stub
89
        return null;
90
    }
91
92
    /* (non-Javadoc)
93
     * @see org.gvsig.fmap.geom.primitive.Surface#getNumInteriorRings()
94
     */
95
    public int getNumInteriorRings() {
96
        String message = "Calling deprecated method getNumInteriorRings of a filled spline";
97
        notifyDeprecated(message);
98
        throw new UnsupportedOperationException(message);
99
    }
100
101
    /* (non-Javadoc)
102
     * @see org.gvsig.fmap.geom.primitive.Surface#getInteriorRing(int)
103
     */
104
    public Ring getInteriorRing(int index) {
105
        String message = "Calling deprecated method getInteriorRing of a filled spline";
106
        notifyDeprecated(message);
107
        throw new UnsupportedOperationException(message);
108
    }
109
110
    /* (non-Javadoc)
111
     * @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Ring)
112
     */
113
    public void addInteriorRing(Ring ring) {
114
        String message = "Calling deprecated method addInteriorRing of a filled spline";
115
        notifyDeprecated(message);
116
        throw new UnsupportedOperationException(message);
117
    }
118
119
    /* (non-Javadoc)
120
     * @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Line)
121
     */
122
    public void addInteriorRing(Line line) {
123
        String message = "Calling deprecated method addInteriorRing of a filled spline";
124
        notifyDeprecated(message);
125
        throw new UnsupportedOperationException(message);
126
    }
127
128
    /* (non-Javadoc)
129
     * @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Polygon)
130
     */
131
    public void addInteriorRing(Polygon polygon) {
132
        String message = "Calling deprecated method addInteriorRing of a filled spline";
133
        notifyDeprecated(message);
134
        throw new UnsupportedOperationException(message);
135
    }
136
137
    /* (non-Javadoc)
138
     * @see org.gvsig.fmap.geom.primitive.Surface#removeInteriorRing(int)
139
     */
140
    public void removeInteriorRing(int index) {
141
        String message = "Calling deprecated method removeInteriorRing of a circle";
142
        notifyDeprecated(message);
143
        throw new UnsupportedOperationException(message);
144
    }
145
146
    /* (non-Javadoc)
147
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
148
     */
149 47346 fdiaz
    @Override
150 42304 fdiaz
    public Geometry cloneGeometry() {
151 47346 fdiaz
        FilledSpline3D clone = new FilledSpline3D(cloneCoordinates().toCoordinateArray());
152
        clone.setProjection(this.getProjection());
153
        return clone;
154 42304 fdiaz
        }
155
156
    /*
157
     * (non-Javadoc)
158
     *
159
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
160
     */
161
    public com.vividsolutions.jts.geom.Geometry getJTS() {
162
        return JTSUtils.createJTSPolygon(getSplineCoordinates());
163
    }
164 42441 fdiaz
165
166
    /* (non-Javadoc)
167
     * @see org.gvsig.fmap.geom.Geometry#offset(double)
168
     */
169
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
170 44099 jjdelcerro
        return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance));
171 42441 fdiaz
    }
172 42464 fdiaz
173 45762 fdiaz
    public Geometry offset(int jointStyle, double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
174
        return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance, JTSUtils.calculateQuadrantSegments(jointStyle)));
175
    }
176
177 42464 fdiaz
    /* (non-Javadoc)
178
     * @see org.gvsig.fmap.geom.jts.primitive.curve.spline.AbstractSpline#reProject(org.cresques.cts.ICoordTrans)
179
     */
180
    @Override
181
    public void reProject(ICoordTrans ct) {
182
        super.reProject(ct);
183
        if (coordinates.size()>=2 && !isClosed()) {
184
            closePrimitive();
185
        }
186
    }
187 42875 fdiaz
188
    @Override
189
    public boolean equals(Object obj) {
190
        boolean res = super.equals(obj);
191
        if(res && obj instanceof FilledSpline3D){
192
            FilledSpline3D other = (FilledSpline3D)obj;
193
            if(this.getNumVertices() != other.getNumVertices()){
194
                return false;
195
            }
196
            for (int i = 0; i < this.getNumVertices(); i++) {
197
                Coordinate coordinate = this.coordinates.get(i);
198
                Coordinate otherCoordinate = other.coordinates.get(i);
199
                if (otherCoordinate.getOrdinate(2) != coordinate.getOrdinate(2)) {
200
                    return false;
201
                }
202
            }
203
            return true;
204
        } else {
205
            return false;
206
        }
207
    }
208 46332 fdiaz
209
    @Override
210
    public Geometry split(Geometry splitter) {
211
        SurfaceSplitOperation op = new SurfaceSplitOperation();
212
        return op.split(this, splitter);
213
    }
214 47432 fdiaz
215
    @Override
216
    public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException {
217
        ArrayListCoordinateSequence coordinates2D = new ArrayListCoordinateSequence(coordinates.size());
218
        for (Coordinate coordinate : this.coordinates) {
219
            coordinates2D.add(new Coordinate(
220
                    coordinate.x,
221
                    coordinate.y
222
            ));
223
        }
224
        FilledSpline2D s = new FilledSpline2D(coordinates2D);
225
        s.setProjection(this.getProjection());
226
        return s;
227
    }
228
229
    @Override
230
    public Geometry force2DM() throws GeometryOperationNotSupportedException, GeometryOperationException {
231
        ArrayListCoordinateSequence coordinates2DM = new ArrayListCoordinateSequence(coordinates.size());
232
        for (Coordinate coordinate : this.coordinates) {
233
            coordinates2DM.add(MCoordinate.create2dWithMeasure(
234
                    coordinate.x,
235
                    coordinate.y,
236
                    0
237
            ));
238
        }
239
        FilledSpline2DM s = new FilledSpline2DM(coordinates2DM);
240
        s.setProjection(this.getProjection());
241
        return s;
242
    }
243
244
    @Override
245
    public Geometry force3D() throws GeometryOperationNotSupportedException, GeometryOperationException {
246
        Geometry geom = this.cloneGeometry();
247
        return geom;
248
    }
249
250
251
252
    @Override
253
    public Geometry force3DM() throws GeometryOperationNotSupportedException, GeometryOperationException {
254
        ArrayListCoordinateSequence coordinates3DM = new ArrayListCoordinateSequence(coordinates.size());
255
        for (Coordinate coordinate : this.coordinates) {
256
            coordinates3DM.add(MCoordinate.create3dWithMeasure(
257
                    coordinate.x,
258
                    coordinate.y,
259
                    coordinate.z,
260
                    0
261
            ));
262
        }
263
        FilledSpline3DM s = new FilledSpline3DM(coordinates3DM);
264
        s.setProjection(this.getProjection());
265
        return s;
266
    }
267
268 42304 fdiaz
}