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 / MultiPoint2D.java @ 44612

History | View | Annotate | Download (4.48 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.Line2D;
34
import org.gvsig.fmap.geom.jts.primitive.point.Point2D;
35
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2D;
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 MultiPoint2D extends AbstractMultiPoint {
48

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

    
54
    public MultiPoint2D() {
55
        super(Geometry.SUBTYPES.GEOM2D);
56
    }
57

    
58
    /* (non-Javadoc)
59
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
60
     */
61
    @Override
62
    public Geometry cloneGeometry() {
63
        MultiPoint2D clone = new MultiPoint2D();
64
        return clonePrimitives(clone);
65

    
66
    }
67

    
68
    @Override
69
    public int getDimension() {
70
        return 2;
71
    }
72

    
73
    @Override
74
    public GeneralPathX getGeneralPath() {
75
        return new DefaultGeneralPathX(new PointIterator(null), false, 0);
76
    }
77

    
78
    @Override
79
    public MultiPoint toPoints() throws GeometryException {
80
        return this;
81
    }
82

    
83
    @Override
84
    public MultiLine toLines() throws GeometryException {
85
        MultiLine multiLine = new MultiLine2D();
86
        Line line = new Line2D();
87
        line.ensureCapacity(primitives.size());
88
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
89
            Point2D point = (Point2D) iterator.next();
90
            line.addVertex(point);
91
        }
92
        multiLine.addPrimitive(line);
93
        return multiLine;
94
    }
95

    
96
    @Override
97
    public MultiPolygon toPolygons() throws GeometryException {
98
        MultiPolygon multiPolygon = new MultiPolygon2D();
99
        Polygon polygon = new Polygon2D();
100
        polygon.ensureCapacity(primitives.size());
101
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
102
            Point2D point = (Point2D) iterator.next();
103
            polygon.addVertex(point);
104
        }
105
        multiPolygon.addPrimitive(polygon);
106
        return multiPolygon;
107
    }
108

    
109
    @Override
110
    protected Geometry fixPrimitive(Primitive primitive) {
111

    
112
        if(primitive instanceof Point2D){
113
            return primitive;
114
        }
115

    
116
        if(primitive instanceof Point){
117
            Point point = (Point)primitive;
118
            return new Point2D(point.getX(), point.getY());
119
        }
120

    
121
        if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM2D){
122
            try {
123
                return primitive.toPoints();
124
            } catch (GeometryException e) {
125
                String message = "Can't convert primitive to lines";
126
                logger.warn(message);
127
                throw new RuntimeException(message);
128
            }
129
        }
130

    
131
        String message = "Only 2D primitives can be fixed to MultiPoint2D";
132
        notifyDeprecated(message);
133
        throw new UnsupportedOperationException(message);
134
    }
135

    
136
    @Override
137
    protected Point fixPoint(Point point) {
138
        if (point instanceof Point2D) {
139
            return point;
140
        } else {
141
            return new Point2D(point.getX(), point.getY());
142
        }
143
    }
144

    
145
}