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 / MultiPolygon3D.java @ 42283
History | View | Annotate | Download (5.56 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.awt.Shape; |
26 |
import java.awt.geom.AffineTransform; |
27 |
import java.awt.geom.PathIterator; |
28 |
import java.util.Iterator; |
29 |
|
30 |
import org.gvsig.fmap.geom.Geometry; |
31 |
import org.gvsig.fmap.geom.GeometryException; |
32 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
33 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
34 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
35 |
import org.gvsig.fmap.geom.handler.Handler; |
36 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2D; |
37 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D; |
38 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2D; |
39 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D; |
40 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM; |
41 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
42 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
43 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
44 |
import org.gvsig.fmap.geom.primitive.Line; |
45 |
import org.gvsig.fmap.geom.primitive.Polygon; |
46 |
import org.gvsig.fmap.geom.primitive.Primitive; |
47 |
import org.gvsig.fmap.geom.primitive.Surface; |
48 |
|
49 |
|
50 |
/**
|
51 |
* @author fdiaz
|
52 |
*
|
53 |
*/
|
54 |
public class MultiPolygon3D extends AbstractMultiPolygon { |
55 |
|
56 |
/**
|
57 |
*
|
58 |
*/
|
59 |
private static final long serialVersionUID = 8074904643192281026L; |
60 |
|
61 |
/**
|
62 |
* @param subtype
|
63 |
*/
|
64 |
public MultiPolygon3D() {
|
65 |
super(Geometry.SUBTYPES.GEOM3D);
|
66 |
} |
67 |
|
68 |
/* (non-Javadoc)
|
69 |
* @see org.gvsig.fmap.geom.aggregate.MultiPolygon#toPoints()
|
70 |
*/
|
71 |
public MultiPoint toPoints() throws GeometryException { |
72 |
MultiPoint multiPoint = new MultiPoint3D();
|
73 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
74 |
Polygon3D polygon = (Polygon3D) iterator.next(); |
75 |
MultiPoint points = polygon.toPoints(); |
76 |
multiPoint.ensureCapacity(multiPoint.getPrimitivesNumber()+points.getPrimitivesNumber()); |
77 |
for(int i=0; i<points.getPrimitivesNumber(); i++){ |
78 |
multiPoint.addPoint(points.getPointAt(i)); |
79 |
} |
80 |
} |
81 |
return multiPoint;
|
82 |
} |
83 |
|
84 |
/* (non-Javadoc)
|
85 |
* @see org.gvsig.fmap.geom.aggregate.MultiPolygon#toLines()
|
86 |
*/
|
87 |
public MultiLine toLines() throws GeometryException { |
88 |
MultiLine multiLine = new MultiLine3D();
|
89 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
90 |
Polygon3D polygon = (Polygon3D) iterator.next(); |
91 |
MultiLine lines = polygon.toLines(); |
92 |
multiLine.ensureCapacity(multiLine.getPrimitivesNumber()+lines.getPrimitivesNumber()); |
93 |
for(int i=0; i<lines.getPrimitivesNumber(); i++){ |
94 |
multiLine.addPrimitive((Line3D)lines.getPrimitiveAt(i)); |
95 |
} |
96 |
} |
97 |
return multiLine;
|
98 |
} |
99 |
|
100 |
/* (non-Javadoc)
|
101 |
* @see org.gvsig.fmap.geom.aggregate.MultiPolygon#toPolygons()
|
102 |
*/
|
103 |
public MultiPolygon toPolygons() throws GeometryException { |
104 |
return this; |
105 |
} |
106 |
|
107 |
/* (non-Javadoc)
|
108 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
109 |
*/
|
110 |
public Geometry cloneGeometry() {
|
111 |
MultiPolygon3D clone = new MultiPolygon3D();
|
112 |
return clonePrimitives(clone);
|
113 |
|
114 |
} |
115 |
|
116 |
/* (non-Javadoc)
|
117 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
118 |
*/
|
119 |
public int getDimension() { |
120 |
return 3; |
121 |
} |
122 |
|
123 |
/* (non-Javadoc)
|
124 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
|
125 |
*/
|
126 |
public Shape getShape(AffineTransform affineTransform) { |
127 |
// TODO Auto-generated method stub
|
128 |
return null; |
129 |
} |
130 |
|
131 |
/* (non-Javadoc)
|
132 |
* @see org.gvsig.fmap.geom.Geometry#getShape()
|
133 |
*/
|
134 |
public Shape getShape() { |
135 |
// TODO Auto-generated method stub
|
136 |
return null; |
137 |
} |
138 |
|
139 |
/* (non-Javadoc)
|
140 |
* @see org.gvsig.fmap.geom.jts.aggregate.AbstractMultiPrimitive#fixPrimitive(org.gvsig.fmap.geom.primitive.Primitive)
|
141 |
*/
|
142 |
@Override
|
143 |
protected Geometry fixPrimitive(Primitive primitive) {
|
144 |
if(primitive instanceof Polygon3D){ |
145 |
return primitive;
|
146 |
} |
147 |
|
148 |
if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM3D){
|
149 |
MultiPolygon polygons; |
150 |
try {
|
151 |
polygons = primitive.toPolygons(); |
152 |
} catch (GeometryException e) {
|
153 |
String message = "Can't convert primitive to polygons"; |
154 |
logger.warn(message); |
155 |
throw new RuntimeException(message); |
156 |
} |
157 |
return polygons;
|
158 |
} |
159 |
|
160 |
String message = "Only 3D primitives can be fixed to MultiPolygon3D"; |
161 |
notifyDeprecated(message); |
162 |
throw new UnsupportedOperationException(message); |
163 |
} |
164 |
} |