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 @ 42283
History | View | Annotate | Download (5.55 KB)
1 | 42269 | fdiaz | /* 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 | 42271 | fdiaz | import java.util.Iterator; |
29 | 42269 | fdiaz | |
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 | 42271 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2D; |
37 | import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2D; |
||
38 | import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2DM; |
||
39 | import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM; |
||
40 | 42269 | fdiaz | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
41 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
42 | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
||
43 | 42274 | fdiaz | import org.gvsig.fmap.geom.primitive.Line; |
44 | import org.gvsig.fmap.geom.primitive.Polygon; |
||
45 | 42271 | fdiaz | import org.gvsig.fmap.geom.primitive.Primitive; |
46 | 42269 | fdiaz | import org.gvsig.fmap.geom.primitive.Surface; |
47 | |||
48 | |||
49 | /**
|
||
50 | * @author fdiaz
|
||
51 | *
|
||
52 | */
|
||
53 | public class MultiPolygon2DM extends AbstractMultiPolygon { |
||
54 | |||
55 | |||
56 | /**
|
||
57 | *
|
||
58 | */
|
||
59 | private static final long serialVersionUID = 2724107572872777191L; |
||
60 | |||
61 | /**
|
||
62 | * @param subtype
|
||
63 | */
|
||
64 | public MultiPolygon2DM() {
|
||
65 | super(Geometry.SUBTYPES.GEOM2DM);
|
||
66 | } |
||
67 | |||
68 | /* (non-Javadoc)
|
||
69 | * @see org.gvsig.fmap.geom.aggregate.MultiPolygon#toPoints()
|
||
70 | */
|
||
71 | public MultiPoint toPoints() throws GeometryException { |
||
72 | 42271 | fdiaz | MultiPoint multiPoint = new MultiPoint2DM();
|
73 | for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
||
74 | Polygon2DM polygon = (Polygon2DM) 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 | 42269 | fdiaz | } |
83 | |||
84 | /* (non-Javadoc)
|
||
85 | * @see org.gvsig.fmap.geom.aggregate.MultiPolygon#toLines()
|
||
86 | */
|
||
87 | public MultiLine toLines() throws GeometryException { |
||
88 | 42271 | fdiaz | MultiLine multiLine = new MultiLine2D();
|
89 | for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
||
90 | Polygon2D polygon = (Polygon2D) 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((Line2D)lines.getPrimitiveAt(i));
|
||
95 | } |
||
96 | } |
||
97 | return multiLine;
|
||
98 | 42269 | fdiaz | } |
99 | |||
100 | /* (non-Javadoc)
|
||
101 | * @see org.gvsig.fmap.geom.aggregate.MultiPolygon#toPolygons()
|
||
102 | */
|
||
103 | public MultiPolygon toPolygons() throws GeometryException { |
||
104 | 42271 | fdiaz | return this; |
105 | 42269 | fdiaz | } |
106 | |||
107 | /* (non-Javadoc)
|
||
108 | * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
||
109 | */
|
||
110 | public Geometry cloneGeometry() {
|
||
111 | 42274 | fdiaz | MultiPolygon2DM clone = new MultiPolygon2DM();
|
112 | return clonePrimitives(clone);
|
||
113 | |||
114 | 42269 | fdiaz | } |
115 | |||
116 | /* (non-Javadoc)
|
||
117 | * @see org.gvsig.fmap.geom.Geometry#getDimension()
|
||
118 | */
|
||
119 | public int getDimension() { |
||
120 | 42274 | fdiaz | return 3; |
121 | 42269 | fdiaz | } |
122 | |||
123 | 42283 | fdiaz | // /* (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 | 42269 | fdiaz | |
139 | /* (non-Javadoc)
|
||
140 | 42271 | fdiaz | * @see org.gvsig.fmap.geom.jts.aggregate.AbstractMultiPrimitive#fixPrimitive(org.gvsig.fmap.geom.primitive.Primitive)
|
141 | */
|
||
142 | @Override
|
||
143 | 42283 | fdiaz | protected Geometry fixPrimitive(Primitive primitive) {
|
144 | if(primitive instanceof Polygon2DM){ |
||
145 | return primitive;
|
||
146 | 42271 | fdiaz | } |
147 | 42283 | fdiaz | |
148 | if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM2DM){
|
||
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 2DM primitives can be fixed to MultiPolygon2DM"; |
||
161 | notifyDeprecated(message); |
||
162 | throw new UnsupportedOperationException(message); |
||
163 | 42271 | fdiaz | } |
164 | 42269 | fdiaz | } |