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

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

    
25
import com.vividsolutions.jts.geom.Coordinate;
26
import java.awt.geom.PathIterator;
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.fmap.geom.GeometryException;
29
import org.gvsig.fmap.geom.aggregate.MultiLine;
30
import org.gvsig.fmap.geom.aggregate.MultiPoint;
31
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
32
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3DM;
33
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3DM;
34
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3DM;
35
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate;
36
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3DM;
37
import org.gvsig.fmap.geom.jts.primitive.point.Point3DM;
38
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM;
39
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
40
import org.gvsig.fmap.geom.primitive.Line;
41
import org.gvsig.fmap.geom.primitive.Point;
42
import org.gvsig.fmap.geom.primitive.Polygon;
43

    
44

    
45
/**
46
 * @author fdiaz
47
 *
48
 */
49
public abstract class BaseEllipse2DZM extends AbstractEllipse {
50

    
51
    private double zValue = Double.NaN;
52
    private double mValue = Double.NaN;
53

    
54
    /**
55
     * @param subtype
56
     */
57
    public BaseEllipse2DZM(int type) {
58
        super(type, Geometry.SUBTYPES.GEOM3DM);
59
    }
60

    
61
    /*
62
     * (non-Javadoc)
63
     *
64
     * @see
65
     * org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
66
     * .gvsig.fmap.geom.primitive.Point)
67
     */
68
    @Override
69
    protected Point fixPoint(Point point) {
70
        if (point instanceof Point3DM) {
71
            Point3DM point3DM = (Point3DM) point;
72
            if (Double.isNaN(zValue) && !(Double.isNaN(point3DM.getZ()))) {
73
                zValue = point3DM.getZ();
74
                if (init!=null) {
75
                    ((Point3DM) init).setZ(zValue);
76
                }
77
                if (end!=null) {
78
                    ((Point3DM) end).setZ(zValue);
79
                }
80
            }
81
            if (Double.isNaN(mValue) && !(Double.isNaN(point3DM.getM()))) {
82
                mValue = point3DM.getM();
83
                if (init!=null) {
84
                    ((Point3DM) init).setM(mValue);
85
                }
86
                if (end!=null) {
87
                    ((Point3DM) end).setM(mValue);
88
                }
89
            }
90
        }
91
        return new Point3DM(point.getX(), point.getY(), Double.isNaN(zValue)?0:zValue, Double.isNaN(mValue)?0:mValue);
92
    }
93

    
94
    /**
95
     * @return
96
     */
97
    protected ArrayListCoordinateSequence getJTSCoordinates() {
98
        PathIterator pi = getPathIterator(null);
99
        ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
100

    
101
        double coords[] = new double[6];
102
        while (!pi.isDone()) {
103
            switch (pi.currentSegment(coords)) {
104
            case PathIterator.SEG_MOVETO:
105
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
106
                break;
107
            case PathIterator.SEG_LINETO:
108
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
109
                break;
110
            case PathIterator.SEG_QUADTO:
111
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
112
                coordinates.add(new MCoordinate(coords[2], coords[3], zValue, mValue));
113
                break;
114
            case PathIterator.SEG_CUBICTO:
115
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
116
                coordinates.add(new MCoordinate(coords[2], coords[3], zValue, mValue));
117
                coordinates.add(new MCoordinate(coords[4], coords[5], zValue, mValue));
118
                break;
119
            case PathIterator.SEG_CLOSE:
120
                if(!coordinates.isEmpty() && !coordinates.get(0).equals(coordinates.get(coordinates.size()-1))){
121
                    coordinates.add((Coordinate) coordinates.get(0).clone());
122
                }
123
                break;
124
            }
125
            pi.next();
126
        }
127
        return coordinates;
128
    }
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 MultiPoint3DM();
136
        Coordinate[] coordinates = getJTS().getCoordinates();
137
        multiPoint.ensureCapacity(coordinates.length);
138
        for (int i = 0; i < coordinates.length; i++) {
139
            multiPoint.addPoint(new Point3DM(this.getProjection(), 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 MultiLine3DM();
149
        Line line = new Line3DM(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 MultiPolygon3DM();
159
        Polygon polygon = new Polygon3DM(getJTS().getCoordinates());
160
        multiPolygon.addPrimitive(polygon);
161
        return multiPolygon;
162
    }
163

    
164

    
165

    
166
}