Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.impl / src / main / java / org / gvsig / fmap / geom / primitive / impl / point / Point2DZ.java @ 41590

History | View | Annotate | Download (3.55 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.geom.primitive.impl.point;
25

    
26
import org.cresques.cts.IProjection;
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.fmap.geom.primitive.FShape;
29
import org.gvsig.fmap.geom.primitive.Point;
30
import org.gvsig.fmap.geom.type.GeometryType;
31

    
32
/**
33
 * 3D point implementation.
34
 * 
35
 * @author Vicente Caballero Navarro
36
 * @author gvSIG team
37
 */
38
public class Point2DZ extends Point2D implements Point {
39

    
40
        private static final long serialVersionUID = 3113070237182638858L;
41

    
42
        public static final String PERSISTENCE_DEFINITION_NAME = "Point2DimensionsZ";
43
        private double z = 0.0d;
44

    
45
        /**
46
         * The constructor with the GeometryType like and argument is used by the
47
         * {@link GeometryType}{@link #create()} to create the geometry
48
         * 
49
         * @param type
50
         *            The geometry type
51
         */
52
        public Point2DZ(GeometryType geomType) {
53
                super(geomType);
54
        }
55

    
56
        /**
57
         * Constructor used in the {@link Geometry#cloneGeometry()} method
58
         * 
59
         * @param id
60
         * @param projection
61
         * @param x
62
         * @param y
63
         * @param z
64
         */
65
        Point2DZ(GeometryType geomType, String id, IProjection projection,
66
                        double x, double y, double z) {
67
                super(geomType, id, projection, x, y);
68
                this.z = z;
69
        }
70

    
71
    public Point2DZ(double x, double y, double z, GeometryType geometryType) {
72
        super(geometryType);
73
        this.x = x;
74
        this.y = y;
75
        this.z = z;
76
    }
77

    
78
        public Point2DZ(double x, double y, double z) {
79
                super(TYPES.POINT, SUBTYPES.GEOM3D);
80
                this.x = x;
81
                this.y = y;
82
                this.z = z;
83
        }
84

    
85
        public int getShapeType() {
86
                return TYPES.POINT;
87
        }
88

    
89
        public FShape cloneFShape() {
90
                return new Point2DZ(getGeometryType(), id, projection, x, y, z);
91
        }
92

    
93
        public int getDimension() {
94
                return 3;
95
        }
96

    
97
        public boolean equals(Object other) {
98
                if (!super.equals(other)) {
99
                        return false;
100
                }
101

    
102
                Point2DZ pother = (Point2DZ) other;
103
                if (Math.abs(this.z - pother.z) > 0.0000001) {
104
                        return false;
105
                }
106
                return true;
107
        }
108

    
109
        public void setCoordinates(double[] values) {
110
                super.setCoordinates(values);
111
                if (values.length > 2) {
112
                        z = values[2];
113
                }
114
        }
115

    
116
        public void setCoordinateAt(int dimension, double value) {
117
                if (dimension == Geometry.DIMENSIONS.Z) {
118
                        this.z = value;
119
                } else {
120
                        super.setCoordinateAt(dimension, value);
121
                }
122
        }
123

    
124
        public double getCoordinateAt(int dimension) {
125
                return (dimension == Geometry.DIMENSIONS.Z) ? this.z : super
126
                                .getCoordinateAt(dimension);
127
        }
128

    
129
        public double getOrdinate(int dimension) {
130
                return (dimension == Geometry.DIMENSIONS.Z) ? this.z : super
131
                                .getCoordinateAt(dimension);
132
        }
133

    
134
        public double[] getCoordinates() {
135
                return new double[] { getX(), getY(), this.z };
136
        }
137

    
138
        protected String getFullTypeName() {
139
                return "Point2DZ";
140
        }
141

    
142
}