svn-gvsig-desktop / branches / org.gvsig.desktop-cvsgis1 / 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 / MultiPoint3DM.java @ 45267
History | View | Annotate | Download (5.39 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.Line3DM; |
34 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
35 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3DM; |
36 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM; |
37 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
38 |
import org.gvsig.fmap.geom.primitive.Line; |
39 |
import org.gvsig.fmap.geom.primitive.Point; |
40 |
import org.gvsig.fmap.geom.primitive.Polygon; |
41 |
import org.gvsig.fmap.geom.primitive.Primitive; |
42 |
|
43 |
|
44 |
/**
|
45 |
* @author fdiaz
|
46 |
*
|
47 |
*/
|
48 |
public class MultiPoint3DM extends AbstractMultiPoint { |
49 |
|
50 |
/**
|
51 |
*
|
52 |
*/
|
53 |
private static final long serialVersionUID = -2230359991187613190L; |
54 |
|
55 |
/**
|
56 |
* @param subtype
|
57 |
*/
|
58 |
public MultiPoint3DM() {
|
59 |
super(Geometry.SUBTYPES.GEOM3DM);
|
60 |
} |
61 |
|
62 |
/* (non-Javadoc)
|
63 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
64 |
*/
|
65 |
public Geometry cloneGeometry() {
|
66 |
MultiPoint3DM clone = new MultiPoint3DM();
|
67 |
return clonePrimitives(clone);
|
68 |
|
69 |
} |
70 |
|
71 |
/* (non-Javadoc)
|
72 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
73 |
*/
|
74 |
public int getDimension() { |
75 |
return 4; |
76 |
} |
77 |
|
78 |
/*
|
79 |
* (non-Javadoc)
|
80 |
*
|
81 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
82 |
*/
|
83 |
public GeneralPathX getGeneralPath() {
|
84 |
return new DefaultGeneralPathX(new PointIterator(null), false, 0); |
85 |
} |
86 |
|
87 |
/* (non-Javadoc)
|
88 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toPoints()
|
89 |
*/
|
90 |
public MultiPoint toPoints() throws GeometryException { |
91 |
return this; |
92 |
} |
93 |
|
94 |
/* (non-Javadoc)
|
95 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toLines()
|
96 |
*/
|
97 |
public MultiLine toLines() throws GeometryException { |
98 |
MultiLine multiLine = new MultiLine3DM();
|
99 |
Line line = new Line3DM(); |
100 |
line.ensureCapacity(primitives.size()); |
101 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
102 |
Point3DM point = (Point3DM) iterator.next(); |
103 |
line.addVertex(point); |
104 |
} |
105 |
multiLine.addPrimitive(line); |
106 |
return multiLine;
|
107 |
} |
108 |
|
109 |
/* (non-Javadoc)
|
110 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toPolygons()
|
111 |
*/
|
112 |
public MultiPolygon toPolygons() throws GeometryException { |
113 |
MultiPolygon multiPolygon = new MultiPolygon3DM();
|
114 |
Polygon polygon = new Polygon3DM(); |
115 |
polygon.ensureCapacity(primitives.size()); |
116 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
117 |
Point3DM point = (Point3DM) iterator.next(); |
118 |
polygon.addVertex(point); |
119 |
} |
120 |
multiPolygon.addPrimitive(polygon); |
121 |
return multiPolygon;
|
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 |
protected Geometry fixPrimitive(Primitive primitive) {
|
129 |
|
130 |
if(primitive instanceof Point3DM){ |
131 |
return primitive;
|
132 |
} |
133 |
|
134 |
if(primitive instanceof Point){ |
135 |
Point point = (Point)primitive; |
136 |
if(point instanceof Point3D){ |
137 |
return new Point3DM(point.getX(), point.getY(), ((Point3DM)point).getZ(), 0); |
138 |
} |
139 |
return new Point3DM(point.getX(), point.getY(), 0, 0); |
140 |
} |
141 |
|
142 |
if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM3DM){
|
143 |
try {
|
144 |
return primitive.toPoints();
|
145 |
} catch (GeometryException e) {
|
146 |
String message = "Can't convert primitive to points"; |
147 |
LOGGER.warn(message); |
148 |
throw new RuntimeException(message); |
149 |
} |
150 |
} |
151 |
|
152 |
String message = "Only 3DM primitives can be fixed to MultiPoint3DM"; |
153 |
notifyDeprecated(message); |
154 |
throw new UnsupportedOperationException(message); |
155 |
|
156 |
} |
157 |
|
158 |
protected Point fixPoint(Point point) { |
159 |
if (point instanceof Point3DM) { |
160 |
return point;
|
161 |
} else if (point instanceof Point3D) { |
162 |
return new Point3DM(point.getX(), point.getY(), ((Point3D)point).getZ(), 0); |
163 |
} else {
|
164 |
return new Point3DM(point.getX(), point.getY(), 0, 0); |
165 |
} |
166 |
} |
167 |
} |