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

History | View | Annotate | Download (4.96 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.Line2DM;
34
import org.gvsig.fmap.geom.jts.primitive.point.Point2DM;
35
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2DM;
36
import org.gvsig.fmap.geom.primitive.GeneralPathX;
37
import org.gvsig.fmap.geom.primitive.Line;
38
import org.gvsig.fmap.geom.primitive.Point;
39
import org.gvsig.fmap.geom.primitive.Polygon;
40
import org.gvsig.fmap.geom.primitive.Primitive;
41

    
42

    
43
/**
44
 * @author fdiaz
45
 *
46
 */
47
public class MultiPoint2DM extends AbstractMultiPoint {
48

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

    
54
    /**
55
     * @param subtype
56
     */
57
    public MultiPoint2DM() {
58
        super(Geometry.SUBTYPES.GEOM2DM);
59
    }
60

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

    
70
    }
71

    
72
    /* (non-Javadoc)
73
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
74
     */
75
    public int getDimension() {
76
        return 3;
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 MultiLine2DM();
100
        Line line = new Line2DM();
101
        line.ensureCapacity(primitives.size());
102
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
103
            Point2DM point = (Point2DM) 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 MultiPolygon2DM();
115
        Polygon polygon = new Polygon2DM();
116
        polygon.ensureCapacity(primitives.size());
117
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
118
            Point2DM point = (Point2DM) iterator.next();
119
            polygon.addVertex(point);
120
        }
121
        multiPolygon.addPrimitive(polygon);
122
        return multiPolygon;
123
    }
124

    
125

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

    
132
        if(primitive instanceof Point2DM){
133
            return primitive;
134
        }
135

    
136
        if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM2DM){
137
            try {
138
                return primitive.toPoints();
139
            } catch (GeometryException e) {
140
                String message = "Can't convert primitive to lines";
141
                LOGGER.warn(message);
142
                throw new RuntimeException(message);
143
            }
144
        }
145

    
146
        String message = "Only 2DM primitives can be fixed to MultiPoint2DM";
147
        notifyDeprecated(message);
148
        throw new UnsupportedOperationException(message);
149

    
150
    }
151

    
152
    protected Point fixPoint(Point point) {
153
        if (point instanceof Point2DM) {
154
            return point;
155
        } else {
156
            return new Point2DM(point.getX(), point.getY(), 0);
157
        }
158
    }
159
}