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 / Point2DZ.java @ 40435

History | View | Annotate | Download (3.5 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.fmap.geom.primitive.impl;
23

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

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

    
38
        private static final long serialVersionUID = 3113070237182638858L;
39

    
40
        public static final String PERSISTENCE_DEFINITION_NAME = "Point2DimensionsZ";
41
        private double z = 0.0d;
42

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

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

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

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

    
83
        public int getShapeType() {
84
                return TYPES.POINT;
85
        }
86

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

    
91
        public int getDimension() {
92
                return 3;
93
        }
94

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

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

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

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

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

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

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

    
136
        protected String getFullTypeName() {
137
                return "Point2DZ";
138
        }
139

    
140
}