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 @ 42283
History | View | Annotate | Download (4.68 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.point.Point3DM; |
36 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2D; |
37 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
38 |
import org.gvsig.fmap.geom.primitive.Line; |
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 |
/**
|
55 |
* @param subtype
|
56 |
*/
|
57 |
public MultiPoint2D() {
|
58 |
super(Geometry.SUBTYPES.GEOM2D);
|
59 |
} |
60 |
|
61 |
/* (non-Javadoc)
|
62 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
63 |
*/
|
64 |
public Geometry cloneGeometry() {
|
65 |
MultiPoint2D clone = new MultiPoint2D();
|
66 |
return clonePrimitives(clone);
|
67 |
|
68 |
} |
69 |
|
70 |
/* (non-Javadoc)
|
71 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
72 |
*/
|
73 |
public int getDimension() { |
74 |
return 2; |
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 |
/* (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 MultiLine2D();
|
98 |
Line line = new Line2D(); |
99 |
line.ensureCapacity(primitives.size()); |
100 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
101 |
Point2D point = (Point2D) 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 MultiPolygon2D();
|
113 |
Polygon polygon = new Polygon2D(); |
114 |
polygon.ensureCapacity(primitives.size()); |
115 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
116 |
Point2D point = (Point2D) iterator.next(); |
117 |
polygon.addVertex(point); |
118 |
} |
119 |
multiPolygon.addPrimitive(polygon); |
120 |
return multiPolygon;
|
121 |
} |
122 |
|
123 |
/* (non-Javadoc)
|
124 |
* @see org.gvsig.fmap.geom.jts.aggregate.AbstractMultiPrimitive#fixPrimitive(org.gvsig.fmap.geom.primitive.Primitive)
|
125 |
*/
|
126 |
@Override
|
127 |
protected Geometry fixPrimitive(Primitive primitive) {
|
128 |
|
129 |
if(primitive instanceof Point2D){ |
130 |
return primitive;
|
131 |
} |
132 |
|
133 |
if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM2D){
|
134 |
try {
|
135 |
return primitive.toPoints();
|
136 |
} catch (GeometryException e) {
|
137 |
String message = "Can't convert primitive to lines"; |
138 |
logger.warn(message); |
139 |
throw new RuntimeException(message); |
140 |
} |
141 |
} |
142 |
|
143 |
String message = "Only 2D primitives can be fixed to MultiPoint2D"; |
144 |
notifyDeprecated(message); |
145 |
throw new UnsupportedOperationException(message); |
146 |
|
147 |
} |
148 |
|
149 |
|
150 |
} |