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 @ 45762
History | View | Annotate | Download (4.89 KB)
1 | 42267 | fdiaz | /* 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 | 42271 | fdiaz | 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 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
33 | 42271 | fdiaz | 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 | 42267 | fdiaz | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
37 | 42271 | fdiaz | import org.gvsig.fmap.geom.primitive.Line; |
38 | 42875 | fdiaz | import org.gvsig.fmap.geom.primitive.Point; |
39 | 42271 | fdiaz | import org.gvsig.fmap.geom.primitive.Polygon; |
40 | import org.gvsig.fmap.geom.primitive.Primitive; |
||
41 | 42267 | fdiaz | |
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 | public Geometry cloneGeometry() {
|
||
65 | MultiPoint2DM clone = new MultiPoint2DM();
|
||
66 | 42274 | fdiaz | return clonePrimitives(clone);
|
67 | |||
68 | 42267 | fdiaz | } |
69 | |||
70 | /* (non-Javadoc)
|
||
71 | * @see org.gvsig.fmap.geom.Geometry#getDimension()
|
||
72 | */
|
||
73 | public int getDimension() { |
||
74 | return 3; |
||
75 | } |
||
76 | |||
77 | /*
|
||
78 | * (non-Javadoc)
|
||
79 | *
|
||
80 | * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
||
81 | */
|
||
82 | public GeneralPathX getGeneralPath() {
|
||
83 | return new DefaultGeneralPathX(new PointIterator(null), false, 0); |
||
84 | } |
||
85 | |||
86 | 42271 | fdiaz | /* (non-Javadoc)
|
87 | * @see org.gvsig.fmap.geom.aggregate.MultiLine#toPoints()
|
||
88 | */
|
||
89 | public MultiPoint toPoints() throws GeometryException { |
||
90 | return this; |
||
91 | } |
||
92 | |||
93 | /* (non-Javadoc)
|
||
94 | * @see org.gvsig.fmap.geom.aggregate.MultiLine#toLines()
|
||
95 | */
|
||
96 | public MultiLine toLines() throws GeometryException { |
||
97 | MultiLine multiLine = new MultiLine2DM();
|
||
98 | Line line = new Line2DM(); |
||
99 | line.ensureCapacity(primitives.size()); |
||
100 | for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
||
101 | Point2DM point = (Point2DM) iterator.next(); |
||
102 | line.addVertex(point); |
||
103 | } |
||
104 | multiLine.addPrimitive(line); |
||
105 | return multiLine;
|
||
106 | } |
||
107 | |||
108 | /* (non-Javadoc)
|
||
109 | * @see org.gvsig.fmap.geom.aggregate.MultiLine#toPolygons()
|
||
110 | */
|
||
111 | public MultiPolygon toPolygons() throws GeometryException { |
||
112 | MultiPolygon multiPolygon = new MultiPolygon2DM();
|
||
113 | Polygon polygon = new Polygon2DM(); |
||
114 | polygon.ensureCapacity(primitives.size()); |
||
115 | for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
||
116 | Point2DM point = (Point2DM) iterator.next(); |
||
117 | polygon.addVertex(point); |
||
118 | } |
||
119 | multiPolygon.addPrimitive(polygon); |
||
120 | return multiPolygon;
|
||
121 | } |
||
122 | |||
123 | |||
124 | /* (non-Javadoc)
|
||
125 | * @see org.gvsig.fmap.geom.jts.aggregate.AbstractMultiPrimitive#fixPrimitive(org.gvsig.fmap.geom.primitive.Primitive)
|
||
126 | */
|
||
127 | @Override
|
||
128 | 42283 | fdiaz | protected Geometry fixPrimitive(Primitive primitive) {
|
129 | |||
130 | if(primitive instanceof Point2DM){ |
||
131 | return primitive;
|
||
132 | 42271 | fdiaz | } |
133 | 42283 | fdiaz | |
134 | if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM2DM){
|
||
135 | try {
|
||
136 | return primitive.toPoints();
|
||
137 | } catch (GeometryException e) {
|
||
138 | String message = "Can't convert primitive to lines"; |
||
139 | 45425 | jjdelcerro | LOGGER.warn(message); |
140 | 42283 | fdiaz | throw new RuntimeException(message); |
141 | } |
||
142 | } |
||
143 | |||
144 | String message = "Only 2DM primitives can be fixed to MultiPoint2DM"; |
||
145 | notifyDeprecated(message); |
||
146 | throw new UnsupportedOperationException(message); |
||
147 | |||
148 | 42271 | fdiaz | } |
149 | 42875 | fdiaz | |
150 | protected Point fixPoint(Point point) { |
||
151 | if (point instanceof Point2DM) { |
||
152 | return point;
|
||
153 | } else {
|
||
154 | return new Point2DM(point.getX(), point.getY(), 0); |
||
155 | } |
||
156 | } |
||
157 | 42267 | fdiaz | } |