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

History | View | Annotate | Download (6.3 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 com.vividsolutions.jts.geom.Coordinate;
26
import java.awt.geom.PathIterator;
27
import org.gvsig.fmap.geom.GeometryException;
28
import org.gvsig.fmap.geom.aggregate.MultiLine;
29
import org.gvsig.fmap.geom.aggregate.MultiPoint;
30
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
31
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D;
32
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint2DM;
33
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D;
34
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate;
35
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2DM;
36
import org.gvsig.fmap.geom.jts.primitive.point.Point2DM;
37
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS;
38
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2DM;
39
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
40
import org.gvsig.fmap.geom.jts.util.JTSUtils;
41
import org.gvsig.fmap.geom.primitive.Line;
42
import org.gvsig.fmap.geom.primitive.Point;
43
import org.gvsig.fmap.geom.primitive.Polygon;
44

    
45

    
46
/**
47
 * @author fdiaz
48
 *
49
 */
50
public abstract class BaseCircle2DM extends AbstractCircle {
51

    
52
    /**
53
     * @param type
54
     * @param subtype
55
     * @param center
56
     * @param radius
57
     */
58
    public BaseCircle2DM(int type, int subtype, Point center, double radius) {
59
        super(type, subtype, center, radius);
60
    }
61

    
62
    /**
63
     * @param circle
64
     * @param geom2d
65
     */
66
    public BaseCircle2DM(int type, int subtype) {
67
        super(type,subtype);
68
    }
69

    
70
    /*
71
     * (non-Javadoc)
72
     *
73
     * @see
74
     * org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive
75
     * .Point, org.gvsig.fmap.geom.primitive.Point,
76
     * org.gvsig.fmap.geom.primitive.Point)
77
     */
78
    public void setPoints(Point p1, Point p2, Point p3) {
79
        this.center = new Point2DM(p1.getProjection(),JTSUtils.getCircumcentre(p1, p2, p3));
80
        //Por si los tres puntos no tienen la misma m
81
        Point2DM aPoint = new Point2DM(p1.getX(), p1.getY(), ((Point2DM)center).getM());
82
        this.radius = ((PointJTS) this.center).getJTS().distance(aPoint.getJTS());
83
        this.setProjection(this.center.getProjection());
84
    }
85

    
86
    /*
87
     * (non-Javadoc)
88
     *
89
     * @see
90
     * org.gvsig.fmap.geom.jts.primitive.surface.circle.AbstractCircle#fixPoint
91
     * (org.gvsig.fmap.geom.primitive.Point)
92
     */
93
    @Override
94
    protected Point fixPoint(Point point) {
95
        if (point instanceof Point2DM) {
96
            return point;
97
        }
98
        return new Point2DM(point.getX(), point.getY(), 0);
99
    }
100

    
101
    /**
102
     * @return
103
     */
104
    protected ArrayListCoordinateSequence getJTSCoordinates() {
105
        PathIterator pi = getPathIterator(null);
106
        ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
107

    
108
        Point2DM c = (Point2DM)getCenter();
109
        double mValue = c.getM();
110
        double coords[] = new double[6];
111
        while (!pi.isDone()) {
112
            switch (pi.currentSegment(coords)) {
113
            case PathIterator.SEG_MOVETO:
114
                coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue));
115
                break;
116
            case PathIterator.SEG_LINETO:
117
                coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue));
118
                break;
119
            case PathIterator.SEG_QUADTO:
120
                coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue));
121
                coordinates.add(new MCoordinate(coords[2], coords[3], Double.NaN, mValue));
122
                break;
123
            case PathIterator.SEG_CUBICTO:
124
                coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue));
125
                coordinates.add(new MCoordinate(coords[2], coords[3], Double.NaN, mValue));
126
                coordinates.add(new MCoordinate(coords[4], coords[5], Double.NaN, mValue));
127
                break;
128
            case PathIterator.SEG_CLOSE:
129
                coordinates.add(coordinates.get(0));
130
                break;
131
            }
132
            pi.next();
133
        }
134
        if(!coordinates.get(0).equals(coordinates.get(coordinates.size()-1))){
135
            coordinates.add((Coordinate)coordinates.get(0).clone());
136
        }
137
        return coordinates;
138
    }
139

    
140
    /* (non-Javadoc)
141
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
142
     */
143
    public MultiPoint toPoints() throws GeometryException {
144
        MultiPoint multiPoint = new MultiPoint2DM();
145
        Coordinate[] coordinates = getJTS().getCoordinates();
146
        multiPoint.ensureCapacity(coordinates.length);
147
        for (int i = 0; i < coordinates.length; i++) {
148
            multiPoint.addPoint(new Point2DM(this.getProjection(), coordinates[i].x, coordinates[i].y, ((Point2DM)getCenter()).getM()));
149
        }
150
        return multiPoint;
151
    }
152

    
153
    /* (non-Javadoc)
154
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
155
     */
156
    public MultiLine toLines() throws GeometryException {
157
        MultiLine multiLine = new MultiLine3D();
158
        Line line = new Line2DM(getJTS().getCoordinates());
159
        multiLine.addPrimitive(line);
160
        return multiLine;
161
    }
162

    
163
    /* (non-Javadoc)
164
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
165
     */
166
    public MultiPolygon toPolygons() throws GeometryException {
167
        MultiPolygon multiPolygon = new MultiPolygon3D();
168
        Polygon polygon = new Polygon2DM(getJTS().getCoordinates());
169
        multiPolygon.addPrimitive(polygon);
170
        return multiPolygon;
171
    }
172

    
173

    
174
}