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