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