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 / aggregate / MultiPoint3DM.java @ 47346

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

    
25
import java.util.Iterator;
26

    
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.gputils.DefaultGeneralPathX;
33
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3DM;
34
import org.gvsig.fmap.geom.jts.primitive.point.Point3D;
35
import org.gvsig.fmap.geom.jts.primitive.point.Point3DM;
36
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM;
37
import org.gvsig.fmap.geom.primitive.GeneralPathX;
38
import org.gvsig.fmap.geom.primitive.Line;
39
import org.gvsig.fmap.geom.primitive.Point;
40
import org.gvsig.fmap.geom.primitive.Polygon;
41
import org.gvsig.fmap.geom.primitive.Primitive;
42

    
43

    
44
/**
45
 * @author fdiaz
46
 *
47
 */
48
public class MultiPoint3DM extends AbstractMultiPoint {
49

    
50
    /**
51
     *
52
     */
53
    private static final long serialVersionUID = -2230359991187613190L;
54

    
55
    /**
56
     * @param subtype
57
     */
58
    public MultiPoint3DM() {
59
        super(Geometry.SUBTYPES.GEOM3DM);
60
    }
61

    
62
    /* (non-Javadoc)
63
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
64
     */
65
    @Override
66
    public Geometry cloneGeometry() {
67
        MultiPoint3DM clone = new MultiPoint3DM();
68
        clone.setProjection(this.getProjection());
69
        return clonePrimitives(clone);
70
    }
71

    
72
    /* (non-Javadoc)
73
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
74
     */
75
    public int getDimension() {
76
        return 4;
77
    }
78

    
79
    /*
80
     * (non-Javadoc)
81
     *
82
     * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
83
     */
84
    public GeneralPathX getGeneralPath() {
85
        return new DefaultGeneralPathX(new PointIterator(null), false, 0);
86
    }
87

    
88
    /* (non-Javadoc)
89
     * @see org.gvsig.fmap.geom.aggregate.MultiLine#toPoints()
90
     */
91
    public MultiPoint toPoints() throws GeometryException {
92
        return this;
93
    }
94

    
95
    /* (non-Javadoc)
96
     * @see org.gvsig.fmap.geom.aggregate.MultiLine#toLines()
97
     */
98
    public MultiLine toLines() throws GeometryException {
99
        MultiLine multiLine = new MultiLine3DM();
100
        Line line = new Line3DM();
101
        line.ensureCapacity(primitives.size());
102
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
103
            Point3DM point = (Point3DM) iterator.next();
104
            line.addVertex(point);
105
        }
106
        multiLine.addPrimitive(line);
107
        return multiLine;
108
    }
109

    
110
    /* (non-Javadoc)
111
     * @see org.gvsig.fmap.geom.aggregate.MultiLine#toPolygons()
112
     */
113
    public MultiPolygon toPolygons() throws GeometryException {
114
        MultiPolygon multiPolygon = new MultiPolygon3DM();
115
        Polygon polygon = new Polygon3DM();
116
        polygon.ensureCapacity(primitives.size());
117
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
118
            Point3DM point = (Point3DM) iterator.next();
119
            polygon.addVertex(point);
120
        }
121
        multiPolygon.addPrimitive(polygon);
122
        return multiPolygon;
123
    }
124

    
125
    /* (non-Javadoc)
126
     * @see org.gvsig.fmap.geom.jts.aggregate.AbstractMultiPrimitive#fixPrimitive(org.gvsig.fmap.geom.primitive.Primitive)
127
     */
128
    @Override
129
    protected Geometry fixPrimitive(Primitive primitive) {
130

    
131
        if(primitive instanceof Point3DM){
132
            return primitive;
133
        }
134

    
135
        if(primitive instanceof Point){
136
            Point point = (Point)primitive;
137
            if(point instanceof Point3D){
138
                return new Point3DM(point.getX(), point.getY(), ((Point3DM)point).getZ(), 0);
139
            }
140
            return new Point3DM(point.getX(), point.getY(), 0, 0);
141
        }
142

    
143
        if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM3DM){
144
            try {
145
                return primitive.toPoints();
146
            } catch (GeometryException e) {
147
                String message = "Can't convert primitive to points";
148
                LOGGER.warn(message);
149
                throw new RuntimeException(message);
150
            }
151
        }
152

    
153
        String message = "Only 3DM primitives can be fixed to MultiPoint3DM";
154
        notifyDeprecated(message);
155
        throw new UnsupportedOperationException(message);
156

    
157
    }
158

    
159
    protected Point fixPoint(Point point) {
160
        if (point instanceof Point3DM) {
161
            return point;
162
        } else if (point instanceof Point3D) {
163
            return new Point3DM(point.getX(), point.getY(), ((Point3D)point).getZ(), 0);
164
        } else {
165
            return new Point3DM(point.getX(), point.getY(), 0, 0);
166
        }
167
    }
168
}