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