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 @ 42283
History | View | Annotate | Download (5.06 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.curve.line.Line2DM; |
35 |
import org.gvsig.fmap.geom.jts.primitive.point.Point2D; |
36 |
import org.gvsig.fmap.geom.jts.primitive.point.Point2DM; |
37 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3DM; |
38 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2D; |
39 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2DM; |
40 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
41 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
42 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
43 |
import org.gvsig.fmap.geom.primitive.Line; |
44 |
import org.gvsig.fmap.geom.primitive.Point; |
45 |
import org.gvsig.fmap.geom.primitive.Polygon; |
46 |
import org.gvsig.fmap.geom.primitive.Primitive; |
47 |
|
48 |
|
49 |
/**
|
50 |
* @author fdiaz
|
51 |
*
|
52 |
*/
|
53 |
public class MultiPoint2DM extends AbstractMultiPoint { |
54 |
|
55 |
/**
|
56 |
*
|
57 |
*/
|
58 |
private static final long serialVersionUID = -2230359991187613190L; |
59 |
|
60 |
/**
|
61 |
* @param subtype
|
62 |
*/
|
63 |
public MultiPoint2DM() {
|
64 |
super(Geometry.SUBTYPES.GEOM2DM);
|
65 |
} |
66 |
|
67 |
/* (non-Javadoc)
|
68 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
69 |
*/
|
70 |
public Geometry cloneGeometry() {
|
71 |
MultiPoint2DM clone = new MultiPoint2DM();
|
72 |
return clonePrimitives(clone);
|
73 |
|
74 |
} |
75 |
|
76 |
/* (non-Javadoc)
|
77 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
78 |
*/
|
79 |
public int getDimension() { |
80 |
return 3; |
81 |
} |
82 |
|
83 |
/*
|
84 |
* (non-Javadoc)
|
85 |
*
|
86 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
87 |
*/
|
88 |
public GeneralPathX getGeneralPath() {
|
89 |
return new DefaultGeneralPathX(new PointIterator(null), false, 0); |
90 |
} |
91 |
|
92 |
/* (non-Javadoc)
|
93 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toPoints()
|
94 |
*/
|
95 |
public MultiPoint toPoints() throws GeometryException { |
96 |
return this; |
97 |
} |
98 |
|
99 |
/* (non-Javadoc)
|
100 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toLines()
|
101 |
*/
|
102 |
public MultiLine toLines() throws GeometryException { |
103 |
MultiLine multiLine = new MultiLine2DM();
|
104 |
Line line = new Line2DM(); |
105 |
line.ensureCapacity(primitives.size()); |
106 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
107 |
Point2DM point = (Point2DM) iterator.next(); |
108 |
line.addVertex(point); |
109 |
} |
110 |
multiLine.addPrimitive(line); |
111 |
return multiLine;
|
112 |
} |
113 |
|
114 |
/* (non-Javadoc)
|
115 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toPolygons()
|
116 |
*/
|
117 |
public MultiPolygon toPolygons() throws GeometryException { |
118 |
MultiPolygon multiPolygon = new MultiPolygon2DM();
|
119 |
Polygon polygon = new Polygon2DM(); |
120 |
polygon.ensureCapacity(primitives.size()); |
121 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
122 |
Point2DM point = (Point2DM) iterator.next(); |
123 |
polygon.addVertex(point); |
124 |
} |
125 |
multiPolygon.addPrimitive(polygon); |
126 |
return multiPolygon;
|
127 |
} |
128 |
|
129 |
|
130 |
/* (non-Javadoc)
|
131 |
* @see org.gvsig.fmap.geom.jts.aggregate.AbstractMultiPrimitive#fixPrimitive(org.gvsig.fmap.geom.primitive.Primitive)
|
132 |
*/
|
133 |
@Override
|
134 |
protected Geometry fixPrimitive(Primitive primitive) {
|
135 |
|
136 |
if(primitive instanceof Point2DM){ |
137 |
return primitive;
|
138 |
} |
139 |
|
140 |
if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM2DM){
|
141 |
try {
|
142 |
return primitive.toPoints();
|
143 |
} catch (GeometryException e) {
|
144 |
String message = "Can't convert primitive to lines"; |
145 |
logger.warn(message); |
146 |
throw new RuntimeException(message); |
147 |
} |
148 |
} |
149 |
|
150 |
String message = "Only 2DM primitives can be fixed to MultiPoint2DM"; |
151 |
notifyDeprecated(message); |
152 |
throw new UnsupportedOperationException(message); |
153 |
|
154 |
} |
155 |
} |