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 / circle / Circle2DZ.java @ 42272

History | View | Annotate | Download (5.79 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.circle;
24

    
25
import java.awt.geom.PathIterator;
26

    
27
import com.vividsolutions.jts.geom.Coordinate;
28

    
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.GeometryException;
31
import org.gvsig.fmap.geom.aggregate.MultiLine;
32
import org.gvsig.fmap.geom.aggregate.MultiPoint;
33
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
34
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D;
35
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D;
36
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D;
37
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D;
38
import org.gvsig.fmap.geom.jts.primitive.point.Point3D;
39
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS;
40
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D;
41
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
42
import org.gvsig.fmap.geom.jts.util.JTSUtils;
43
import org.gvsig.fmap.geom.primitive.Line;
44
import org.gvsig.fmap.geom.primitive.Point;
45
import org.gvsig.fmap.geom.primitive.Polygon;
46

    
47
/**
48
 * @author fdiaz
49
 *
50
 */
51
public class Circle2DZ extends AbstractCircle {
52

    
53
    /**
54
     *
55
     */
56
    private static final long serialVersionUID = 4678092839213094025L;
57

    
58
    /**
59
     * @param subtype
60
     */
61
    protected Circle2DZ() {
62
        super(Geometry.SUBTYPES.GEOM3D);
63
    }
64

    
65
    /*
66
     * (non-Javadoc)
67
     *
68
     * @see
69
     * org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive
70
     * .Point, org.gvsig.fmap.geom.primitive.Point,
71
     * org.gvsig.fmap.geom.primitive.Point)
72
     */
73
    public void setPoints(Point p1, Point p2, Point p3) {
74
        this.center = new Point3D(JTSUtils.getCircumcentre(p1, p2, p3));
75
        //Por si los tres puntos no tienen la misma z
76
        Point3D aPoint = new Point3D(p1.getX(), p1.getY(), ((Point3D)center).getZ());
77
        this.radious = ((PointJTS) this.center).getJTS().distance(aPoint.getJTS());
78
    }
79

    
80
    /*
81
     * (non-Javadoc)
82
     *
83
     * @see
84
     * org.gvsig.fmap.geom.jts.primitive.surface.circle.AbstractCircle#fixPoint
85
     * (org.gvsig.fmap.geom.primitive.Point)
86
     */
87
    @Override
88
    protected Point fixPoint(Point point) {
89
        if (point instanceof Point3D) {
90
            return point;
91
        }
92
        return new Point3D(point.getX(), point.getY(), 0);
93
    }
94

    
95
    /* (non-Javadoc)
96
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
97
     */
98
    public com.vividsolutions.jts.geom.Geometry getJTS() {
99
        PathIterator pi = getPathIterator(null);
100
        ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
101

    
102
        Point3D c = (Point3D)getCenter();
103
        double zValue = c.getZ();
104
        double coords[] = new double[6];
105
        while (!pi.isDone()) {
106
            switch (pi.currentSegment(coords)) {
107
            case PathIterator.SEG_MOVETO:
108
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
109
                break;
110
            case PathIterator.SEG_LINETO:
111
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
112
                break;
113
            case PathIterator.SEG_QUADTO:
114
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
115
                coordinates.add(new Coordinate(coords[2], coords[3], zValue));
116
                break;
117
            case PathIterator.SEG_CUBICTO:
118
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
119
                coordinates.add(new Coordinate(coords[2], coords[3], zValue));
120
                coordinates.add(new Coordinate(coords[4], coords[5], zValue));
121
                break;
122
            case PathIterator.SEG_CLOSE:
123
                coordinates.add(coordinates.get(0));
124
                break;
125
            }
126
            pi.next();
127
        }
128
        return JTSUtils.createJTSLinearRing(coordinates);
129
    }
130

    
131
    /* (non-Javadoc)
132
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
133
     */
134
    public MultiPoint toPoints() throws GeometryException {
135
        MultiPoint multiPoint = new MultiPoint3D();
136
        Coordinate[] coordinates = getJTS().getCoordinates();
137
        multiPoint.ensureCapacity(coordinates.length);
138
        for (int i = 0; i < coordinates.length; i++) {
139
            multiPoint.addPoint(new Point3D(coordinates[i]));
140
        }
141
        return multiPoint;
142
    }
143

    
144
    /* (non-Javadoc)
145
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
146
     */
147
    public MultiLine toLines() throws GeometryException {
148
        MultiLine multiLine = new MultiLine3D();
149
        Line line = new Line3D(getJTS().getCoordinates());
150
        multiLine.addPrimitive(line);
151
        return multiLine;
152
    }
153

    
154
    /* (non-Javadoc)
155
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
156
     */
157
    public MultiPolygon toPolygons() throws GeometryException {
158
        MultiPolygon multiPolygon = new MultiPolygon3D();
159
        Polygon polygon = new Polygon3D(getJTS().getCoordinates());
160
        multiPolygon.addPrimitive(polygon);
161
        return multiPolygon;
162
    }
163

    
164

    
165
}